Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cd053b1
docs(readme): Drive a real terminal program
tony Dec 1, 2026
ab3dca9
CHANGES(docs): Show a child responding in a PTY
tony Dec 3, 2026
addc80f
snapshot(feat): Locate text by cell coordinates
tony Dec 5, 2026
32f1bfd
docs(snapshot): Document CellSpan ownership
tony Dec 5, 2026
3b71dd5
CHANGES(docs): Describe matches in display cells
tony Dec 5, 2026
938735d
docs(testing): Drive an interactive fzf picker
tony Dec 1, 2026
d733fad
docs(fzf): Name the empty cancellation result
tony Dec 1, 2026
c113cd1
docs(fzf): Bound the picker test environment
tony Dec 3, 2026
15942ef
CHANGES(docs): Document fzf selection and cancel
tony Dec 3, 2026
faadbb7
docs(readme): Use full GitHub URL for fzf cookbook link
tony Dec 5, 2026
befb5fe
pytest(feat): Replay failed terminal screens
tony Dec 5, 2026
56d7b8a
docs(replay): Document pytest terminal replays
tony Dec 5, 2026
6d5ffbd
docs(testing): Drive a playable terminal game
tony Dec 1, 2026
09b64c7
docs(game): Guard POSIX terminal setup on Windows
tony Dec 1, 2026
d55d61d
docs(game): Validate the example walkthrough
tony Dec 3, 2026
9a54ff2
CHANGES(docs): Document The Last Beacon replay
tony Dec 3, 2026
2aed448
docs(game): Narrow FlightRecorder and use full README docs URL
tony Dec 5, 2026
188c314
docs(tmux): Compare the pane and attached client
tony Dec 1, 2026
5e12ba1
docs(tmux): Include the tested coordinate formula
tony Dec 1, 2026
f26b67c
docs(tmux): Guard the POSIX mouse guest
tony Dec 1, 2026
9617134
docs(tmux): Verify attached client observations
tony Dec 3, 2026
d85290c
CHANGES(docs): Distinguish pane and client views
tony Dec 3, 2026
a12dc76
docs(readme): Use full docs and GitHub URLs for tmux guide links
tony Dec 5, 2026
0eb832a
aio(refactor[pty]): Share POSIX PTY setup helpers
tony Dec 5, 2026
eaa0410
contrib(feat): Drive terminal subprocesses
tony Dec 5, 2026
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
60 changes: 60 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ _Notes on the upcoming release will go here._

### What's new

#### Drive terminal processes synchronously (#142)

{func}`~libvt.contrib.subprocess.open_terminal` opens an interactive child on a
POSIX PTY or Windows ConPTY, returning a
{class}`~libvt.contrib.subprocess.TerminalProcess` handle. Use
{func}`~libvt.contrib.subprocess.run_terminal` to collect a child's exit
status, final viewport, and bounded output in a
{class}`~libvt.contrib.subprocess.CompletedTerminal` result. Both
{class}`~libvt.contrib.subprocess.TerminalProcess` and
{class}`~libvt.contrib.subprocess.Capture` implement
{class}`~libvt.testing.SupportsVtTarget` for
{func}`~libvt.testing.vt_screen` and
{func}`~libvt.testing.serialize_vt_snapshot`.

#### Recorder protocol, target protocol, and state replacement (#203)

Pass any {class}`~libvt.recorder.TerminalRecorder` implementation to
Expand All @@ -26,6 +40,28 @@ directly. {func}`~libvt.modes.is_private_mode_supported` exposes profile mode
support queries, and {class}`~libvt.snapshot.SnapshotDict` types the dictionary
returned by {meth}`~libvt.snapshot.Snapshot.to_dict`.

#### Find snapshot text by cell coordinates (#133)

{meth}`~libvt.snapshot.Snapshot.find_cells` returns each visible match as a
{class}`~libvt.snapshot.CellSpan` with a row and a half-open column range.
Use the coordinates to click or inspect labels that include wide or
combined graphemes.

#### Replay failed pytest terminal tests (#139)

