fix(vterm): replay DEC private modes on attach so resume restores scroll and arrows#28
Merged
Merged
Conversation
…oll and arrows Reported against v0.2.1: on a session's first launch scroll and arrow keys work, but after detach+re-attach (or resume) they go dead. Root cause, same family as #24 (which replayed SGR colors): the vterm captured screen content but discarded the agent's input-affecting DEC private modes. setPrivateMode treated mouse tracking, bracketed paste, and cursor visibility as "no effect on captured text" and never tracked application cursor keys (DECCKM ?1) or keypad mode at all; Redraw emitted only SGR + content + cursor position. On first attach the agent's mode setup flowed live through the PTY to the attached client, so it worked. On detach the attach client resets those modes; on re-attach the host sends only Redraw(), leaving the client in default mode while the still-running agent expects application-cursor (SS3) arrows and mouse reporting -- so arrows are ignored and the wheel does nothing (v0.2.1's ?1007 change removed the wheel->arrow fallback that had masked it). The vterm now tracks the input/cursor-affecting modes (DECCKM ?1, mouse ?1000/1002/1003 + focus ?1004 + encodings ?1005/1006/1015, bracketed paste ?2004, cursor visibility ?25, application keypad ESC=) and Redraw replays the ones that differ from their power-on default, before the grid content, so a re-attaching or resuming client lands in the agent's expected state. Capture stays plain text; alt-screen and SGR replay are unchanged. Adds unit coverage for each replayed mode (incl. default suppression, toggle-off, RIS reset, alt-screen, ordering) and an end-to-end TestReattachReplaysAgentPrivateModes that detaches and re-attaches to a live host and asserts the modes come back.
|
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
Reported against v0.2.1: on a session's first launch mouse scroll and arrow keys work, but after detach + re-attach (or resume) they go dead.
Same bug family as #24 — which replayed SGR colors so re-attach wasn't black-and-white. This is the modes version.
Root cause
The vterm captured screen content but discarded the agent's input-affecting DEC private modes:
setPrivateModetreated mouse tracking (?1000/1002/1003/1006), bracketed paste (?2004), and cursor visibility (?25) as "no effect on captured text", and never tracked application cursor keys (DECCKM?1) or keypad mode at all.Redraw()— what the host sends on every attach — emitted only SGR + content + cursor position.On first attach the agent's mode-setup sequences flow live through the PTY to the already-attached client, so everything works. On detach the attach client resets those modes (mouse off,
DECSTRresets DECCKM,?2004l). On re-attach the host sends onlyRedraw(), leaving the client in default mode while the still-running agent expects application-cursor (SS3) arrows and mouse reporting — so arrows are ignored and the wheel does nothing (v0.2.1's?1007change removed the wheel→arrow side effect that had masked it).This also covers literal resume (
ResumeBackgroundspawns a fresh host+agent): if you resume-then-attach, the agent emits its modes into a clientless vterm and the attach replay would otherwise drop them.Fix
Mirror #24's per-cell SGR tracking, for modes: the vterm now tracks the input/cursor-affecting private modes in a
privModes map[int]bool+appKeypad bool(DECCKM?1, mouse?1000/1002/1003+ focus?1004+ encodings?1005/1006/1015, bracketed paste?2004, cursor visibility?25, application keypadESC=).Redraw()replays the ones that differ from their power-on default (only?25defaults on → emitted as?25lwhen hidden), before the grid content, so a re-attaching/resuming client lands in the agent's expected state.reset()(RIS) clears them. Alt-screen (?1049, owned by the attach client) and SGR replay are unchanged;Capturestays plain text.Out of scope (noted): autowrap
?7, kitty keyboard flags, and charset — none cause the reported symptoms.Testing
?25h), toggle-off, RIS reset, modes set on the alt screen, and mode-before-content ordering — all written red-firstTestReattachReplaysAgentPrivateModes: spawns a live host whose agent enables?1h ?1000h ?1006h, attaches, detaches, re-attaches, and asserts the modes are replayed (the regression the test suite previously lacked)-race🤖 Generated with Claude Code