tmuxp formatter - tmuxp.cli._formatter¶
Custom help formatter for tmuxp CLI with colorized examples.
This module provides a custom argparse formatter that colorizes example sections in help output, similar to vcspull’s formatter.
Examples
>>> from tmuxp.cli._formatter import TmuxpHelpFormatter
>>> TmuxpHelpFormatter
<class '...TmuxpHelpFormatter'>
-
class tmuxp.cli._formatter.TmuxpHelpFormatter¶class tmuxp.cli._formatter.TmuxpHelpFormatter¶
Bases:
RawDescriptionHelpFormatterHelp formatter with colorized examples for tmuxp CLI.
This formatter extends RawDescriptionHelpFormatter to preserve formatting of description text while adding syntax highlighting to example sections.
Example colors come from
_example_theme(): argparse’s own theme on Python 3.14+, where argparse colors help itself, and the bound_help_themeon older Pythons. With neither, the formatter falls back to plain text output.Examples
>>> formatter = TmuxpHelpFormatter("tmuxp") >>> formatter <...TmuxpHelpFormatter object at ...>
-
class tmuxp.cli._formatter.HelpTheme¶class tmuxp.cli._formatter.HelpTheme¶
Bases:
NamedTupleTheme colors for help output.
Each field is the ANSI escape prefix written before a token;
resetcloses it.from_colors()sets every field to""when color is disabled, so the same formatting code emits plain text.Examples
>>> from tmuxp.cli._formatter import HelpTheme >>> theme = HelpTheme.from_colors(None) >>> theme.reset ''
-
tmuxp.cli._formatter.create_themed_formatter(colors=None)¶tmuxp.cli._formatter.create_themed_formatter(colors=None)¶
Create a help formatter class with theme bound.
This factory creates a formatter subclass with the theme injected, allowing colorized help output without modifying argparse internals.
When no colors argument is provided, uses AUTO mode which respects NO_COLOR, FORCE_COLOR environment variables and TTY detection. The bound theme colors examples below Python 3.14; from 3.14 argparse’s own theme does (see
TmuxpHelpFormatter._example_theme()).Examples
>>> from tmuxp.cli._colors import ColorMode, Colors >>> from tmuxp.cli._formatter import create_themed_formatter, HelpTheme
With explicit colors enabled:
>>> colors = Colors(ColorMode.ALWAYS) >>> formatter_cls = create_themed_formatter(colors) >>> formatter_cls._help_theme is not None True
With colors disabled:
>>> colors = Colors(ColorMode.NEVER) >>> formatter_cls = create_themed_formatter(colors) >>> formatter_cls._help_theme is None True