Run pytest with `--vt-replay-dir` to save the bytes fed to the terminal,
resizes, initial encoding, and the observed screen from a failed test. Run
`python -m libvt replay` on the saved file to check the final rows, wraps,
styles, and cursor offline. See {ref}`replaying-pytest-failures`.

### Fixes

#### Identify hidden screen assertion differences (#139)

{func}`~libvt.testing.assert_screen` reports the first differing row or
column even when box padding hides a written space or expected text lies
beyond the viewport.

### Documentation

#### Split API reference into per-module pages
Expand All @@ -36,6 +72,30 @@ Add dedicated API reference pages for {mod}`libvt.views`,
`syrupy`) into per-module directories, and add Sphinx `rediraffe` redirects for
moved API URLs.

#### Drive a Python child from the README (#131)

The README example starts a child in a POSIX terminal, sends input, and
waits for the child's response on screen. Use it to check that a program
consumed input after the terminal echoed it.

#### Test selection and cancellation in fzf (#138)

The {ref}`fzf recipe <topics-testing-fzf>` drives a real picker in a private
PTY. Check the highlighted item, selected output, and exit status after
sending Enter or Escape.

#### Play and replay The Last Beacon (#140)

The {ref}`game walkthrough <topics-interactive-game>` drives a playable
terminal game, checks its winning screen after resizing, and replays a
saved run from the command line.

#### Observe a pane and its attached tmux client (#141)

The {doc}`tmux screen guide <topics/tmux-screens>` compares application
output with an attached client's copy-mode view. The example translates a
pane-local click after resize and checks which child received it.

## libvt 0.0.1a6 (2026-12-05)

`libvt` 0.0.1a6 adds soft-wrapped logical-line reading and `wait_for()`
Expand Down
56 changes: 53 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,32 @@ or use it to test terminal programs.
Requires Python 3.12 or later (CPython and PyPy). Written in Python, with type
annotations and no runtime dependencies.

## Drive a terminal program

On POSIX, use [`open_pty()`][open_pty] to launch a program, send input, and
wait for a response on its screen. The child prints `Taken: key` after it
reads the command.

```python
>>> import asyncio
>>> import os
>>> import sys
>>> from libvt.aio import open_pty

>>> async def take_key() -> None:
... child = "print('Quay'); print('Taken: ' + input())"
... async with open_pty([sys.executable, "-u", "-c", child]) as session:
... await session.wait_for("Quay", timeout=5)
... session.paste("key")
... session.send_key("enter")
... await session.wait_for(
... lambda screen: "Taken: key" in screen.lines, timeout=5
... )

>>> if os.name == "posix":
... asyncio.run(take_key())
```

## Installation

Install with `uv`:
Expand Down Expand Up @@ -41,6 +67,9 @@ breaking API changes; pin `libvt>=0.0.1a6,<0.1` while the package is pre-1.0.

## Quickstart

