fix(tui): preserve scrollback on content-driven full redraws - #7718
Closed
mjapple8 wants to merge 2 commits into
Closed
fix(tui): preserve scrollback on content-driven full redraws#7718mjapple8 wants to merge 2 commits into
mjapple8 wants to merge 2 commits into
Conversation
When a line above the previous viewport changes (e.g. streaming markdown re-flowing while the message has grown past the visible area), the renderer fell back to fullRender(true), which unconditionally emitted ESC[2J ESC[H ESC[3J and wiped the terminal's scrollback buffer. In normal-screen mode pi-tui relies on terminal scrollback to keep conversation history scrollable, so users reading earlier output lost it all at once. Split fullRender's clear flag into three modes: - false: first render, writes everything - true: clear viewport but PRESERVE scrollback, write only the last height lines so earlier content is not pushed into scrollback a second time - "scrollback": clear viewport AND scrollback, write everything (reserved for width changes where prior wrapping is invalid)
…edraws Covers the content-driven full redraw path (line above the viewport changes): pre-TUI shell history must survive, earlier content must not be duplicated into scrollback, and width changes still clear stale scrollback.
Contributor
|
This PR was auto-closed. Only contributors approved with Maintainers review auto-closed issues daily. Issues that do not meet the quality bar in CONTRIBUTING.md will not be reopened or receive a reply. If a maintainer replies See CONTRIBUTING.md. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In normal-screen mode, pi-tui renders conversation history into the terminal's scrollback buffer so users can scroll up to read earlier output. When any rendered line above the previous viewport changes (e.g. streaming markdown re-flowing while the message grows past the visible area),
TuiMainScreen.doRender()falls back tofullRender(true), which unconditionally emitted\x1b[2J\x1b[H\x1b[3J— and\x1b[3Jwipes the entire scrollback.Result: while viewing a session, the view "jumps to the top" and scrollback (conversation history, shell history) disappears; during streaming the redraw fires repeatedly so the view keeps jumping.
This is the same class of bug reported in #7304, #4626 and #5576. An earlier fix (PR #4204) targeted the old
TUIclass inpackages/tui/src/tui.ts; it was lost during the refactor that split the renderer intotui-main-screen.ts/tui-alt-screen.ts.Fix
Split the
clearflag offullRenderinto three modes:falsetrue\x1b[2J\x1b[H) but PRESERVE scrollback; write only the lastheightlines so earlier content isn't pushed into scrollback a second timefirstChanged < prevViewportTop, height change, clear-on-shrink"scrollback"\x1b[2J\x1b[H\x1b[3J); write everythingmaxLinesRenderedis now reset only on a scrollback wipe; otherwise it keeps tracking growth since scrollback still holds the content.Tests
Added
packages/tui/test/tui-scrollback-preserve.test.tswith three cases (verified locally against a real xterm.js headless terminal):