fix(vt): send SS3 for Home and End under DECCKM - #960
Open
midagedev wants to merge 1 commit into
Open
Conversation
SendKey already computes `ack` from ModeCursorKeys and uses it to choose between SS3 and CSI for the four arrow keys, but Home and End twenty lines below it emit CSI unconditionally. Under DECCKM they should be `ESC O H` and `ESC O F`. The forms are the ones this stack already recognizes on the way in: ultraviolet's key table lists them under its own "Application Cursor Key Mode (DECCKM)" heading, next to `ESC O A`..`ESC O D`. So an Emulator whose output is decoded by ultraviolet round-trips the arrows and loses Home and End. terminfo agrees — xterm-256color pairs `smkx=\E[?1h` with `khome=\EOH` and `kend=\EOF` — which is why an ncurses application that called keypad(true) does not recognize the CSI forms as Home or End. The added test covers all six cursor keys in both modes, so the arrows document the behaviour Home and End now match.
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.
SendKeycomputesackfromansi.ModeCursorKeysand uses it to pick SS3 or CSI for the four arrow keys (vt/key.goL124-147), butKeyHomeandKeyEndtwenty lines below emit CSI unconditionally (L153-156). Under DECCKM they should beESC O HandESC O F.Those are the forms this stack already recognizes on the way in.
ultraviolet's key table lists them under its own// Application Cursor Key Mode (DECCKM)heading, right besideESC O A..ESC O D:So an
Emulatorwhose output is decoded byultravioletround-trips the arrows and drops Home and End.terminfosays the same thing from the other side —xterm-256colorpairssmkx=\E[?1h(which is DECCKM) withkhome=\EOHandkend=\EOF, so an ncurses application that calledkeypad(true)compares against the SS3 forms and never matches the CSI ones.How this has been tested
vt/key_test.go(new) covers all six cursor keys in both modes, so the four arrows document the behaviour Home and End now match.A/B on this branch, against its parent
96af6d2:go test -race ./...green invt/, repeated 5×;gofmt -lempty;go build ./...clean.Bounds, honestly: this was run on darwin/arm64 with Go 1.26 only. I did not exercise it against a real ncurses application — the terminfo entry above is the evidence for that claim, not a live run.
Two things a reviewer will notice
The test starts goroutines.
SendKeywrites into the emulator'sio.Pipe, which blocks until something reads, so the read has to be waiting before the send. That is the same blocking #953 is addressing; if that lands first, the helper simplifies and I am happy to follow up.Modified cursor keys are a separate defect and not in this PR.
KeyPressEvent{Code: KeyUp, Mod: ModCtrl}matches no case and falls todefault:, whereif key.Mod == 0means nothing is written at all — the keystroke disappears. xterm sendsESC [ 1 ; 5 A. I have kept it out to keep this PR single-purpose, and I want to flag that this is a different axis from the// TODO: Support Kitty, CSI u, and XTerm modifyOtherKeysat the top of the function:CSI 1 ; m Ais plain xterm cursor-key modifier encoding, not modifyOtherKeys and not the Kitty protocol. Happy to open an issue or a follow-up PR, whichever you prefer.