libvt.contrib.tmux.window

Multi-pane tmux window layout, scene compositing, and capture bundles.

libvt.contrib.tmux.window.TMUX_WINDOW_METADATA_FORMAT: str = <...truncated, 738 chars>
data
data
libvt.contrib.tmux.window.TMUX_WINDOW_METADATA_FORMAT: str = <...truncated, 738 chars>

Format string passed to tmux display-message -p for window layout state.

libvt.contrib.tmux.window.TMUX_WINDOW_PANE_FORMAT: str = <...truncated, 275 chars>
data
data
libvt.contrib.tmux.window.TMUX_WINDOW_PANE_FORMAT: str = <...truncated, 275 chars>

Format string passed to tmux list-panes -F for per-pane geometry & styles.

class libvt.contrib.tmux.window.TmuxWindowCaptureCommand
class libvt.contrib.tmux.window.TmuxWindowCaptureCommand

Bases: object

Stateless tmux command capturing all panes in a window.

class libvt.contrib.tmux.window.TmuxWindowCaptureResult
class libvt.contrib.tmux.window.TmuxWindowCaptureResult

Bases: object

Decoded tmux window capture of pane application screens.

class libvt.contrib.tmux.window.TmuxWindowLayout
class libvt.contrib.tmux.window.TmuxWindowLayout

Bases: object

Window geometry, border options, and pane descriptors for a tmux window.

class libvt.contrib.tmux.window.TmuxWindowListCommand
class libvt.contrib.tmux.window.TmuxWindowListCommand

Bases: object

Stateless Step 1 tmux command querying window geometry and panes.

class libvt.contrib.tmux.window.TmuxWindowPane
class libvt.contrib.tmux.window.TmuxWindowPane

Bases: object

Geometry and border styling metadata for one pane inside a tmux window.

libvt.contrib.tmux.window.build_tmux_window_capture_command(layout, *, tmux_version='3.8a', include_saved_primary=False, history_lines=0, include_layout=False, nonce=None)
function[source]
function[source]
libvt.contrib.tmux.window.build_tmux_window_capture_command(layout, *, tmux_version='3.8a', include_saved_primary=False, history_lines=0, include_layout=False, nonce=None)

Build an atomic tmux command capturing every pane in layout.

Chains per-pane build_tmux_capture_command() invocations separated by ";" inside a single tmux command batch, optionally prepending an inline build_tmux_window_list_command() header when include_layout=True (for 1-round-trip capture from parse_tmux_window_layout()), and appends a WIN_POST layout stability check.

Parameters:
  • layout (TmuxWindowLayout) – Window descriptor from build_tmux_window_list_command() or parse_tmux_window_layout().

  • tmux_version (tuple[int, int] | str, default “3.8a”) – Target tmux version string or (major, minor) tuple.

  • include_saved_primary (bool, default False) – Whether each per-pane capture includes capture-pane -a -q primary history when alternate_on is active.

  • history_lines (int | None, default 0) – Scrollback lines captured per pane (0 for viewport-only, None for full history, or N > 0 for -S -N).

  • include_layout (bool, default False) – When True, query live window metadata, client theme colors, border styles, and pane-border-format inline in the same tmux batch.

  • nonce (str | None, optional) – Explicit ASCII boundary token matching [0-9A-Za-z_-]{8,80}; generated via secrets.token_hex() when None.

Returns:

Chained multi-pane capture command with argv and parse().

Return type:

TmuxWindowCaptureCommand

Raises:
  • TypeError – If history_lines is not an int or None.

  • ValueError – If tmux_version, history_lines, or nonce is invalid.

Examples

>>> from libvt.contrib.tmux.window import (
...     TmuxWindowLayout,
...     TmuxWindowPane,
...     build_tmux_window_capture_command,
... )
>>> layout = TmuxWindowLayout(
...     panes=(TmuxWindowPane("%0"), TmuxWindowPane("%1", active=True)),
... )
>>> cmd = build_tmux_window_capture_command(layout, nonce="WCAP_1234")
>>> len(cmd.pane_commands)
2
libvt.contrib.tmux.window.build_tmux_window_list_command(target=None, *, nonce=None)
function[source]
function[source]
libvt.contrib.tmux.window.build_tmux_window_list_command(target=None, *, nonce=None)

Build Step 1 tmux command querying window layout and pane descriptors.

Chains display-message and list-panes in one atomic tmux command-queue batch so window dimensions, zoom state, client theme colors, border styles, and expanded pane-border-format strings come from a single server tick.

Parameters:
  • target (str | None, optional) – Optional tmux target window (e.g. "@0" or "mysess:0"); None targets the current window.

  • nonce (str | None, optional) – Explicit ASCII boundary token matching [0-9A-Za-z_-]{8,96}; generated via secrets.token_hex() when None.

Returns:

Command specification with argv and parse().

Return type:

TmuxWindowListCommand

Raises:

ValueError – If target or nonce is invalid.

Examples

>>> from libvt.contrib.tmux.window import build_tmux_window_list_command
>>> cmd = build_tmux_window_list_command("@0", nonce="WIN_LIST_1")
>>> "list-panes" in cmd.argv
True
libvt.contrib.tmux.window.composite_tmux_window(layout, panes, *, tmux_version='3.8a', profile=None)
function[source]
function[source]
libvt.contrib.tmux.window.composite_tmux_window(layout, panes, *, tmux_version='3.8a', profile=None)

