fix(cli): support CJK input and full Unicode scalar values in terminal protocols (#22353)

This commit is contained in:
Tommaso Sciortino
2026-03-13 21:24:26 +00:00
committed by GitHub
parent fa024133e6
commit 24933a90d0
6 changed files with 78 additions and 38 deletions
@@ -610,20 +610,28 @@ function* emitKeys(
if (code.endsWith('u') || code.endsWith('~')) {
// CSI-u or tilde-coded functional keys: ESC [ <code> ; <mods> (u|~)
const codeNumber = parseInt(code.slice(1, -1), 10);
if (codeNumber >= 33 && codeNumber <= 126) {
const char = String.fromCharCode(codeNumber);
const mapped = KITTY_CODE_MAP[codeNumber];
if (mapped) {
name = mapped.name;
if (mapped.sequence && !ctrl && !cmd && !alt) {
sequence = mapped.sequence;
insertable = true;
}
} else if (
codeNumber >= 33 && // Printable characters start after space (32),
codeNumber <= 0x10ffff && // Valid Unicode scalar values (excluding control characters)
(codeNumber < 0xd800 || codeNumber > 0xdfff) // Exclude UTF-16 surrogate halves
) {
// Valid printable Unicode scalar values (up to Unicode maximum)
// Note: Kitty maps its special keys to the PUA (57344+), which are handled by KITTY_CODE_MAP above.
const char = String.fromCodePoint(codeNumber);
name = char.toLowerCase();
if (char >= 'A' && char <= 'Z') {
if (char !== name) {
shift = true;
}
} else {
const mapped = KITTY_CODE_MAP[codeNumber];
if (mapped) {
name = mapped.name;
if (mapped.sequence && !ctrl && !cmd && !alt) {
sequence = mapped.sequence;
insertable = true;
}
if (!ctrl && !cmd && !alt) {
sequence = char;
insertable = true;
}
}
}
@@ -696,6 +704,10 @@ function* emitKeys(
alt = ch.length > 0;
} else {
// Any other character is considered printable.
name = ch.toLowerCase();
if (ch !== name) {
shift = true;
}
insertable = true;
}