Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
run: |
aws cloudfront create-invalidation \
--distribution-id "${{ secrets.LIBVT_DOCS_DISTRIBUTION }}" \
--paths "/index.html" "/objects.inv" "/searchindex.js"
--paths "/*"

- name: Purge cache on Cloudflare
if: env.BUILD_DOCS == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/master' && vars.LIBVT_DOCS_DEPLOY == 'true'
Expand Down
49 changes: 48 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: read
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
Expand All @@ -35,11 +38,55 @@ jobs:
- name: Tests (pytest)
run: uv run pytest -m ""

test-macos:
runs-on: macos-latest
permissions:
contents: read
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
- uses: astral-sh/setup-uv@v10.2.0
with:
version-file: .tool-versions
enable-cache: true
- uses: actions/setup-python@v7
with:
python-version: "3.14"
- name: Install dependencies
run: uv sync --all-groups
- name: Type check (ty)
run: uv run ty check --output-format github
- name: Tests (pytest + POSIX PTY)
run: uv run pytest -m ""

test-windows:
runs-on: windows-latest
permissions:
contents: read
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
- uses: astral-sh/setup-uv@v10.2.0
with:
version-file: .tool-versions
enable-cache: true
- uses: actions/setup-python@v7
with:
python-version: "3.14"
- name: Install dependencies
run: uv sync --all-groups
- name: Type check (ty)
run: uv run ty check --output-format github
- name: Tests (portable core + stream)
run: uv run pytest -m ""

release:
runs-on: ubuntu-latest
needs: test
needs: [test, test-macos, test-windows]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
timeout-minutes: 10
permissions:
contents: read
id-token: write
attestations: write

Expand Down
171 changes: 171 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,177 @@
_Notes on the upcoming release will go here._
<!-- END PLACEHOLDER - ADD NEW CHANGELOG ENTRIES BELOW THIS LINE -->

### Breaking changes

#### Cell-calibrated `MouseEvent.pixel_x` and `pixel_y` defaults (#26)

{attr}`~libvt.input.MouseEvent.pixel_x` and
{attr}`~libvt.input.MouseEvent.pixel_y` now default to `None`
(`int | None = None`) instead of `0` so `?1016` SGR-Pixel encoding derives
cell-center pixel coordinates from `row`, `col`, and
{class}`~libvt.config.Profile` cell geometry unless explicit pixel coordinates
are supplied:

```python
# Before
ev = MouseEvent(button=MouseButton.LEFT, action=MouseAction.PRESS, row=2, col=3)
assert (ev.pixel_x, ev.pixel_y) == (0, 0)

# After
ev = MouseEvent(button=MouseButton.LEFT, action=MouseAction.PRESS, row=2, col=3)
assert (ev.pixel_x, ev.pixel_y) == (None, None) # encodes cell center (28, 40)
```

#### Scoped `CSI 5:3 m` overline decoding (#18)

{func}`~libvt.parser.parse_sgr` and live {meth}`~libvt.terminal.Terminal.feed`
ignore `CSI 5:3 m` (`5` with colon subparameter `3`, neither enabling overline
nor blink), matching `tmux` and `Ghostty` input parsing, while
{func}`~libvt.tmux.decode_tmux_capture` continues decoding `tmux`
`grid_string_cells_code`'s `5:3m` overline serialization:

```python
# Before
style = parse_sgr(CsiParams((5, 3), colon_mask=0b10)) # overline=True

# After
style = parse_sgr(CsiParams((53,))) # standard SGR 53 overline
res = decode_tmux_capture(["\x1b[5:3mOV\x1b[0m"], rows=1, cols=4)
```

#### Opaque per-terminal sync watermarks (#22)

{class}`~libvt.terminal.SyncToken` keeps its watermark state private, disallows
direct instantiation, and renders a compact `repr()`. Read snapshot state from
{attr}`~libvt.terminal.ScreenDelta.snapshot` rather than inspecting token
attributes directly:

```python
# Before
cur = tok.cursor

# After
delta = term.changes_since(tok)
cur = delta.snapshot.cursor
```

### What's new

#### `OSC 4`/`12` queries, `XTMODKEYS`, `?1007`, and pixel `?1016` (#26)

