Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ cursor state, and active terminal modes, paired with
{func}`~libtmux.vt.assert_pane_screen_box` for test assertions; the surface is
provisional while `libvt` is pre-`0.1`. See {ref}`vt` for details.

#### Composite multi-pane window screens (#939)

{meth}`~libtmux.Window.capture_vt` and
{meth}`~libtmux.vt.VtSessionObserver.snapshot_window` composite split pane
grids, box-drawing dividers and junctions, `pane-border-status` labels, and the
active pane cursor into a single window `Snapshot`, paired with
{func}`~libtmux.vt.assert_window_screen` and
{func}`~libtmux.vt.assert_window_screen_box`. See {ref}`vt`.

#### Stream live pane updates over control mode (#934)

{meth}`~libtmux.Session.observe_vt`, {meth}`~libtmux.Pane.observe_vt`, and the
Expand Down
104 changes: 97 additions & 7 deletions docs/api/libtmux.vt.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
# VT Integration (`libtmux.vt`)

{mod}`libtmux.vt` pairs `libtmux` with [libvt](https://libvt.git-pull.com) on
Python 3.12+ to reconstruct pane screens, immutable `Snapshot` grids, and `SGR`
styles via {meth}`~libtmux.Pane.capture_vt`, stream live `tmux -C` updates via
{meth}`~libtmux.Session.observe_vt`, {meth}`~libtmux.Pane.observe_vt`, and
Python 3.12+ to reconstruct pane and multi-pane window screens, immutable
`Snapshot` grids, and `SGR` styles via {meth}`~libtmux.Pane.capture_vt` and
{meth}`~libtmux.Window.capture_vt`, stream live `tmux -C` updates via
{meth}`~libtmux.Session.observe_vt`, {meth}`~libtmux.Pane.observe_vt`,
{meth}`~libtmux.vt.VtSessionObserver.snapshot_window`, and
{fixture}`vt_observer`, encode mode-aware input via
{meth}`~libtmux.Pane.send_vt_input`, and check screens with
{func}`~libtmux.vt.assert_pane_screen` and
{func}`~libtmux.vt.assert_pane_screen_box`.
{func}`~libtmux.vt.assert_pane_screen`,
{func}`~libtmux.vt.assert_pane_screen_box`,
{func}`~libtmux.vt.assert_window_screen`, and
{func}`~libtmux.vt.assert_window_screen_box`.

Install with the `vt` extra:

Expand All @@ -20,8 +24,9 @@ $ uv add "libtmux[vt]"
```{note}
{mod}`libtmux.vt`, {meth}`~libtmux.Pane.capture_vt`,
{meth}`~libtmux.Pane.observe_vt`, {meth}`~libtmux.Pane.send_vt_input`,
{meth}`~libtmux.Session.observe_vt`, and {fixture}`vt_observer` are provisional
while `libvt` is pre-`0.1` and may change across minor releases.
{meth}`~libtmux.Window.capture_vt`, {meth}`~libtmux.Session.observe_vt`, and
{fixture}`vt_observer` are provisional while `libvt` is pre-`0.1` and may
change across minor releases.
```

## Capture a pane and inspect its `Snapshot` grid
Expand Down Expand Up @@ -97,6 +102,91 @@ means disabled. When tmux omits the state, the flag is `None` and
On those servers, attach with {meth}`~libtmux.Pane.observe_vt` before the
application enables `?2004` to observe the mode change.

## Capture a multi-pane window (`Window.capture_vt`)

When a window holds split panes, {meth}`~libtmux.Window.capture_vt` captures
every pane in one `tmux` command batch and composites their cells, box-drawing
dividers and junctions (`│`, `─`, `├`), `pane-border-status` labels, and the
active pane's cursor into a single window `Snapshot` (alongside each pane's
individual capture in `win_captured.panes`):

```python
>>> import pytest; _ = pytest.importorskip("libvt") # doctest: +HIDE
>>> import shlex
>>> import sys
>>> from libvt.testing import serialize_vt_snapshot
>>> from libtmux.constants import PaneDirection
>>> from libtmux.test.retry import retry_until
>>> from libtmux.vt import assert_window_screen_box
>>> py = shlex.quote(sys.executable)
>>> def _pane_cmd(title: str, body: str) -> str:
... script = (
... "import sys; "
... f"sys.stdout.write({title!r} + {body!r}); "
... "sys.stdout.flush(); sys.stdin.read(1)"
... )
... return f"{py} -u -c {shlex.quote(script)}"
>>> win_session = server.new_session(
... session_name="vt-window",
... x=21,
... y=5,
... window_command=_pane_cmd("\x1b]2;api\x07", "\x1b[1;32m200 OK\x1b[0m\r\nready"),
... )
>>> split_win = win_session.active_window
>>> _ = split_win.set_option("pane-border-style", "default")
>>> _ = split_win.set_option("pane-active-border-style", "fg=green")
>>> right_top = split_win.split(
... direction=PaneDirection.Right,
... attach=True,
... shell=_pane_cmd("\x1b]2;db\x07", "\x1b[36mpg:up\x1b[0m"),
... size=10,
... )
>>> right_bot = split_win.split(
... direction=PaneDirection.Below,
... attach=True,
... shell=_pane_cmd("\x1b]2;jobs\x07", "q=0"),
... size=2,
... )
>>> def _win_ready() -> bool:
... txt = split_win.capture_vt().snapshot.text
... return "ready" in txt and "pg:up" in txt and "q=0" in txt
>>> retry_until(_win_ready)
True
>>> win_captured = split_win.capture_vt()
>>> print(serialize_vt_snapshot(win_captured.snapshot))
size=21x5 cursor=(3,14,vis=True) alt=False modes=[]
┌─────────────────────┐
│200 OK │pg:up │
│ready │ │
│ ├──────────│
│ │q=0 │
│ │ │
└─────────────────────┘
styles:
r0[0..6]: bold fg=green
r0[11..16]: fg=cyan
r2[10..21]: fg=green
r3[10..11]: fg=green
r4[10..11]: fg=green
>>> assert_window_screen_box(
... win_captured,
... """
... ┌─────────────────────┐
... │200 OK │pg:up │
... │ready │ │
... │ ├──────────│
... │ │q=0 │
... │ │ │
... └─────────────────────┘
... """,
... cursor=(3, 14),
... )
>>> len(win_captured.panes), win_captured.zoomed, win_captured.layout_stable
(3, False, True)
>>> for p in split_win.panes:
... _ = p.send_vt_input("enter")
```

## Page through captured scrollback (`snap.viewport()`)

When `history_lines` retains primary scrollback (`None` for full history or a
Expand Down
Loading
Loading