Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d5b6818
Docs(feat[adr]): Add ADRs 0001-0010 for libvt
tony Nov 21, 2026
1f71633
Core(feat[vt]): Add VT engine, RLE grid, and tests
tony Nov 21, 2026
c2f36db
Docs(feat[site]): Add API reference and guides
tony Nov 21, 2026
94ef6f1
Core(fix[vt]): Harden UCD 17, parser, and grid
tony Nov 21, 2026
742256f
Aio(fix[pty]): Add TIOCSCTTY and boxed asserts
tony Nov 21, 2026
eadf3ac
Docs(docs[adr]): Sync ADRs and changelog
tony Nov 21, 2026
743728a
Core(fix[vt]): Harden UCD 17, grid, and PTY
tony Nov 22, 2026
63e126a
Docs(docs[adr]): Sync ADRs and changelog
tony Nov 22, 2026
ae61d4f
Screen(fix[resize]): Preserve pending_wrap on resize (#4)
tony Nov 22, 2026
a3ac0e9
Terminal(fix[sync]): Freeze ?2026 state at BSU (#5)
tony Nov 22, 2026
571ffd9
Terminal(fix[erase]): Keep viewport on CSI 3 J (#6)
tony Nov 22, 2026
5ad89f2
Terminal(feat[csi]): Add HPR and VPR motions (#7)
tony Nov 22, 2026
9d49d61
Grid(fix[margins]): Fix DECSLRM scroll and REP (#8)
tony Nov 22, 2026
22d9726
Format(fix[export]): Keep VT BCE and timeout info (#9)
tony Nov 22, 2026
5eda5ff
Config(feat[tmux]): Model phantom col and versions (#10)
tony Nov 22, 2026
6eee7b3
Parser(feat[scan]): Add regex and BMP fast paths (#11)
tony Nov 22, 2026
1827597
exc(fix[timeout]): Put diagnostics in notes (#15)
tony Nov 22, 2026
efc978a
ucd(perf[slice]): Add SAFE_NARROW_BMP_RE table (#16)
tony Nov 22, 2026
213ba0b
config(feat[tmux]): Add profile and row-gen fields (#17)
tony Nov 22, 2026
6f2d40b
graphics(feat[vt]): Add SIXEL and Kitty tracker (#14)
tony Nov 22, 2026
e85c42c
terminal(feat[sync]): Add deltas and graphics hooks (#13)
tony Nov 22, 2026
852eeb5
tmux(feat[capture]): Add capture-pane decoder (#18)
tony Nov 22, 2026
1997997
tests(refactor[suite]): Split tests by module
tony Nov 22, 2026
feccc67
tmux(fix[capture]): Support pre-3.8 capture-pane (#18)
tony Nov 22, 2026
d1ab911
tmux(fix[capture]): Decode ACS and tabs in -J wraps (#18)
tony Nov 22, 2026
83dd0a5
exc(fix[timeout]): Initialize C OSError slots in reconstructor (#15)
tony Nov 23, 2026
25ec9ea
grid(fix[cluster]): Copy base pen to SPACER_TAIL (#16)
tony Nov 23, 2026
7524975
terminal(feat[coords]): Resolve rows via at_abs (#19)
tony Nov 23, 2026
d9a0774
grid(fix[history]): Add CoW Sequence history (#20)
tony Nov 23, 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
39 changes: 22 additions & 17 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# AGENTS.md

libvt is a pure-Python, zero-dependency, typed virtual terminal emulator
and streaming VT parser (`Parser` → `Effects` → `Terminal` / `Screen` /
`Snapshot`). It ships an `asyncio` stream adapter (`libvt.aio`), a
namespace-safe pytest plugin (`libvt.pytest_plugin`), and visual boxed
screen assertions (`libvt.testing`), serving [libtmux](https://github.com/tmux-python/libtmux)
and general Python terminal testing without LGPL copyleft obligations.
and streaming VT parser (`Parser` → `Terminal` / `Screen` / `Snapshot` +
`Event`s). It ships a transport-only `asyncio` stream and POSIX PTY
adapter (`libvt.aio`), a namespace-safe pytest plugin
(`libvt.pytest_plugin`), mode-aware input encoders (`libvt.input`), and
visual boxed screen assertions (`libvt.testing`), serving
[libtmux](https://github.com/tmux-python/libtmux) and general Python
terminal testing without LGPL copyleft obligations.

Follow the conventions already in the tree, and keep a change scoped to
what was asked for.
Expand All @@ -14,13 +16,15 @@ what was asked for.

| Path | What it is |
| ---- | ---------- |
| `src/libvt/parser.py`, `modes.py`, `style.py` | VT500 byte parser, CSI subparameters, modes, and SGR styles |
| `src/libvt/_grid.py`, `screen.py`, `terminal.py` | Packed row storage, `Screen` / `ScreenSet`, `Terminal`, and `Snapshot` |
| `src/libvt/aio.py` | Transport-only `asyncio` stream wrapper (`AsyncTerminalStream`) |
| `src/libvt/testing.py`, `pytest_plugin.py` | Visual boxed screen assertions and `vt_*` pytest fixtures |
| `tests/` | Unit, property, and fixture tests, one file per module under test |
| `docs/` | Sphinx/MyST site: `topics/` (concepts), `api/` (autodoc), `project/` (contributing, releasing, ADRs) |
| `scripts/` | Cross-commit and in-process VT throughput benchmark harnesses |
| `src/libvt/parser.py`, `modes.py`, `style.py`, `config.py` | VT500 byte parser, CSI subparameters, modes, SGR styles, and `Profile` / `Policy` / `Limits` |
| `src/libvt/_ucd.py`, `_grid.py`, `screen.py`, `terminal.py` | Unicode 17 width/clustering tables, packed viewport & RLE scrollback rows, `Screen` / `ScreenSet`, `Terminal`, `Snapshot`, and `Formatter` |
| `src/libvt/status.py`, `events.py`, `input.py`, `codec.py` | Rex `OSC 7501` program status store, closed `Event` union, mode-aware input encoders, and cold-path VT sequence explainer |
| `src/libvt/graphics.py`, `tmux.py` | Zero-dependency `SIXEL` / Kitty `APC G` placement tracker and `tmux capture-pane` / `-CC` decoders |
| `src/libvt/aio.py`, `__main__.py` | `AsyncTerminalStream`, POSIX `open_pty()`, and `python -m libvt` CLI (`explain`, `render`, `strip`) |
| `src/libvt/testing.py`, `pytest_plugin.py`, `exc.py` | Boxed `assert_screen`, `FlightRecorder` diagnostics, `vt_*` pytest fixtures, and exceptions |
| `tests/` | Functional, property-fuzz, PTY, CLI, and fixture tests organized by module under test |
| `docs/` | Sphinx/MyST site: `topics/` (concepts), `api/` (autodoc), `project/` (contributing, releasing, ADRs `0001`–`0010`) |
| `scripts/` | Unicode table generator (`generate_ucd.py`) and VT throughput benchmarks (`bench_vt.py`, `benchmark.py`) |
| `README.md` | Doctested quickstart — every `>>> ` block is a real test |
| `CHANGES` | The changelog, rendered as a docs page |
| `MIGRATION` | Deprecation and migration notes |
Expand Down Expand Up @@ -51,14 +55,15 @@ be stated twice, the file listed above is the one that governs.
- A passing gate is evidence only once it has been shown capable of
failing. Pair a new test with a deliberate break that proves it bites.
- Maintain strict clean-room MIT provenance: derive state transitions
and test vectors from public standards (ECMA-48, DEC STD 070, Paul Flo
Williams' VT500 state diagram) and permissive (`MIT`, `ISC`,
`Apache-2.0`, `BSD`) references — never copy or translate from `LGPL`
or `GPL` terminal implementations (`pyte`, `vte`/GTK, `asciinema`).
and test vectors from public standards (ECMA-48, ITU T.416, Unicode
UAX #11 / #29, Paul Flo Williams' VT500 state diagram) and permissive
(`MIT`, `ISC`, `Apache-2.0`, `BSD`) references — never copy or
translate from `LGPL` or `GPL` terminal implementations (`pyte`,
`vte`/GTK, `asciinema`).

Python >= 3.12 is the compatibility floor, and runtime dependencies stay
empty (`dependencies = []`). Importing `libvt` performs no I/O and does
not load `asyncio` or `pytest`.
not load `asyncio`, `pty`, or `pytest`.

## References

Expand Down
107 changes: 107 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,110 @@
<!-- KEEP THIS PLACEHOLDER - DO NOT REMOVE OR MODIFY THIS LINE -->
_Notes on the upcoming release will go here._
<!-- END PLACEHOLDER - ADD NEW CHANGELOG ENTRIES BELOW THIS LINE -->

### What's new

#### Sans-I/O terminal core, two-tier RLE grid, and Unicode 17 width (#2)

{class}`~libvt.terminal.Terminal`, {class}`~libvt.screen.Screen`, and
{class}`~libvt.terminal.Snapshot` emulate primary and `?1049` alternate
screens with zero-based `(row, col)` coordinates, lazy 64-bit inline
viewport attributes, run-length-encoded scrollback history, and
primary-screen soft-wrap resize reflow. Top-level
{func}`~libvt.terminal.render`, {func}`~libvt.terminal.strip`, and
{func}`~libvt.codec.explain` helpers handle common rendering, stripping,
and sequence disassembly tasks, backed by `python -m libvt` CLI
subcommands.

{class}`~libvt.parser.Parser` decodes incremental UTF-8, colon-delimited
ITU T.416 SGR subparameters (`4:3`, `38:2::R:G:B`, `58:5:idx`), `G0`–`G3`
character-set designations (`ESC ( 0` DEC Special Graphics, `SO`/`SI`,
`SS2`/`SS3`), `HPR`/`VPR` (`CSI a` / `CSI e`), `CBT`/`CHT`,
`DECSCA`/`DECSED`/`DECSEL`, `CSI 3 J` / `CSI 22 J`, and `DCS tmux;`
passthrough framing while isolating UTF-8 `0x9C` and `U+009B` bytes from
8-bit `C1` controls (with optional `encoding="latin-1"` 8-bit wire mode).
SHA-256-pinned Unicode 17.0.0 two-stage tables drive East Asian width and
DEC `?2027` UAX #29 grapheme clustering across ZWJ emoji, Regional
Indicator flag pairs, Indic conjuncts, Hangul jamo, and `VS15` / `VS16`
emoji variation sequences. See {doc}`topics/architecture` for details.

#### Synchronized output stepping, Rex `OSC 7501`, and host queries (#2)

{meth}`~libvt.terminal.Terminal.committed`,
{meth}`~libvt.terminal.Terminal.feed_until`, and
{meth}`~libvt.terminal.Terminal.expire_synchronized_output` provide
lazy copy-on-write frame holds and generation-tagged timeout recovery
for DEC mode `?2026` synchronized updates.
{class}`~libvt.terminal.Formatter` exports snapshots to plain text, VT
escape sequences, and span-coalesced HTML with URI scheme allowlisting.

{class}`~libvt.status.ProgramStatusStore` and
{class}`~libvt.status.ProgramStatus` implement the Rex `OSC 7501`
Program Status specification, including hierarchical task identifiers,
ancestor `app` inheritance, urgency ranking, base64 `title`/`msg`
validation, profile- and policy-gated `OSC 7501 ; ?` capability replies,
`OSC 9;4` fallback, and lifecycle pruning alongside `OSC 133` prompt zones,
`OSC 7` RFC 8089 working directory updates, `OSC 52` clipboard writes,
`OSC 10`/`11` and `OSC 110`/`111` dynamic colors, `tmux` `ESC k` window
renames ({class}`~libvt.events.WindowRenamed`), `DA1`/`DA2`, `DSR`,
`DECRQM`, `DECRQSS`, `XTVERSION`, `XTGETTCAP`, and `?2031`/`?996n`
color-scheme queries. Configuration splits cleanly across {class}`~libvt.config.Profile`
(including versioned {meth}`~libvt.config.Profile.tmux` phantom-column
and resize compatibility profiles), {class}`~libvt.config.Policy`, and
{class}`~libvt.config.Limits`. See {doc}`topics/protocols-and-input` for
details.

#### Mode-aware input encoding, `asyncio` PTY bridge, and pytest plugin (#2)

{class}`~libvt.input.KeyEvent`, {class}`~libvt.input.MouseEvent`,
{class}`~libvt.input.FocusEvent`, and {class}`~libvt.input.PasteEvent`
encode outbound PTY bytes against active terminal modes, including
per-screen Kitty `CSI u` keyboard stacks (`>u`, `<u`, `=u`, `?u`), `SGR`
and `SGR-Pixel` mouse tracking (`?1006`, `?1016`), and fail-closed
bracketed paste validation raising {exc}`~libvt.exc.UnsafePasteError`.

{class}`~libvt.aio.AsyncTerminalStream` and {func}`~libvt.aio.open_pty`
connect sans-I/O terminals to `asyncio` streams and controlling POSIX
pseudo-terminals (`TIOCSCTTY` and `tty_mode`) without importing `asyncio`
or `pty` on `import libvt`. The `pytest11` plugin provides
protocol-typed `vt_terminal`, `vt_factory`, `vt_parser`, `vt_recorder`,
and `vt_pty` fixtures alongside {func}`~libvt.testing.assert_screen`,
{func}`~libvt.testing.assert_screen_box`,
{exc}`~libvt.exc.TerminalTimeoutError` stream diagnostics, and
{class}`~libvt.terminal.FlightRecorder` ring buffers. See
{doc}`topics/sync-and-asyncio` for details.

#### Incremental sync deltas, `tmux` capture reconstruction, and graphics (#13–#20)

{meth}`~libvt.terminal.Terminal.sync_token` and
{meth}`~libvt.terminal.Terminal.changes_since` emit non-destructive
multi-consumer {class}`~libvt.terminal.ScreenDelta` updates across both
`"committed"` (`?2026`-held) and `"working"` views, paired with
{meth}`~libvt.terminal.ScreenDelta.apply_lines`,
{meth}`~libvt.terminal.ScreenDelta.apply_rows`, and `O(1)` copy-on-write
{attr}`~libvt.terminal.Snapshot.history` sequence views.

{func}`~libvt.tmux.decode_tmux_capture`,
{class}`~libvt.tmux.TmuxPaneMetadata`, and
{func}`~libvt.tmux.unescape_tmux_control_output` reconstruct live
{class}`~libvt.terminal.Terminal` and {class}`~libvt.terminal.Snapshot`
state from `tmux capture-pane` (handling bare `SO`/`SI` ACS borders,
`GRID_FLAG_TAB` tabstops, `-F` / `-J` soft wraps, phantom-column
`pending_wrap`, and `-a` saved primary screens).
{mod}`libvt.graphics` tracks zero-dependency `SIXEL` and Kitty `APC G`
image metadata ({class}`~libvt.graphics.ImageMeta`) and monotonic
`abs_row` grid placements ({class}`~libvt.graphics.ImagePlacement` and
{meth}`~libvt.graphics.ImagePlacement.occupies_abs`) resolved alongside
{class}`~libvt.events.PromptZone` anchors via
{meth}`~libvt.terminal.Snapshot.at_abs` and
{meth}`~libvt.terminal.Snapshot.viewport_row`.
{exc}`~libvt.exc.TerminalTimeoutError` attaches multi-line viewport and
flight-recorder diagnostics via PEP 678 `__notes__` while keeping
`str(exc)` single-line.

### Documentation

- Add Architecture Decision Records `0001`–`0010` documenting clean-room
provenance, sans-I/O layering, two-tier RLE storage, Unicode 17
clustering, protocol semantics, input safety, and `asyncio`/pytest
boundaries in {doc}`project/adr/index` (#2).
65 changes: 61 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@ zero-dependency, typed virtual terminal emulator and streaming VT parser
[![tests](https://github.com/tmux-python/libvt/actions/workflows/tests.yml/badge.svg)](https://github.com/tmux-python/libvt/actions/workflows/tests.yml)
[![license](https://img.shields.io/badge/license-MIT-blue)](https://github.com/tmux-python/libvt/blob/master/LICENSE)

## Highlights

- **Sans-I/O core**: Zero runtime dependencies, zero I/O on `import libvt`,
and no `asyncio`, `pty`, or `pytest` imports until requested.
- **Compact two-tier grid**: Lazy 64-bit inline viewport attributes plus
run-length-encoded scrollback rows and primary-screen soft-wrap resize
reflow.
- **Unicode 17 clustering**: Bundled two-stage width and UAX #29 tables
handling CJK wide glyphs, ZWJ emoji, Regional Indicator flag pairs,
Indic conjuncts, and `VS15` / `VS16` under DEC `?2027`.
- **Modern terminal protocols**: Rex `OSC 7501` Program Status (with
`OSC 9;4` fallback), `OSC 133` semantic prompt zones, `OSC 7` working
directory, `OSC 8` hyperlinks, `OSC 52` clipboard, `?2026`
synchronized-output stepping, `DECRQM`, `DECRQSS`, `XTGETTCAP`, and
`DCS tmux;` passthrough events.
- **Mode-aware input & testing**: Outbound key/mouse/focus/paste
encoding (including Kitty `CSI u` and fail-closed bracketed paste),
`libvt.aio` stream and controlling-TTY POSIX PTY helpers, `vt_*`
pytest fixtures, and `assert_screen` / `assert_screen_box` diffs with
`FlightRecorder` disassembly.

## Requirements

- Python >= 3.12 (CPython and PyPy)
Expand All @@ -31,13 +52,49 @@ $ pip install libvt

## Quickstart

`libvt` performs no network or filesystem I/O and leaves `asyncio`
unloaded on `import libvt`:
One-liner helpers render, strip, or disassemble VT byte streams without
managing an emulator instance:

```python
>>> import libvt
>>> libvt.__title__
'libvt'
>>> libvt.render(b"\x1b[1;32mready\x1b[0m\r\nitem 1", rows=4, cols=20)
'ready\nitem 1'
>>> libvt.strip(b"\x1b[31merror:\x1b[0m failed")
'error: failed'
```

Stateful emulation tracks zero-based `(row, col)` cells, SGR colon
subparameters, query replies, and `OSC 7501` program status:

```python
>>> term = libvt.Terminal(rows=4, cols=20)
>>> term.feed(b"\x1b[1;4:3;38:2::40:180:160mstatus\x1b[0m\x1b[6n")
>>> term[0, 0].style.underline
<UnderlineStyle.CURLY: 3>
>>> term.drain_replies()
b'\x1b[1;7R'
>>> term.feed(b"\x1b]7501;state=working:id=build:progress=60\x1b\\")
>>> term.program_status.value, term.program_status.progress
('working', 60)
```

Boxed visual assertions verify CJK wide-character alignment and cursor
coordinates in tests:

```python
>>> from libvt.testing import assert_screen_box
>>> t = libvt.Terminal(rows=2, cols=8)
>>> t.feed("日本ok\r\ndone".encode())
>>> assert_screen_box(
... t,
... """
... ┌────────┐
... │日本ok │
... │done │
... └────────┘
... """,
... cursor=(1, 4),
... )
```

## License
Expand Down
7 changes: 6 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
import pytest

import libvt
from libvt.testing import assert_screen, assert_screen_box


@pytest.fixture(autouse=True)
def _seed_doctest_namespace(doctest_namespace: dict[str, t.Any]) -> None:
"""Populate doctest globals with ``libvt``."""
"""Populate doctest globals with common ``libvt`` entry points."""
doctest_namespace["libvt"] = libvt
doctest_namespace["Terminal"] = libvt.Terminal
doctest_namespace["AnsiColor"] = libvt.AnsiColor
doctest_namespace["assert_screen"] = assert_screen
doctest_namespace["assert_screen_box"] = assert_screen_box
6 changes: 6 additions & 0 deletions docs/api/aio.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# `libvt.aio`

```{eval-rst}
.. automodule:: libvt.aio
:members:
```
6 changes: 6 additions & 0 deletions docs/api/codec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# `libvt.codec`

```{eval-rst}
.. automodule:: libvt.codec
:members:
```
6 changes: 6 additions & 0 deletions docs/api/config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# `libvt.config`

```{eval-rst}
.. automodule:: libvt.config
:members:
```
6 changes: 6 additions & 0 deletions docs/api/events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# `libvt.events`

```{eval-rst}
.. automodule:: libvt.events
:members:
```
6 changes: 6 additions & 0 deletions docs/api/exc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# `libvt.exc`

```{eval-rst}
.. automodule:: libvt.exc
:members:
```
6 changes: 6 additions & 0 deletions docs/api/graphics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# `libvt.graphics`

```{eval-rst}
.. automodule:: libvt.graphics
:members:
```
Loading
Loading