mirror of
https://github.com/ihabunek/toot
synced 2025-02-03 20:57:38 +01:00
Add tui command
This commit is contained in:
parent
3947b28de5
commit
4dfab69f3b
@ -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
16
toot/cli/tui.py
Normal 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()
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user