Skip to content

fix(ui): prevent terminal screen cheese on TUI resize#76

Merged
digitarald merged 2 commits intomainfrom
copilot/scientific-anaconda
Mar 22, 2026
Merged

fix(ui): prevent terminal screen cheese on TUI resize#76
digitarald merged 2 commits intomainfrom
copilot/scientific-anaconda

Conversation

@digitarald
Copy link
Collaborator

Problem

Resizing the terminal while the TUI is running causes "screen cheese" — old renders stack and overlap instead of being replaced, producing multiple AGENTRC ASCII banners on screen simultaneously.

Screenshot showing stacked banner artifacts

Root Cause

Ink 6.x tracks previousLineCount in its log-update module for cursor math (eraseLines, cursorUp). When the terminal resizes, the emulator reflows existing text — changing how many visual lines the content occupies — but Ink's internal counters stay stale.

Ink's own resized() handler only calls this.log.clear() on width decrease. Width increases and height-only changes leave the stale state in place, causing partial erasure and ghost content on the next render.

Fix

Clear the visible terminal area (\x1b[2J\x1b[H) in the useTerminalColumns resize handler, using prependListener so it fires before Ink's own resized(). This ensures Ink re-renders onto a clean slate on every resize direction — no wasted double-paint.

Details

  • Uses stdout.prependListener("resize", ...) to run before Ink's handler
  • \x1b[2J clears the visible area (not scrollback); \x1b[H homes the cursor
  • Ink's subsequent resized()onRender() paints fresh content immediately
  • No impact on screen reader mode (separate render path)
  • Batch TUIs are unaffected (they don't use useTerminalColumns)

Verification

  • ✅ Typecheck passes
  • ✅ Lint passes
  • ✅ Build passes
  • ✅ All 574 tests pass

Copilot AI review requested due to automatic review settings March 22, 2026 04:23
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes Ink TUI “screen cheese” artifacts that appear when resizing the terminal by clearing the visible terminal area before Ink processes the resize, ensuring the next render starts from a clean screen.

Changes:

  • Clears the terminal (\x1b[2J\x1b[H) on every resize event to avoid stale line-tracking artifacts.
  • Uses stdout.prependListener("resize", ...) so the clear runs before Ink’s internal resize handler.
  • Keeps columns state updated on resize for responsive layout.

readers are not exposed to raw ANSI noise on resize. The columns state
update still fires, keeping layout responsive in accessible mode.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@digitarald digitarald merged commit ce0b509 into main Mar 22, 2026
10 checks passed
@digitarald digitarald deleted the copilot/scientific-anaconda branch March 22, 2026 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants