Add option to display relative datetimes

This commit is contained in:
Ivan Habunek 2023-01-29 09:23:57 +01:00
parent deebdf7141
commit f3b90c947e
No known key found for this signature in database
GPG Key ID: F5F0623FF5EBCB3D
4 changed files with 22 additions and 6 deletions

View File

@ -417,4 +417,4 @@ def notifications(app, user, args):
def tui(app, user, args): def tui(app, user, args):
from .tui.app import TUI from .tui.app import TUI
TUI.create(app, user).run() TUI.create(app, user, args).run()

View File

@ -254,7 +254,13 @@ TUI_COMMANDS = [
Command( Command(
name="tui", name="tui",
description="Launches the toot terminal user interface", description="Launches the toot terminal user interface",
arguments=[], arguments=[
(["--relative-datetimes"], {
"action": "store_true",
"default": False,
"help": "Show relative datetimes in status list.",
}),
],
require_auth=True, require_auth=True,
), ),
] ]

View File

@ -73,10 +73,10 @@ class TUI(urwid.Frame):
"""Main TUI frame.""" """Main TUI frame."""
@classmethod @classmethod
def create(cls, app, user): def create(cls, app, user, args):
"""Factory method, sets up TUI and an event loop.""" """Factory method, sets up TUI and an event loop."""
tui = cls(app, user) tui = cls(app, user, args)
loop = urwid.MainLoop( loop = urwid.MainLoop(
tui, tui,
palette=PALETTE, palette=PALETTE,
@ -87,9 +87,10 @@ class TUI(urwid.Frame):
return tui return tui
def __init__(self, app, user): def __init__(self, app, user, args):
self.app = app self.app = app
self.user = user self.user = user
self.args = args
self.config = config.load_config() self.config = config.load_config()
self.loop = None # set in `create` self.loop = None # set in `create`

View File

@ -1,4 +1,5 @@
import logging import logging
import sys
import urwid import urwid
import webbrowser import webbrowser
@ -421,7 +422,15 @@ class StatusDetails(urwid.Pile):
class StatusListItem(SelectableColumns): class StatusListItem(SelectableColumns):
def __init__(self, status): def __init__(self, status):
edited = status.data["edited_at"] edited = status.data["edited_at"]
created_at = time_ago(status.created_at).ljust(3, " ")
# 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")
)
edited_flag = "*" if edited else " " edited_flag = "*" if edited else " "
favourited = ("yellow", "") if status.original.favourited else " " favourited = ("yellow", "") if status.original.favourited else " "
reblogged = ("yellow", "") if status.original.reblogged else " " reblogged = ("yellow", "") if status.original.reblogged else " "