fix: support CSI-u printable input on Windows

This commit is contained in:
Vasanthdev2004
2026-04-02 10:05:16 +05:30
parent 1a60509fdc
commit ffbc1f8f6e
2 changed files with 76 additions and 1 deletions

View File

@@ -468,7 +468,10 @@ function decodeModifier(modifier: number): {
ctrl: boolean
super: boolean
} {
const m = modifier - 1
// Some Windows VT stacks use 0 instead of 1 for an unmodified CSI-u key.
// Clamp to the protocol default so plain printable keys don't look like
// ctrl+meta+shift+super all at once.
const m = Math.max(modifier, 1) - 1
return {
shift: !!(m & 1),
meta: !!(m & 2),
@@ -477,6 +480,14 @@ function decodeModifier(modifier: number): {
}
}
function isPrivateUseCodepoint(codepoint: number): boolean {
return (
(codepoint >= 0xe000 && codepoint <= 0xf8ff) ||
(codepoint >= 0xf0000 && codepoint <= 0xffffd) ||
(codepoint >= 0x100000 && codepoint <= 0x10fffd)
)
}
/**
* Map keycode to key name for modifyOtherKeys/CSI u sequences.
* Handles both ASCII keycodes and Kitty keyboard protocol functional keys.
@@ -536,6 +547,21 @@ function keycodeToName(keycode: number): string | undefined {
if (keycode >= 32 && keycode <= 126) {
return String.fromCharCode(keycode).toLowerCase()
}
// CSI-u can carry printable Unicode codepoints directly on some
// Windows terminals and keyboard layouts. Keep kitty's private-use
// functional key range excluded so special keys still stay non-text.
if (
keycode > 0x1f &&
keycode !== 0x7f &&
(keycode < 0x80 || keycode > 0x9f) &&
keycode <= 0x10ffff &&
(keycode < 0xd800 || keycode > 0xdfff) &&
!isPrivateUseCodepoint(keycode)
) {
return String.fromCodePoint(keycode)
}
return undefined
}
}