Skip to content

Replace signed row on PromptZone and ImagePlacement with Snapshot.at_abs() #19

Closed

Description

@tony

Summary

PromptZone in src/libvt/events.py and ImagePlacement in src/libvt/graphics.py (#2, #14) expose a signed row: int attribute that turns negative once the anchor scrolls into history. Passing zone.row or placement.row into Snapshot[row] triggers Python negative sequence indexing from the bottom of the active viewport instead of addressing scrollback, and any viewport row stored on a persistent event or placement record goes stale after the next scroll linefeed.

Reproduction

  1. Emit an OSC 133;A prompt marker, scroll it one row into history, and index snap[pz.row]:
uv run python -c 'from libvt import Terminal; vt = Terminal(rows=2, cols=10, scrollback=10); vt.feed(b"\x1b]133;A\x07cmd\r\nline1\r\nline2"); snap = vt.snapshot(); pz = snap.prompt_zones[0]; print("abs_row:", pz.abs_row, "row:", pz.row, "snap[pz.row]:", repr(snap[pz.row].text))'

Expected

  • PromptZone and ImagePlacement carry only monotonic abs_row: int (and col: int) without a signed row field that aliases Snapshot[-1].
  • Snapshot.at_abs(abs_row) returns the RowView from history or the active viewport (or raises IndexError / returns None via Snapshot.viewport_row(abs_row) -> int | None when evicted or inside history), matching WezTerm (repo, wezterm-surface StableRowIndex at ee6f3044d) stable row addressing.

Actual

abs_row: 0 row: -1 snap[pz.row]: 'line2' — snap[pz.row] reads the bottom viewport row 'line2' instead of scrollback row 'cmd'.

Environment

Versions
  • libvt: #2 (0.1.0a0)
  • Python: 3.15.1
  • OS: Linux x86_64

Proposal

Invariants

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

  • PromptZone and ImagePlacement store abs_row: int and omit signed row: int, closing the Snapshot[-1] negative-indexing footgun before 0.1.0 locks public fields.
  • Snapshot.viewport_row(abs_row) returns 0 <= r < rows when abs_row is visible in the snapshot's active viewport and None when abs_row lies in scrollback or has been evicted.
  • Snapshot.at_abs(abs_row) resolves any retained row across scrollback plus the primary viewport in O(1) time and raises IndexError when abs_row was evicted or out of range.

Intent (non-binding)

  • Record scrolled_total and evicted_total on Snapshot so at_abs(abs_row), viewport_row(abs_row), and ImagePlacement.occupies_viewport_cell(row, col, scrolled_total=...) (or Snapshot-scoped helpers) need no mutable screen reference.
  • Include abs_row (and computed viewport_row) in Snapshot.to_dict() placement records.

Not doing

  • Storing a mutable or snapshot-relative viewport_row field on PromptZone or ImagePlacement instances emitted in PromptMark events.

References

Activity

  1. added
    bug
    on Nov 23, 2026
  2. tony commented on Nov 23, 2026

    @tony
    MemberAuthor

    Resolved in #2 (0c7ee41).

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions