Repository navigation
TUI: rejoin escape sequences split across reads (fixes #130) - #133
Merged
Merged
Conversation
Over `adb shell`'s pty an arrow key's `ESC [ A` can arrive as a read of just the 0x1B byte; crossterm 0.29 commits a lone trailing ESC of a short read as KeyCode::Esc immediately (crossterm#993), and Esc quits the viewer, so navigating with the cursor keys randomly exits on Android (also seen over ssh). The tail then leaks as stray `[`/`A` keys. A new input layer (src/tui/input.rs) sits between crossterm's EventStream and the app: a bare Esc press is held for 100ms (vim's ttimeoutlen default); if a `[`/`O` tail follows within the window its bytes are collected and re-mapped to the event the sequence was - arrows, Home/End, PageUp/PageDown, Insert/Delete, BackTab, F-keys, SGR/normal/rxvt mouse reports, SS3, with CSI modifier params (`ESC [ 1 ; 5 A` = Ctrl+Up). If nothing or another key follows in time, the held Esc is emitted as-is, so a real Escape still works. Unparseable sequences are dropped, exactly as crossterm's parser drops them when they arrive in one read. UI::next_event wires it in with a sleep branch in the existing select loop. Tests: 11 unit tests of the rejoin state machine, and a Linux pty e2e (tests/tui_split_escape.rs) that sends a split Down arrow (ESC, 50ms, "[B") to the real binary under `script` and asserts the viewer stays up and redraws, then that a lone Esc still quits cleanly; verified to fail with the hold disabled. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.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.
Fixes #130.
Over
adb shell's pty an arrow key'sESC [ Acan arrive as aread()of just the0x1Bbyte. crossterm 0.29 commits a lone trailing ESC of a short read asKeyCode::Escimmediately (crossterm-rs/crossterm#993), and Esc quits the viewer — so navigating with the cursor keys randomly exits on Android (also reproducible over ssh). The rest of the sequence then leaks as stray[/Akey events.A new input layer (
src/tui/input.rs) sits between crossterm'sEventStreamand the app: a bare Esc press is held for 100 ms (vim'sttimeoutlendefault); if a[/Otail follows within the window, its bytes are collected and re-mapped to the event the sequence was — arrows, Home/End, PgUp/PgDn, Insert/Delete, BackTab, F-keys, SGR/normal/rxvt mouse reports, SS3, CSI modifier params (ESC [ 1 ; 5 A= Ctrl+Up). If nothing or another key follows in time, the held Esc is emitted as-is, so a real Escape still quits, just up to 100 ms later.Tests:
tests/tui_split_escape.rs: Linux pty e2e viascript— a split Down arrow (ESC, 50 ms,[B) to the real binary keeps the viewer alive and redraws; a loneESCstill quits cleanly. Verified to fail with the hold disabled (pre-fix binary quits on the split arrow).No CI changes needed: the e2e runs in the existing ubuntu-latest nextest job.