From 13fffd9fc18778ccefafa233000b7e41ffe6e0d7 Mon Sep 17 00:00:00 2001 From: Daniel Schwarz Date: Thu, 22 Dec 2022 13:40:22 -0500 Subject: [PATCH] Screen refresh after web browser invocation and exit --- toot/tui/app.py | 8 +++++++- toot/tui/overlays.py | 8 +++++++- toot/tui/timeline.py | 3 +++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/toot/tui/app.py b/toot/tui/app.py index 9f917ec..3ab44e7 100644 --- a/toot/tui/app.py +++ b/toot/tui/app.py @@ -210,6 +210,7 @@ class TUI(urwid.Frame): urwid.connect_signal(timeline, "links", _links) urwid.connect_signal(timeline, "zoom", _zoom) urwid.connect_signal(timeline, "translate", self.async_translate) + urwid.connect_signal(timeline, "clear-screen", self.loop.screen.clear) def build_timeline(self, name, statuses, local): def _close(*args): @@ -347,6 +348,9 @@ class TUI(urwid.Frame): title="Status source", ) + def _clear_screen(self, widget): + self.loop.screen.clear() + def show_links(self, status): links = parse_content_links(status.data["content"]) if status else [] post_attachments = status.data["media_attachments"] or [] @@ -355,8 +359,10 @@ class TUI(urwid.Frame): url = a["remote_url"] or a["url"] links.append((url, a["description"] if a["description"] else url)) if links: + sl_widget=StatusLinks(links) + urwid.connect_signal(sl_widget, "clear-screen", self._clear_screen) self.open_overlay( - widget=StatusLinks(links), + widget=sl_widget, title="Status links", options={"height": len(links) + 2}, ) diff --git a/toot/tui/overlays.py b/toot/tui/overlays.py index 9af13ce..1fa09da 100644 --- a/toot/tui/overlays.py +++ b/toot/tui/overlays.py @@ -30,17 +30,23 @@ class StatusZoom(urwid.ListBox): class StatusLinks(urwid.ListBox): """Shows status links.""" + signals = ["clear-screen"] def __init__(self, links): def widget(url, title): - return Button(title or url, on_press=lambda btn: webbrowser.open(url)) + return Button(title or url, on_press=lambda btn: self.browse(url)) walker = urwid.SimpleFocusListWalker( [widget(url, title) for url, title in links] ) super().__init__(walker) + def browse(self, url): + webbrowser.open(url) + # force a screen refresh; necessary with console browsers + self._emit("clear-screen") + class ExceptionStackTrace(urwid.ListBox): """Shows an exception stack trace.""" diff --git a/toot/tui/timeline.py b/toot/tui/timeline.py index 86d3e78..05c5f1f 100644 --- a/toot/tui/timeline.py +++ b/toot/tui/timeline.py @@ -33,6 +33,7 @@ class Timeline(urwid.Columns): "translate", # Translate status "save", # Save current timeline "zoom", # Open status in scrollable popup window + "clear-screen", # clear the screen (used internally) ] def __init__(self, name, statuses, can_translate, focus=0, is_thread=False): @@ -182,6 +183,8 @@ class Timeline(urwid.Columns): if key in ("v", "V"): if status.original.url: webbrowser.open(status.original.url) + # force a screen refresh; necessary with console browsers + self._emit("clear-screen") return if key in ("p", "P"):