Composite a multi-pane tmux window into one immutable Snapshot.

Pure sans-I/O compositor built on blit(), put_text(), and snapshot(), matching tmux’s screen-redraw.c scene builder across perimeter L|R|U|D junctions, pane-border-lines, two-pane half-colored active borders, pane-border-status format lines, theme color tables, full-width soft-wrap flags, zoomed windows, and active-pane cursor positioning.

Parameters:
  • layout (TmuxWindowLayout) – Window dimensions, border options, and pane geometry descriptors.

  • panes (Mapping[str, TmuxPaneSource]) – Mapping from pane_id (e.g. "%0") to each pane’s Snapshot, Screen, Terminal, TmuxCaptureResult, or live TmuxPaneSync handle.

  • tmux_version (tuple[int, int] | str, default “3.8a”) – Target tmux version governing right-edge pending_wrap cursor visibility (tmux >= 3.7 hides a pending_wrap cursor at the window right margin via screen_redraw_get_visible_ranges, whereas tmux <= 3.6 keeps it visible at cols - 1).

  • profile (Profile | None, default None) – Terminal compatibility profile for width calculations and the returned Snapshot.

Returns:

Composited window snapshot with active-pane cursor and metadata.

Return type:

Snapshot

References

Examples

>>> from libvt.contrib.tmux.window import (
...     TmuxWindowLayout,
...     TmuxWindowPane,
...     composite_tmux_window,
... )
>>> from libvt.terminal import Terminal
>>> from libvt.testing import format_screen_box
>>> left, right = Terminal(rows=2, cols=4), Terminal(rows=2, cols=4)
>>> left.feed(b"LEFT")
>>> right.feed(b"RGHT")
>>> win_layout = TmuxWindowLayout(
...     width=9,
...     height=2,
...     panes=(
...         TmuxWindowPane("%0", left=0, top=0, width=4, height=2, index=0),
...         TmuxWindowPane(
...             "%1", left=5, top=0, width=4, height=2, active=True, index=1
...         ),
...     ),
... )
>>> snap = composite_tmux_window(win_layout, {"%0": left, "%1": right})
>>> print(format_screen_box(snap))
┌─────────┐
│LEFT│RGHT│
│    │    │
└─────────┘
libvt.contrib.tmux.window.parse_tmux_window_layout(window_layout, *, window_id='@0', width=None, height=None, zoomed=False, border_lines='single', border_status='off', border_indicators='colour', border_style='fg=themelightgrey', active_pane_id=None)
function[source]
function[source]
libvt.contrib.tmux.window.parse_tmux_window_layout(window_layout, *, window_id='@0', width=None, height=None, zoomed=False, border_lines='single', border_status='off', border_indicators='colour', border_style='fg=themelightgrey', active_pane_id=None)

Parse a tmux #{window_layout} descriptor into TmuxWindowLayout.

Accepts both tmux >= 3.8 V2 JSON layouts ({"V":2,"L":{...}}) and legacy V1 checksum tree strings ("b25f,20x6,0,0{10x6,0,0,0,9x6,11,0,1}"), allowing callers such as libtmux that already hold window_layout to build a single-invocation build_tmux_window_capture_command() with include_layout=True or composite pane handles directly.

Parameters:
  • window_layout (str) – Raw #{window_layout} or #{window_visible_layout} string.

  • window_id (str, default “@0”) – tmux window identifier stored on the returned layout.

  • width (int | None, optional) – Explicit window width override; inferred from root cell when None.

  • height (int | None, optional) – Explicit window height override; inferred from root cell when None.

  • zoomed (bool, default False) – Whether the window is currently zoomed.

  • border_lines (str, default “single”) – Window pane-border-lines setting.

  • border_status (str, default “off”) – Window pane-border-status setting.

  • border_indicators (str, default “colour”) – Window pane-border-indicators setting.

  • border_style (str, default “fg=themelightgrey”) – Window fallback pane-border-style.

  • active_pane_id (str | None, optional) – Explicit active pane_id (used for V1 strings which omit active flags).

Returns:

Parsed window dimensions and TmuxWindowPane geometries.

Return type:

TmuxWindowLayout

Raises:

ValueError – If window_layout is empty or malformed.

References

Examples

>>> from libvt.contrib.tmux.window import parse_tmux_window_layout
>>> v1 = parse_tmux_window_layout(
...     "b25f,20x6,0,0{10x6,0,0,0,9x6,11,0,1}", active_pane_id="%1"
... )
>>> (v1.width, v1.height, [p.pane_id for p in v1.panes], v1.active_pane.pane_id)
(20, 6, ['%0', '%1'], '%1')
>>> v2 = parse_tmux_window_layout(
...     '{"V":2,"L":{"t":"h","w":20,"h":6,"x":0,"y":0,"c":['
...     '{"t":"p","w":10,"h":6,"x":0,"y":0,"i":0,"I":"%0"},'
...     '{"t":"p","w":9,"h":6,"x":11,"y":0,"a":true,"i":1,"I":"%1"}]}}'
... )
>>> (v2.width, v2.height, v2.panes[1].left, v2.panes[1].active)
(20, 6, 11, True)
type libvt.contrib.tmux.window.TmuxPaneSource = Snapshot | Screen | Terminal | TmuxCaptureResult | object
type
type
type libvt.contrib.tmux.window.TmuxPaneSource = Snapshot | Screen | Terminal | TmuxCaptureResult | object

Accepted per-pane state source for composite_tmux_window().