For a complete PTY walkthrough,
[play, test, and replay The Last Beacon](https://libvt.git-pull.com/topics/interactive-game/).

### Feed bytes and inspect immutable snapshots

Each call to [`feed()`][feed] updates the screen. Read live text and cursor
Expand All @@ -65,8 +94,13 @@ styles:
r0[0..11]: bold fg=green
>>> snap.viewport(offset=1).lines
('booting', 'Loading 20%')
>>> snap.find_cells("done")
(CellSpan(row=1, start=0, stop=4),)
```

Use [`Snapshot.find_cells()`][find_cells] to turn a visible label into cell
coordinates for a click, highlight, or assertion.

### Assert screen boxes inline

Most unit tests can stop at [`assert_screen_box()`][assert_screen_box], which
Expand Down Expand Up @@ -133,7 +167,10 @@ styles:

[`libvt.pytest_plugin`][pytest_plugin] (`libvt[pytest]`) provides `vt_terminal`
(wired to a 4 KiB `FlightRecorder`), `vt_factory`, `vt_recorder`, `vt_parser`,
and POSIX `vt_pty` fixtures with no snapshot-tool dependencies:
and POSIX `vt_pty` fixtures with no snapshot-tool dependencies.

Use `--vt-replay-dir` to [replay a failed terminal test][pytest_replay]
from the bytes and resizes saved by pytest.

```python
>>> import libvt
Expand All @@ -155,6 +192,10 @@ and POSIX `vt_pty` fixtures with no snapshot-tool dependencies:
>>> test_prompt(libvt.Terminal)
```

The [fzf cookbook test](https://github.com/tmux-python/libvt/blob/master/tests/test_fzf_cookbook.py)
checks the highlighted row, the record accepted with Enter, and the empty result
on Escape.

### Persist `.ambr` snapshots (`libvt[syrupy]`)

[`libvt.contrib.syrupy`][contrib_syrupy] (`libvt[syrupy]`) adapts
Expand Down Expand Up @@ -203,22 +244,31 @@ styles:
(`?2026`).
- Encode keyboard, mouse, focus, and paste events according to the active
terminal modes.
- Drive [terminal processes](https://libvt.git-pull.com/api/contrib/subprocess/)
synchronously on POSIX or Windows.
- Run terminal programs on POSIX PTYs or connect to `asyncio` streams.

Read `tmux` captures as screen cells and decode control-mode output with
[`libvt.contrib.tmux`](https://libvt.git-pull.com/api/contrib/tmux/). Full
guides and API reference are at [libvt.git-pull.com](https://libvt.git-pull.com/).
[`libvt.contrib.tmux`](https://libvt.git-pull.com/api/contrib/tmux/). See
[Which screen am I testing?](https://libvt.git-pull.com/topics/tmux-screens/)
and its
[runnable example](https://github.com/tmux-python/libvt/blob/master/examples/tmux_screens.py)
for attached-client checks. Full guides and API reference are at
[libvt.git-pull.com](https://libvt.git-pull.com/).

## License

MIT License. See [LICENSE](LICENSE).

[open_pty]: https://libvt.git-pull.com/api/aio/pty/#libvt.aio.open_pty
[feed]: https://libvt.git-pull.com/api/terminal/#libvt.terminal.Terminal.feed
[find_cells]: https://libvt.git-pull.com/topics/snapshots/#locate-text-by-cell-coordinates
[committed]: https://libvt.git-pull.com/api/terminal/#libvt.terminal.Terminal.committed
[viewport]: https://libvt.git-pull.com/api/snapshot/#libvt.snapshot.Snapshot.viewport
[assert_screen_box]: https://libvt.git-pull.com/api/testing/#libvt.testing.assert_screen_box
[contrib_syrupy]: https://libvt.git-pull.com/api/contrib/syrupy/
[pytest_plugin]: https://libvt.git-pull.com/api/pytest_plugin/
[pytest_replay]: https://libvt.git-pull.com/topics/testing/#replay-a-failed-terminal-test
[vt_snapshot]: https://libvt.git-pull.com/api/contrib/syrupy/#libvt.contrib.syrupy.vt_snapshot
[vt_screen]: https://libvt.git-pull.com/api/testing/#libvt.testing.vt_screen
[serialize_vt_snapshot]: https://libvt.git-pull.com/api/testing/#libvt.testing.serialize_vt_snapshot
Expand Down
7 changes: 7 additions & 0 deletions docs/api/contrib/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ Decoupled `tmux` profiles, `capture-pane` decoders, multi-pane window
compositing, and `-C` / `-CC` control-mode synchronization.
:::

:::{grid-item-card} `libvt.contrib.subprocess`
:link: subprocess
:link-type: doc
Synchronous child processes on POSIX PTYs and Windows ConPTY.
:::

:::{grid-item-card} `libvt.contrib.syrupy`
:link: syrupy
:link-type: doc
Expand All @@ -30,5 +36,6 @@ fixture (`libvt[syrupy]`).
:maxdepth: 2
tmux/index
subprocess
syrupy
```
86 changes: 86 additions & 0 deletions docs/api/contrib/subprocess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Synchronous terminal processes

Use {mod}`libvt.contrib.subprocess` to drive a terminal application from
synchronous Python. The session reads merged terminal output in the
background while your test waits for text, sends keys, or resizes the
viewport.

```python
>>> import ctypes
>>> import sys
>>> from libvt.contrib import subprocess as sp
>>> command = [sys.executable, "-u", "-c",
... "print('Ready'); print('Result:', input()[::-1])"]
>>> supported = sys.platform != "win32" or hasattr(
... ctypes.WinDLL("kernel32"), "ReleasePseudoConsole",
... )
>>> if supported:
... with sp.open_terminal(command, vt=sp.VT(rows=6, cols=40)) as child:
... _ = child.wait_for("Ready", timeout=8)
... child.resize(rows=8, cols=48)
... child.paste("pear")
... child.send_key("enter")
... status = child.wait(timeout=8)
... final = child.wait_eof(timeout=8)
... assert status == 0 and final.snapshot.cols == 48
... assert "Result: raep" in final.snapshot.text
```

{meth}`~libvt.contrib.subprocess.TerminalProcess.wait` returns the direct
child's exit status. Use
{meth}`~libvt.contrib.subprocess.TerminalProcess.wait_eof` to collect the
final output after every process attached to the terminal has closed its
terminal handles. Descendants can keep the terminal open after the direct
child exits. Both waits accept timeouts and leave the live handle available
when they time out.
{meth}`~libvt.contrib.subprocess.TerminalProcess.wait_for` times out through
{exc}`libvt.exc.TerminalTimeoutError`.

For a command that finishes on its own, call
{func}`~libvt.contrib.subprocess.run_terminal`. It waits for both the direct
child and terminal EOF. Its timeout covers both waits after launch. It closes
the terminal and reaps the direct child before raising
{exc}`~libvt.contrib.subprocess.TerminalTimeoutExpired`. Use the exception's
`phase` and `capture` to inspect where it timed out and what it recorded. The
optional `input` bytes are queued after launch. Interactive commands that
wait for a prompt before accepting input work with
{func}`~libvt.contrib.subprocess.open_terminal`.

Use the live handle from its creating thread.
{meth}`~libvt.contrib.subprocess.TerminalProcess.close` and context exit shut
down the terminal and may interrupt its remaining clients. Call `wait_eof()`
first when their output matters. On POSIX, a descendant that ignores hangup
can outlive the terminal after the direct child exits. This also applies when
`run_terminal()` closes a terminal after a timeout.
{class}`~libvt.contrib.subprocess.Capture`,
{class}`~libvt.contrib.subprocess.CompletedTerminal`, and
{class}`~libvt.contrib.subprocess.TerminalProcess` implement
{class}`~libvt.testing.SupportsVtTarget` so you can pass them directly to
{func}`~libvt.testing.vt_screen` and
{func}`~libvt.testing.serialize_vt_snapshot`.

The result includes a snapshot, the retained raw tail, and the total number
of recorded bytes. The terminal and recorder retain only the configured
scrollback and byte tail (`raw_limit=0` disables raw tail retention while
still counting `raw_total`). Raw bytes include terminal control sequences and
native console translation.

Terminal mode uses a POSIX PTY or native ConPTY. On macOS a single-trampoline
helper owns the terminal session over a socketpair so the direct child's exit
leaves the terminal available to descendants.

Opening `/dev/tty` can leave a Darwin kernel reference to the terminal until
the session closes. If that reference keeps EOF pending, use `close()` after
collecting the output you need.
[Apple's controlling-terminal driver](https://github.com/apple-oss-distributions/xnu/blob/f6217f891ac0bb64f3d375211650a4c1ff8ca1ea/bsd/kern/tty_tty.c)

On Windows terminal mode requires `ReleasePseudoConsole` (Windows 11 24H2 or
Windows Server 2025, build 26100) to observe natural EOF after the last
console client exits. Pass an absolute executable path when you need
consistent executable selection across operating systems.
[Microsoft's ReleasePseudoConsole documentation](https://learn.microsoft.com/en-us/windows/console/releasepseudoconsole)

```{eval-rst}
.. automodule:: libvt.contrib.subprocess
:members: VT, Capture, CompletedTerminal, TerminalProcess, CalledTerminalError, TerminalTimeoutExpired, open_terminal, run_terminal
```
6 changes: 6 additions & 0 deletions docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ Import-light `vt_terminal`, `vt_factory`, `vt_recorder`, `vt_parser`, and
Decoupled `tmux` `profile`, `capture`, `window`, and `control` submodules.
:::

:::{grid-item-card} `libvt.contrib.subprocess`
:link: contrib/subprocess
:link-type: doc
Synchronous child processes on POSIX PTYs and Windows ConPTY.
:::

:::{grid-item-card} `libvt.contrib.syrupy`
:link: contrib/syrupy
:link-type: doc
Expand Down
2 changes: 1 addition & 1 deletion docs/api/terminal.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ re-exports live in their owning modules: {mod}`libvt.snapshot`,
.. automodule:: libvt.terminal
:members: Terminal, StopOn, StepResult, render, strip
:no-private-members:
:exclude-members: _state, __new__, FlightRecorder, Formatter, OutputFormat, ResyncReason, ScreenDelta, Snapshot, SnapshotDict, SyncToken, SyncView, TerminalRecorder
:exclude-members: _state, __new__, CellSpan, FlightRecorder, Formatter, OutputFormat, ResyncReason, ScreenDelta, Snapshot, SnapshotDict, SyncToken, SyncView, TerminalRecorder
```
6 changes: 5 additions & 1 deletion docs/project/public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ Import specialized types and helpers from their owning submodules:
- {mod}`libvt.parser`, {mod}`libvt.screen`, {mod}`libvt.views`,
{mod}`libvt.snapshot`, {mod}`libvt.format`, {mod}`libvt.recorder`, and
{mod}`libvt.terminal` — streaming VT500 parser, screen grids and views,
immutable snapshots and incremental {class}`~libvt.snapshot.SyncToken` /
immutable snapshots, incremental {class}`~libvt.snapshot.SyncToken` /
{class}`~libvt.snapshot.ScreenDelta` replicas,
{class}`~libvt.snapshot.CellSpan` coordinates,
{class}`~libvt.format.Formatter`, and {class}`~libvt.recorder.TerminalRecorder`
- {mod}`libvt.input`, {mod}`libvt.aio`, and {mod}`libvt.codec` — mode-aware
input encoders, {class}`~libvt.aio.AsyncSession` transports, and sequence
Expand All @@ -44,6 +45,9 @@ Import specialized types and helpers from their owning submodules:
{mod}`~libvt.contrib.tmux.control`) — decoupled `tmux` inner-pane profiles,
`capture-pane` decoders, multi-pane window compositing, and `-C` / `-CC`
control-mode parser and pane sync
- {mod}`libvt.contrib.subprocess` — synchronous child processes with
{func}`~libvt.contrib.subprocess.open_terminal` and
{func}`~libvt.contrib.subprocess.run_terminal` on POSIX PTYs and Windows ConPTY
- {mod}`libvt.contrib.syrupy` — optional `syrupy` `.ambr` adapter
(`libvt[syrupy]`): {class}`~libvt.contrib.syrupy.VtSnapshotExtension` and
conditional {fixture}`vt_snapshot` `pytest11` fixture
Expand Down
16 changes: 16 additions & 0 deletions docs/topics/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ Immutable {class}`~libvt.snapshot.Snapshot` captures, {attr}`~libvt.terminal.Ter
Three decoupled testing systems built on snapshots: {mod}`libvt.testing`, {mod}`libvt.pytest_plugin` (`libvt[pytest]`), and {mod}`libvt.contrib.syrupy` (`libvt[syrupy]`).
:::

:::{grid-item-card} Test an Interactive Game
:link: interactive-game
:link-type: doc
Drive a text adventure on a PTY, verify its window size and replay the
winning screen.
:::

:::{grid-item-card} Which screen am I testing?
:link: tmux-screens
:link-type: doc
Compare a tmux pane with an attached client in copy mode and route a mouse
click after a resize.
:::

:::{grid-item-card} Synchronized Output & `asyncio`
:link: sync-and-asyncio
:link-type: doc
Expand Down Expand Up @@ -55,6 +69,8 @@ Differences in terminal construction, coordinates, alternate screens, and query
architecture
snapshots
testing
interactive-game
tmux-screens
sync-and-asyncio
protocols-and-input
migrating-from-pyte
Expand Down
Loading
Loading