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)
function[source]

Return visible length of s, ignoring ANSI escapes.

Examples

>>> _visible_len("hello")
5
>>> _visible_len("\033[32mgreen\033[0m")
5
>>> _visible_len("")
0
Parameters:

s (str)

Return type:

int

tmuxp.cli._progress._truncate_visible(text, max_visible, suffix='...')
function[source]

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[0m reset is appended (to prevent color bleed), followed by suffix.

Parameters:
  • text (str) – Input string, possibly containing ANSI escape sequences.

  • max_visible (int) – Maximum number of visible (non-ANSI) characters to keep.

  • suffix (str) – Appended after the reset when truncation occurs. Default "...".

Returns:

Truncated string with ANSI sequences intact.

Return type:

str

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)
function[source]

Render a plain-text ASCII progress bar without color.

Parameters:
  • done (int) – Completed units.

  • total (int) – Total units. When <= 0, returns "".

  • width (int) – Inner fill character count; default BAR_WIDTH.

Returns:

A bar like "█████░░░░░". Returns "" when total <= 0 or width <= 0.

Return type:

str

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: dict

dict subclass that returns {key} for missing keys in format_map.

tmuxp.cli._progress.resolve_progress_format(fmt)
function[source]

Return the format string for fmt, resolving preset names.

If fmt is a key in PROGRESS_PRESETS the 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'
Parameters:

fmt (str)

Return type:

str

class tmuxp.cli._progress._WindowStatus

Bases: object

State for a single window in the build tree.

class tmuxp.cli._progress.BuildTree

Bases: object

Tracks 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_created

After session_created

After window_started

After pane_creating

After window_done

{session}

""

session name

{window}

""

""

window name

last window name

{window_index}

0

0

N (1-based started count)

{window_total}

0

total

{window_progress}

""

""

"N/M" when > 0

{windows_done}

0

0

0

0

increments

{windows_remaining}

0

total

total

total

decrements

{window_progress_rel}

""

"0/M"

"0/M"

"N/M"

{pane_index}

0

0

0

pane_num

0

{pane_total}

0

0

window’s pane total

window’s pane total

{pane_progress}

""

""

""

"N/M"

""

{pane_done}

0

0

0

pane_num

pane_total

{pane_remaining}

0

0

pane_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}

0

total

{session_panes_done}

0

0

0

0

accumulated

{session_panes_remaining}

0

total

total

total

decrements

{session_pane_progress}

""

"0/T"

"N/T"

{overall_percent}

0

0

0

0

updates

{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: object

A 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")