/** * [WHO]: Terminal, ProcessTerminal * [FROM]: Depends on node:fs, node:module, ./keys.js, ./stdin-buffer.js * [TO]: Consumed by core/lib/tui/src/index.ts * [HERE]: core/lib/tui/src/terminal.ts - */ /** * Minimal terminal interface for TUI */ export interface Terminal { start(onInput: (data: string) => void, onResize: () => void): void; stop(): void; /** * Drain stdin before exiting to prevent Kitty key release events from * leaking to the parent shell over slow SSH connections. * @param maxMs - Maximum time to drain (default: 1000ms) * @param idleMs - Exit early if no input arrives within this time (default: 50ms) */ drainInput(maxMs?: number, idleMs?: number): Promise; write(data: string): void; get columns(): number; get rows(): number; get kittyProtocolActive(): boolean; moveBy(lines: number): void; hideCursor(): void; showCursor(): void; clearLine(): void; clearFromCursor(): void; clearScreen(): void; setTitle(title: string): void; } /** * Real terminal using process.stdin/stdout */ export declare class ProcessTerminal implements Terminal { private wasRaw; private inputHandler?; private resizeHandler?; private _kittyProtocolActive; private stdinBuffer?; private stdinDataHandler?; private writeLogPath; get kittyProtocolActive(): boolean; start(onInput: (data: string) => void, onResize: () => void): void; /** * Set up StdinBuffer to split batched input into individual sequences. * This ensures components receive single events, making matchesKey/isKeyRelease work correctly. * * Also watches for Kitty protocol response and enables it when detected. * This is done here (after stdinBuffer parsing) rather than on raw stdin * to handle the case where the response arrives split across multiple events. */ private setupStdinBuffer; /** * Query terminal for Kitty keyboard protocol support and enable if available. * * Sends CSI ? u to query current flags. If terminal responds with CSI ? u, * it supports the protocol and we enable it with CSI > 1 u. * * The response is detected in setupStdinBuffer's data handler, which properly * handles the case where the response arrives split across multiple stdin events. * * GPU-renderer terminals (Warp, Wave) may have issues with Kitty protocol queries. * Skip the query on these terminals to prevent crashes or hangs. */ private queryAndEnableKittyProtocol; /** * On Windows, add ENABLE_VIRTUAL_TERMINAL_INPUT (0x0200) to the stdin * console handle so the terminal sends VT sequences for modified keys * (e.g. \x1b[Z for Shift+Tab). Without this, libuv's ReadConsoleInputW * discards modifier state and Shift+Tab arrives as plain \t. */ private enableWindowsVTInput; drainInput(maxMs?: number, idleMs?: number): Promise; stop(): void; write(data: string): void; get columns(): number; get rows(): number; moveBy(lines: number): void; hideCursor(): void; showCursor(): void; clearLine(): void; clearFromCursor(): void; clearScreen(): void; setTitle(title: string): void; }