fix(tui): handle Ctrl+Enter and Shift+Enter as newline on WSL/Windows - #29445
Closed
nathanmilot wants to merge 1 commit into
Closed
fix(tui): handle Ctrl+Enter and Shift+Enter as newline on WSL/Windows#29445nathanmilot wants to merge 1 commit into
nathanmilot wants to merge 1 commit into
Conversation
Ctrl+Enter and Shift+Enter insert a newline in the TUI input on platforms where the terminal collapses modified Enter to bare CR. Three layers of defense: 1. parse-keypress.ts — isCtrlEnterAsLF() detects WSL/Windows/SSH/WT and treats bare LF as return+ctrl (mirrors cli.py's _preserve_ctrl_enter_newline). Also adds ESC+CR fallback as return+shift for terminals that don't support kitty protocol. 2. terminal.ts — supportsExtendedKeys() now also returns true for WSL/Windows/SSH/WT environments so kitty keyboard protocol and xterm modifyOtherKeys are enabled on terminals (like Tabby) that don't set TERM_PROGRAM. 3. Tabby added to EXTENDED_KEYS_TERMINALS for when TERM_PROGRAM is set.
Author
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.
Problem
On WSL, Windows, SSH sessions, and Windows Terminal, pressing Ctrl+Enter or Shift+Enter in the Hermes TUI submits the prompt instead of inserting a newline. The non-TUI CLI handles this correctly via
_preserve_ctrl_enter_newline()incli.py, but the TUI's key parser has no equivalent detection.Root Cause
Three interrelated issues:
Ctrl+Enter arrives as bare LF (
\n) on WSL/Windows platforms, butparseKeypresstreats LF identically to CR — both map toreturnwith no modifiers. ThetextInputhandler needsctrl/shift/metaset to insert a newline.Terminals without
TERM_PROGRAM(like Tabby) never get kitty keyboard protocol or xterm modifyOtherKeys enabled, so Ctrl+Enter and Shift+Enter arrive as undifferentiated CR.No ESC+CR fallback — some terminals send
ESC + CR(\e\r) for Shift+Enter as a legacy fallback when enhanced protocols aren't active. The parser had no handler for this.Fix
Three layers of defense added to
parse-keypress.tsandterminal.ts:parse-keypress.tsisCtrlEnterAsLF()detects WSL/Windows/SSH/WT environments (mirrorscli.py). On these platforms, bare LF =return+ctrl→ newline.parse-keypress.ts\e\r/\e\nparsed asreturn+shift→ newline for terminals without kitty protocol.terminal.tssupportsExtendedKeys()now also returns true when WSL/Windows/SSH/WT is detected, enabling kitty keyboard protocol on terminals (like Tabby) that don't setTERM_PROGRAM.Tested on: Tabby (xterm.js) → WSL2 (Ubuntu) → tmux → Hermes TUI, with and without tmux. Ctrl+Enter and Shift+Enter now insert newlines.
Relation to existing PRs
fix(tui): distinguish LF from Return in key parser) — that PR makes LF → Ctrl unconditional, which would break plain Enter on native Linux where Enter = LF. This PR adds platform detection viaisCtrlEnterAsLF().fix(tui): Shift+Enter inserts newline instead of submitting) — that PR fixes CSI u setup in VS Code/Cursor terminals; this PR handles the fallback case for terminals without CSI u.