Skip to content

Commit

Permalink
refactor: Change menu entry wrap to "ellipsis"
Browse files Browse the repository at this point in the history
- Change: Set text wrap mode for all `MenuEntry` instances to
  "ellipsis".
- Change: The `MenuEntry` constructor now accepts only the entry name.
- Change: Extend the menu body instead of first concatenating lists
  before copying, in `.tui.main.update_menu()`.
  • Loading branch information
AnonymouX47 committed Apr 13, 2023
1 parent 4339777 commit f790806
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/termvisage/tui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,7 @@ def scan_dir_menu() -> None:
if result == IMAGE:
items.append(item)
menu_body.append(
urwid.AttrMap(
MenuEntry(item[0], "left", "clip"),
"default",
"focused entry",
)
urwid.AttrMap(MenuEntry(item[0]), "default", "focused entry")
)
if page_not_complete:
if len(items) <= menu._ti_height:
Expand All @@ -547,11 +543,7 @@ def scan_dir_menu() -> None:
elif result == DIR:
items.append(item)
menu_body.append(
urwid.AttrMap(
MenuEntry(item[0] + "/", "left", "clip"),
"default",
"focused entry",
)
urwid.AttrMap(MenuEntry(item[0] + "/"), "default", "focused entry")
)
if page_not_complete:
if len(items) <= menu._ti_height:
Expand Down Expand Up @@ -628,12 +620,11 @@ def update_menu(
urwid.Text(("inactive", ".."))
if top_level
else urwid.AttrMap(MenuEntry(".."), "default", "focused entry")
] + [
]
menu.body += [
urwid.AttrMap(
MenuEntry(
(basename(entry) if at_top_level else entry) + "/" * (value is ...),
"left",
"clip",
(basename(entry) if at_top_level else entry) + "/" * (value is ...)
),
"default",
"focused entry",
Expand Down
3 changes: 3 additions & 0 deletions src/termvisage/tui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,9 @@ def rows(self, size: Tuple[int, int], focus: bool = False) -> int:
class MenuEntry(urwid.Text):
_selectable = True

def __init__(self, name: str) -> None:
super().__init__(name, "left", "ellipsis")

def keypress(self, size: Tuple[int, int], key: str) -> str:
return key

Expand Down

0 comments on commit f790806

Please sign in to comment.