Skip to content

fix(attach): detect ctrl+\ encoded by xterm modifyOtherKeys#125

Open
myeongjjun wants to merge 1 commit into
neurosnap:mainfrom
myeongjjun:fix/modifyotherkeys-detach
Open

fix(attach): detect ctrl+\ encoded by xterm modifyOtherKeys#125
myeongjjun wants to merge 1 commit into
neurosnap:mainfrom
myeongjjun:fix/modifyotherkeys-detach

Conversation

@myeongjjun

Copy link
Copy Markdown

Fixes #124. Follow-up to #92.

The kitty CSI u parser added in #92 doesn't cover xterm modifyOtherKeys, so ctrl+\ silently fails to detach when the inner program enables modifyOtherKeys level 2 and the outer terminal honors it (notably iTerm2). Real-world trigger is Claude Code, which emits \e[>4;2m on startup.

Mirrors the #92 approach with a separate matcher for the modifyOtherKeys form:

  • Scans the buffer for \x1b[27;<mod>;<key>~
  • Same lock modifier tolerance as keypressWithMod
  • Rejects extra intentional modifiers and lookalike CSI sequences (\x1b[27m, \x1b[27~, \x1b[27;5R)

Also force-resets modifyOtherKeys (\e[>4;0m) in the detach restore_seq, mirroring the existing unconditional disables for mouse modes, bracketed paste, focus events, and alt screen — without it the outer shell ends up encoding ctrl combos as escape sequences after detach.

Tests in test "isCtrlBackslash xterm modifyOtherKeys" cover lock modifier permutations, lookalikes, embedded-buffer matches, and malformed input. Existing test suite passes.

PR neurosnap#92 made the ctrl+\ matcher handle the kitty CSI u encoding. The
older xterm modifyOtherKeys encoding (CSI 27 ; mod ; key ~) was still
missed, which broke detach when the inner program (e.g. claude) enables
modifyOtherKeys level 2 and the outer terminal honors it (e.g. iTerm2).

Add a separate matcher mirroring keypressWithMod, with the same lock
modifier tolerance. Also force modifyOtherKeys back to level 0 in the
detach restore sequence; xterm modifyOtherKeys has no push/pop, so this
is unconditional, mirroring the existing unconditional disables for
mouse modes, bracketed paste, focus events, and alt screen. Without
it the outer shell ends up encoding ctrl combos as escape sequences
after detach, corrupting input at the prompt.
@neurosnap

Copy link
Copy Markdown
Owner

Hi, this is on my radar, just haven't had the time to dig into the spec for these escape sequences to better understand what this PR is doing.

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.

ctrl+\ detach not detected when inner program enables xterm modifyOtherKeys

2 participants