libvt.contrib.tmux.control¶
A pane size change starts the same native refresh as
resync(). Send the commands
returned by handle_event() and
wait for LIVE before reading the new dimensions. The terminal keeps its
last frame until the new capture installs.
Keep a scrollback bookmark across updates¶
Store an absolute row with a SyncToken from the
same terminal. A native refresh retains the current visible rows and the
requested history that tmux still holds. Once tmux has evicted earlier
history, the capture cannot recover the previous absolute origin. The
same row number may resolve to different text after a refresh.
>>> from libvt import Terminal
>>> from libvt.terminal import ResyncReason, SyncToken
>>> def bookmarked_text(term: Terminal, token: SyncToken, row: int) -> str | None:
... delta = term.changes_since(token)
... expired = (ResyncReason.EPOCH_CHANGED, ResyncReason.TERMINAL_MISMATCH)
... if delta.resync_reason in expired or delta.snapshot.active_is_alt:
... return None
... try:
... return delta.snapshot.at_abs(row).text
... except IndexError:
... return None
>>> term = Terminal(rows=2, cols=8, scrollback=3)
>>> term.feed(b"r0\r\nr1\r\nr2")
>>> bookmark = (term.sync_token(), term.committed.scrolled_total + 1)
>>> bookmarked_text(term, *bookmark)
'r2'
>>> term.resize(rows=2, cols=10)
>>> bookmarked_text(term, *bookmark) is None
True
Use the same check with sync.terminal after a native tmux refresh.
An immutable snapshot retained with the bookmark still resolves rows in
its original frame.
tmux -C / -CC byte-oriented control-mode parser and pane sync.
-
class libvt.contrib.tmux.control.TmuxAttachPhase¶class libvt.contrib.tmux.control.TmuxAttachPhase¶
Bases:
StrEnumLifecycle phase of sans-I/O two-phase
TmuxPaneSync.References
Examples
>>> from libvt.contrib.tmux.control import TmuxAttachPhase >>> TmuxAttachPhase.LIVE.value 'live'
-
class libvt.contrib.tmux.control.TmuxCommandBlock¶class libvt.contrib.tmux.control.TmuxCommandBlock¶
Bases:
objectCompleted
%begin..%end/%errorcontrol-mode reply block.References
Examples
>>> from libvt.contrib.tmux.control import TmuxCommandBlock >>> TmuxCommandBlock(timestamp=1, command_number=2, flags=1, lines=(b"ok",)).lines (b'ok',)
-
class libvt.contrib.tmux.control.TmuxContinue¶class libvt.contrib.tmux.control.TmuxContinue¶
Bases:
object%continue %<pane_id>flow-control notification.References
Examples
>>> from libvt.contrib.tmux.control import TmuxContinue >>> TmuxContinue(pane_id="%0").pane_id '%0'
-
class libvt.contrib.tmux.control.TmuxControlParser¶class libvt.contrib.tmux.control.TmuxControlParser¶
Bases:
objectStreaming sans-I/O byte parser for
tmux -C/-CCstdout.Operates strictly on raw
bytesso multi-byte UTF-8 sequences split across consecutive%outputor%extended-outputlines reassemble cleanly insideTerminalwithoutU+FFFDloss, and strips optionaltmux -CCDCS 1000p(ESC P 1000p..ST) framing automatically.- Parameters:
- Raises:
ValueError– If max_line_bytes or max_block_bytes is less than64.
References
Examples
>>> from libvt.contrib.tmux.control import TmuxControlParser >>> p = TmuxControlParser() >>> p.feed(b"%output %0 hi\\012\n") [TmuxOutput(pane_id='%0', data=b'hi\n')]
-
class libvt.contrib.tmux.control.TmuxExit¶class libvt.contrib.tmux.control.TmuxExit¶
Bases:
object%exit [reason]control client termination notification.References
Examples
>>> from libvt.contrib.tmux.control import TmuxExit >>> TmuxExit(reason="detached").reason 'detached'
-
class libvt.contrib.tmux.control.TmuxExtendedOutput¶class libvt.contrib.tmux.control.TmuxExtendedOutput¶
Bases:
objectUnescaped
%extended-output %<pane_id> <age> : <data>notification.References
Examples
>>> from libvt.contrib.tmux.control import TmuxExtendedOutput >>> TmuxExtendedOutput(pane_id="%1", age_ms=25, data=b"x").age_ms 25
-
class libvt.contrib.tmux.control.TmuxLayoutChange¶class libvt.contrib.tmux.control.TmuxLayoutChange¶
Bases:
object%layout-change @<win> <layout> <visible_layout> <flags>notification.References
Examples
>>> from libvt.contrib.tmux.control import TmuxLayoutChange >>> TmuxLayoutChange(window_id="@0", layout="a", visible_layout="a").window_id '@0'
-
class libvt.contrib.tmux.control.TmuxNotification¶class libvt.contrib.tmux.control.TmuxNotification¶
Bases:
objectFallback
%<name> ...control-mode notification record.References
Examples
>>> from libvt.contrib.tmux.control import TmuxNotification >>> TmuxNotification(name="sessions-changed", args=b"").name 'sessions-changed'
-
class libvt.contrib.tmux.control.TmuxOutput¶class libvt.contrib.tmux.control.TmuxOutput¶
Bases:
objectUnescaped
%output %<pane_id> <data>byte notification.References
Examples
>>> from libvt.contrib.tmux.control import TmuxOutput >>> TmuxOutput(pane_id="%0", data=b"hi").pane_id '%0'
-
class libvt.contrib.tmux.control.TmuxPaneSync¶class libvt.contrib.tmux.control.TmuxPaneSync¶
Bases:
objectSans-I/O two-phase
tmux -C/-CCpane-attachment coordinator.Checks membership in the control client’s session, then implements a pause barrier and a single atomic
capture-pane+capture-pane -P -p -C+refresh-client -A '%N:continue'command batch sotmuxexecutes capture and resume in onecmdq_nextturn without dropping live PTY bytes.On a shared control client, feed each event to every pane sync. Send each returned string in one write followed by a newline. The two lines identify the reply owner and submit its command batch.
A topology change can put a live pane into
TmuxAttachPhase.CHECKING_SCOPEwhile the session query runs. If the pane leaves the client’s session,phasebecomesTmuxAttachPhase.OUT_OF_SCOPEandterminalretains its last view. Callresync()from a control client whose session contains the pane.- Parameters:
pane_id (
str) – Targettmuxpane identifier (e.g."%0").tmux_version (
tuple[int,int] |str,default "3.8a") – Targettmuxversion string or(major, minor)tuple.scrollback (
int,default 2_000) – Scrollback capacity for the reconstructedTerminal.history_lines (
int|None,default None) – Maximum scrollback lines requested on each capture/resync (Nonefor full history,0for viewport-only, orNfor-S -N).profile (
Profile|None,default None) – Optional inner-pane profile (defaults totmux_profile(tmux_version)).policy (
Policy|None,default None) – Optional security/reply policy (defaults toTMUX_OBSERVER_POLICY).limits (
Limits|None,default None) – Optional terminal resource limits.
- Raises:
ValueError– If pane_id is not"%<ascii_digits>"or tmux_version is invalid.
References
Examples
>>> from libvt.contrib.tmux.control import TmuxAttachPhase, TmuxPaneSync >>> sync = TmuxPaneSync("%0") >>> "list-panes -s" in sync.begin_attach() True >>> sync.phase == TmuxAttachPhase.PAUSING True
-
class libvt.contrib.tmux.control.TmuxPause¶class libvt.contrib.tmux.control.TmuxPause¶
Bases:
object%pause %<pane_id>flow-control notification.References
Examples
>>> from libvt.contrib.tmux.control import TmuxPause >>> TmuxPause(pane_id="%0").pane_id '%0'
-
class libvt.contrib.tmux.control.TmuxSubscriptionChanged¶class libvt.contrib.tmux.control.TmuxSubscriptionChanged¶
Bases:
object%subscription-changed <name> $<sess> <win> <idx> <pane> : <value>.References
Examples
>>> from libvt.contrib.tmux.control import TmuxSubscriptionChanged >>> TmuxSubscriptionChanged( ... name="s", session_id="$0", window_id="-", window_index="-", ... pane_id="-", value="1", ... ).value '1'
-
libvt.contrib.tmux.control.unescape_tmux_control_output(data)¶libvt.contrib.tmux.control.unescape_tmux_control_output(data)¶
Decode
tmux -CC%outputoctal escapes into raw PTY bytes.tmuxcontrol mode escapes bytes< 0x20and backslash (0x5c->\134) as three-digit octal sequences\ooowhile 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:
References
Examples
>>> from libvt.contrib.tmux.control import unescape_tmux_control_output >>> unescape_tmux_control_output(r"\033[32mok\033[0m\015\012") b'\x1b[32mok\x1b[0m\r\n'
-
type libvt.contrib.tmux.control.TmuxControlEvent = TmuxCommandBlock | TmuxOutput | TmuxExtendedOutput | TmuxPause | TmuxContinue | TmuxLayoutChange | TmuxSubscriptionChanged | TmuxExit | TmuxNotification¶type libvt.contrib.tmux.control.TmuxControlEvent = TmuxCommandBlock | TmuxOutput | TmuxExtendedOutput | TmuxPause | TmuxContinue | TmuxLayoutChange | TmuxSubscriptionChanged | TmuxExit | TmuxNotification¶
Union of typed events emitted by
feed().