Skip to content

Forward bare Escape to PTY in normal mode#16

Merged
dcosson merged 1 commit intodcosson:mainfrom
mikeschinkel:fix/bare-escape-normal-mode
Apr 1, 2026
Merged

Forward bare Escape to PTY in normal mode#16
dcosson merged 1 commit intodcosson:mainfrom
mikeschinkel:fix/bare-escape-normal-mode

Conversation

@mikeschinkel
Copy link
Copy Markdown
Contributor

@mikeschinkel mikeschinkel commented Apr 1, 2026

Pressing Escape in normal mode does nothing — the keypress is silently dropped. This prevents Claude Code and other child processes from receiving bare Escape, which Claude Code uses for interrupt/pause. The current workaround requires Ctrl+\ -> p -> <esc> -> Ctrl+\, which is clunky.

HandleDefaultBytes had no StartPendingEsc path for ESC at end of buffer, and StartPendingEsc's timer callback had no ModeNormal case. Both passthrough and scroll modes already handled this correctly.

This PR:

  • Adds ModeNormal case to StartPendingEsc timer — forwards bare Escape (0x1B) to PTY
  • Adds PendingEsc continuation handling to HandleDefaultBytes — also fixes split-read escape sequences (e.g. arrow keys split across two read() calls)
  • Calls StartPendingEsc() when ESC is the last byte in the buffer

Four (4) tests cover:

  1. pending flag set,
  2. bare ESC delivery to PTY,
  3. split-read continuation, and
  4. mid-buffer sequences unchanged.

In normal mode, pressing Escape with no following bytes (bare Escape)
was silently dropped. This prevented Claude Code from receiving its
interrupt/pause signal without first entering passthrough mode.

- Add ModeNormal case to StartPendingEsc timer callback
- Add PendingEsc continuation handling to HandleDefaultBytes (fixes
  split-read escape sequences too)
- Start pending esc timer when ESC is last byte in buffer
@dcosson
Copy link
Copy Markdown
Owner

dcosson commented Apr 1, 2026

Looks good, thanks!

@dcosson dcosson merged commit 4bfd840 into dcosson:main Apr 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants