Skip to content

Commit

Permalink
Add option to display relative datetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
ihabunek committed Jan 29, 2023
1 parent deebdf7 commit f3b90c9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion toot/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,4 +417,4 @@ def notifications(app, user, args):

def tui(app, user, args):
from .tui.app import TUI
TUI.create(app, user).run()
TUI.create(app, user, args).run()
8 changes: 7 additions & 1 deletion toot/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,13 @@ def editor(value):
Command(
name="tui",
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,
),
]
Expand Down
7 changes: 4 additions & 3 deletions toot/tui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ class TUI(urwid.Frame):
"""Main TUI frame."""

@classmethod
def create(cls, app, user):
def create(cls, app, user, args):
"""Factory method, sets up TUI and an event loop."""

tui = cls(app, user)
tui = cls(app, user, args)
loop = urwid.MainLoop(
tui,
palette=PALETTE,
Expand All @@ -87,9 +87,10 @@ def create(cls, app, user):

return tui

def __init__(self, app, user):
def __init__(self, app, user, args):
self.app = app
self.user = user
self.args = args
self.config = config.load_config()

self.loop = None # set in `create`
Expand Down
11 changes: 10 additions & 1 deletion toot/tui/timeline.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import sys
import urwid
import webbrowser

Expand Down Expand Up @@ -421,7 +422,15 @@ def poll_generator(self, poll):
class StatusListItem(SelectableColumns):
def __init__(self, status):
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 " "
favourited = ("yellow", "★") if status.original.favourited else " "
reblogged = ("yellow", "♺") if status.original.reblogged else " "
Expand Down

0 comments on commit f3b90c9

Please sign in to comment.