{class}`~libvt.terminal.Terminal` answers `OSC 4` / `OSC 104` 256-palette
overrides and queries, semicolon-chained `OSC 10`–`12` / `OSC 110`–`112`
foreground, background, and cursor color queries
({attr}`~libvt.config.Profile.cursor_rgb`), `DECRQM` across all ANSI and DEC
modes, `XTSMGRAPHICS` (`CSI ? Pi ; Pa ; Pv S` returning `\x1b[?{pi};3S`), and
`XTMODKEYS` (`CSI > 4 ; pv m` and `CSI ? 4 m` via
{attr}`~libvt.terminal.Terminal.modify_other_keys` and
{attr}`~libvt.screen.Screen.modify_other_keys`), while consuming `OSC 9`,
`OSC 99`, and `OSC 777` notifications silently.
{func}`~libvt.input.encode_input` and {meth}`~libvt.terminal.Terminal.encode`
encode `XTMODKEYS` levels `1` and `2`, default-enabled `?1007`
({attr}`~libvt.modes.Mode.ALTERNATE_SCROLL`) wheel-to-arrow presses on the
alternate screen, and cell-calibrated `?1016`
({attr}`~libvt.input.MouseEvent.pixel_x` /
{attr}`~libvt.input.MouseEvent.pixel_y`) mouse coordinates, while
{meth}`~libvt.terminal.Terminal.resize`, {func}`~libvt.aio.open_pty`, and
{meth}`~libvt.aio.PtySession.resize` report pixel dimensions in `?2048` and
`TIOCSWINSZ`.

#### Chained `tmux` capture bundles and `-N -T -F` wide-wrap decoding (#18)

{func}`~libvt.tmux.build_tmux_capture_command` and
{class}`~libvt.tmux.TmuxCaptureCommand` construct single-invocation `tmux`
command chains bracketing `capture-pane -S - -E - -e -p -N -T -F` (`-e -p -N
-T` + `-e -p -J` on `3.4`–`3.7`, `-e -p -N` + `-e -p -J` on `3.3a`) with
`display-message` metadata headers and footers so pane output cannot drift
mid-capture and trailing blank viewport lines survive line-splitting wrappers.
{func}`~libvt.tmux.decode_tmux_capture`,
{meth}`~libvt.terminal.Terminal.from_tmux_capture`, and
{meth}`~libvt.terminal.Snapshot.from_tmux_capture` accept `trim_trailing=True`
to preserve explicit trailing spaces and disambiguate `GRID_FLAG_PADDING`
wide-wrap spacers in a single pass.

### Fixes

#### `BCE` hyperlinks, `SU` scrollback, `DEL` UTF-8 flush, and profiles (#25)

{class}`~libvt.terminal.Terminal` strips `OSC 8` hyperlinks from `BCE` blank
fills, pushes primary-screen `SU` (`CSI Ps S`) lines into scrollback when
unbounded horizontally, ignores non-`m` `CSI` sequences carrying `:`
subparameters while restricting {func}`~libvt.parser.parse_sgr` colons to
well-formed `4`/`38`/`48`/`58` groups, and flushes incomplete multi-byte UTF-8
sequences on `0x7F` (`DEL`) in {class}`~libvt.parser.Parser`. `DECSLRM` partial
scrolls preserve wide glyphs wholly inside `[left, right]`, and
{class}`~libvt.terminal.Formatter` restores `IRM`, `DECOM`, `DECLRMM`, and
`DECSCUSR` after rendering cells while padding `wrapped=True` rows to `cols`.
{class}`~libvt.config.Profile` splits {data}`~libvt.config.DEFAULT_PROFILE` and
{data}`~libvt.config.XTERM_PROFILE` (VT510 `DECSTR` mode set, shared primary
`DECSC`/`?1049h` save slot with isolated alternate `DECSC` slot, and
`SS2`/`SS3` single-shift preservation) from {data}`~libvt.config.TMUX_PROFILE`
({attr}`~libvt.config.Profile.declrmm_enabled` `False` so `CSI 5;10 s` saves
the cursor, {attr}`~libvt.config.Profile.top_margin_scrolls_to_history` `True`,
and {attr}`~libvt.config.Profile.separate_alt_save_cursor` `True`).

#### Buffered PTY writes, `?2026` EOF expiry, and frame-commit wakeups (#24)

