libvt.contrib.tmux.capture¶
Use build_tmux_capture_command() to
capture the pane’s written extent and trailing styles together on tmux 3.4
and later. For raw captures, use the same pane, line range and line flags
with capture-pane -e -p -N -T and capture-pane -e -p -N.
>>> from libvt.contrib.tmux import decode_tmux_capture
>>> capture = decode_tmux_capture(
... b"\n",
... rows=1, cols=3, trim_trailing=True,
... untrimmed_capture=b"\x1b[41m \n",
... )
>>> capture.snapshot.lines
('',)
>>> capture.snapshot[0, 2].style.bg.name
'RED'
>>> capture.completeness.exact_cells
True
An older tmux can return the same trailing spaces for a written blank row
and an erased row. The decoder retains the available styles, and reports
trailing_cells in completeness.unexposed_fields when it cannot establish
which spaces were written. A -T capture without its untrimmed companion
likewise reports uncertainty when a row stops short of the pane width.
Preserve empty physical rows when passing a sequence of lines. A capture
with missing viewport, requested history, or requested saved-primary rows
reports capture_rows and clears exact_cells and exact_wraps. The
generation bracket reports the metadata comparison independently.
Continue after a capture¶
exact_cells
describes the captured frame. Later input can depend on earlier bytes.
unexposed_fields
reports state outside the capture’s visible cells.
preceding_graphicis the glyph that a following REP (CSI Ps b) repeats. A cursor movement can clear it without changing the visible cells.grapheme_continuationis the state used to join a following combining mark or emoji component to the preceding glyph.utf8_prefixis an incomplete UTF-8 code point at the checkpoint.
TmuxPaneSync feeds the pending escape
bytes tmux returns through capture-pane -P -C. The native command can
return an empty prefix while the UTF-8 decoder still has buffered bytes.
Resume from a known input boundary when continuation must be exact. A
redraw that supplies complete encoded text and establishes its own first
graphic can serve as that checkpoint.
tmux capture-pane reconstruction and chained command bundles.
Format string passed to
tmux display-message -pfor pane metadata.
-
class libvt.contrib.tmux.capture.CaptureCompleteness¶class libvt.contrib.tmux.capture.CaptureCompleteness¶
Bases:
objectExplicit fidelity report for a decoded
tmux capture-panesnapshot.Cell fidelity describes the captured frame. The preceding graphic for REP, the active grapheme, and an incomplete UTF-8 code point can remain unknown even when the cells are exact.
-
class libvt.contrib.tmux.capture.TmuxCaptureCommand¶class libvt.contrib.tmux.capture.TmuxCaptureCommand¶
Bases:
objectChained
tmuxcapture command specification and bundle parser.
-
class libvt.contrib.tmux.capture.TmuxCaptureResult¶class libvt.contrib.tmux.capture.TmuxCaptureResult¶
Bases:
objectDecoded
tmuxcapture bundle ready for inspection or live streaming.Examples
>>> from libvt.contrib.tmux.capture import decode_tmux_capture >>> from libvt.testing import serialize_vt_snapshot >>> res = decode_tmux_capture( ... ["\x1b[1;32mPASS\x1b[0m suite", "done"], ... rows=2, ... cols=12, ... ) >>> print(serialize_vt_snapshot(res.snapshot)) size=12x2 cursor=(0,0,vis=True) alt=False modes=[] ┌────────────┐ │PASS suite │ │done │ └────────────┘ styles: r0[0..4]: bold fg=green
-
class libvt.contrib.tmux.capture.TmuxLineFlags¶class libvt.contrib.tmux.capture.TmuxLineFlags¶
Bases:
IntFlagPer-line flags emitted by
tmux capture-pane -F(tmux >= 3.7).
-
class libvt.contrib.tmux.capture.TmuxPaneMetadata¶class libvt.contrib.tmux.capture.TmuxPaneMetadata¶
Bases:
objectOut-of-band
tmuxpane state queried viaTMUX_METADATA_FORMAT.
-
libvt.contrib.tmux.capture.build_tmux_capture_command(target=None, *, tmux_version='3.8a', include_saved_primary=True, history_lines=None, nonce=None)¶libvt.contrib.tmux.capture.build_tmux_capture_command(target=None, *, tmux_version='3.8a', include_saved_primary=True, history_lines=None, nonce=None)¶
Build a single-invocation
tmuxcommand chaining metadata and capture.Chains metadata and
capture-pane -e -p -Nin one tmux command queue. From tmux 3.4, a companion-Tcapture establishes the written extent while the untrimmed capture retains trailing cell styles. From tmux 3.7 the captures use-Ffor wrap flags. Older versions add a-Jcapture to infer wraps. A closingPOSTfooter preserves trailing blank viewport rows in line-based stdout.- Parameters:
target (
str|None) – Optionaltmuxtarget pane (e.g."%0"); whenNone,-tis omitted sotmuxtargets the current pane.tmux_version (
tuple[int,int] |str) – Targettmuxversion as(major, minor)ortmux -Vstring (e.g."3.8a","3.7","3.6","3.3a").include_saved_primary (
bool) – Includecapture-pane -a -qsections to restore backgrounded primary history whenalternate_onis active.history_lines (
int|None) – Maximum scrollback lines to capture above the viewport (Nonefor-S -full history,0for-S 0viewport-only, orN > 0for-S -N).nonce (
str|None) – Explicit ASCII boundary token matching[0-9A-Za-z_-]{8,128}; generated viasecrets.token_hex()whenNone.
- Returns:
- Return type:
- Raises:
TypeError– If history_lines is not anintorNone.ValueError– If target, tmux_version, history_lines, or nonce is invalid.
References
Examples
>>> from libvt.contrib.tmux.capture import build_tmux_capture_command >>> cmd = build_tmux_capture_command("%1", tmux_version="3.8a", nonce="CAP_NONCE_1") >>> cmd.flagged, cmd.trim_trailing, cmd.has_joined (True, True, False)
-
libvt.contrib.tmux.capture.decode_tmux_capture(captured, *, metadata=None, rows=24, cols=80, scrollback=None, history_lines=None, flagged=False, trim_trailing=False, untrimmed_capture=None, joined_capture=None, saved_primary_capture=None, saved_primary_flagged=None, saved_primary_trim_trailing=None, saved_primary_untrimmed_capture=None, saved_primary_joined_capture=None, post_metadata=None, tmux_version=None, profile=¶
TMUX_PROFILE, policy=TMUX_CAPTURE_POLICY, limits=DEFAULT_LIMITS)libvt.contrib.tmux.capture.decode_tmux_capture(captured, *, metadata=None, rows=24, cols=80, scrollback=None, history_lines=None, flagged=False, trim_trailing=False, untrimmed_capture=None, joined_capture=None, saved_primary_capture=None, saved_primary_flagged=None, saved_primary_trim_trailing=None, saved_primary_untrimmed_capture=None, saved_primary_joined_capture=None, post_metadata=None, tmux_version=None, profile=¶TMUX_PROFILE, policy=TMUX_CAPTURE_POLICY, limits=DEFAULT_LIMITS) Reconstruct a
Terminalfromtmux capture-pane.Handles bare
SO/SI(0x0e/0x0f) ACS box-drawing runs without polluting the reconstructed terminal’s liveG1charset, decodestmux’sCSI 5:3 moverline serialization strictly on the capture scratch grid, expandsGRID_FLAG_TAB\tcells against#{pane_tabs}while preserving active SGR background/attributes, carries SGR across rows just liketmux’sgrid_string_cells(&gc), reconstructspending_wrapfromcursor_x >= pane_width, and optionally populates backgrounded primary history whenalternate_onis active.- Parameters:
captured (
CaptureInput) – Output oftmux capture-pane -S - -E - -e -p -N [-T] [-F]asstr,bytes, or a line sequence (e.g.libtmuxPane.capture_pane).metadata (
TmuxPaneMetadata|str|None) – ParsedTmuxPaneMetadataor raw format line emitted bydisplay-message -p TMUX_METADATA_FORMAT; whenNone, rows, cols, and scrollback defaults are used.rows (
int) – Fallback pane height when metadata isNone.cols (
int) – Fallback pane width when metadata isNone.scrollback (
int|None) – Explicit scrollback line cap; whenNone, defaults tometadata.history_limitif metadata is provided, else2000.history_lines (
int|None) – Maximum scrollback lines requested viacapture-pane -S(Nonefor full history-S -,0for viewport-only-S 0, orNfor-S -N).flagged (
bool) –Truewhen captured includescapture-pane -Fline prefixes.trim_trailing (
bool) –Truewhen captured usedcapture-pane -N -T(tmux >= 3.4) to record the written extent. Styled cells beyond it need a companion.untrimmed_capture (
CaptureInput|None) – Optionalcapture-pane -e -p -Noutput from the same pane state. Use the same line range and-Fsetting as captured and omit-T. Supplies trailing cell styles when trim_trailing isTrue.joined_capture (
CaptureInput|None) – Optionalcapture-pane -S - -E - -e -p -Joutput used to infer soft wraps ontmux < 3.8whenflagged=False.saved_primary_capture (
CaptureInput|None) – Optionalcapture-pane -a -q -S - -E - -e -p -N [-T] [-F]output restoring the backgrounded primary screen and scrollback whenalternate_onisTrue.saved_primary_flagged (
bool|None) – Whether saved_primary_capture carries-Fprefixes (defaults to flagged).saved_primary_trim_trailing (
bool|None) – Whether saved_primary_capture used-T(defaults to trim_trailing).saved_primary_untrimmed_capture (
CaptureInput|None) – Untrimmed companion from the same saved primary grid and line range.saved_primary_joined_capture (
CaptureInput|None) – Optionalcapture-pane -a -q -S - -E - -e -p -Jcompanion capture for saved_primary_capture whensaved_primary_flaggedisFalse.post_metadata (
TmuxPaneMetadata|str|None) – Optional second metadata sample taken immediately aftercapture-paneto verifypane_output_generationstability.tmux_version (
tuple[int,int] |str|None) – Release that produced the capture. Before tmux 3.5, a widening emoji selector can shift the next captured cell. An unknown release receives the same qualification in the completeness report.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:
- Raises:
ValueError– When an untrimmed companion has no corresponding-Tcapture.
References
Examples
>>> from libvt.contrib.tmux.capture import decode_tmux_capture >>> from libvt.testing import serialize_vt_snapshot >>> res = decode_tmux_capture(["\x1b[32mready\x1b[0m", "done"], rows=2, cols=10) >>> print(serialize_vt_snapshot(res.snapshot)) size=10x2 cursor=(0,0,vis=True) alt=False modes=[] ┌──────────┐ │ready │ │done │ └──────────┘ styles: r0[0..5]: fg=green
-
libvt.contrib.tmux.capture.parse_flagged_line(line)¶libvt.contrib.tmux.capture.parse_flagged_line(line)¶
Split a
tmux capture-pane -Fline into(flags, body).- Parameters:
line (
str) – Single line emitted bytmux capture-pane -F(without trailing\n).- Returns:
Parsed
TmuxLineFlagsand remaining SGR/text payload.- Return type:
- Raises:
ValueError– If line does not start with a valid<flags>space-delimited prefix.
References
Examples
>>> from libvt.contrib.tmux.capture import TmuxLineFlags, parse_flagged_line >>> flags, body = parse_flagged_line("PW $ echo hi") >>> flags == (TmuxLineFlags.START_PROMPT | TmuxLineFlags.WRAPPED), body (True, '$ echo hi')
-
Accepted input representation for
tmux capture-panelines or raw text.