Skip to content

Add changes_since(), pyte migration guide, and libtmux helpers #13

Done

Description

@tony

Summary

Downstream consumers migrating from pyte (docs, PyPI) and integrating with libtmux (repo, PyPI, libtmux#886) lack four ergonomic building blocks on #2: coordinate-versioned per-row change tracking for live renderers, an executable pyte-to-libvt migration guide covering HistoryScreen paging and Char quirks, libtmux send-keys / tmux -CC %output / OSC 133 command-block helpers, and cross-platform CI verification matching pyproject.toml claims.

Motivation

  • Live UI renderers and multiplexers cannot safely use a pyte-style caller-cleared screen.dirty: set[int] when multiple consumers (wait_for predicates, recorders, and UI painters) observe one Terminal, while Snapshot.generation alone forces scanning all rows on 1-cell updates.
  • libtmux callers pass tmux key names ("C-c", "M-a", "BSpace", "PPage", "BTab"), receive octal-escaped %output / %extended-output lines (\xxx) in tmux -CC control mode, and inspect command/output blocks delimited by OSC 133 PromptZone markers.
  • src/libvt/terminal.py currently combines Terminal, Snapshot, Formatter, and FlightRecorder in one large module, and .github/workflows/tests.yml (7a72ae8) runs only ubuntu-latest CPython 3.12–3.15 without a portable Windows core leg or an experimental PyPy 3.12 (8.0.1 beta) leg.

Proposal

Invariants

The invariants below are load-bearing; everything under Intent is open.

  • Change tracking is multi-consumer safe (never requiring a caller to mutate or .clear() shared Terminal state) and accounts for vertical scrolling, resize(), alternate-screen switches, cursor/visibility changes, and ?2026 synchronized commits.
  • Core libvt types (Terminal, Screen, Snapshot, Cell, Style) remain free of pyte legacy quirks ("brown" ANSI color 3, bare 6-hex RGB strings, Screen(columns, lines) vs resize(lines, columns) transposed parameter order, wide-glyph "" trailing cells shortening display string length, and mutating HistoryScreen pagination).
  • Splitting Snapshot, Formatter, and FlightRecorder into dedicated modules preserves top-level from libvt import ... imports.
  • Portable import libvt on Windows never imports pty, termios, or fcntl, and documentation scopes libvt.aio.open_pty() explicitly to POSIX (Linux, plus macOS tracked in Verify open_pty() TIOCSCTTY controlling-TTY behavior on macOS #3).

Intent (non-binding)

  • Stamp monotonic per-row generations on _Row and expose Snapshot.row_generations: tuple[int, ...] plus Terminal.changes_since(token) returning (new_token, changed_rows, cursor_changed, full_refresh).
  • Add docs/topics/migrating-from-pyte.md with a runnable mapping guide and a pure viewport-offset HistoryScreen adapter recipe (_scroll_offset over append-only history + lines), promoting it to an isolated libvt.compat.pyte module only if migrating libtmux's screen tests from a built libvt wheel demonstrates clear boilerplate reduction.
  • Add KeyEvent.from_tmux() (translating tmux send-keys chord names), unescape_tmux_control_output() (decoding tmux -CC octal escapes), and Snapshot.command_blocks() (pairing OSC 133 A/B/C/D zones across history and screen into command, output, and exit_code records).
  • Add a windows-latest portable-core job and an allow-failure pypy3.12 job in .github/workflows/tests.yml, and validate libtmux's screen test suite against an installed libvt wheel in a clean virtual environment (paired with a deliberate failing screen assertion) before freezing 1.0.

Not doing

  • Baking mutating prev_page() / next_page() deques into Screen.
  • Wrapping Win32 ConPTY (pywinpty) in libvt.

Alternatives

  • A pyte-style mutable Terminal.dirty: set[int] was weighed and rejected as the primary API because clearing it from one observer hides dirty rows from concurrent observers (wait_for, logger, renderer); single-consumer callers can derive a dirty set in 5 lines from changes_since(token).

References

Activity

  1. added
    enhancement
    on Nov 22, 2026
  2. tony commented on Nov 23, 2026

    @tony
    MemberAuthor

    Pre-0.1.0 contract refinements

    Follow-up review narrows three items from this tracking issue into dedicated issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions