fix(terminal): place cursor correctly after restart for persistent TUIs#1324
Open
fix(terminal): place cursor correctly after restart for persistent TUIs#1324
Conversation
SerializeAddon emits a relative cursor-move tail (\x1b[NA\x1b[MD)
computed from the last content cell it serialized to the terminal's real
cursor. That math drifts when a TUI drew rows below the cursor (border,
status lines) and then parked the cursor back on an input prompt above
— on replay the cursor lands one row below the prompt.
Append an authoritative absolute CSI row;col H after SerializeAddon
output at both capture sites (renderer captureBuffers and daemon
HeadlessEmulator.getSnapshot) using the terminal's live
buffer.active.cursorY/cursorX. The absolute positioner is the last
cursor-move seen on replay, overriding SerializeAddon's drifty relative
tail.
Also remove two cooperating bugs in restoreScrollbackBuffers and
document the contract:
1. Alt-screen trim (slice(0, lastIndexOf('\x1b[?1049h'))) discarded
not only alt-buffer content but the cursor-position tail, mode
bits, and scroll region — fueling the "cursor lands below input
box" bug for Claude Code, vim, lazygit.
2. Unconditional trailing \r\n append for PROMPT_EOL_MARK pushed the
cursor one extra row down on top of the alt-trim drift.
The reattach path in pty-connection.ts is authoritative when it has
data; restoreScrollbackBuffers is the pre-paint and must replay the
serialized buffer verbatim + POST_REPLAY_MODE_RESET only.
Co-authored-by: Orca <help@stably.ai>
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.
Summary
CSI row;col Hcursor positioner afterSerializeAddonoutput in both capture sites (renderercaptureBuffers, daemonHeadlessEmulator.getSnapshot). SerializeAddon's relative cursor-move tail drifts when a TUI drew rows below the cursor (border/status lines) and parked the cursor back on an input prompt above — on replay the cursor lands one row below the prompt.\r\nappend inrestoreScrollbackBuffers(both contributed to the drift) and document the pre-paint/authoritative-reattach contract on the function.docs/design/fix-persistent-terminal-cursor-after-restart.mdcaptures the two restore paths, root cause, and chosen fix.Test plan
pnpm test—src/main/daemon/headless-emulator.test.ts(23 pass, +2 new) andsrc/renderer/src/components/terminal-pane/layout-serialization.test.ts(26 pass, +3 new)shell-readyfailures unchanged from baseline)pnpm tsc --noEmitcleanvim/lazygitin alt-screen — cursor lands where it wasMade with Orca 🐋