toot/toot/cli/tui.py

74 wiersze
2.1 KiB
Python
Czysty Zwykły widok Historia

2023-12-03 12:53:52 +00:00
import click
2023-12-05 08:25:02 +00:00
2023-12-07 18:11:59 +00:00
from typing import Optional
2024-04-13 06:14:36 +00:00
from toot.cli import TUI_COLORS, VISIBILITY_CHOICES, IMAGE_FORMAT_CHOICES, Context, cli, pass_context
from toot.cli.validators import validate_tui_colors, validate_cache_size
2023-12-03 12:53:52 +00:00
from toot.tui.app import TUI, TuiOptions
2023-12-07 18:11:59 +00:00
COLOR_OPTIONS = ", ".join(TUI_COLORS.keys())
2023-12-05 08:25:02 +00:00
2023-12-03 12:53:52 +00:00
@cli.command()
@click.option(
2023-12-07 18:11:59 +00:00
"-r", "--relative-datetimes",
2023-12-03 12:53:52 +00:00
is_flag=True,
help="Show relative datetimes in status list"
)
2023-12-07 18:11:59 +00: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."""
)
2024-04-13 06:14:36 +00:00
@click.option(
"-s", "--cache-size",
callback=validate_cache_size,
help="""Specify the image cache maximum size in megabytes. Default: 10MB.
Minimum: 1MB."""
)
@click.option(
"-v", "--default-visibility",
type=click.Choice(VISIBILITY_CHOICES),
help="Default visibility when posting new toots; overrides the server-side preference"
)
@click.option(
2024-03-09 09:16:41 +00:00
"-s", "--always-show-sensitive",
is_flag=True,
help="Expand toots with content warnings automatically"
)
2024-04-13 06:14:36 +00:00
@click.option(
"-f", "--image-format",
type=click.Choice(IMAGE_FORMAT_CHOICES),
help="Image output format; support varies across terminals. Default: block"
)
2023-12-03 12:53:52 +00:00
@pass_context
2023-12-07 18:11:59 +00:00
def tui(
ctx: Context,
colors: Optional[int],
media_viewer: Optional[str],
always_show_sensitive: bool,
2023-12-07 18:11:59 +00:00
relative_datetimes: bool,
2024-04-13 06:14:36 +00:00
cache_size: Optional[int],
default_visibility: Optional[str],
image_format: Optional[str]
2023-12-07 18:11:59 +00:00
):
2023-12-03 12:53:52 +00:00
"""Launches the toot terminal user interface"""
2023-12-07 18:11:59 +00:00
if colors is None:
colors = 16 if ctx.color else 1
options = TuiOptions(
colors=colors,
media_viewer=media_viewer,
relative_datetimes=relative_datetimes,
2024-04-13 06:14:36 +00:00
cache_size=cache_size,
default_visibility=default_visibility,
always_show_sensitive=always_show_sensitive,
2024-04-13 06:14:36 +00:00
image_format=image_format,
2023-12-07 18:11:59 +00:00
)
tui = TUI.create(ctx.app, ctx.user, options)
tui.run()