feat(shell): add Shift+Enter as newline shortcut alongside Ctrl-J and Alt-Enter#2302
feat(shell): add Shift+Enter as newline shortcut alongside Ctrl-J and Alt-Enter#2302ktwu01 wants to merge 1 commit into
Conversation
|
|
||
| @_kb.add("escape", "enter", eager=True) | ||
| @_kb.add("c-j", eager=True) | ||
| @_kb.add("s-enter", eager=True) |
There was a problem hiding this comment.
🔴 s-enter is not a valid prompt_toolkit key name, crashing CustomPromptSession.__init__
_kb.add("s-enter", eager=True) raises ValueError: Invalid key: s-enter at call time because s-enter does not exist in prompt_toolkit's ALL_KEYS (verified on both 3.0.28 and the pinned 3.0.52). Because Python evaluates stacked decorators bottom-up, this error fires before the c-j and escape+enter decorators above it are applied, so all three newline bindings fail to register and the CustomPromptSession.__init__ crashes entirely. This means the interactive shell UI cannot start at all.
Reproduction confirming the issue on prompt_toolkit 3.0.52
from prompt_toolkit.key_binding import KeyBindings
kb = KeyBindings()
try:
@kb.add('escape', 'enter', eager=True)
@kb.add('c-j', eager=True)
@kb.add('s-enter', eager=True)
def handler(event):
pass
except Exception as e:
print(f'Error: {e}') # ValueError: Invalid key: s-enter
print(len(kb.bindings)) # 0 — none of the three bindings were registeredShift+Enter is indistinguishable from Enter in most terminals because they both send \r. Modern terminals supporting the Kitty keyboard protocol can distinguish them, but prompt_toolkit does not expose a s-enter key. A different approach is needed (e.g., handling via a VT100 escape sequence or the Kitty protocol directly).
Prompt for agents
The key name `s-enter` is not recognized by prompt_toolkit (tested on 3.0.52, the pinned version). The `_kb.add("s-enter", eager=True)` call at `src/kimi_cli/ui/shell/prompt.py:1324` raises ValueError immediately, which also prevents the Ctrl-J and Alt-Enter bindings from being registered (since decorators are evaluated bottom-up), and crashes the entire CustomPromptSession.__init__.
Shift+Enter is fundamentally indistinguishable from Enter in classic terminal protocols (both send CR). Only terminals implementing the Kitty keyboard protocol can differentiate them, and prompt_toolkit has no built-in support for this.
Possible approaches:
1. Remove the `s-enter` binding entirely and keep only `c-j` and `escape+enter` (Alt-Enter) as before, updating docs accordingly.
2. If Kitty protocol support is desired, handle the raw escape sequence `\x1b[13;2u` (Shift+Enter in Kitty protocol) by adding it to prompt_toolkit's VT100 input parser, or use a custom key binding approach that works with terminals that report this sequence.
3. At minimum, the `@_kb.add("s-enter", eager=True)` line must be separated from the other two decorators (or wrapped in a try/except) so that its failure does not break Ctrl-J and Alt-Enter.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8b456c5fdc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| @_kb.add("escape", "enter", eager=True) | ||
| @_kb.add("c-j", eager=True) | ||
| @_kb.add("s-enter", eager=True) |
There was a problem hiding this comment.
Replace unsupported Shift-Enter key spec
Using @_kb.add("s-enter", eager=True) introduces a startup-breaking binding because prompt-toolkit==3.0.52 does not define s-enter as a valid special key (it only supports s-tab and a limited set of other s-* keys), and KeyBindings.add() validates keys eagerly via _parse_key, which raises ValueError("Invalid key: s-enter") for multi-character unknown keys. As a result, constructing CustomPromptSession fails before the shell prompt can run.
Useful? React with 👍 / 👎.
Summary
s-enter(Shift+Enter) to the newline keybinding insrc/kimi_cli/ui/shell/prompt.py, alongside the existingescape+enter(Alt-Enter) andc-j(Ctrl-J) bindingsctrl-j: newlinetoshift-enter / ctrl-j: newlinekeyboard.md,interaction.md) to list Shift+Enter as the primary newline shortcutNo breaking changes. Ctrl-J and Alt-Enter continue to work exactly as before.
Closes #2254
Test plan
Shift+Enterin the interactive prompt: a newline is inserted, message is NOT submittedCtrl-J: still inserts a newline (backward compat)Alt-Enter: still inserts a newline (backward compat)shift-enter / ctrl-j: newlinedocs/en/reference/keyboard.mdanddocs/zh/reference/keyboard.mdlist Shift-Enter in the shortcuts table🤖 Generated with Claude Code