fix(core): keep cursor on screen when shrinking the terminal vertically#89
Open
Ramalama2 wants to merge 1 commit into
Open
fix(core): keep cursor on screen when shrinking the terminal vertically#89Ramalama2 wants to merge 1 commit into
Ramalama2 wants to merge 1 commit into
Conversation
Terminal.resize() always kept the top `rows` rows on a vertical shrink and pushed the bottom rows into scrollback, no matter where the cursor was. At a fresh or cleared shell prompt the cursor sits on the first row and the rest of the screen is blank, so shrinking the viewport pushed all of those trailing blank rows into scrollback. That left phantom blank lines stuck above the prompt, and the shell never learns that the cursor moved. The only way out was `clear`, and the next resize brought the blank lines right back. This makes the shrink cursor-aware, the same way xterm, VTE and ghostty handle it: - Content scrolls off the top only, and only as far as needed to keep the cursor inside the smaller viewport (scroll = cursor_row - rows + 1, else 0). - Rows that scroll off the top become real scrollback history. - Trailing rows below the cursor are discarded instead of preserved. - The alt screen keeps its current behaviour. It has no scrollback and its app repaints on SIGWINCH, so its top rows stay put and only the cursor is clamped. Shrinking at a top-of-screen prompt now adds no scrollback at all. Shrinking a full screen scrolls the top into history while the cursor stays visible. Adds two regression tests.
|
@Ramalama2 is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
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
Terminal.resize()always keeps the toprowsrows on a vertical shrink and pushes the bottom rows into scrollback, no matter where the cursor is:At a fresh or cleared shell prompt the cursor sits on row 0 and the rest of the screen is blank. Shrinking the viewport then pushes all of those trailing blank rows into scrollback, so you end up with phantom blank lines stuck above the prompt. The shell never learns that the cursor moved. The only way out is
clear, and the next resize brings the blank lines right back.To reproduce, sit at a fresh
$prompt on a tall terminal and drag the window shorter. Scroll up afterwards and there are several blank lines above the prompt that were not there before.Fix
The shrink is now cursor-aware, the same way xterm, VTE and ghostty handle it.
scroll = cursor_row - rows + 1, otherwise 0).Shrinking at a top-of-screen prompt now adds no scrollback at all. Shrinking a full screen scrolls the top into history while the cursor stays visible.
Tests
Two regression tests in
src/terminal.zig:resize shrink at top-of-screen prompt adds no phantom scrollbackresize shrink at bottom scrolls top rows into scrollbackzig build testpasses andzig fmt --check src/terminal.zigis clean.packages/@wterm/core/wasm/wterm.wasmwas rebuilt withzig build -Doptimize=ReleaseSmall(Zig 0.16.0) so the WASM drift check stays green.