diff --git a/toot/cli/__init__.py b/toot/cli/__init__.py index d4d14ed..2499e0e 100644 --- a/toot/cli/__init__.py +++ b/toot/cli/__init__.py @@ -9,3 +9,4 @@ from toot.cli.read import * from toot.cli.statuses import * from toot.cli.tags import * from toot.cli.timelines import * +from toot.cli.tui import * diff --git a/toot/cli/tui.py b/toot/cli/tui.py new file mode 100644 index 0000000..bfc37d5 --- /dev/null +++ b/toot/cli/tui.py @@ -0,0 +1,16 @@ +from typing import NamedTuple +import click +from toot.cli.base import Context, cli, pass_context +from toot.tui.app import TUI, TuiOptions + +@cli.command() +@click.option( + "--relative-datetimes", + is_flag=True, + help="Show relative datetimes in status list" +) +@pass_context +def tui(ctx: Context, relative_datetimes: bool): + """Launches the toot terminal user interface""" + options = TuiOptions(relative_datetimes, ctx.color) + TUI.create(ctx.app, ctx.user, options).run() diff --git a/toot/tui/app.py b/toot/tui/app.py index 8a2ce09..77cbaaf 100644 --- a/toot/tui/app.py +++ b/toot/tui/app.py @@ -3,9 +3,11 @@ import subprocess import urwid from concurrent.futures import ThreadPoolExecutor +from typing import NamedTuple from toot import api, config, __version__, settings -from toot.console import get_default_visibility +from toot import App, User +from toot.cli.base import get_default_visibility from toot.exceptions import ApiError from .compose import StatusComposer @@ -25,6 +27,11 @@ urwid.set_encoding('UTF-8') DEFAULT_MAX_TOOT_CHARS = 500 +class TuiOptions(NamedTuple): + relative_datetimes: bool + color: bool + + class Header(urwid.WidgetWrap): def __init__(self, app, user): self.app = app @@ -80,7 +87,7 @@ class TUI(urwid.Frame): screen: urwid.BaseScreen @staticmethod - def create(app, user, args): + def create(app: App, user: User, args: TuiOptions): """Factory method, sets up TUI and an event loop.""" screen = TUI.create_screen(args) tui = TUI(app, user, screen, args) @@ -102,18 +109,18 @@ class TUI(urwid.Frame): return tui @staticmethod - def create_screen(args): + def create_screen(args: TuiOptions): screen = urwid.raw_display.Screen() # Determine how many colors to use - default_colors = 1 if args.no_color else 16 + default_colors = 16 if args.color else 1 colors = settings.get_setting("tui.colors", int, default_colors) logger.debug(f"Setting colors to {colors}") screen.set_terminal_properties(colors) return screen - def __init__(self, app, user, screen, args): + def __init__(self, app, user, screen, args: TuiOptions): self.app = app self.user = user self.args = args diff --git a/toot/tui/compose.py b/toot/tui/compose.py index 05bfaaf..4d4b77a 100644 --- a/toot/tui/compose.py +++ b/toot/tui/compose.py @@ -1,7 +1,7 @@ import urwid import logging -from toot.console import get_default_visibility +from toot.cli.base import get_default_visibility from .constants import VISIBILITY_OPTIONS from .widgets import Button, EditBox