tmuxp progress - tmuxp.cli._progress¶
Progress indicators for tmuxp CLI.
This module provides a threaded spinner for long-running operations, using only standard library and ANSI escape sequences.
-
tmuxp.cli._progress._visible_len(s)¶
Return visible length of s, ignoring ANSI escapes.
Examples
>>> _visible_len("hello") 5 >>> _visible_len("\033[32mgreen\033[0m") 5 >>> _visible_len("") 0
-
tmuxp.cli._progress._truncate_visible(text, max_visible, suffix='...')¶
Truncate text to max_visible visible characters, preserving ANSI sequences.
If the visible length of text is already within max_visible, it is returned unchanged. Otherwise the text is cut so that exactly max_visible visible characters remain, a
\x1b[0mreset is appended (to prevent color bleed), followed by suffix.- Parameters:
- Returns:
Truncated string with ANSI sequences intact.
- Return type:
Examples
Plain text truncation:
>>> _truncate_visible("hello world", 5) 'hello\x1b[0m...'
ANSI sequences are preserved whole:
>>> _truncate_visible("\033[32mgreen\033[0m", 3) '\x1b[32mgre\x1b[0m...'
No truncation needed:
>>> _truncate_visible("short", 10) 'short'
Empty string:
>>> _truncate_visible("", 5) ''
-
tmuxp.cli._progress.render_bar(done, total, width=10)¶
Render a plain-text ASCII progress bar without color.
Examples
>>> render_bar(0, 10) '░░░░░░░░░░' >>> render_bar(5, 10) '█████░░░░░' >>> render_bar(10, 10) '██████████' >>> render_bar(0, 0) '' >>> render_bar(3, 10, width=5) '█░░░░'
-
class tmuxp.cli._progress._SafeFormatMap¶
Bases:
dictdict subclass that returns
{key}for missing keys in format_map.
-
tmuxp.cli._progress.resolve_progress_format(fmt)¶
Return the format string for fmt, resolving preset names.
If fmt is a key in
PROGRESS_PRESETSthe corresponding format string is returned; otherwise fmt is returned as-is.Examples
>>> resolve_progress_format("minimal") == PROGRESS_PRESETS["minimal"] True >>> resolve_progress_format("{session} w{window_progress}") '{session} w{window_progress}' >>> resolve_progress_format("unknown-preset") 'unknown-preset'
-
class tmuxp.cli._progress.BuildTree¶
Bases:
objectTracks session/window/pane build state; renders a structural progress tree.
Template Token Lifecycle
Each token is first available at the event listed in its column.
—means the value does not change at that phase.Token
Pre-
session_createdAfter
session_createdAfter
window_startedAfter
pane_creatingAfter
window_done{session}""session name
—
—
—
{window}""""window name
—
last window name
{window_index}00N (1-based started count)
—
—
{window_total}0total
—
—
—
{window_progress}"""""N/M"when > 0—
—
{windows_done}0000increments
{windows_remaining}0total
total
total
decrements
{window_progress_rel}"""0/M""0/M"—
"N/M"{pane_index}000pane_num
0{pane_total}00window’s pane total
—
window’s pane total
{pane_progress}"""""""N/M"""{pane_done}000pane_num
pane_total
{pane_remaining}00pane_total
decrements
0{pane_progress_rel}"""""0/M""N/M""M/M"{progress}"""""N/M win""N/M win · P/Q pane"—
{session_pane_total}0total
—
—
—
{session_panes_done}0000accumulated
{session_panes_remaining}0total
total
total
decrements
{session_pane_progress}"""0/T"—
—
"N/T"{overall_percent}0000updates
{summary}"""""""""[N win, M panes]"{bar}(spinner)[░░…][░░…]starts filling
fractional
jumps
{pane_bar}(spinner)""[░░…]—
—
updates
{window_bar}(spinner)""[░░…]—
—
updates
{status_icon}(spinner)""""""""""During
before_script:{bar},{pane_bar},{window_bar}show a marching animation;{status_icon}=⏸.Examples
Empty tree renders nothing:
>>> from tmuxp.cli._colors import ColorMode, Colors >>> colors = Colors(ColorMode.NEVER) >>> tree = BuildTree() >>> tree.render(colors, 80) []
After session_created event the header appears:
>>> tree.on_event({"event": "session_created", "name": "my-session"}) >>> tree.render(colors, 80) ['Session']
After window_started and pane_creating:
>>> tree.on_event({"event": "window_started", "name": "editor", "pane_total": 2}) >>> tree.on_event({"event": "pane_creating", "pane_num": 1, "pane_total": 2}) >>> lines = tree.render(colors, 80) >>> lines[1] '- editor, pane (1 of 2)'
After window_done the window gets a checkmark:
>>> tree.on_event({"event": "window_done"}) >>> lines = tree.render(colors, 80) >>> lines[1] '- ✓ editor'
Inline status format:
>>> tree2 = BuildTree() >>> tree2.format_inline("Building projects...") 'Building projects...' >>> tree2.on_event({"event": "session_created", "name": "cihai", "window_total": 3}) >>> tree2.format_inline("Building projects...") 'Building projects... cihai' >>> tree2.on_event({"event": "window_started", "name": "gp-libs", "pane_total": 2}) >>> tree2.on_event({"event": "pane_creating", "pane_num": 1, "pane_total": 2}) >>> tree2.format_inline("Building projects...") 'Building projects... cihai [1 of 3 windows, 1 of 2 panes] gp-libs'
-
class tmuxp.cli._progress.Spinner¶
Bases:
objectA threaded spinner for CLI progress.
Examples
>>> import io >>> stream = io.StringIO() >>> with Spinner("Build...", color_mode=ColorMode.NEVER, stream=stream) as spinner: ... spinner.add_output_line("Session created: test") ... spinner.update_message("Creating window: editor")