Skip to content

Commit

Permalink
Merge pull request #460 from danschwarz/roundrect
Browse files Browse the repository at this point in the history
Converted LineBoxes to RoundedLineBoxes that look nicer
  • Loading branch information
ihabunek authored Jan 10, 2024
2 parents fb36561 + 593c95e commit a34831a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
4 changes: 2 additions & 2 deletions toot/tui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .poll import Poll
from .timeline import Timeline
from .utils import get_max_toot_chars, parse_content_links, copy_to_clipboard
from .widgets import ModalBox
from .widgets import ModalBox, RoundedLineBox

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -769,7 +769,7 @@ def copy_status(self, status):
)

def open_overlay(self, widget, options={}, title=""):
top_widget = urwid.LineBox(widget, title=title)
top_widget = RoundedLineBox(widget, title=title)
bottom_widget = self.body

_options = self.default_overlay_options.copy()
Expand Down
4 changes: 2 additions & 2 deletions toot/tui/poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from toot import api
from toot.exceptions import ApiError
from toot.utils.datetime import parse_datetime
from .widgets import Button, CheckBox, RadioButton
from .widgets import Button, CheckBox, RadioButton, RoundedLineBox
from .richtext import html_to_widgets


Expand All @@ -27,7 +27,7 @@ def setup_listbox(self):
def build_linebox(self, contents):
contents = urwid.Pile(list(contents))
contents = urwid.Padding(contents, left=1, right=1)
return urwid.LineBox(contents)
return RoundedLineBox(contents)

def vote(self, button_widget):
poll = self.status.original.data.get("poll")
Expand Down
4 changes: 2 additions & 2 deletions toot/tui/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from toot.entities import Status
from toot.tui.scroll import Scrollable, ScrollBar
from toot.tui.utils import highlight_keys
from toot.tui.widgets import SelectableText, SelectableColumns
from toot.tui.widgets import SelectableText, SelectableColumns, RoundedLineBox

logger = logging.getLogger("toot")

Expand Down Expand Up @@ -415,7 +415,7 @@ def content_generator(self, status, reblogged_by):
def build_linebox(self, contents):
contents = urwid.Pile(list(contents))
contents = urwid.Padding(contents, left=1, right=1)
return urwid.LineBox(contents)
return RoundedLineBox(contents)

def card_generator(self, card):
yield urwid.Text(("card_title", card["title"].strip()))
Expand Down
30 changes: 30 additions & 0 deletions toot/tui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,33 @@ def __init__(self, message):
filler = urwid.Filler(text, valign='top', top=1, bottom=1)
padding = urwid.Padding(filler, left=1, right=1)
return super().__init__(padding)


class RoundedLineBox(urwid.LineBox):
"""LineBox that defaults to rounded corners."""
def __init__(self,
original_widget,
title="",
title_align="center",
title_attr=None,
tlcorner="\u256d",
tline="─",
lline="│",
trcorner="\u256e",
blcorner="\u2570",
rline="│",
bline="─",
brcorner="\u256f",
) -> None:
return super().__init__(original_widget,
title,
title_align,
title_attr,
tlcorner,
tline,
lline,
trcorner,
blcorner,
rline,
bline,
brcorner)

0 comments on commit a34831a

Please sign in to comment.