Skip to content

Commit f3554df

Browse files
fix: add Kitty keyboard protocol Shift+Enter sequences for broader terminal compatibility
SHIFT_RETURN_SEQUENCES now covers both xterm modifyOtherKeys (Shift=2) and Kitty keyboard protocol (Shift=1) encodings. Also clear input when key.return is true to prevent escape sequence artifacts from leaking into the text buffer.
1 parent 5e23d3c commit f3554df

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/tests/promptInputKeys.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ test("parseTerminalInput keeps BS payload for meta+backspace", () => {
8080

8181
test("parseTerminalInput recognizes shifted return sequences", () => {
8282
const { input, key } = parseTerminalInput("\u001B\r");
83-
assert.equal(input, "\r");
83+
assert.equal(input, "");
8484
assert.equal(key.return, true);
8585
assert.equal(key.shift, true);
8686
assert.equal(key.meta, false);

src/ui/prompt/useTerminalInput.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ const BACKSPACE_BYTES = new Set(["\u007F", "\b"]);
2626
const FORWARD_DELETE_SEQUENCES = new Set(["\u001B[3~", "\u001B[P"]);
2727
const HOME_SEQUENCES = new Set(["\u001B[H", "\u001B[1~", "\u001B[7~", "\u001BOH"]);
2828
const END_SEQUENCES = new Set(["\u001B[F", "\u001B[4~", "\u001B[8~", "\u001BOF"]);
29-
const SHIFT_RETURN_SEQUENCES = new Set(["\u001B\r", "\u001B[13;2u", "\u001B[13;2~", "\u001B[27;2;13~"]);
29+
const SHIFT_RETURN_SEQUENCES = new Set([
30+
"\u001B\r",
31+
"\u001B[13;2u", // xterm modifyOtherKeys: keycode=13 (Enter), modifier=2 (Shift)
32+
"\u001B[13;1u", // Kitty keyboard protocol: keycode=13, modifier=1 (Shift)
33+
"\u001B[13;2~",
34+
"\u001B[13;1~", // tmux / alternate terminals may use ~ terminator
35+
"\u001B[27;2;13~",
36+
"\u001B[27;1;13~", // extended format, Kitty encoding
37+
]);
3038
const META_RETURN_SEQUENCES = new Set(["\u001B[13;3u", "\u001B[13;4u"]);
3139
const CTRL_LEFT_SEQUENCES = new Set(["\u001B[1;5D", "\u001B[5D"]);
3240
const CTRL_RIGHT_SEQUENCES = new Set(["\u001B[1;5C", "\u001B[5C"]);
@@ -162,7 +170,7 @@ export function parseTerminalInput(data: Buffer | string): { input: string; key:
162170
key.shift = true;
163171
}
164172

165-
if (key.tab || key.backspace || key.delete) {
173+
if (key.tab || key.backspace || key.delete || key.return) {
166174
input = "";
167175
}
168176

0 commit comments

Comments
 (0)