Skip to content

Fix scrollback corruption when editor exceeds terminal height#147

Merged
shellicar merged 15 commits intomainfrom
fix/terminal-rendering-redesign
Mar 29, 2026
Merged

Fix scrollback corruption when editor exceeds terminal height#147
shellicar merged 15 commits intomainfrom
fix/terminal-rendering-redesign

Conversation

@shellicar
Copy link
Copy Markdown
Owner

@shellicar shellicar commented Mar 29, 2026

Summary

Complete rewrite of the terminal functionality.

Terminal no longer writes more rows than screen.rows, eliminating scrollback corruption when the editor exceeds terminal height.

Changes

  • Layout/Viewport/Renderer pipeline replaces buildSticky()/clearStickyZone()
  • Viewport bounds every frame to screen.rows with cursor chasing on scroll and resize
  • MockScreen test double detects scrollback violations for automated verification

Related Issues

Closes #146

Co-Authored-By: Claude noreply@anthropic.com

@shellicar shellicar added this to the 1.0 milestone Mar 29, 2026
@shellicar shellicar added the bug Something isn't working label Mar 29, 2026
@shellicar shellicar self-assigned this Mar 29, 2026
@shellicar shellicar requested a review from bananabot9000 March 29, 2026 04:58
@shellicar shellicar enabled auto-merge (squash) March 29, 2026 04:59
@shellicar shellicar disabled auto-merge March 29, 2026 04:59
Copy link
Copy Markdown
Collaborator

@bananabot9000 bananabot9000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full terminal rendering redesign from Issue #146, implemented across 5 micro-session stages. 1,307 additions, 167 tests, matches the design doc.

Architecture verified:

  • Screen interface + StdoutScreen + MockScreen (with ANSI interpreter and scrollback violation tracking)
  • Layout -- pure function, correct component ordering, wrapLine with stringWidth
  • Viewport -- 31 lines, cursor chasing, resize capping
  • Renderer (as TerminalRenderer.ts -- smart macOS case collision avoidance) -- sync markers, zone-aware rendering
  • terminal.ts -- buildSticky()/clearStickyZone() replaced with renderZone() pipeline through Layout > Viewport > Renderer

Bugs caught during Stage 5 (good catches):

  1. Viewport padding caused scrollback violations on first render when cursor was not at row 0 -- fixed by trimming trailing empty rows before writing
  2. writeHistory re-rendered stale lastFrame with cleared question still visible -- fixed by splitting into writeHistoryLine + fresh renderZone()

Minor notes (non-blocking):

  • wrapLine iterates by code point not grapheme cluster (Intl.Segmenter would handle compound emoji at wrap boundaries). Not a regression.
  • Deprecated writeHistory on Renderer -- can it be removed if only writeHistoryLine + external render is used?

The one invariant holds: the renderer never writes more rows than screen.rows. Scrollback corruption is now structurally impossible.

@shellicar shellicar merged commit 732f0ee into main Mar 29, 2026
4 checks passed
@shellicar shellicar deleted the fix/terminal-rendering-redesign branch March 29, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scrollback history corruption when editor exceeds terminal height

2 participants