2019-08-24 09:20:31 +00:00
|
|
|
import logging
|
2023-01-29 08:23:57 +00:00
|
|
|
import sys
|
2019-08-24 09:20:31 +00:00
|
|
|
import urwid
|
2019-08-24 11:13:22 +00:00
|
|
|
import webbrowser
|
2019-08-24 09:20:31 +00:00
|
|
|
|
2023-01-19 08:53:38 +00:00
|
|
|
from typing import Optional
|
2019-08-24 10:53:55 +00:00
|
|
|
|
2023-01-19 08:53:38 +00:00
|
|
|
from .entities import Status
|
|
|
|
from .scroll import Scrollable, ScrollBar
|
2019-08-28 13:32:57 +00:00
|
|
|
from .utils import highlight_hashtags, parse_datetime, highlight_keys
|
2019-08-24 09:20:31 +00:00
|
|
|
from .widgets import SelectableText, SelectableColumns
|
2023-01-19 08:53:38 +00:00
|
|
|
from toot.utils import format_content
|
|
|
|
from toot.utils.language import language_name
|
2023-01-20 20:51:05 +00:00
|
|
|
from toot.tui.utils import time_ago
|
2019-08-24 09:20:31 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger("toot")
|
|
|
|
|
|
|
|
|
|
|
|
class Timeline(urwid.Columns):
|
|
|
|
"""
|
|
|
|
Displays a list of statuses to the left, and status details on the right.
|
|
|
|
"""
|
2019-08-24 10:53:55 +00:00
|
|
|
signals = [
|
2023-01-01 10:13:21 +00:00
|
|
|
"close", # Close thread
|
|
|
|
"compose", # Compose a new toot
|
|
|
|
"delete", # Delete own status
|
|
|
|
"favourite", # Favourite status
|
|
|
|
"focus", # Focus changed
|
|
|
|
"bookmark", # Bookmark status
|
|
|
|
"media", # Display media attachments
|
|
|
|
"menu", # Show a context menu
|
|
|
|
"next", # Fetch more statuses
|
|
|
|
"reblog", # Reblog status
|
|
|
|
"reply", # Compose a reply to a status
|
|
|
|
"source", # Show status source
|
|
|
|
"links", # Show status links
|
|
|
|
"thread", # Show thread for status
|
|
|
|
"translate", # Translate status
|
|
|
|
"save", # Save current timeline
|
|
|
|
"zoom", # Open status in scrollable popup window
|
|
|
|
"clear-screen", # Clear the screen (used internally)
|
2019-08-24 10:53:55 +00:00
|
|
|
]
|
2019-08-24 09:20:31 +00:00
|
|
|
|
2022-12-20 21:28:24 +00:00
|
|
|
def __init__(self, name, statuses, can_translate, followed_tags=[], focus=0, is_thread=False):
|
2019-08-28 13:32:57 +00:00
|
|
|
self.name = name
|
|
|
|
self.is_thread = is_thread
|
2019-08-24 09:20:31 +00:00
|
|
|
self.statuses = statuses
|
2022-12-08 00:57:56 +00:00
|
|
|
self.can_translate = can_translate
|
2019-08-28 13:32:57 +00:00
|
|
|
self.status_list = self.build_status_list(statuses, focus=focus)
|
2022-12-20 21:28:24 +00:00
|
|
|
self.followed_tags = followed_tags
|
2023-01-09 04:20:33 +00:00
|
|
|
|
2023-01-19 10:10:36 +00:00
|
|
|
try:
|
|
|
|
focused_status = statuses[focus]
|
2020-05-19 22:50:21 +00:00
|
|
|
except IndexError:
|
2023-01-19 10:10:36 +00:00
|
|
|
focused_status = None
|
|
|
|
|
|
|
|
self.status_details = StatusDetails(self, focused_status)
|
|
|
|
status_widget = self.wrap_status_details(self.status_details)
|
2019-08-24 09:20:31 +00:00
|
|
|
|
|
|
|
super().__init__([
|
2019-08-26 11:28:37 +00:00
|
|
|
("weight", 40, self.status_list),
|
2019-08-27 12:55:02 +00:00
|
|
|
("weight", 0, urwid.AttrWrap(urwid.SolidFill("│"), "blue_selected")),
|
2023-01-19 10:10:36 +00:00
|
|
|
("weight", 60, status_widget),
|
2019-08-30 10:28:03 +00:00
|
|
|
])
|
2019-08-24 09:20:31 +00:00
|
|
|
|
2023-01-19 10:10:36 +00:00
|
|
|
def wrap_status_details(self, status_details: "StatusDetails") -> urwid.Widget:
|
|
|
|
"""Wrap StatusDetails widget with a scollbar and footer."""
|
|
|
|
return urwid.Padding(
|
|
|
|
urwid.Frame(
|
|
|
|
body=ScrollBar(
|
|
|
|
Scrollable(urwid.Padding(status_details, right=1)),
|
|
|
|
thumb_char="\u2588",
|
|
|
|
trough_char="\u2591",
|
|
|
|
),
|
|
|
|
footer=self.get_option_text(status_details.status),
|
|
|
|
),
|
|
|
|
left=1
|
|
|
|
)
|
|
|
|
|
2019-08-28 13:32:57 +00:00
|
|
|
def build_status_list(self, statuses, focus):
|
2019-08-24 10:53:55 +00:00
|
|
|
items = [self.build_list_item(status) for status in statuses]
|
2019-08-24 09:20:31 +00:00
|
|
|
walker = urwid.SimpleFocusListWalker(items)
|
2019-08-28 13:32:57 +00:00
|
|
|
walker.set_focus(focus)
|
|
|
|
urwid.connect_signal(walker, "modified", self.modified)
|
2019-08-24 09:20:31 +00:00
|
|
|
return urwid.ListBox(walker)
|
|
|
|
|
2019-08-24 10:53:55 +00:00
|
|
|
def build_list_item(self, status):
|
|
|
|
item = StatusListItem(status)
|
2019-08-30 10:28:03 +00:00
|
|
|
urwid.connect_signal(item, "click", lambda *args:
|
|
|
|
self._emit("menu", status))
|
2019-08-24 10:53:55 +00:00
|
|
|
return urwid.AttrMap(item, None, focus_map={
|
|
|
|
"blue": "green_selected",
|
|
|
|
"green": "green_selected",
|
|
|
|
"yellow": "green_selected",
|
2019-08-31 13:24:03 +00:00
|
|
|
"cyan": "green_selected",
|
2022-12-27 10:39:50 +00:00
|
|
|
"red": "green_selected",
|
2019-08-24 10:53:55 +00:00
|
|
|
None: "green_selected",
|
|
|
|
})
|
|
|
|
|
2023-01-19 10:10:36 +00:00
|
|
|
def get_option_text(self, status: Optional[Status]) -> Optional[urwid.Text]:
|
|
|
|
if not status:
|
|
|
|
return None
|
|
|
|
|
2023-01-09 04:20:33 +00:00
|
|
|
options = [
|
|
|
|
"[B]oost",
|
|
|
|
"[D]elete" if status.is_mine else "",
|
|
|
|
"B[o]okmark",
|
|
|
|
"[F]avourite",
|
|
|
|
"[V]iew",
|
|
|
|
"[T]hread" if not self.is_thread else "",
|
|
|
|
"[L]inks",
|
|
|
|
"[R]eply",
|
|
|
|
"So[u]rce",
|
|
|
|
"[Z]oom",
|
|
|
|
"Tra[n]slate" if self.can_translate else "",
|
|
|
|
"[H]elp",
|
|
|
|
]
|
|
|
|
options = "\n" + " ".join(o for o in options if o)
|
|
|
|
options = highlight_keys(options, "white_bold", "cyan")
|
2023-01-19 10:10:36 +00:00
|
|
|
return urwid.Text(options)
|
2023-01-09 04:20:33 +00:00
|
|
|
|
2019-08-24 09:20:31 +00:00
|
|
|
def get_focused_status(self):
|
2020-05-19 22:50:21 +00:00
|
|
|
try:
|
|
|
|
return self.statuses[self.status_list.body.focus]
|
|
|
|
except TypeError:
|
|
|
|
return None
|
2019-08-24 09:20:31 +00:00
|
|
|
|
2019-08-28 13:32:57 +00:00
|
|
|
def get_focused_status_with_counts(self):
|
2019-08-29 08:43:56 +00:00
|
|
|
"""Returns a tuple of:
|
|
|
|
* focused status
|
|
|
|
* focused status' index in the status list
|
|
|
|
* length of the status list
|
|
|
|
"""
|
2019-08-28 13:32:57 +00:00
|
|
|
return (
|
|
|
|
self.get_focused_status(),
|
|
|
|
self.status_list.body.focus,
|
|
|
|
len(self.statuses),
|
|
|
|
)
|
|
|
|
|
|
|
|
def modified(self):
|
2019-08-24 09:20:31 +00:00
|
|
|
"""Called when the list focus switches to a new status"""
|
2019-08-28 13:32:57 +00:00
|
|
|
status, index, count = self.get_focused_status_with_counts()
|
2019-08-27 08:02:13 +00:00
|
|
|
self.draw_status_details(status)
|
2019-08-28 13:32:57 +00:00
|
|
|
self._emit("focus")
|
2019-08-24 09:20:31 +00:00
|
|
|
|
2019-08-28 13:32:57 +00:00
|
|
|
def refresh_status_details(self):
|
|
|
|
"""Redraws the details of the focused status."""
|
|
|
|
status = self.get_focused_status()
|
|
|
|
self.draw_status_details(status)
|
2019-08-24 09:20:31 +00:00
|
|
|
|
2019-08-27 08:02:13 +00:00
|
|
|
def draw_status_details(self, status):
|
2023-01-19 08:53:38 +00:00
|
|
|
self.status_details = StatusDetails(self, status)
|
2023-01-19 10:10:36 +00:00
|
|
|
widget = self.wrap_status_details(self.status_details)
|
|
|
|
self.contents[2] = widget, ("weight", 60, False)
|
2019-08-27 08:02:13 +00:00
|
|
|
|
2019-08-24 11:13:22 +00:00
|
|
|
def keypress(self, size, key):
|
2019-08-29 09:01:49 +00:00
|
|
|
status = self.get_focused_status()
|
2019-08-29 08:43:56 +00:00
|
|
|
command = self._command_map[key]
|
|
|
|
|
2020-05-19 22:50:21 +00:00
|
|
|
if not status:
|
|
|
|
return super().keypress(size, key)
|
|
|
|
|
2019-08-24 11:13:22 +00:00
|
|
|
# If down is pressed on last status in list emit a signal to load more.
|
|
|
|
# TODO: Consider pre-loading statuses earlier
|
2020-05-19 22:50:21 +00:00
|
|
|
if command in [urwid.CURSOR_DOWN, urwid.CURSOR_PAGE_DOWN] \
|
|
|
|
and self.status_list.body.focus:
|
2019-08-24 11:13:22 +00:00
|
|
|
index = self.status_list.body.focus + 1
|
|
|
|
count = len(self.statuses)
|
|
|
|
if index >= count:
|
|
|
|
self._emit("next")
|
|
|
|
|
2019-08-26 11:28:37 +00:00
|
|
|
if key in ("b", "B"):
|
2019-08-28 15:00:46 +00:00
|
|
|
self._emit("reblog", status)
|
2019-08-26 11:28:37 +00:00
|
|
|
return
|
|
|
|
|
2019-08-28 15:00:46 +00:00
|
|
|
if key in ("c", "C"):
|
|
|
|
self._emit("compose")
|
2019-08-27 08:02:13 +00:00
|
|
|
return
|
|
|
|
|
2019-09-04 14:16:16 +00:00
|
|
|
if key in ("d", "D"):
|
|
|
|
self._emit("delete", status)
|
|
|
|
return
|
|
|
|
|
2019-08-26 11:28:37 +00:00
|
|
|
if key in ("f", "F"):
|
2019-08-28 15:00:46 +00:00
|
|
|
self._emit("favourite", status)
|
2019-08-26 11:28:37 +00:00
|
|
|
return
|
|
|
|
|
2019-08-29 09:47:44 +00:00
|
|
|
if key in ("m", "M"):
|
|
|
|
self._emit("media", status)
|
|
|
|
return
|
|
|
|
|
2019-08-28 15:00:46 +00:00
|
|
|
if key in ("q", "Q"):
|
2019-08-28 13:32:57 +00:00
|
|
|
self._emit("close")
|
|
|
|
return
|
|
|
|
|
2019-09-06 13:12:18 +00:00
|
|
|
if key == "esc" and self.is_thread:
|
|
|
|
self._emit("close")
|
|
|
|
return
|
|
|
|
|
2019-08-29 09:01:49 +00:00
|
|
|
if key in ("r", "R"):
|
|
|
|
self._emit("reply", status)
|
|
|
|
return
|
|
|
|
|
2019-08-29 12:01:26 +00:00
|
|
|
if key in ("s", "S"):
|
2019-09-22 10:13:40 +00:00
|
|
|
status.original.show_sensitive = True
|
2019-08-29 12:01:26 +00:00
|
|
|
self.refresh_status_details()
|
|
|
|
return
|
|
|
|
|
2022-12-27 10:46:29 +00:00
|
|
|
if key in ("o", "O"):
|
2022-12-27 10:39:50 +00:00
|
|
|
self._emit("bookmark", status)
|
|
|
|
return
|
|
|
|
|
2020-01-26 10:13:45 +00:00
|
|
|
if key in ("l", "L"):
|
|
|
|
self._emit("links", status)
|
|
|
|
return
|
|
|
|
|
2022-12-08 00:57:56 +00:00
|
|
|
if key in ("n", "N"):
|
|
|
|
if self.can_translate:
|
|
|
|
self._emit("translate", status)
|
|
|
|
return
|
|
|
|
|
2019-08-28 15:00:46 +00:00
|
|
|
if key in ("t", "T"):
|
2019-08-28 13:32:57 +00:00
|
|
|
self._emit("thread", status)
|
|
|
|
return
|
|
|
|
|
2019-08-29 09:47:44 +00:00
|
|
|
if key in ("u", "U"):
|
|
|
|
self._emit("source", status)
|
|
|
|
return
|
|
|
|
|
2019-08-24 11:13:22 +00:00
|
|
|
if key in ("v", "V"):
|
2019-09-22 10:13:40 +00:00
|
|
|
if status.original.url:
|
|
|
|
webbrowser.open(status.original.url)
|
2022-12-22 18:40:22 +00:00
|
|
|
# force a screen refresh; necessary with console browsers
|
|
|
|
self._emit("clear-screen")
|
2019-08-29 08:43:56 +00:00
|
|
|
return
|
2019-08-24 11:13:22 +00:00
|
|
|
|
2020-01-26 20:29:08 +00:00
|
|
|
if key in ("p", "P"):
|
|
|
|
self._emit("save", status)
|
|
|
|
return
|
|
|
|
|
2021-10-09 23:29:46 +00:00
|
|
|
if key in ("z", "Z"):
|
|
|
|
self._emit("zoom", self.status_details)
|
|
|
|
return
|
|
|
|
|
2019-08-24 11:13:22 +00:00
|
|
|
return super().keypress(size, key)
|
|
|
|
|
2019-08-27 10:57:18 +00:00
|
|
|
def append_status(self, status):
|
2019-08-26 11:28:37 +00:00
|
|
|
self.statuses.append(status)
|
|
|
|
self.status_list.body.append(self.build_list_item(status))
|
|
|
|
|
2019-08-27 08:02:13 +00:00
|
|
|
def prepend_status(self, status):
|
|
|
|
self.statuses.insert(0, status)
|
|
|
|
self.status_list.body.insert(0, self.build_list_item(status))
|
|
|
|
|
2019-08-27 10:57:18 +00:00
|
|
|
def append_statuses(self, statuses):
|
2019-08-26 11:28:37 +00:00
|
|
|
for status in statuses:
|
2019-08-27 10:57:18 +00:00
|
|
|
self.append_status(status)
|
|
|
|
|
|
|
|
def get_status_index(self, id):
|
|
|
|
# TODO: This is suboptimal, consider a better way
|
|
|
|
for n, status in enumerate(self.statuses):
|
|
|
|
if status.id == id:
|
|
|
|
return n
|
|
|
|
raise ValueError("Status with ID {} not found".format(id))
|
2019-08-26 11:28:37 +00:00
|
|
|
|
2019-08-28 15:04:45 +00:00
|
|
|
def focus_status(self, status):
|
|
|
|
index = self.get_status_index(status.id)
|
|
|
|
self.status_list.body.set_focus(index)
|
|
|
|
|
2019-08-26 11:28:37 +00:00
|
|
|
def update_status(self, status):
|
|
|
|
"""Overwrite status in list with the new instance and redraw."""
|
2019-08-27 10:57:18 +00:00
|
|
|
index = self.get_status_index(status.id)
|
|
|
|
assert self.statuses[index].id == status.id # Sanity check
|
2019-08-26 11:28:37 +00:00
|
|
|
|
|
|
|
# Update internal status list
|
|
|
|
self.statuses[index] = status
|
|
|
|
|
|
|
|
# Redraw list item
|
|
|
|
self.status_list.body[index] = self.build_list_item(status)
|
2019-08-24 11:13:22 +00:00
|
|
|
|
2019-08-26 11:28:37 +00:00
|
|
|
# Redraw status details if status is focused
|
|
|
|
if index == self.status_list.body.focus:
|
2019-08-27 08:02:13 +00:00
|
|
|
self.draw_status_details(status)
|
|
|
|
|
2019-09-04 14:16:16 +00:00
|
|
|
def remove_status(self, status):
|
|
|
|
index = self.get_status_index(status.id)
|
|
|
|
assert self.statuses[index].id == status.id # Sanity check
|
|
|
|
|
2022-12-27 11:31:55 +00:00
|
|
|
del self.statuses[index]
|
|
|
|
del self.status_list.body[index]
|
2019-09-04 14:16:16 +00:00
|
|
|
self.refresh_status_details()
|
|
|
|
|
2019-08-24 09:20:31 +00:00
|
|
|
|
|
|
|
class StatusDetails(urwid.Pile):
|
2023-01-19 08:53:38 +00:00
|
|
|
def __init__(self, timeline: Timeline, status: Optional[Status]):
|
2023-01-19 10:10:36 +00:00
|
|
|
self.status = status
|
2023-01-19 08:53:38 +00:00
|
|
|
self.followed_tags = timeline.followed_tags
|
2023-01-19 10:10:36 +00:00
|
|
|
|
2020-05-19 22:50:21 +00:00
|
|
|
reblogged_by = status.author if status and status.reblog else None
|
|
|
|
widget_list = list(self.content_generator(status.original, reblogged_by)
|
|
|
|
if status else ())
|
2019-08-24 10:53:55 +00:00
|
|
|
return super().__init__(widget_list)
|
|
|
|
|
2019-09-22 10:13:40 +00:00
|
|
|
def content_generator(self, status, reblogged_by):
|
|
|
|
if reblogged_by:
|
2019-10-01 07:27:27 +00:00
|
|
|
text = "♺ {} boosted".format(reblogged_by.display_name or reblogged_by.username)
|
2019-09-22 10:13:40 +00:00
|
|
|
yield ("pack", urwid.Text(("gray", text)))
|
2019-08-25 15:58:46 +00:00
|
|
|
yield ("pack", urwid.AttrMap(urwid.Divider("-"), "gray"))
|
2019-08-24 11:43:41 +00:00
|
|
|
|
|
|
|
if status.author.display_name:
|
2019-08-25 15:58:46 +00:00
|
|
|
yield ("pack", urwid.Text(("green", status.author.display_name)))
|
2019-08-25 08:00:48 +00:00
|
|
|
|
2019-08-25 15:58:46 +00:00
|
|
|
yield ("pack", urwid.Text(("yellow", status.author.account)))
|
|
|
|
yield ("pack", urwid.Divider())
|
2019-08-24 10:53:55 +00:00
|
|
|
|
2019-08-29 12:01:26 +00:00
|
|
|
if status.data["spoiler_text"]:
|
|
|
|
yield ("pack", urwid.Text(status.data["spoiler_text"]))
|
|
|
|
yield ("pack", urwid.Divider())
|
|
|
|
|
|
|
|
# Show content warning
|
|
|
|
if status.data["spoiler_text"] and not status.show_sensitive:
|
|
|
|
yield ("pack", urwid.Text(("content_warning", "Marked as sensitive. Press S to view.")))
|
|
|
|
else:
|
2022-12-11 21:51:32 +00:00
|
|
|
content = status.translation if status.show_translation else status.data["content"]
|
|
|
|
for line in format_content(content):
|
2022-12-20 21:28:24 +00:00
|
|
|
yield ("pack", urwid.Text(highlight_hashtags(line, self.followed_tags)))
|
2019-08-24 09:20:31 +00:00
|
|
|
|
2022-12-27 09:53:58 +00:00
|
|
|
media = status.data["media_attachments"]
|
|
|
|
if media:
|
|
|
|
for m in media:
|
|
|
|
yield ("pack", urwid.AttrMap(urwid.Divider("-"), "gray"))
|
|
|
|
yield ("pack", urwid.Text([("bold", "Media attachment"), " (", m["type"], ")"]))
|
|
|
|
if m["description"]:
|
|
|
|
yield ("pack", urwid.Text(m["description"]))
|
|
|
|
yield ("pack", urwid.Text(("link", m["url"])))
|
|
|
|
|
|
|
|
poll = status.data.get("poll")
|
|
|
|
if poll:
|
|
|
|
yield ("pack", urwid.Divider())
|
|
|
|
yield ("pack", self.build_linebox(self.poll_generator(poll)))
|
|
|
|
|
|
|
|
card = status.data.get("card")
|
|
|
|
if card:
|
|
|
|
yield ("pack", urwid.Divider())
|
|
|
|
yield ("pack", self.build_linebox(self.card_generator(card)))
|
2019-08-25 15:58:46 +00:00
|
|
|
|
2019-08-31 13:05:50 +00:00
|
|
|
application = status.data.get("application") or {}
|
|
|
|
application = application.get("name")
|
|
|
|
|
2019-08-27 13:08:40 +00:00
|
|
|
yield ("pack", urwid.AttrWrap(urwid.Divider("-"), "gray"))
|
2022-12-08 00:57:56 +00:00
|
|
|
|
2022-12-11 22:26:15 +00:00
|
|
|
translated_from = (
|
|
|
|
language_name(status.translated_from)
|
|
|
|
if status.show_translation and status.translated_from
|
|
|
|
else None
|
|
|
|
)
|
2022-12-08 00:57:56 +00:00
|
|
|
|
2022-12-21 23:30:29 +00:00
|
|
|
visibility_colors = {
|
|
|
|
"public": "gray",
|
|
|
|
"unlisted": "white",
|
|
|
|
"private": "cyan",
|
|
|
|
"direct": "yellow"
|
|
|
|
}
|
|
|
|
|
2022-12-28 06:48:53 +00:00
|
|
|
visibility = status.visibility.title()
|
|
|
|
visibility_color = visibility_colors.get(status.visibility, "gray")
|
|
|
|
|
2019-08-27 13:08:40 +00:00
|
|
|
yield ("pack", urwid.Text([
|
2023-01-20 20:51:05 +00:00
|
|
|
("blue", f"{status.created_at.strftime('%Y-%m-%d %H:%M')} "),
|
|
|
|
("red" if status.bookmarked else "gray", "🠷 "),
|
2022-12-11 22:26:15 +00:00
|
|
|
("gray", f"⤶ {status.data['replies_count']} "),
|
|
|
|
("yellow" if status.reblogged else "gray", f"♺ {status.data['reblogs_count']} "),
|
|
|
|
("yellow" if status.favourited else "gray", f"★ {status.data['favourites_count']}"),
|
2022-12-28 06:48:53 +00:00
|
|
|
(visibility_color, f" · {visibility}"),
|
2023-01-20 20:51:05 +00:00
|
|
|
("yellow", f" · Translated from {translated_from} " if translated_from else ""),
|
2022-12-11 22:26:15 +00:00
|
|
|
("gray", f" · {application}" if application else ""),
|
2019-08-27 13:08:40 +00:00
|
|
|
]))
|
|
|
|
|
2019-08-25 15:58:46 +00:00
|
|
|
# Push things to bottom
|
2023-01-09 04:20:33 +00:00
|
|
|
yield ("weight", 1, urwid.BoxAdapter(urwid.SolidFill(" "), 1))
|
2019-08-24 10:53:55 +00:00
|
|
|
|
2019-08-27 12:59:06 +00:00
|
|
|
def build_linebox(self, contents):
|
|
|
|
contents = urwid.Pile(list(contents))
|
|
|
|
contents = urwid.Padding(contents, left=1, right=1)
|
|
|
|
return urwid.LineBox(contents)
|
|
|
|
|
2019-08-24 10:53:55 +00:00
|
|
|
def card_generator(self, card):
|
|
|
|
yield urwid.Text(("green", card["title"].strip()))
|
2019-09-07 18:48:11 +00:00
|
|
|
if card.get("author_name"):
|
2019-08-24 10:53:55 +00:00
|
|
|
yield urwid.Text(["by ", ("yellow", card["author_name"].strip())])
|
2019-08-24 12:14:46 +00:00
|
|
|
yield urwid.Text("")
|
|
|
|
if card["description"]:
|
|
|
|
yield urwid.Text(card["description"].strip())
|
|
|
|
yield urwid.Text("")
|
2019-08-24 10:53:55 +00:00
|
|
|
yield urwid.Text(("link", card["url"]))
|
|
|
|
|
2019-08-27 12:34:51 +00:00
|
|
|
def poll_generator(self, poll):
|
2022-11-28 02:27:02 +00:00
|
|
|
for idx, option in enumerate(poll["options"]):
|
2019-08-27 12:34:51 +00:00
|
|
|
perc = (round(100 * option["votes_count"] / poll["votes_count"])
|
|
|
|
if poll["votes_count"] else 0)
|
2022-11-28 02:27:02 +00:00
|
|
|
|
|
|
|
if poll["voted"] and poll["own_votes"] and idx in poll["own_votes"]:
|
|
|
|
voted_for = " ✓"
|
|
|
|
else:
|
|
|
|
voted_for = ""
|
|
|
|
|
|
|
|
yield urwid.Text(option["title"] + voted_for)
|
2019-08-31 13:06:17 +00:00
|
|
|
yield urwid.ProgressBar("", "poll_bar", perc)
|
2019-08-27 12:34:51 +00:00
|
|
|
|
2022-11-12 06:55:25 +00:00
|
|
|
status = "Poll · {} votes".format(poll["votes_count"])
|
|
|
|
|
2019-08-27 12:34:51 +00:00
|
|
|
if poll["expired"]:
|
2022-11-12 06:55:25 +00:00
|
|
|
status += " · Closed"
|
|
|
|
|
|
|
|
if poll["expires_at"]:
|
2019-08-27 12:34:51 +00:00
|
|
|
expires_at = parse_datetime(poll["expires_at"]).strftime("%Y-%m-%d %H:%M")
|
2022-11-12 06:55:25 +00:00
|
|
|
status += " · Closes on {}".format(expires_at)
|
2019-08-27 12:34:51 +00:00
|
|
|
|
|
|
|
yield urwid.Text(("gray", status))
|
|
|
|
|
2019-08-24 09:20:31 +00:00
|
|
|
|
|
|
|
class StatusListItem(SelectableColumns):
|
2019-08-24 10:53:55 +00:00
|
|
|
def __init__(self, status):
|
2023-01-20 20:51:05 +00:00
|
|
|
edited = status.data["edited_at"]
|
2023-01-29 08:23:57 +00:00
|
|
|
|
|
|
|
# TODO: hacky implementation to avoid creating conflicts for existing
|
|
|
|
# pull reuqests, refactor when merged.
|
|
|
|
created_at = (
|
|
|
|
time_ago(status.created_at).ljust(3, " ")
|
|
|
|
if "--relative-datetimes" in sys.argv
|
|
|
|
else status.created_at.strftime("%Y-%m-%d %H:%M")
|
|
|
|
)
|
|
|
|
|
2023-01-20 20:51:05 +00:00
|
|
|
edited_flag = "*" if edited else " "
|
2019-09-22 10:13:40 +00:00
|
|
|
favourited = ("yellow", "★") if status.original.favourited else " "
|
|
|
|
reblogged = ("yellow", "♺") if status.original.reblogged else " "
|
2019-09-09 08:43:13 +00:00
|
|
|
is_reblog = ("cyan", "♺") if status.reblog else " "
|
2019-09-22 10:13:40 +00:00
|
|
|
is_reply = ("cyan", "⤶") if status.original.in_reply_to else " "
|
2019-08-24 09:20:31 +00:00
|
|
|
|
|
|
|
return super().__init__([
|
|
|
|
("pack", SelectableText(("blue", created_at), wrap="clip")),
|
2023-01-20 20:51:05 +00:00
|
|
|
("pack", urwid.Text(("blue", edited_flag))),
|
2019-08-24 09:20:31 +00:00
|
|
|
("pack", urwid.Text(" ")),
|
|
|
|
("pack", urwid.Text(favourited)),
|
2019-08-24 10:53:55 +00:00
|
|
|
("pack", urwid.Text(" ")),
|
2019-08-24 09:20:31 +00:00
|
|
|
("pack", urwid.Text(reblogged)),
|
2019-08-27 12:55:02 +00:00
|
|
|
("pack", urwid.Text(" ")),
|
2019-09-22 10:13:40 +00:00
|
|
|
urwid.Text(("green", status.original.account), wrap="clip"),
|
2019-08-31 13:24:03 +00:00
|
|
|
("pack", urwid.Text(is_reply)),
|
2019-09-09 08:43:13 +00:00
|
|
|
("pack", urwid.Text(is_reblog)),
|
2019-08-31 13:24:03 +00:00
|
|
|
("pack", urwid.Text(" ")),
|
2019-08-24 09:20:31 +00:00
|
|
|
])
|