libvt.tmux

Sans-I/O tmux capture-pane and control-mode (-CC) decoders.

class libvt.tmux.CaptureCompleteness
class libvt.tmux.CaptureCompleteness

Bases: object

Explicit fidelity report for a decoded tmux capture-pane snapshot.

class libvt.tmux.TmuxCaptureResult
class libvt.tmux.TmuxCaptureResult

Bases: object

Decoded tmux capture bundle ready for inspection or live streaming.

class libvt.tmux.TmuxLineFlags
class libvt.tmux.TmuxLineFlags

Bases: IntFlag

Per-line flags emitted by tmux capture-pane -F (tmux >= 3.8).

class libvt.tmux.TmuxPaneMetadata
class libvt.tmux.TmuxPaneMetadata

Bases: object

Out-of-band tmux pane state queried via TMUX_METADATA_FORMAT.

libvt.tmux.decode_tmux_capture(captured, *, metadata=None, rows=24, cols=80, scrollback=None, flagged=False, joined_capture=None, saved_primary_capture=None, saved_primary_flagged=None, post_metadata=None, profile=TMUX_PROFILE, policy=TMUX_CAPTURE_POLICY, limits=DEFAULT_LIMITS)
function[source]
function[source]
libvt.tmux.decode_tmux_capture(captured, *, metadata=None, rows=24, cols=80, scrollback=None, flagged=False, joined_capture=None, saved_primary_capture=None, saved_primary_flagged=None, post_metadata=None, profile=TMUX_PROFILE, policy=TMUX_CAPTURE_POLICY, limits=DEFAULT_LIMITS)

Reconstruct a Terminal from tmux capture-pane.

Handles bare SO/SI (0x0e/0x0f) ACS box-drawing runs without polluting the reconstructed terminal’s live G1 charset, expands GRID_FLAG_TAB \t cells against #{pane_tabs} while preserving active SGR background/attributes, carries SGR across rows just like tmux’s grid_string_cells(&gc), reconstructs pending_wrap from cursor_x >= pane_width, and optionally populates backgrounded primary history when alternate_on is active.

Parameters:
  • captured (CaptureInput) – Output of tmux capture-pane -S - -E - -e -p -N [-F] as str, bytes, or a line sequence (e.g. libtmux Pane.capture_pane).

  • metadata (TmuxPaneMetadata | str | None) – Parsed TmuxPaneMetadata or raw format line emitted by display-message -p TMUX_METADATA_FORMAT; when None, rows, cols, and scrollback defaults are used.

  • rows (int) – Fallback pane height when metadata is None.

  • cols (int) – Fallback pane width when metadata is None.

  • scrollback (int | None) – Explicit scrollback line cap; when None, defaults to metadata.history_limit if metadata is provided, else 2000.

  • flagged (bool) – True when captured includes capture-pane -F line prefixes.

  • joined_capture (CaptureInput | None) – Optional capture-pane -S - -E - -e -p -J output used to infer soft wraps on tmux < 3.8 when flagged=False.

  • saved_primary_capture (CaptureInput | None) – Optional capture-pane -a -q -S - -E - -e -p -N [-F] output restoring the backgrounded primary screen and scrollback when alternate_on is True.

  • saved_primary_flagged (bool | None) – Whether saved_primary_capture carries -F prefixes (defaults to flagged).

  • post_metadata (TmuxPaneMetadata | str | None) – Optional second metadata sample taken immediately after capture-pane to verify pane_output_generation stability.

  • profile (Profile) – Compatibility profile for the reconstructed terminal.

  • policy (Policy) – Security policy for the reconstructed terminal.

  • limits (Limits) – Resource ceilings for the reconstructed terminal.

Returns:

Reconstructed terminal, immutable snapshot, completeness report, and parsed per-line flags.

Return type:

TmuxCaptureResult

libvt.tmux.parse_flagged_line(line)
function[source]
function[source]
libvt.tmux.parse_flagged_line(line)

Split a tmux capture-pane -F line into (flags, body).

Parameters:

line (str) – Single line emitted by tmux capture-pane -F (without trailing \n).

Returns:

Parsed TmuxLineFlags and remaining SGR/text payload.

Return type:

tuple[TmuxLineFlags, str]

Raises:

ValueError – If line does not start with a valid <flags> space-delimited prefix.

libvt.tmux.unescape_tmux_control_output(data)
function[source]
function[source]
libvt.tmux.unescape_tmux_control_output(data)

Decode tmux -CC %output octal escapes into raw PTY bytes.

tmux control mode escapes bytes < 0x20 and backslash (0x5c -> \134) as three-digit octal sequences \ooo while passing printable ASCII and UTF-8 bytes verbatim (including split multi-byte UTF-8 sequences).

Parameters:

data (collections.abc.Buffer | str) – Escaped payload following %output %<pane_id>.

Returns:

Unescaped raw VT byte stream ready for feed().

Return type:

bytes