CLI utilities - tmuxp.cli.utils¶
CLI utility helpers for tmuxp.
-
class tmuxp.cli.utils.ColorMode¶class tmuxp.cli.utils.ColorMode¶
Bases:
EnumColor output modes for CLI.
Examples
>>> ColorMode.AUTO.value 'auto' >>> ColorMode.ALWAYS.value 'always' >>> ColorMode.NEVER.value 'never'
-
class tmuxp.cli.utils.Colors¶class tmuxp.cli.utils.Colors¶
Bases:
objectSemantic color utilities for CLI output.
Provides semantic color methods (success, warning, error, etc.) that conditionally apply ANSI colors based on the color mode and environment.
- Parameters:
mode (
ColorMode) – Color mode to use. Default is AUTO which detects TTY.
Examples
>>> colors = Colors(ColorMode.NEVER) >>> colors.success("session loaded") 'session loaded' >>> colors.error("failed to load") 'failed to load'
>>> colors = Colors(ColorMode.ALWAYS) >>> result = colors.success("ok")
Check that result contains ANSI escape codes:
>>> "\033[" in result True
-
exception tmuxp.cli.utils.UnknownStyleColor¶exception tmuxp.cli.utils.UnknownStyleColor¶
Bases:
ExceptionRaised when encountering an unknown terminal style color.
Examples
>>> try: ... raise UnknownStyleColor("invalid_color") ... except UnknownStyleColor as e: ... "invalid_color" in str(e) True
-
tmuxp.cli.utils.prompt(name, default=None, value_proc=None, *, color_mode=None)¶tmuxp.cli.utils.prompt(name, default=None, value_proc=None, *, color_mode=None)¶
Return user input from command line.
See also
prompt(),prompt_bool(), :py:obj:``flask-script`, :py:obj:``flask-script`
-
tmuxp.cli.utils.prompt_bool(name, default=False, yes_choices=None, no_choices=None, *, color_mode=None)¶tmuxp.cli.utils.prompt_bool(name, default=False, yes_choices=None, no_choices=None, *, color_mode=None)¶
Return True / False by prompting user input from command line.
- Parameters:
name (
str) – prompt textdefault (
bool) – default value if no input provided.yes_choices (
Sequence[Any] |None) – default ‘y’, ‘yes’, ‘1’, ‘on’, ‘true’, ‘t’no_choices (
Sequence[Any] |None) – default ‘n’, ‘no’, ‘0’, ‘off’, ‘false’, ‘f’color_mode (
ColorMode|None) – color mode for prompt styling. Defaults to AUTO if not specified.
- Return type:
-
tmuxp.cli.utils.prompt_choices(name, choices, default=None, no_choice=('none',), *, color_mode=None)¶tmuxp.cli.utils.prompt_choices(name, choices, default=None, no_choice=('none',), *, color_mode=None)¶
Return user input from command line from set of provided choices.
- Parameters:
name (
str) – prompt textchoices (
Sequence[str|tuple[str,str]]) – Sequence of available choices. Each choice may be a single string or a (key, value) tuple where key is used for matching.no_choice (
Sequence[str]) – acceptable list of strings for “null choice”color_mode (
ColorMode|None) – color mode for prompt styling. Defaults to AUTO if not specified.
- Return type:
-
tmuxp.cli.utils.prompt_yes_no(name, default=True, *, color_mode=None)¶tmuxp.cli.utils.prompt_yes_no(name, default=True, *, color_mode=None)¶
prompt_bool()returning yes by default.
-
tmuxp.cli.utils.strip_ansi(value)¶tmuxp.cli.utils.strip_ansi(value)¶
Clear ANSI escape codes from a string value.
Examples
>>> strip_ansi("\033[32mgreen\033[0m") 'green' >>> strip_ansi("plain text") 'plain text'
-
tmuxp.cli.utils.style(text, fg=None, bg=None, bold=None, dim=None, underline=None, overline=None, italic=None, blink=None, reverse=None, strikethrough=None, reset=True)¶tmuxp.cli.utils.style(text, fg=None, bg=None, bold=None, dim=None, underline=None, overline=None, italic=None, blink=None, reverse=None, strikethrough=None, reset=True)¶
Apply ANSI styling to text.
Credit: click.
Examples
>>> style("hello", fg="green") '\x1b[32m...' >>> "hello" in style("hello", fg="green") True
-
tmuxp.cli.utils.tmuxp_echo(message=None, file=None)¶tmuxp.cli.utils.tmuxp_echo(message=None, file=None)¶
Print user-facing CLI output.
Examples
>>> tmuxp_echo("Session loaded") Session loaded
>>> tmuxp_echo("Warning message") Warning message