From 9ebf3217174e8076916d69225a39a57c6f65704c Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Wed, 19 Nov 2025 21:50:05 -0800 Subject: [PATCH] Use synchronous writes when detecting keyboard modes (#13478) --- .../cli/src/ui/utils/kittyProtocolDetector.ts | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/packages/cli/src/ui/utils/kittyProtocolDetector.ts b/packages/cli/src/ui/utils/kittyProtocolDetector.ts index 0dc1d02ace..e5682566c0 100644 --- a/packages/cli/src/ui/utils/kittyProtocolDetector.ts +++ b/packages/cli/src/ui/utils/kittyProtocolDetector.ts @@ -4,6 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as fs from 'node:fs'; + let detectionComplete = false; let kittySupported = false; @@ -91,9 +93,8 @@ export async function detectAndEnableKittyProtocol(): Promise { process.stdin.on('data', handleData); - // Send queries - process.stdout.write('\x1b[?u'); // Query progressive enhancement - process.stdout.write('\x1b[c'); // Query device attributes + // Query progressive enhancement and device attributes + fs.writeSync(process.stdout.fd, '\x1b[?u\x1b[c'); // Timeout after 200ms // When a iterm2 terminal does not have focus this can take over 90s on a @@ -107,13 +108,17 @@ export function isKittyProtocolEnabled(): boolean { } function disableAllProtocols() { - if (kittyEnabled) { - process.stdout.write('\x1b[1u'); - kittyEnabled = true; - } - if (sgrMouseSupported) { - process.stdout.write('\x1b[?1006h'); - sgrMouseEnabled = true; + try { + if (kittySupported) { + fs.writeSync(process.stdout.fd, '\x1b[>1u'); + kittyEnabled = true; + } + if (sgrMouseSupported) { + fs.writeSync(process.stdout.fd, '\x1b[?1006h'); + sgrMouseEnabled = true; + } + } catch { + // Ignore } }