Skip to content

screen(fix[erase]): Preserve rows through erases and scrubbing (#153) - #149

Open
tony wants to merge 6 commits into
masterfrom
fix/145-scrubber-scrollback-pullback
Open

tony wants to merge 6 commits into
masterfrom
fix/145-scrubber-scrollback-pullback

Conversation

@tony

@tony tony commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Keep new viewport text separate from earlier scrollback after an in-place erase or alignment test. Widening preserves the blank rows below fresh output. Protect wide glyphs during selective erases.
  • Advance sync-token history epochs on scrollback wrap severing so Terminal.changes_since() resyncs history[-1] without mutating earlier CoW Snapshot instances, and emit ECH (\x1b[X) instead of EL 0 (\x1b[K) in Formatter VT wrap replay. The Ghostty profile retains incoming wraps across the applicable erases.
  • Apply snapshot scrubbers within captured rows. Preserve the viewport geometry, wrap markers, cursor, and styles around replacements, including horizontally clipped wide glyphs and fixed-width fields.

In v0.0.1a5, erasing row 0 in place under DEFAULT_PROFILE (ed2_scrolls_primary_to_history=False) clears row 0's cells without clearing history[-1].wrapped. Subsequent Terminal.resize(..., reflow=True) can join post-clear text at (0, 0) to the pre-clear scrollback row. Snapshot scrubbing also needs to preserve the captured frame when a replacement changes a row's width.

Fixes #153
Closes #145
Closes #85
Closes #143

Feed b"abcdefghijklmnopqr\x1b[2J\x1b[HFresh" into an 8×2 terminal, serialize the box with scrubbers=[("Fresh", "OK")], and widen to 16 columns with reflow=True.

Before (v0.0.1a5):

history: [('abcdefgh', True)]
size=8x2 cursor=(1,2,vis=True) alt=False modes=[]
┌────────┐
│abcdefgh│W
│OK      │
└────────┘
after widen: ('abcdefghFresh', '')

After:

history: [('abcdefgh', False)]
size=8x2 cursor=(0,2,vis=True) alt=False modes=[]
┌────────┐
│OK      │
│        │
└────────┘
after widen: ('Fresh', '')

Changes by area

Screen & history wrap severing

  • src/libvt/_grid.py: add _HistoryBuffer.sever_last_wrap() to clear wrapped and any trailing SPACER_HEAD on history[-1] via CoW block or tail replacement while preserving frozen Snapshot history rows.
  • src/libvt/screen.py and src/libvt/config.py: preserve viewport padding at a hard history boundary, heal split wide cells, and use ScreenBehavior.erase_severs_history_wrap to select the in-place erase behavior. The Ghostty preset retains the link.

Terminal erases & VT formatter

  • src/libvt/terminal.py: apply the wrap policy to erasable incoming continuations and DECALN, keep history epoch tracking, and use \x1b[X (ECH) when replaying synthetic soft-wraps in Formatter._render_vt().
  • src/libvt/testing.py: apply scrubbers within each captured row and use the source frame's profile and cell widths when measuring replacements.

Tests & changelog

  • tests/test_screen.py: cover frozen and held frames, changes_since(), erased viewport reflow, Ghostty behavior, wide boundary protection, and display, line, and alignment operations.
  • tests/test_testing.py: check that scrubbing preserves rows after an erase, clipped wide cells, stored graphemes, and explicit fixed-width padding.
  • CHANGES and MIGRATION: document row-local scrubbers and how to keep temporary paths and fixed-width fields within a captured row.

Test plan

  • Reproduce displaced fresh text after erase and widening. Check protected wide cells and verify a scrubbed box retains its captured geometry.
  • Check formatting and lint rules with uv run ruff format --check . and uv run ruff check .
  • Check static types on Linux across Python 3.12–3.15 with uv run ty check.
  • Run the full test and doctest suite with uv run pytest -q
  • Build documentation cleanly with just -f docs/justfile sphinxopts="-W --keep-going" html

tony pushed a commit that referenced this pull request Dec 2, 2026
why: Checking only whether the viewport reached its bottom row still
resurrects pre-clear scrollback when post-ED 2 output fills the screen
with a multi-row soft-wrap or shrinks by more rows than scrolled since
the clear (#145, #149).

what:
- Track monotonic _viewport_clear_at on Screen and Snapshot across full
  primary-screen erases, resets, and primary reflow
- Sever orphaned pre-clear soft-wraps at _viewport_clear_at during
  Screen._reflow_primary
- Bound prefix_hist and scrollback pullback in _serialize_extracted by
  min_hist_idx derived from _viewport_clear_at
- Expand tests/test_testing.py across DEFAULT_PROFILE, tmux_profile(),
  and resize(reflow=True), and reference #149 in CHANGES
@tony tony changed the title testing(fix[scrub]): Restore displaced top rows (#145) screen(fix[erase]): Sever dangling history wrap on row-0 erase (#153) Dec 2, 2026
why: A wrapped temporary path can displace earlier rows in full-screen
     output.

what:
- Fill the vacated rows when a scrubber collapses wrapped output
- Cover single-path and multiple-path screen captures
temp-merge and others added 5 commits December 2, 2026 20:43
why: A fully redrawn viewport can still have unrelated output before an
     erase.

what:
- Track the display clear boundary for reflow and scrubbing
- Check post-clear wrapping under default and tmux profiles
why: Erased or overwritten leading cells must leave the earlier
     scrollback line separate.

what:
- Sever incoming wraps during erases and heal split wide cells
- Keep frozen history and change tokens consistent
- Replay synthetic wraps with ECH and exercise screen erases
why: Widening after an in-place erase must preserve the fresh viewport,
     retained history, and its protected wide cells.

what:
- Preserve the history break and viewport padding during reflow
- Apply the profile's erase policy and honor protected wide glyphs
- Freeze synchronized frames before public Screen edits
- Cover the resize, protected erase and host profile behavior
why: Scrubbing needs to preserve the captured rows, columns and cursor
     even when replacement text changes width.

what:
- Apply scrubbers one row at a time within the captured viewport
- Measure replacement cells with the source profile and crop
- Cover clipped wide cells, stored graphemes and fixed-width fields
- Document how to keep temporary paths on one captured row
why: Record the branch's user-visible change in the unreleased notes.

what:
- Add the #149 entry under Breaking changes in CHANGES
- Add the #149 entry under Fixes in CHANGES
@tony
tony force-pushed the fix/145-scrubber-scrollback-pullback branch from 97e7b01 to 2d1b6fe Compare December 3, 2026 02:48
@tony tony changed the title screen(fix[erase]): Sever dangling history wrap on row-0 erase (#153) screen(fix[erase]): Preserve rows through erases and scrubbing (#153) Dec 3, 2026

This branch was successfully deployed

1 active deployment
docs — 2d1b6fe8 Deployed Dec 3, 2026 by tony via build (3.14) #291
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant