libvt.snapshot

Immutable terminal snapshots, incremental sync watermarks, and deltas.

class libvt.snapshot.ResyncReason
class libvt.snapshot.ResyncReason

Bases: StrEnum

Reason changes_since() emitted a full resync.

class libvt.snapshot.ScreenDelta
class libvt.snapshot.ScreenDelta

Bases: object

Multi-consumer incremental update from Terminal.changes_since.

class libvt.snapshot.Snapshot
class libvt.snapshot.Snapshot

Bases: object

Immutable point-in-time capture of terminal screen, history, and metadata.

Obtain instances via committed (tear-free across ?2026 synchronized frames) or snapshot() (immediate working buffer). Once captured, a Snapshot never mutates when later bytes arrive on the Terminal and can be shared across threads without locking.

Index snap[row] for a RowView, snap[row, col] for an immutable Cell, or snap[r0:r1, c0:c1] for a rectangular RegionView. Render a visual grid box with format_screen_box() or include header metadata and SGR spans with serialize_vt_snapshot().

Examples

>>> from libvt.terminal import Terminal
>>> from libvt.testing import serialize_vt_snapshot
>>> term = Terminal(rows=2, cols=14)
>>> term.feed(b"\x1b[1;32mREADY\x1b[0m  api\r\n\x1b[7m> worker\x1b[0m")
>>> snap = term.committed
>>> print(serialize_vt_snapshot(snap))
size=14x2 cursor=(1,8,vis=True) alt=False modes=[]
┌──────────────┐
│READY  api    │
│> worker      │
└──────────────┘
styles:
  r0[0..5]: bold fg=green
  r1[0..8]: reverse
>>> snap[0, 0].text, snap[0, 0].style.bold, snap[1, 0].style.reverse
('R', True, True)
class libvt.snapshot.SnapshotDict
class libvt.snapshot.SnapshotDict

Bases: TypedDict

Typed JSON-compatible dictionary returned by Snapshot.to_dict().

class libvt.snapshot.SyncToken
class libvt.snapshot.SyncToken

Bases: object

Opaque per-Terminal watermark for incremental sync.

Compare tokens with == and store them in sets or dictionaries via hash(); obtain instances from sync_token() or ScreenDelta.token.

Examples

>>> from libvt.terminal import Terminal
>>> term = Terminal(rows=2, cols=12)
>>> tok0 = term.sync_token()
>>> term.feed(b"status: ok")
>>> delta = term.changes_since(tok0)
>>> delta.dirty_rows, delta.snapshot.lines
((0,), ('status: ok', ''))
type libvt.snapshot.SyncView = Literal['working', 'committed']
type
type
type libvt.snapshot.SyncView = Literal['working', 'committed']

Buffer view selector for sync_token() and changes_since().