Add tui command

This commit is contained in:
Ivan Habunek 2023-12-03 13:53:52 +01:00
parent 3947b28de5
commit 4dfab69f3b
No known key found for this signature in database
GPG Key ID: F5F0623FF5EBCB3D
4 changed files with 30 additions and 6 deletions

View File

@ -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 *

16
toot/cli/tui.py Normal file
View File

@ -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()

View File

@ -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

View File

@ -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