mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-22 02:03:42 +00:00
fix(tui): remove Kitty protocol query timeout
The 100ms timeout was causing Kitty protocol detection to fail when the terminal response was delayed (e.g., due to event loop blocking during startup). This resulted in shift+enter not working in some scenarios. Changes: - Remove timeout-based Kitty detection, process input immediately - Detect Kitty response in stdinBuffer output (handles split data) - Add modifyOtherKeys fallback for terminals without Kitty support (matches xterm format \x1b[27;modifier;keycode~)
This commit is contained in:
parent
f1e225d9e7
commit
c07126c0fd
2 changed files with 48 additions and 73 deletions
|
|
@ -437,6 +437,21 @@ function matchesKittySequence(data: string, expectedCodepoint: number, expectedM
|
|||
return parsed.codepoint === expectedCodepoint && actualMod === expectedMod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Match xterm modifyOtherKeys format: CSI 27 ; modifiers ; keycode ~
|
||||
* This is used by terminals when Kitty protocol is not enabled.
|
||||
* Modifier values are 1-indexed: 2=shift, 3=alt, 5=ctrl, etc.
|
||||
*/
|
||||
function matchesModifyOtherKeys(data: string, expectedKeycode: number, expectedModifier: number): boolean {
|
||||
const match = data.match(/^\x1b\[27;(\d+);(\d+)~$/);
|
||||
if (!match) return false;
|
||||
const modValue = parseInt(match[1]!, 10);
|
||||
const keycode = parseInt(match[2]!, 10);
|
||||
// Convert from 1-indexed xterm format to our 0-indexed format
|
||||
const actualMod = modValue - 1;
|
||||
return keycode === expectedKeycode && actualMod === expectedModifier;
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Generic Key Matching
|
||||
// =============================================================================
|
||||
|
|
@ -515,6 +530,10 @@ export function matchesKey(data: string, keyId: KeyId): boolean {
|
|||
) {
|
||||
return true;
|
||||
}
|
||||
// xterm modifyOtherKeys format (fallback when Kitty protocol not enabled)
|
||||
if (matchesModifyOtherKeys(data, CODEPOINTS.enter, MODIFIERS.shift)) {
|
||||
return true;
|
||||
}
|
||||
// When Kitty protocol is active, legacy sequences are custom terminal mappings
|
||||
// \x1b\r = Kitty's "map shift+enter send_text all \e\r"
|
||||
// \n = Ghostty's "keybind = shift+enter=text:\n"
|
||||
|
|
@ -531,6 +550,10 @@ export function matchesKey(data: string, keyId: KeyId): boolean {
|
|||
) {
|
||||
return true;
|
||||
}
|
||||
// xterm modifyOtherKeys format (fallback when Kitty protocol not enabled)
|
||||
if (matchesModifyOtherKeys(data, CODEPOINTS.enter, MODIFIERS.alt)) {
|
||||
return true;
|
||||
}
|
||||
// \x1b\r is alt+enter only in legacy mode (no Kitty protocol)
|
||||
// When Kitty protocol is active, alt+enter comes as CSI u sequence
|
||||
if (!_kittyProtocolActive) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue