'm' command to view images is now surfaced in help and on the status
detail page. Also, an in-console image viewer "chafa" is now supported.
(Try it; it's surprisingly good, and supports pixel accurate image display
if you use kitty or xterm) https://github.com/hpjansson/chafa
diff --git a/toot/tui/app.py b/toot/tui/app.py
index f0fc425..49b3711 100644
--- a/toot/tui/app.py
+++ b/toot/tui/app.py
@@ -188,6 +188,7 @@ class TUI(urwid.Frame):
def _media(timeline, status):
self.show_media(status)
+ self.loop.screen.clear()
def _menu(timeline, status):
self.show_context_menu(status)
diff --git a/toot/tui/entities.py b/toot/tui/entities.py
index 3cf2122..e086387 100644
--- a/toot/tui/entities.py
+++ b/toot/tui/entities.py
@@ -55,6 +55,7 @@ class Status:
self.url = data.get("url")
self.mentions = data.get("mentions")
self.reblog = self._get_reblog()
+ self.has_media = data.get("media_attachments",False)
@property
def original(self):
diff --git a/toot/tui/overlays.py b/toot/tui/overlays.py
index d7301d3..d13b1f9 100644
--- a/toot/tui/overlays.py
+++ b/toot/tui/overlays.py
@@ -156,6 +156,7 @@ class Help(urwid.Padding):
yield urwid.Text(h(" [B] - Boost/unboost status"))
yield urwid.Text(h(" [C] - Compose new status"))
yield urwid.Text(h(" [F] - Favourite/unfavourite status"))
+ yield urwid.Text(h(" [M] - View media attachment"))
yield urwid.Text(h(" [R] - Reply to current status"))
yield urwid.Text(h(" [S] - Show text marked as sensitive"))
yield urwid.Text(h(" [T] - Show status thread (replies)"))
diff --git a/toot/tui/timeline.py b/toot/tui/timeline.py
index 8faafd4..f20dd33 100644
--- a/toot/tui/timeline.py
+++ b/toot/tui/timeline.py
@@ -301,6 +301,7 @@ class StatusDetails(urwid.Pile):
"[D]elete" if status.is_mine else "",
"[F]avourite",
"[V]iew",
+ "[M]edia" if status.has_media else "",
"[T]hread" if not self.in_thread else "",
"[L]inks",
"[R]eply",
diff --git a/toot/tui/utils.py b/toot/tui/utils.py
index a9ab122..9514dd8 100644
--- a/toot/tui/utils.py
+++ b/toot/tui/utils.py
@@ -70,7 +70,8 @@ def show_media(paths):
potential_viewers = [
"feh",
"eog",
- "display"
+ "display",
+ "chafa" # https://github.com/hpjansson/chafa
]
for v in potential_viewers:
viewer = shutil.which(v)
@@ -80,8 +81,18 @@ def show_media(paths):
if not viewer:
raise Exception("Cannot find an image viewer")
- subprocess.run([viewer] + paths)
-
+ if v == 'chafa': # this is a terminal-based image viewer so needs extra help
+ subprocess.run('clear')
+ for p in paths:
+ subprocess.run([viewer] + [p])
+ # it'd be nice to show the path p for each, but best to avoid
+ # shell injection vulnerabilities.
+ subprocess.run('''
+ read -p 'Press ENTER to continue.' -s; clear''',
+ shell=True,
+ executable='/bin/bash')
+ else:
+ subprocess.run([viewer] + paths)
class LinkParser(HTMLParser):
On Sun, 27 Nov 2022, at 04:25, Daniel Schwarz wrote:
> 'm' command to view images is now surfaced in help and on the status
> detail page. Also, an in-console image viewer "chafa" is now supported.
> (Try it; it's surprisingly good, and supports pixel accurate image display
> if you use kitty or xterm) https://github.com/hpjansson/chafa
Thanks, but I'd prefer to leave this until I've added user settings.
Regards,
-- Ivan