{class}`~libvt.aio.PtySession` queues synchronous
{meth}`~libvt.aio.PtySession.send`, {meth}`~libvt.aio.PtySession.paste`, and
terminal query auto-replies onto a single bounded FIFO drained via
`loop.add_writer` with {meth}`~libvt.aio.PtySession.drain` high-water
backpressure, keeping bracketed pastes atomic above kernel `TTYHOG` limits
while flushing `?2048` replies inside {meth}`~libvt.aio.PtySession.resize` and
closing `master_fd` inside non-awaiting `finally` guards.
{class}`~libvt.aio.AsyncTerminalStream` and {class}`~libvt.aio.PtySession`
drive {meth}`~libvt.aio.AsyncTerminalStream.wait_for` and
{meth}`~libvt.aio.PtySession.wait_for` from
{attr}`~libvt.terminal.Terminal.committed_generation` and expire unclosed
`?2026` holds on `EOF`, {meth}`~libvt.aio.AsyncTerminalStream.aclose`, and
{meth}`~libvt.aio.PtySession.aclose`.

#### Bounded ASCII integer parsing and UTF-8 event accounting (#23)

{class}`~libvt.parser.Parser`, {class}`~libvt.terminal.Terminal`,
{mod}`libvt.graphics`, {mod}`libvt.status`, and {mod}`libvt.tmux` parse numeric
parameters strictly from ASCII digits `0`–`9` with bounded accumulators
(`<= 65535` for `OSC` command codes, unsigned 32-bit Kitty `i=` / `I=` / `p=` /
`P=` / `Q=` identifiers, and signed 32-bit `OSC 133;D` exit codes), while
{meth}`~libvt.terminal.Terminal.feed` isolates malformed `OSC 7` / `OSC 9;9`
URIs and non-hex `OSC 10` / `OSC 11` color specs without raising `ValueError`.
Event retention limits charge UTF-8 payload bytes across every `Event` variant
in {mod}`libvt.events` under {attr}`~libvt.config.Limits.max_event_bytes`.

#### Per-terminal sync isolation and horizontal-margin edits (#22)

{meth}`~libvt.terminal.Terminal.sync_token` and
{meth}`~libvt.terminal.Terminal.changes_since` isolate row-mutation watermarks
per {class}`~libvt.terminal.Terminal` instance and report every cell,
soft-wrap, and direct {attr}`~libvt.terminal.Terminal.screen` mutation in
{attr}`~libvt.terminal.ScreenDelta.dirty_rows`, while `ICH` and `DCH` outside
`DECLRMM` horizontal margins leave soft-wrapped rows intact.

#### Graphics retention, `DECSTBM` `SIXEL` masking, and streaming reflow (#21)

{meth}`~libvt.graphics.GraphicsTracker.on_region_scroll` preserves `SIXEL`
visibility masks and scrollback-bound placements when `DECSTBM` top-zero
margins advance scrollback history. {meth}`~libvt.terminal.Terminal.resize`
and {meth}`~libvt.screen.Screen.resize` retain stored images and placements
across reflow and non-reflow resizes, stream unwrapped scrollback lines that
fit within `cols` in `O(1)` per row without reallocating history blocks,
preserve monotonic {attr}`~libvt.terminal.Snapshot.scrolled_total`
continuity, and remap {class}`~libvt.events.PromptZone` and cell-anchored
Kitty {class}`~libvt.graphics.ImagePlacement` `(abs_row, col)` pins.

### Development

#### macOS PTY and Windows portable-core CI (#3)

GitHub Actions exercises Darwin {func}`~libvt.aio.open_pty` (`TIOCSCTTY`,
`TTYHOG` write queueing, and fast-exiting child drain) on `macos-latest` and
portable sans-I/O and {class}`~libvt.aio.AsyncTerminalStream` tests plus `ty`
checks on `windows-latest`, alongside the `Operating System :: Microsoft ::
Windows` classifier.

## libvt 0.0.1a0 (2026-11-22)

Initial pre-alpha release of `libvt`: a pure-Python, zero-dependency virtual
Expand Down
56 changes: 56 additions & 0 deletions MIGRATION
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,59 @@ Migration and deprecation notes for `libvt` are recorded here; see
<!-- KEEP THIS PLACEHOLDER - DO NOT REMOVE OR MODIFY THIS LINE -->
_Detailed migration steps for the next version will be posted here._
<!-- END PLACEHOLDER - ADD NEW MIGRATION ENTRIES BELOW THIS LINE -->

### `MouseEvent.pixel_x` and `pixel_y` default to `None` (#26)

{attr}`~libvt.input.MouseEvent.pixel_x` and
{attr}`~libvt.input.MouseEvent.pixel_y` now have type `int | None = None` so
`?1016` SGR-Pixel encoding derives cell-center coordinates when omitted; pass
`pixel_x=0, pixel_y=0` explicitly when origin `(0, 0)` pixels are intended:

