From dfa3cf1b6868402960e71fb5d02b9d23420ae769 Mon Sep 17 00:00:00 2001 From: Dan Schwarz Date: Sun, 12 Mar 2023 22:00:05 -0400 Subject: [PATCH] Restructured Goto Menu items for clarity, added error display --- toot/tui/app.py | 2 +- toot/tui/overlays.py | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/toot/tui/app.py b/toot/tui/app.py index 937b7da..ded4809 100644 --- a/toot/tui/app.py +++ b/toot/tui/app.py @@ -472,7 +472,7 @@ class TUI(urwid.Frame): self.open_overlay(menu, title="Go to", options=dict( align="center", width=("relative", 60), - valign="middle", height=11 + len(user_timelines), + valign="middle", height=16 + len(user_timelines), )) def show_help(self): diff --git a/toot/tui/overlays.py b/toot/tui/overlays.py index 67b3c1e..58b902a 100644 --- a/toot/tui/overlays.py +++ b/toot/tui/overlays.py @@ -106,13 +106,14 @@ class GotoMenu(urwid.ListBox): def __init__(self, user_timelines): self.hash_edit = EditBox(caption="Hashtag: ") + self.message_widget = urwid.Text("") actions = list(self.generate_actions(user_timelines)) walker = urwid.SimpleFocusListWalker(actions) super().__init__(walker) def get_hashtag(self): - return self.hash_edit.edit_text.strip() + return self.hash_edit.edit_text.strip().lstrip("#") def generate_actions(self, user_timelines): def _home(button): @@ -134,11 +135,12 @@ class GotoMenu(urwid.ListBox): self._emit("conversation_timeline", False) def _hashtag(local): + self.message_widget.set_text("") hashtag = self.get_hashtag() if hashtag: self._emit("hashtag_timeline", hashtag, local) else: - self.set_focus(4) + self.message_widget.set_text(("warning", "Hashtag name required")) def mk_on_press_user_hashtag(tag, local): def on_press(btn): @@ -146,21 +148,28 @@ class GotoMenu(urwid.ListBox): return on_press yield Button("Home timeline", on_press=_home) - - for tag, cfg in user_timelines.items(): - is_local = cfg["local"] - yield Button("#{}".format(tag) + (" (local)" if is_local else ""), - on_press=mk_on_press_user_hashtag(tag, is_local)) - yield Button("Local public timeline", on_press=_local_public) yield Button("Global public timeline", on_press=_global_public) yield Button("Bookmarks", on_press=_bookmarks) yield Button("Notifications", on_press=_notifications) yield Button("Conversations", on_press=_conversations) + + if len(user_timelines): + yield urwid.Divider() + yield urwid.Text(("bold", "Shortcuts:")) + + # show all hashtag shortcuts + for tag, cfg in sorted(user_timelines.items()): + is_local = cfg["local"] + yield Button(f"#{tag}" + (" (local)" if is_local else ""), + on_press=mk_on_press_user_hashtag(tag, is_local)) + yield urwid.Divider() yield self.hash_edit yield Button("Local hashtag timeline", on_press=lambda x: _hashtag(True)) yield Button("Public hashtag timeline", on_press=lambda x: _hashtag(False)) + yield urwid.Divider() + yield self.message_widget class Help(urwid.Padding):