Skip to content

Commit

Permalink
Screen refresh after web browser invocation and exit
Browse files Browse the repository at this point in the history
  • Loading branch information
danschwarz authored and ihabunek committed Jan 1, 2023
1 parent 6633b75 commit 13fffd9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
8 changes: 7 additions & 1 deletion toot/tui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def _zoom(timeline, status_details):
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):
Expand Down Expand Up @@ -347,6 +348,9 @@ def show_status_source(self, status):
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 []
Expand All @@ -355,8 +359,10 @@ def show_links(self, status):
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},
)
Expand Down
8 changes: 7 additions & 1 deletion toot/tui/overlays.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,23 @@ def __init__(self, status_details):

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."""
Expand Down
3 changes: 3 additions & 0 deletions toot/tui/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -182,6 +183,8 @@ def keypress(self, size, key):
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"):
Expand Down

0 comments on commit 13fffd9

Please sign in to comment.