2023-12-03 13:53:52 +01:00
|
|
|
import click
|
2023-12-05 09:25:02 +01:00
|
|
|
|
2023-12-07 19:11:59 +01:00
|
|
|
from typing import Optional
|
|
|
|
from toot.cli.base import TUI_COLORS, Context, cli, pass_context
|
|
|
|
from toot.cli.validators import validate_tui_colors
|
2023-12-03 13:53:52 +01:00
|
|
|
from toot.tui.app import TUI, TuiOptions
|
|
|
|
|
2023-12-07 19:11:59 +01:00
|
|
|
COLOR_OPTIONS = ", ".join(TUI_COLORS.keys())
|
|
|
|
|
2023-12-05 09:25:02 +01:00
|
|
|
|
2023-12-03 13:53:52 +01:00
|
|
|
@cli.command()
|
|
|
|
@click.option(
|
2023-12-07 19:11:59 +01:00
|
|
|
"-r", "--relative-datetimes",
|
2023-12-03 13:53:52 +01:00
|
|
|
is_flag=True,
|
|
|
|
help="Show relative datetimes in status list"
|
|
|
|
)
|
2023-12-07 19:11:59 +01:00
|
|
|
@click.option(
|
|
|
|
"-m", "--media-viewer",
|
|
|
|
help="Program to invoke with media URLs to display the media files, such as 'feh'"
|
|
|
|
)
|
|
|
|
@click.option(
|
|
|
|
"-c", "--colors",
|
|
|
|
callback=validate_tui_colors,
|
|
|
|
help=f"""Number of colors to use, one of {COLOR_OPTIONS}, defaults to 16 if
|
|
|
|
using --color, and 1 if using --no-color."""
|
|
|
|
)
|
2023-12-03 13:53:52 +01:00
|
|
|
@pass_context
|
2023-12-07 19:11:59 +01:00
|
|
|
def tui(
|
|
|
|
ctx: Context,
|
|
|
|
colors: Optional[int],
|
|
|
|
media_viewer: Optional[str],
|
|
|
|
relative_datetimes: bool,
|
|
|
|
):
|
2023-12-03 13:53:52 +01:00
|
|
|
"""Launches the toot terminal user interface"""
|
2023-12-07 19:11:59 +01:00
|
|
|
if colors is None:
|
|
|
|
colors = 16 if ctx.color else 1
|
|
|
|
|
|
|
|
options = TuiOptions(
|
|
|
|
colors=colors,
|
|
|
|
media_viewer=media_viewer,
|
|
|
|
relative_datetimes=relative_datetimes,
|
|
|
|
)
|
|
|
|
tui = TUI.create(ctx.app, ctx.user, options)
|
|
|
|
tui.run()
|