```python
# Before
ev = MouseEvent(button=MouseButton.LEFT, action=MouseAction.PRESS, row=2, col=3)

# After (explicit origin pixels)
ev = MouseEvent(
button=MouseButton.LEFT,
action=MouseAction.PRESS,
row=2,
col=3,
pixel_x=0,
pixel_y=0,
)
```

### `CSI 5:3 m` overline scoped to `tmux` capture decoding (#18)

{func}`~libvt.parser.parse_sgr` and live {meth}`~libvt.terminal.Terminal.feed`
no longer treat `CSI 5:3 m` as overline (or blink); emit standard `CSI 53 m` on
live VT streams and pass `tmux capture-pane -e` output through
{func}`~libvt.tmux.decode_tmux_capture` or
{meth}`~libvt.terminal.Terminal.from_tmux_capture`:

```python
# Before
term.feed(b"\x1b[5:3moverline\x1b[0m")

# After
term.feed(b"\x1b[53moverline\x1b[0m")
cap_term = Terminal.from_tmux_capture(["\x1b[5:3moverline\x1b[0m"])
```

### Opaque `SyncToken` watermarks (#22)

{class}`~libvt.terminal.SyncToken` no longer exposes internal watermark fields
or direct construction; obtain tokens from
{meth}`~libvt.terminal.Terminal.sync_token` or
{attr}`~libvt.terminal.ScreenDelta.token` and inspect terminal state via
{attr}`~libvt.terminal.ScreenDelta.snapshot`:

```python
# Before
cur = tok.cursor

# After
delta = term.changes_since(tok)
cur = delta.snapshot.cursor
```
17 changes: 17 additions & 0 deletions docs/_static/css/libvt.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Keep triple-quoted string literals (.sd) upright for box-drawing alignment. */
.highlight .sd {
font-style: normal;
}

/* Prevent unscoped light-theme italic rules from bleeding into dark Monokai. */
@media not print {
body[data-theme="dark"] .highlight span:not(.ge):not(.ges) {
font-style: normal;
}
}

@media not print and (prefers-color-scheme: dark) {
body:not([data-theme="light"]) .highlight span:not(.ge):not(.ges) {
font-style: normal;
}
}
6 changes: 6 additions & 0 deletions docs/api/aio.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
```{eval-rst}
.. automodule:: libvt.aio
:members:
:no-private-members:

.. py:type:: TtyMode
:canonical: typing.Literal["cooked", "cbreak", "raw"]

Slave pseudo-terminal line discipline mode passed to :func:`open_pty`.
```
15 changes: 15 additions & 0 deletions docs/api/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,19 @@
```{eval-rst}
.. automodule:: libvt.config
:members:
:no-private-members:
:exclude-members: Charset, SixelErasePolicy

.. py:type:: Charset
:module: libvt.config
:canonical: typing.Literal['B', '0', 'A']

Supported ``G0``–``G3`` character-set designators (US-ASCII, DEC Special,
UK).

.. py:type:: SixelErasePolicy
:module: libvt.config
:canonical: typing.Literal['cell_mask', 'whole_image']

``SIXEL`` cell-overwrite and rectangular-erase clipping policy.
```
1 change: 1 addition & 0 deletions docs/api/graphics.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
```{eval-rst}
.. automodule:: libvt.graphics
:members:
:no-private-members:
```
2 changes: 1 addition & 1 deletion docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Zero-dependency `SIXEL` and Kitty `APC G` `ImageMeta` and `ImagePlacement`.
:::{grid-item-card} `libvt.tmux`
:link: tmux
:link-type: doc
`decode_tmux_capture`, `TmuxPaneMetadata`, and `-CC` `%output` unescaping.
`build_tmux_capture_command`, `decode_tmux_capture`, and `-CC` unescaping.
:::

::::
Expand Down
9 changes: 9 additions & 0 deletions docs/api/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,13 @@
```{eval-rst}
.. automodule:: libvt.input
:members:
:no-private-members:
:exclude-members: InputEvent

.. py:type:: InputEvent
:module: libvt.input
:canonical: KeyEvent | MouseEvent | FocusEvent | PasteEvent

Outbound input event union accepted by :func:`encode_input` and
:meth:`~libvt.terminal.Terminal.encode`.
```
1 change: 1 addition & 0 deletions docs/api/modes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
```{eval-rst}
.. automodule:: libvt.modes
:members:
:no-private-members:
```
Loading
Loading