commit 9b4c540f53b026c233142a05ac06480bb4fbe23b
parent 9a30c5fa556b914289513ddcc1f651fd2a76e6e3
Author: quantumish <freifeld.david@gmail.com>
Date: Sun, 9 Aug 2026 18:28:07 -0700
Somewhat improve UX of opening single comments or stories from URLs
Default to unfolding message if it's the only one. Display the story
title associated with a single comment thread (still no way to jump to
the story from the comment thread, though).
Diffstat:
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/retronews.py b/retronews.py
@@ -181,7 +181,7 @@ GROUP_TABS = [
class MessageFlags:
- def __init__(self, read = False, starred=False):
+ def __init__(self, read=False, starred=False):
self.read = False
self.starred = False
@@ -1000,12 +1000,12 @@ def hn_parse_search_hit(hit):
)
-def hn_parse_entry(entry, thread_id = "", parent = None):
+def hn_parse_entry(entry, thread_id="", parent=None, parent_title=""):
thread_id = thread_id or str(entry["id"])
my_title = html_unescape(entry["title"]) if entry["title"] else None
- parent_title = parent.title if parent else ""
+ parent_title = parent.title if parent else parent_title
parent_title = parent_title if parent_title.startswith("Re: ") else "Re: {}".format(parent_title)
body = "<p>{}</p>".format(entry['url']) if entry["url"] else ""
@@ -1067,7 +1067,13 @@ def hn_fetch_new_threads(page = 1):
def hn_fetch_thread(entry_id):
resp = fetch("http://hn.algolia.com/api/v1/items/{}".format(entry_id))
entry = json.loads(resp)
- return hn_parse_entry(entry)
+
+ parent_title = ""
+ if not entry["title"] and "story_id" in entry:
+ resp = fetch("http://hn.algolia.com/api/v1/items/{}".format(entry["story_id"]))
+ parent_title = json.loads(resp)["title"]
+
+ return hn_parse_entry(entry, parent_title=parent_title)
def datetime_from_iso(iso):
@@ -1368,7 +1374,7 @@ def app_show_links_screen(app):
else:
app_show_flash(app, "Opening " + url)
webbrowser.open(url)
-
+
# Refresh window in case a terminal browser was used
app.screen.clearok(True)
@@ -1577,7 +1583,7 @@ def app_init_colors(app):
app.monochrome = True
-def app_main(screen, db, group, ascii, monochrome):
+def app_main(screen, db, group, ascii, monochrome, default_open=False):
curses.curs_set(0)
app = AppState(screen=screen, db=db, group=group, ascii=ascii, monochrome=monochrome)
@@ -1585,6 +1591,9 @@ def app_main(screen, db, group, ascii, monochrome):
app_init_colors(app)
app_load_group(app, app.group)
+ if default_open and app.selected_message is not None:
+ app_open_thread(app, app.selected_message)
+
while True:
app_render(app)
app.flash = ""
@@ -1652,7 +1661,8 @@ if __name__ == "__main__":
ascii = args.ascii
monochrome = args.monochrome or "NO_COLOR" in os.environ
- ret = curses.wrapper(app_main, db=db, group=group, ascii=ascii, monochrome=monochrome)
+ ret = curses.wrapper(app_main, db=db, group=group, ascii=ascii,
+ monochrome=monochrome, default_open=(args.msg is not None))
except ExitException as e:
if e.message:
sys.stderr.write(e.message + "\n")