fix(cli): support Shift+Enter for newline in modern terminals#852
Closed
ZealousEar wants to merge 1 commit intoNousResearch:mainfrom
Closed
fix(cli): support Shift+Enter for newline in modern terminals#852ZealousEar wants to merge 1 commit intoNousResearch:mainfrom
ZealousEar wants to merge 1 commit intoNousResearch:mainfrom
Conversation
Modern terminals (Ghostty, Kitty, WezTerm) using the Kitty keyboard protocol or xterm's modifyOtherKeys send distinct escape sequences for Shift+Enter (\x1b[13;2u and \x1b[27;2;13~), but prompt_toolkit maps them to plain ControlM (Enter), which submits the message instead of inserting a newline. This patch remaps both sequences to ControlJ so they trigger the existing Ctrl+Enter handler that inserts a newline. Also moves the prompt_toolkit Keys import to module level (was a local import that caused an UnboundLocalError in certain code paths) and updates the /help text to list all three multi-line shortcuts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
Closing — we've extensively tested ANSI_SEQUENCES remapping for Shift+Enter and unfortunately it doesn't work reliably in practice. Thanks for the effort though! |
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.
Summary
\x1b[13;2uand\x1b[27;2;13~), butprompt_toolkitmaps both to plainControlM(Enter) — so pressing Shift+Enter submits the message instead of inserting a newline.Keys.ControlJ, which triggers the existing Ctrl+Enter handler that inserts a newline. Shift+Enter now works identically to Alt+Enter and Ctrl+Enter for multi-line input.from prompt_toolkit.keys import Keysimport from a local scope to module level, fixing anUnboundLocalErrorthat could occur whenKeyswas referenced before the local import line./helptext to list all three multi-line shortcuts.Details
The Kitty keyboard protocol encodes modifier+key as CSI sequences:
\x1b[13;2uKeys.ControlM(submit)Keys.ControlJ(newline)\x1b[27;2;13~Keys.ControlM(submit)Keys.ControlJ(newline)No behavioral change for terminals that don't use these protocols — plain Enter still submits as before.
Test plan
ValueErrororUnboundLocalError🤖 Generated with Claude Code