feat(shell): support Shift+Enter for inserting newlines#2255
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b4643ce401
ℹ️ 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".
b4643ce to
d9d0daa
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d9d0daa4c2
ℹ️ 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".
fe7dd7b to
0181b2b
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0181b2badd
ℹ️ 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".
| self._session.app.output.write_raw("\x1b[>4;1m") | ||
| self._session.app.output.flush() |
There was a problem hiding this comment.
Preserve Alt-Enter newline after enabling modifyOtherKeys
Enabling xterm modifyOtherKeys here changes how modified Enter keys are encoded in supporting terminals, so Alt+Enter is no longer sent as escape + enter and the existing @_kb.add("escape", "enter") newline binding won’t fire. Because this patch only registers \x1b[27;2;13~ (Shift+Enter), users on terminals that honor \x1b[>4;1m will lose the previously supported Alt-Enter newline shortcut, which is a behavioral regression from prior releases and contradicts the updated docs/PR notes.
Useful? React with 👍 / 👎.
0181b2b to
d1d24f2
Compare
Add Shift+Enter as an alternative shortcut for inserting a newline in the interactive prompt, alongside the existing Ctrl-J and Alt-Enter bindings. This aligns Kimi CLI with the de-facto standard used by Claude Code, Codex CLI, ChatGPT, Discord, Slack, and most modern chat UIs. Changes: - Register xterm modifyOtherKeys ANSI sequences for Shift+Enter and Alt+Enter, mapping Alt+Enter to a private-use character so it can be bound independently of the plain Enter key (preserving Alt+Enter newline behavior during completions). - Intercept plain Enter to distinguish Shift+Enter (insert \n) from plain Enter (submit). - Enable xterm modifyOtherKeys on session startup and disable it on exit so supporting terminals emit distinct sequences. - Update bottom toolbar hint to "shift-enter / ctrl-j: newline". - Update English documentation (keyboard.md, interaction.md). - Update existing test assertions for toolbar tips. - Add PTY e2e tests for Shift+Enter and Alt+Enter newline insertion. - Add ANSI sequence registration tests. Ctrl-J and Alt-Enter continue to work exactly as before. Closes MoonshotAI#2254 Related: MoonshotAI#2010, MoonshotAI#2121, MoonshotAI#1585, MoonshotAI#1574 Signed-off-by: Alexey Zhokhov <alexey@zhokhov.com>
d1d24f2 to
7397236
Compare
Related Issue
Closes #2254
Related: #2010, #2121, #1585, #1574
Description
This PR adds Shift+Enter as an alternative shortcut for inserting a newline in the interactive prompt, complementing the existing
Ctrl-JandAlt-Enterbindings.Why this matters
Shift+Enterhas become the de-facto standard across modern chat UIs and CLI agents:Shift+Enterinserts newlineShift+Enterinserts newlineShift+Enterinserts newlineShift+Enterinserts newlineShift+Enterfor newlineKimi CLI's current
Ctrl-J/Alt-Entershortcuts work, but they break muscle memory for users coming from any of these platforms. This small UX friction is one of the most frequently requested features in the issue tracker (4+ open issues).What changed
\x1b[27;2;13~) and Alt+Enter (\x1b[27;3;13~). Alt+Enter is mapped to a private-use character (\ue000) so it can be bound independently of plain Enter, preserving its newline behavior during completions.\n) from plain Enter (submit message).\x1b[>4;1m) and disable it on exit (\x1b[>4;0m) so supporting terminals emit distinct sequences.ctrl-j: newlinetoshift-enter / ctrl-j: newline.docs/en/reference/keyboard.md,docs/en/guides/interaction.md).tests/ui_and_conv/test_prompt_tips.py.tests/ui_and_conv/test_prompt_shift_enter.py.Backward compatibility
Ctrl-JandAlt-Entercontinue to work exactly as before.Test plan
make formatpassesmake checkpasses (pre-existing diagnostics unrelated to this change)pytest tests/ui_and_conv/test_prompt_tips.pypasses (60/60)pytest tests/ui_and_conv/passes (723/723)pytest tests/e2e/test_shell_pty_e2e.py::test_shell_shift_enter_inserts_newlinepassespytest tests/e2e/test_shell_pty_e2e.py::test_shell_alt_enter_inserts_newlinepassesctrl-jstill inserts a newline in existing testsChecklist
make gen-changelogto update the changelog.make gen-docsto update the user documentation.