fix(tui): handle Kitty protocol lock key modifiers

Fixes keyboard input in Ghostty on Linux when Num Lock is enabled.
The Kitty protocol includes Caps Lock (64) and Num Lock (128) bits
in modifier values. Now masks out lock bits when matching shortcuts.

Added helper functions: isArrowUp/Down/Left/Right, isEnter, isTab,
isBackspace, isShiftEnter, isAltEnter, isAltLeft/Right, isCtrlLeft/Right

fixes #243
This commit is contained in:
Mario Zechner 2025-12-19 20:34:20 +01:00
parent 7e38897673
commit 28c3ffb914
6 changed files with 278 additions and 42 deletions

View file

@ -1,4 +1,4 @@
import { isAltBackspace, isCtrlA, isCtrlE, isCtrlK, isCtrlU, isCtrlW } from "../keys.js";
import { isAltBackspace, isArrowLeft, isArrowRight, isCtrlA, isCtrlE, isCtrlK, isCtrlU, isCtrlW } from "../keys.js";
import type { Component } from "../tui.js";
import { visibleWidth } from "../utils.js";
@ -78,7 +78,7 @@ export class Input implements Component {
return;
}
if (data === "\x1b[D") {
if (isArrowLeft(data)) {
// Left arrow
if (this.cursor > 0) {
this.cursor--;
@ -86,7 +86,7 @@ export class Input implements Component {
return;
}
if (data === "\x1b[C") {
if (isArrowRight(data)) {
// Right arrow
if (this.cursor < this.value.length) {
this.cursor++;