Skip to content

Fix DECSTBM SIXEL shift crash and preserve graphics and unwrapped rows on resize() #21

Done

Description

@tony

Summary

GraphicsTracker.on_region_scroll() in src/libvt/graphics.py (#14) increments p.abs_row += history_advanced before computing ir0 = max(p_top, abs_top + history_advanced) - p.abs_row, raising ValueError: negative shift count when a SIXEL placement straddles a DECSTBM scroll margin that saves into history. Meanwhile, Screen._reflow_primary() in src/libvt/screen.py (#2, #4) calls self._gfx.reset() (wiping all stored images and placements on any column resize), thaws every FrozenRow in scrollback even when not fr.wrapped and fr.used <= cols, resets _scrolled_total = len(self._history), and leaves PromptZone and cell-anchored Kitty placement (abs_row, col) pins unmapped.

Reproduction

  1. Place a 4-row SIXEL starting at row 2 (1-based row 3) and scroll DECSTBM 1..4 upward by 2 lines:
uv run python -c 'from libvt import Terminal; vt = Terminal(rows=6, cols=10, scrollback=10); vt.feed(b"\x1b[3;1H\x1bPq\"1;1;20;64#0~\x1b\\\x1b[1;4r\x1b[4;1H\n\n")'
  1. Place a SIXEL graphic and widen the terminal from 10 to 12 columns:
uv run python -c 'from libvt import Terminal; vt = Terminal(rows=6, cols=10, scrollback=10); vt.feed(b"\x1bPq\"1;1;20;20#0~\x1b\\"); vt.resize(rows=6, cols=12); print("placements:", len(vt.snapshot().placements))'

Expected

  • Step 1 clips the straddling SIXEL bitmask cleanly without raising ValueError.
  • Step 2 retains the image and placement across resize(rows=6, cols=12).
  • Primary-screen resize() streams logical lines without thawing unwrapped FrozenRow entries whose used <= cols, preserves monotonic scrolled_total continuity (evicted_total + len(history)), and remaps PromptZone and non-virtual Kitty placement (abs_row, col) anchors through reflow.

Actual

  • Step 1 raises ValueError: negative shift count.
  • Step 2 prints placements: 0.

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.

  • Terminal.feed() and Screen.scroll_up() never raise ValueError for any combination of DECSTBM margins, history_advanced, and SIXEL or Kitty placement bounds.
  • Terminal.resize() retains GraphicsTracker image metadata and placements across both reflow and non-reflow resizes, remapping cell-anchored placements and PromptZone pins on primary reflow and clipping/evicting only placements scrolled past retained history.
  • Unwrapped FrozenRow lines with used <= new_cols pass through primary reflow as sealed FrozenRow objects without thaw()/freeze() round-tripping.

Intent (non-binding)

  • Compute ir0 and ir1 against pre-advance p_top (or eff_top - p.abs_row after consistent coordinate translation) in GraphicsTracker.on_region_scroll().
  • Build a streaming pin-mapping table for active PromptZone and placement (abs_row, col) coordinates during _reflow_primary(), adjusting _evicted_total and _scrolled_total so monotonic row anchors never regress.

Not doing

  • Scaling SIXEL pixel bitmaps in software during column resize.

References

Activity

  1. added
    bug
    on Nov 23, 2026
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