Skip to content

Fix right-arrow navigation not entering folders under fragmented terminal input - #106

Open
ScottMorris wants to merge 1 commit into
mainfrom
fix/escape-sequence-quit-92
Open

Fix right-arrow navigation not entering folders under fragmented terminal input#106
ScottMorris wants to merge 1 commit into
mainfrom
fix/escape-sequence-quit-92

Conversation

@ScottMorris

Copy link
Copy Markdown
Collaborator

Summary

  • Terminal input can deliver a multi-byte escape sequence (e.g. the right arrow key's \x1b[C) split across separate reads under real-world conditions such as SSH/tmux/mosh latency
  • Ink's keypress parser has no way to know more bytes are coming, so it parses a lone leading \x1b byte as a standalone Escape keypress, which triggers smdu's quit-on-escape binding before the rest of the sequence arrives — from the user's side this looks like the arrow key doing nothing (or the app exiting) instead of navigating into the selected folder
  • Adds StdinEscapeBuffer, a small stream wrapper between process.stdin and Ink, that holds a lone leading escape byte for 50ms to see whether the rest of the sequence follows, reassembling it if so; a genuine standalone Escape press still quits, just ~50ms later
  • Root cause was confirmed by reproduction: driving the built CLI through a real pty with an artificially fragmented right-arrow sequence reliably killed the app before the fix, and navigated correctly after

Closes #92

Test plan

  • pnpm build
  • pnpm test (26 suites, 103 passed / 2 pre-existing skips) — includes new tests/stdinEscapeBuffer.test.ts covering reassembly, timeout-based flush, flush-on-rawmode-disable, and stream proxying
  • pnpm lint
  • Manually reproduced the original bug via a real pty with a split \x1b[C write — confirmed the app exited before the fix
  • Re-ran the same repro with the fix applied and a realistic ~5ms fragmentation gap — navigation now works correctly, no crash
  • Confirmed a genuine standalone Escape keypress still quits the app

🤖 Generated with Claude Code

Terminal input can deliver a multi-byte escape sequence (e.g. the right
arrow key's `\x1b[C`) split across separate reads under real-world
conditions such as SSH/tmux/mosh latency. Ink's keypress parser has no
way to know more bytes are coming, so it parses a lone leading `\x1b`
byte as a standalone Escape keypress, which triggers smdu's
quit-on-escape binding before the rest of the sequence arrives. From
the user's side this looks like the arrow key doing nothing (or the
app exiting) instead of navigating.

Add `StdinEscapeBuffer`, a small stream wrapper between `process.stdin`
and Ink that holds a lone leading escape byte for 50ms to see whether
the rest of the sequence follows, reassembling it if so. A genuine
standalone Escape press still quits, just ~50ms later.

Reproduced the original failure and verified the fix end-to-end by
driving the built CLI through a real pty with an artificially
fragmented right-arrow sequence.

Closes #92

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something is not working cli CLI commands, arguments, or terminal behaviour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hitting Right Arrow doens't navigate down into the selected folder

1 participant