kopia lustrzana https://github.com/ihabunek/toot
Add a [P]in action to save a hashtag timeline
This goes along with the ability to "go to" a saved hashtag timeline. We need to pass the "local" flag down build_timeline() method so that this is also saved. Note that we cannot save both a local and a federated timeline for the same hashtag: I'm not sure it's worth supporting both options?pull/171/head
rodzic
949b5552ca
commit
3e11153640
|
@ -203,7 +203,7 @@ class TUI(urwid.Frame):
|
||||||
urwid.connect_signal(timeline, "source", _source)
|
urwid.connect_signal(timeline, "source", _source)
|
||||||
urwid.connect_signal(timeline, "links", _links)
|
urwid.connect_signal(timeline, "links", _links)
|
||||||
|
|
||||||
def build_timeline(self, name, statuses):
|
def build_timeline(self, name, statuses, local):
|
||||||
def _close(*args):
|
def _close(*args):
|
||||||
raise urwid.ExitMainLoop()
|
raise urwid.ExitMainLoop()
|
||||||
|
|
||||||
|
@ -213,12 +213,21 @@ class TUI(urwid.Frame):
|
||||||
def _thread(timeline, status):
|
def _thread(timeline, status):
|
||||||
self.show_thread(status)
|
self.show_thread(status)
|
||||||
|
|
||||||
|
def _save(timeline, status):
|
||||||
|
if not timeline.name.startswith("#"):
|
||||||
|
return
|
||||||
|
hashtag = timeline.name[1:]
|
||||||
|
assert isinstance(local, bool), local
|
||||||
|
self.config.setdefault("timelines", {})[hashtag] = {"local": local}
|
||||||
|
config.save_config(self.config)
|
||||||
|
|
||||||
timeline = Timeline(name, statuses)
|
timeline = Timeline(name, statuses)
|
||||||
|
|
||||||
self.connect_default_timeline_signals(timeline)
|
self.connect_default_timeline_signals(timeline)
|
||||||
urwid.connect_signal(timeline, "next", _next)
|
urwid.connect_signal(timeline, "next", _next)
|
||||||
urwid.connect_signal(timeline, "close", _close)
|
urwid.connect_signal(timeline, "close", _close)
|
||||||
urwid.connect_signal(timeline, "thread", _thread)
|
urwid.connect_signal(timeline, "thread", _thread)
|
||||||
|
urwid.connect_signal(timeline, "save", _save)
|
||||||
|
|
||||||
return timeline
|
return timeline
|
||||||
|
|
||||||
|
@ -249,7 +258,7 @@ class TUI(urwid.Frame):
|
||||||
self.body = timeline
|
self.body = timeline
|
||||||
self.refresh_footer(timeline)
|
self.refresh_footer(timeline)
|
||||||
|
|
||||||
def async_load_timeline(self, is_initial, timeline_name=None):
|
def async_load_timeline(self, is_initial, timeline_name=None, local=None):
|
||||||
"""Asynchronously load a list of statuses."""
|
"""Asynchronously load a list of statuses."""
|
||||||
|
|
||||||
def _load_statuses():
|
def _load_statuses():
|
||||||
|
@ -265,7 +274,7 @@ class TUI(urwid.Frame):
|
||||||
|
|
||||||
def _done_initial(statuses):
|
def _done_initial(statuses):
|
||||||
"""Process initial batch of statuses, construct a Timeline."""
|
"""Process initial batch of statuses, construct a Timeline."""
|
||||||
self.timeline = self.build_timeline(timeline_name, statuses)
|
self.timeline = self.build_timeline(timeline_name, statuses, local)
|
||||||
self.timeline.refresh_status_details() # Draw first status
|
self.timeline.refresh_status_details() # Draw first status
|
||||||
self.refresh_footer(self.timeline)
|
self.refresh_footer(self.timeline)
|
||||||
self.body = self.timeline
|
self.body = self.timeline
|
||||||
|
@ -367,7 +376,9 @@ class TUI(urwid.Frame):
|
||||||
def goto_tag_timeline(self, tag, local):
|
def goto_tag_timeline(self, tag, local):
|
||||||
self.timeline_generator = api.tag_timeline_generator(
|
self.timeline_generator = api.tag_timeline_generator(
|
||||||
self.app, self.user, tag, local=local, limit=40)
|
self.app, self.user, tag, local=local, limit=40)
|
||||||
promise = self.async_load_timeline(is_initial=True, timeline_name="#{}".format(tag))
|
promise = self.async_load_timeline(
|
||||||
|
is_initial=True, timeline_name="#{}".format(tag), local=local,
|
||||||
|
)
|
||||||
promise.add_done_callback(lambda *args: self.close_overlay())
|
promise.add_done_callback(lambda *args: self.close_overlay())
|
||||||
|
|
||||||
def show_media(self, status):
|
def show_media(self, status):
|
||||||
|
|
|
@ -145,6 +145,7 @@ class Help(urwid.Padding):
|
||||||
yield urwid.Divider()
|
yield urwid.Divider()
|
||||||
yield urwid.Text(h(" [Q] - quit toot"))
|
yield urwid.Text(h(" [Q] - quit toot"))
|
||||||
yield urwid.Text(h(" [G] - go to - switch timelines"))
|
yield urwid.Text(h(" [G] - go to - switch timelines"))
|
||||||
|
yield urwid.Text(h(" [P] - save (pin) current timeline"))
|
||||||
yield urwid.Text(h(" [H] - show this help"))
|
yield urwid.Text(h(" [H] - show this help"))
|
||||||
yield urwid.Divider()
|
yield urwid.Divider()
|
||||||
yield urwid.Text(("bold", "Status keys"))
|
yield urwid.Text(("bold", "Status keys"))
|
||||||
|
|
|
@ -28,6 +28,7 @@ class Timeline(urwid.Columns):
|
||||||
"source", # Show status source
|
"source", # Show status source
|
||||||
"links", # Show status links
|
"links", # Show status links
|
||||||
"thread", # Show thread for status
|
"thread", # Show thread for status
|
||||||
|
"save", # Save current timeline
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, name, statuses, focus=0, is_thread=False):
|
def __init__(self, name, statuses, focus=0, is_thread=False):
|
||||||
|
@ -158,6 +159,10 @@ class Timeline(urwid.Columns):
|
||||||
webbrowser.open(status.original.url)
|
webbrowser.open(status.original.url)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if key in ("p", "P"):
|
||||||
|
self._emit("save", status)
|
||||||
|
return
|
||||||
|
|
||||||
return super().keypress(size, key)
|
return super().keypress(size, key)
|
||||||
|
|
||||||
def append_status(self, status):
|
def append_status(self, status):
|
||||||
|
|
Ładowanie…
Reference in New Issue