@code-yeongyu/senpi-tui 2026.9.4 → 2026.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"terminal.js","sourceRoot":"","sources":["../src/terminal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAElD,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAC5C,MAAM,iCAAiC,GAAG,gBAAgB,CAAC;AAC3D,MAAM,gCAAgC,GAAG,gBAAgB,CAAC;AAC1D,MAAM,2BAA2B,GAAG,YAAY,CAAC;AACjD,MAAM,qCAAqC,GAAG,CAAC,CAAC;AAChD,MAAM,yBAAyB,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AACxE,uGAAuG;AACvG,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,4FAA4F;AAC5F,2FAA2F;AAC3F,6FAA6F;AAC7F,0FAA0F;AAC1F,kGAAkG;AAClG,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC;AAC/D,MA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AAC,gBAAgB,GAAG,SAAS,CAAC;QAClC,OAAO,IAAI,CAAC;IACb,CAAC;CACD","sourcesContent":["import * as fs from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport * as path from \"node:path\";\nimport { setKittyProtocolActive } from \"./keys.ts\";\nimport { isMultiplexerSession } from \"./mux.ts\";\nimport { isNativeModifierPressed } from \"./native-modifiers.ts\";\nimport { getNativeModuleCandidates } from \"./native-module-path.ts\";\nimport { StdinBuffer } from \"./stdin-buffer.ts\";\n\nconst cjsRequire = createRequire(import.meta.url);\n\nconst TERMINAL_PROGRESS_KEEPALIVE_MS = 1000;\nconst TERMINAL_PROGRESS_ACTIVE_SEQUENCE = \"\\x1b]9;4;3\\x07\";\nconst TERMINAL_PROGRESS_CLEAR_SEQUENCE = \"\\x1b]9;4;0\\x07\";\nconst NATIVE_SHIFT_ENTER_SEQUENCE = \"\\x1b[13;2u\";\nconst DESIRED_KITTY_KEYBOARD_PROTOCOL_FLAGS = 7;\nconst DEAD_TERMINAL_ERROR_CODES = new Set([\"EIO\", \"EPIPE\", \"ENOTCONN\"]);\n// Bun's macOS tty shim can report synchronous ioctl EIO as raw positive errno 5 without a string code.\nconst EIO_ERRNO = 5;\n// Bun's tty shim can also drop both properties and leave the errno only in the message text\n// (`new Error(\"setRawMode failed with errno: 5\")` - no `code`, no `errno`), so the numeric\n// fallback has to read the message. Restricted to errno values that are stable across darwin\n// and linux: EIO (5) and EPIPE (32). ENOTCONN is deliberately excluded because its number\n// differs per platform (57 on darwin, 107 on linux) and a wrong guess would swallow a live error.\nconst EPIPE_ERRNO = 32;\nconst DEAD_TERMINAL_ERRNOS = new Set([EIO_ERRNO, EPIPE_ERRNO]);\nconst ERRNO_IN_MESSAGE_PATTERN = /errno:\\s*(\\d+)/;\nconst KEYBOARD_PROTOCOL_RESPONSE_FRAGMENT_TIMEOUT_MS = 150;\nconst KITTY_KEYBOARD_PROTOCOL_QUERY = `\\x1b[>${DESIRED_KITTY_KEYBOARD_PROTOCOL_FLAGS}u\\x1b[?u\\x1b[c`;\n\nexport type KeyboardProtocolNegotiationSequence =\n\t| { type: \"kitty-flags\"; flags: number }\n\t| { type: \"device-attributes\" };\n\nexport function parseKeyboardProtocolNegotiationSequence(\n\tsequence: string,\n): KeyboardProtocolNegotiationSequence | undefined {\n\tconst kittyFlags = sequence.match(/^\\x1b\\[\\?(\\d+)u$/);\n\tif (kittyFlags) {\n\t\treturn { type: \"kitty-flags\", flags: Number.parseInt(kittyFlags[1]!, 10) };\n\t}\n\tif (/^\\x1b\\[\\?[\\d;]*c$/.test(sequence)) {\n\t\treturn { type: \"device-attributes\" };\n\t}\n\treturn undefined;\n}\n\nfunction isKeyboardProtocolNegotiationSequencePrefix(sequence: string): boolean {\n\treturn sequence === \"\\x1b[\" || /^\\x1b\\[\\?[\\d;]*$/.test(sequence);\n}\n\nexport function isAppleTerminalSession(): boolean {\n\treturn process.platform === \"darwin\" && process.env.TERM_PROGRAM === \"Apple_Terminal\";\n}\n\nexport function normalizeNativeShiftEnterInput(\n\tdata: string,\n\tshouldDetectNativeShiftEnter: boolean,\n\tisShiftPressed: boolean,\n): string {\n\tif (shouldDetectNativeShiftEnter && data === \"\\r\" && isShiftPressed) return NATIVE_SHIFT_ENTER_SEQUENCE;\n\treturn data;\n}\n\nexport function normalizeAppleTerminalInput(data: string, isAppleTerminal: boolean, isShiftPressed: boolean): string {\n\treturn normalizeNativeShiftEnterInput(data, isAppleTerminal, isShiftPressed);\n}\n\nexport function normalizeWarpWslShiftEnterInput(\n\tdata: string,\n\tenv: NodeJS.ProcessEnv = process.env,\n\tplatform: NodeJS.Platform = process.platform,\n\tsocketExists: (socketPath: string) => boolean = (socketPath) => {\n\t\ttry {\n\t\t\treturn fs.statSync(socketPath).isSocket();\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t},\n): string {\n\tif (data !== \"\\n\" || platform !== \"linux\") return data;\n\tif (isMultiplexerSession(env) || env.SSH_CONNECTION?.trim() || env.SSH_CLIENT?.trim() || env.SSH_TTY?.trim()) {\n\t\treturn data;\n\t}\n\tconst isWarp = Boolean(env.WARP_SESSION_ID?.trim() || env.WARP_TERMINAL_SESSION_UUID?.trim());\n\tconst interopPath = env.WSL_INTEROP?.trim();\n\tconst isWsl =\n\t\tisWarp && interopPath !== undefined && /^\\/run\\/WSL\\/\\d+_interop$/.test(interopPath) && socketExists(interopPath);\n\treturn isWarp && isWsl ? NATIVE_SHIFT_ENTER_SEQUENCE : data;\n}\n\nexport function keyboardEnhancementEnabled(): boolean {\n\tconst value = process.env.PI_TUI_KEYBOARD_PROTOCOL;\n\tif (value === undefined) return true;\n\treturn ![\"0\", \"false\", \"no\", \"off\"].includes(value.toLowerCase());\n}\n\nfunction isDeadTerminalError(error: unknown): boolean {\n\tif (!(error instanceof Error)) return false;\n\tif (\"code\" in error && typeof error.code === \"string\") return DEAD_TERMINAL_ERROR_CODES.has(error.code);\n\tif (\"errno\" in error && error.errno === EIO_ERRNO) return true;\n\tconst messageErrno = ERRNO_IN_MESSAGE_PATTERN.exec(error.message);\n\tif (!messageErrno) return false;\n\treturn DEAD_TERMINAL_ERRNOS.has(Number.parseInt(messageErrno[1]!, 10));\n}\n\nconst STDIN_ERROR_HANDLER_GRACE_MS = 250;\nconst stdinErrorSubscribers = new Set<(err: Error) => void>();\n\nexport function __stdinErrorSubscriberCountForTests(): number {\n\treturn stdinErrorSubscribers.size;\n}\nexport function __stdinErrorDispatcherInstalledForTests(): boolean {\n\treturn process.stdin.listeners(\"error\").includes(dispatchStdinError);\n}\n\n/**\n * A vanished or re-backgrounded controlling terminal fails the next stdin\n * read with EIO; that is the only stdin error this module owns. Node reports\n * it as code \"EIO\" (errno -5), Bun's macOS tty shim as a bare positive\n * errno 5 — both shapes classify. Any other stdin failure (EBADF, EPIPE, an\n * unexpected platform error) keeps its default EventEmitter propagation so it\n * stays observable instead of being downgraded to a silently ignored error.\n */\nfunction isTerminalDetachStdinError(err: Error): boolean {\n\tif ((err as NodeJS.ErrnoException).code === \"EIO\") return true;\n\tconst errno = (err as NodeJS.ErrnoException).errno;\n\treturn errno === EIO_ERRNO || errno === -EIO_ERRNO;\n}\n\nconst dispatchStdinError = (err: Error): void => {\n\tif (!isTerminalDetachStdinError(err)) {\n\t\t// Our listener must not be the reason a non-EIO error stops propagating.\n\t\t// When no other \"error\" listener exists, EventEmitter would have thrown;\n\t\t// rethrowing from inside emit() reproduces that exact contract.\n\t\tconst hasOtherListener = process.stdin.listeners(\"error\").some((listener) => listener !== dispatchStdinError);\n\t\tif (!hasOtherListener) throw err;\n\t\treturn;\n\t}\n\tfor (const subscriber of stdinErrorSubscribers) subscriber(err);\n};\n\nfunction subscribeToStdinErrors(subscriber: (err: Error) => void): void {\n\tif (stdinErrorSubscribers.size === 0) process.stdin.on(\"error\", dispatchStdinError);\n\tstdinErrorSubscribers.add(subscriber);\n}\n\nfunction unsubscribeFromStdinErrors(subscriber: (err: Error) => void): void {\n\tstdinErrorSubscribers.delete(subscriber);\n\tif (stdinErrorSubscribers.size === 0) process.stdin.removeListener(\"error\", dispatchStdinError);\n}\n\n/**\n * Minimal terminal interface for TUI\n */\nexport interface Terminal {\n\t// Start the terminal with input and resize handlers\n\tstart(onInput: (data: string) => void, onResize: () => void): void;\n\n\t// Stop the terminal and restore state\n\tstop(): void;\n\n\t/**\n\t * Drain stdin before exiting to prevent Kitty key release events from\n\t * leaking to the parent shell over slow SSH connections.\n\t * @param maxMs - Maximum time to drain (default: 1000ms)\n\t * @param idleMs - Exit early if no input arrives within this time (default: 50ms)\n\t */\n\tdrainInput(maxMs?: number, idleMs?: number): Promise<void>;\n\n\t// Write output to terminal\n\twrite(data: string): void;\n\n\t// Get terminal dimensions\n\tget columns(): number;\n\tget rows(): number;\n\n\t// Whether Kitty keyboard protocol is active\n\tget kittyProtocolActive(): boolean;\n\n\t// Cursor positioning (relative to current position)\n\tmoveBy(lines: number): void; // Move cursor up (negative) or down (positive) by N lines\n\n\t// Cursor visibility\n\thideCursor(): void; // Hide the cursor\n\tshowCursor(): void; // Show the cursor\n\n\t// Clear operations\n\tclearLine(): void; // Clear current line\n\tclearFromCursor(): void; // Clear from cursor to end of screen\n\tclearScreen(): void; // Clear entire screen and move cursor to (0,0)\n\n\t// Title operations\n\tsetTitle(title: string): void; // Set terminal window title\n\n\t// Progress indicator (OSC 9;4)\n\tsetProgress(active: boolean): void;\n}\n\nexport interface ProcessTerminalOptions {\n\t/**\n\t * When set, stdout writes not issued by this terminal are hidden from the\n\t * screen while the terminal is started and forwarded to this handler\n\t * instead. External writes (console.log, libraries) would otherwise\n\t * interleave with frames and desynchronize differential rendering.\n\t */\n\tonExternalStdoutWrite?: (text: string) => void;\n}\n\nconst DEFAULT_ESCAPE_TIMEOUT_MS = 10;\nconst DEFAULT_SSH_ESCAPE_TIMEOUT_MS = 100;\n\n/**\n * Resolve how long to wait for the rest of an escape sequence before\n * dispatching a lone ESC as the Escape key. Legacy Alt+key input is ESC plus\n * another byte, so high-latency transports need a longer reassembly window.\n */\nexport function resolveEscapeTimeoutMs(env: NodeJS.ProcessEnv = process.env): number {\n\tconst configured = Number(env.PI_TUI_ESC_TIMEOUT);\n\tif (Number.isFinite(configured) && configured > 0) {\n\t\treturn configured;\n\t}\n\tif (env.SSH_CONNECTION || env.SSH_TTY) {\n\t\treturn DEFAULT_SSH_ESCAPE_TIMEOUT_MS;\n\t}\n\treturn DEFAULT_ESCAPE_TIMEOUT_MS;\n}\n\n/**\n * Real terminal using process.stdin/stdout\n */\nexport class ProcessTerminal implements Terminal {\n\tprivate wasRaw = false;\n\tprivate onExternalStdoutWrite?: (text: string) => void;\n\tprivate originalStdoutWrite?: typeof process.stdout.write;\n\tprivate rawStdoutWrite?: (data: string) => void;\n\tprivate forwardingExternalWrite = false;\n\tprivate inputHandler?: (data: string) => void;\n\tprivate resizeHandler?: () => void;\n\tprivate _kittyProtocolActive = false;\n\tprivate _modifyOtherKeysActive = false;\n\tprivate keyboardProtocolPushed = false;\n\tprivate keyboardProtocolNegotiationBuffer = \"\";\n\tprivate keyboardProtocolBufferFlushTimer?: ReturnType<typeof setTimeout>;\n\tprivate stdinBuffer?: StdinBuffer;\n\tprivate stdinDataHandler?: (data: string | Buffer) => void;\n\tprivate stdinErrorHandler?: (err: Error) => void;\n\tprivate stdinErrorHandlerCleanupTimer?: ReturnType<typeof setTimeout>;\n\tprivate progressInterval?: ReturnType<typeof setInterval>;\n\tprivate writeLogPath = (() => {\n\t\tconst env = process.env.PI_TUI_WRITE_LOG || \"\";\n\t\tif (!env) return \"\";\n\t\ttry {\n\t\t\tif (fs.statSync(env).isDirectory()) {\n\t\t\t\tconst now = new Date();\n\t\t\t\tconst ts = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, \"0\")}-${String(now.getDate()).padStart(2, \"0\")}_${String(now.getHours()).padStart(2, \"0\")}-${String(now.getMinutes()).padStart(2, \"0\")}-${String(now.getSeconds()).padStart(2, \"0\")}`;\n\t\t\t\treturn path.join(env, `tui-${ts}-${process.pid}.log`);\n\t\t\t}\n\t\t} catch {\n\t\t\t// Not an existing directory - use as-is (file path)\n\t\t}\n\t\treturn env;\n\t})();\n\n\tconstructor(options?: ProcessTerminalOptions) {\n\t\tthis.onExternalStdoutWrite = options?.onExternalStdoutWrite;\n\t}\n\n\tget kittyProtocolActive(): boolean {\n\t\treturn this._kittyProtocolActive;\n\t}\n\n\tprivate rawWrite(data: string): void {\n\t\tif (this.rawStdoutWrite) {\n\t\t\tthis.rawStdoutWrite(data);\n\t\t\treturn;\n\t\t}\n\t\tprocess.stdout.write(data);\n\t}\n\n\tprivate installExternalStdoutGuard(): void {\n\t\tconst handler = this.onExternalStdoutWrite;\n\t\tif (!handler || this.originalStdoutWrite) {\n\t\t\treturn;\n\t\t}\n\t\tthis.originalStdoutWrite = process.stdout.write;\n\t\tconst rawWrite = process.stdout.write.bind(process.stdout);\n\t\tthis.rawStdoutWrite = rawWrite;\n\n\t\tprocess.stdout.write = ((\n\t\t\tchunk: string | Uint8Array,\n\t\t\tencodingOrCallback?: BufferEncoding | ((error?: Error | null) => void),\n\t\t\tcallback?: (error?: Error | null) => void,\n\t\t): boolean => {\n\t\t\tconst cb = typeof encodingOrCallback === \"function\" ? encodingOrCallback : callback;\n\t\t\tconst encoding = typeof encodingOrCallback === \"string\" ? encodingOrCallback : undefined;\n\t\t\tconst text = typeof chunk === \"string\" ? chunk : Buffer.from(chunk).toString(encoding);\n\t\t\tif (this.forwardingExternalWrite) {\n\t\t\t\trawWrite(text);\n\t\t\t\tcb?.(null);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tthis.forwardingExternalWrite = true;\n\t\t\ttry {\n\t\t\t\thandler(text);\n\t\t\t} catch {\n\t\t\t\trawWrite(text);\n\t\t\t} finally {\n\t\t\t\tthis.forwardingExternalWrite = false;\n\t\t\t}\n\t\t\tcb?.(null);\n\t\t\treturn true;\n\t\t}) as typeof process.stdout.write;\n\t}\n\n\tprivate removeExternalStdoutGuard(): void {\n\t\tif (!this.originalStdoutWrite) {\n\t\t\treturn;\n\t\t}\n\t\tprocess.stdout.write = this.originalStdoutWrite;\n\t\tthis.originalStdoutWrite = undefined;\n\t\tthis.rawStdoutWrite = undefined;\n\t}\n\n\tget modifyOtherKeysActive(): boolean {\n\t\treturn this._modifyOtherKeysActive;\n\t}\n\n\tstart(onInput: (data: string) => void, onResize: () => void): void {\n\t\tthis.installExternalStdoutGuard();\n\t\tthis.inputHandler = onInput;\n\t\tthis.resizeHandler = onResize;\n\n\t\t// Save previous state and enable raw mode\n\t\tthis.wasRaw = process.stdin.isRaw || false;\n\t\tif (process.stdin.setRawMode) {\n\t\t\tprocess.stdin.setRawMode(true);\n\t\t}\n\t\tprocess.stdin.resume();\n\n\t\t// stdin carries the same hazard as stdout: when the controlling PTY\n\t\t// disappears (launcher killed, tmux pane closed, SSH dropped) or this\n\t\t// pgrp loses the tty foreground, the next read fails with EIO.\n\t\t// `process.stdin` is an EventEmitter, so an unobserved \"error\" event is\n\t\t// rethrown as an uncaught exception that kills the whole agent process.\n\t\tif (this.stdinErrorHandlerCleanupTimer) {\n\t\t\tclearTimeout(this.stdinErrorHandlerCleanupTimer);\n\t\t\tthis.stdinErrorHandlerCleanupTimer = undefined;\n\t\t}\n\t\tif (!this.stdinErrorHandler) {\n\t\t\t// Swallow only: the stream stays resumable, so if this pgrp regains\n\t\t\t// the tty foreground the session keeps accepting input.\n\t\t\tthis.stdinErrorHandler = () => {};\n\t\t\tsubscribeToStdinErrors(this.stdinErrorHandler);\n\t\t}\n\n\t\t// Enable bracketed paste mode - terminal will wrap pastes in \\x1b[200~ ... \\x1b[201~\n\t\tthis.rawWrite(\"\\x1b[?2004h\");\n\n\t\t// Set up resize handler immediately\n\t\tprocess.stdout.on(\"resize\", this.resizeHandler);\n\n\t\t// Refresh terminal dimensions - they may be stale after suspend/resume\n\t\t// (SIGWINCH is lost while process is stopped). Unix only.\n\t\tif (process.platform !== \"win32\") {\n\t\t\tprocess.kill(process.pid, \"SIGWINCH\");\n\t\t}\n\n\t\t// On Windows, enable ENABLE_VIRTUAL_TERMINAL_INPUT so the console sends\n\t\t// VT escape sequences (e.g. \\x1b[Z for Shift+Tab) instead of raw console\n\t\t// events that lose modifier information. Must run AFTER setRawMode(true)\n\t\t// since that resets console mode flags.\n\t\tthis.enableWindowsVTInput();\n\n\t\t// Query Kitty keyboard protocol and fall back to modifyOtherKeys when DA confirms no Kitty response.\n\t\t// See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/\n\t\tthis.queryAndEnableKittyProtocol();\n\t}\n\n\t/**\n\t * Set up StdinBuffer to split batched input into individual sequences.\n\t * This ensures components receive single events, making matchesKey/isKeyRelease work correctly.\n\t *\n\t * Also watches for Kitty protocol response and enables it when detected.\n\t * This is done here (after stdinBuffer parsing) rather than on raw stdin\n\t * to handle the case where the response arrives split across multiple events.\n\t */\n\tprivate setupStdinBuffer(): void {\n\t\tthis.stdinBuffer = new StdinBuffer({ escapeTimeout: resolveEscapeTimeoutMs() });\n\n\t\t// Forward individual sequences to the input handler\n\t\tthis.stdinBuffer.on(\"data\", (sequence) => {\n\t\t\tconst negotiationSequence = this.readKeyboardProtocolNegotiationSequence(sequence);\n\t\t\tif (negotiationSequence === \"pending\") {\n\t\t\t\tthis.scheduleKeyboardProtocolNegotiationBufferFlush();\n\t\t\t\treturn; // Wait briefly for the rest of a split Kitty response.\n\t\t\t}\n\t\t\tif (this.handleKeyboardProtocolNegotiationSequence(negotiationSequence)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.forwardInputSequence(sequence);\n\t\t});\n\n\t\t// Re-wrap paste content with bracketed paste markers for existing editor handling\n\t\tthis.stdinBuffer.on(\"paste\", (content) => {\n\t\t\tif (this.inputHandler) {\n\t\t\t\tthis.inputHandler(`\\x1b[200~${content}\\x1b[201~`);\n\t\t\t}\n\t\t});\n\n\t\t// Handler that pipes stdin data through the buffer\n\t\tthis.stdinDataHandler = (data: string | Buffer) => {\n\t\t\tthis.stdinBuffer!.process(data);\n\t\t};\n\t}\n\n\t/**\n\t * Query terminal for Kitty keyboard protocol support and enable it if available.\n\t *\n\t * Kitty's progressive enhancement detection requires requesting the desired\n\t * flags before querying them. The trailing DA query is a sentinel supported by\n\t * terminals that do not know Kitty keyboard protocol; receiving DA before a\n\t * Kitty response enables modifyOtherKeys fallback without a startup timeout.\n\t *\n\t * The requested flags are:\n\t * - 1 = disambiguate escape codes\n\t * - 2 = report event types (press/repeat/release)\n\t * - 4 = report alternate keys (shifted key, base layout key)\n\t */\n\tprivate queryAndEnableKittyProtocol(): void {\n\t\tthis.setupStdinBuffer();\n\t\tprocess.stdin.on(\"data\", this.stdinDataHandler!);\n\t\tif (!keyboardEnhancementEnabled()) {\n\t\t\treturn;\n\t\t}\n\t\tif (process.env.TMUX !== undefined || process.env.TMUX_PANE !== undefined) {\n\t\t\tthis.enableModifyOtherKeys();\n\t\t}\n\t\tthis.keyboardProtocolPushed = true;\n\t\tthis.clearKeyboardProtocolNegotiationBuffer();\n\t\tthis.rawWrite(KITTY_KEYBOARD_PROTOCOL_QUERY);\n\t}\n\n\tprivate handleKeyboardProtocolNegotiationSequence(\n\t\tnegotiationSequence: KeyboardProtocolNegotiationSequence | undefined,\n\t): boolean {\n\t\tif (!negotiationSequence) return false;\n\t\tthis.clearKeyboardProtocolNegotiationBuffer();\n\t\tif (negotiationSequence.type === \"kitty-flags\") {\n\t\t\tif (negotiationSequence.flags !== 0) {\n\t\t\t\tthis.disableModifyOtherKeys();\n\t\t\t\tif (!this._kittyProtocolActive) {\n\t\t\t\t\tthis._kittyProtocolActive = true;\n\t\t\t\t\tsetKittyProtocolActive(true);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthis.enableModifyOtherKeys();\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tif (!this._kittyProtocolActive) {\n\t\t\tthis.enableModifyOtherKeys();\n\t\t}\n\t\treturn true;\n\t}\n\n\tprivate readKeyboardProtocolNegotiationSequence(\n\t\tsequence: string,\n\t): KeyboardProtocolNegotiationSequence | \"pending\" | undefined {\n\t\tif (this.keyboardProtocolNegotiationBuffer) {\n\t\t\tconst bufferedSequence = this.keyboardProtocolNegotiationBuffer + sequence;\n\t\t\tconst negotiationSequence = parseKeyboardProtocolNegotiationSequence(bufferedSequence);\n\t\t\tif (negotiationSequence) {\n\t\t\t\tthis.clearKeyboardProtocolNegotiationBuffer();\n\t\t\t\treturn negotiationSequence;\n\t\t\t}\n\t\t\tif (isKeyboardProtocolNegotiationSequencePrefix(bufferedSequence)) {\n\t\t\t\tthis.setKeyboardProtocolNegotiationBuffer(bufferedSequence);\n\t\t\t\treturn \"pending\";\n\t\t\t}\n\t\t\tthis.flushKeyboardProtocolNegotiationBufferAsInput();\n\t\t}\n\n\t\tconst negotiationSequence = parseKeyboardProtocolNegotiationSequence(sequence);\n\t\tif (negotiationSequence) return negotiationSequence;\n\t\tif (isKeyboardProtocolNegotiationSequencePrefix(sequence)) {\n\t\t\tthis.setKeyboardProtocolNegotiationBuffer(sequence);\n\t\t\treturn \"pending\";\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tprivate setKeyboardProtocolNegotiationBuffer(sequence: string): void {\n\t\tthis.clearKeyboardProtocolNegotiationBufferFlushTimer();\n\t\tthis.keyboardProtocolNegotiationBuffer = sequence;\n\t}\n\n\tprivate clearKeyboardProtocolNegotiationBuffer(): void {\n\t\tthis.clearKeyboardProtocolNegotiationBufferFlushTimer();\n\t\tthis.keyboardProtocolNegotiationBuffer = \"\";\n\t}\n\n\tprivate flushKeyboardProtocolNegotiationBufferAsInput(): void {\n\t\tif (!this.keyboardProtocolNegotiationBuffer) return;\n\t\tconst sequence = this.keyboardProtocolNegotiationBuffer;\n\t\tthis.clearKeyboardProtocolNegotiationBuffer();\n\t\tthis.forwardInputSequence(sequence);\n\t}\n\n\tprivate scheduleKeyboardProtocolNegotiationBufferFlush(): void {\n\t\tif (!this.keyboardProtocolNegotiationBuffer || this.keyboardProtocolBufferFlushTimer) return;\n\t\tthis.keyboardProtocolBufferFlushTimer = setTimeout(() => {\n\t\t\tthis.keyboardProtocolBufferFlushTimer = undefined;\n\t\t\tthis.flushKeyboardProtocolNegotiationBufferAsInput();\n\t\t}, KEYBOARD_PROTOCOL_RESPONSE_FRAGMENT_TIMEOUT_MS);\n\t}\n\n\tprivate clearKeyboardProtocolNegotiationBufferFlushTimer(): void {\n\t\tif (!this.keyboardProtocolBufferFlushTimer) return;\n\t\tclearTimeout(this.keyboardProtocolBufferFlushTimer);\n\t\tthis.keyboardProtocolBufferFlushTimer = undefined;\n\t}\n\n\tprivate forwardInputSequence(sequence: string): void {\n\t\tif (!this.inputHandler) return;\n\t\tconst shouldDetectNativeShiftEnter =\n\t\t\tsequence === \"\\r\" && (isAppleTerminalSession() || process.platform === \"win32\");\n\t\tconst input = normalizeNativeShiftEnterInput(\n\t\t\tsequence,\n\t\t\tshouldDetectNativeShiftEnter,\n\t\t\tshouldDetectNativeShiftEnter && isNativeModifierPressed(\"shift\"),\n\t\t);\n\t\tthis.inputHandler(input);\n\t}\n\n\tprivate enableModifyOtherKeys(): void {\n\t\tif (this._kittyProtocolActive || this._modifyOtherKeysActive) return;\n\t\tthis.rawWrite(\"\\x1b[>4;2m\");\n\t\tthis._modifyOtherKeysActive = true;\n\t}\n\n\tprivate disableModifyOtherKeys(): void {\n\t\tif (!this._modifyOtherKeysActive) return;\n\t\tthis.rawWrite(\"\\x1b[>4;0m\");\n\t\tthis._modifyOtherKeysActive = false;\n\t}\n\n\t/**\n\t * On Windows, add ENABLE_VIRTUAL_TERMINAL_INPUT (0x0200) to the stdin\n\t * console handle so the terminal sends VT sequences for modified keys\n\t * (e.g. \\x1b[Z for Shift+Tab). Without this, libuv's ReadConsoleInputW\n\t * discards modifier state and Shift+Tab arrives as plain \\t.\n\t */\n\tprivate enableWindowsVTInput(): void {\n\t\tif (process.platform !== \"win32\") return;\n\t\ttry {\n\t\t\tconst arch = process.arch;\n\t\t\tif (arch !== \"x64\" && arch !== \"arm64\") return;\n\n\t\t\t// Dynamic require so non-Windows and bundled/browser paths never load the\n\t\t\t// native helper. Installed packages resolve it from pi-tui; standalone\n\t\t\t// binaries resolve the copy next to the executable.\n\t\t\tconst nativePath = path.join(\"native\", \"win32\", \"prebuilds\", `win32-${arch}`, \"win32-console-mode.node\");\n\t\t\tfor (const modulePath of getNativeModuleCandidates(nativePath)) {\n\t\t\t\ttry {\n\t\t\t\t\tconst helper = cjsRequire(modulePath) as { enableVirtualTerminalInput?: () => boolean };\n\t\t\t\t\thelper.enableVirtualTerminalInput?.();\n\t\t\t\t\treturn;\n\t\t\t\t} catch {\n\t\t\t\t\t// Try the next possible packaging location.\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Native helper not available — Shift+Tab won't be distinguishable from Tab.\n\t\t}\n\t}\n\n\tasync drainInput(maxMs = 1000, idleMs = 50): Promise<void> {\n\t\tconst shouldDisableKittyProtocol = this.keyboardProtocolPushed || this._kittyProtocolActive;\n\t\tthis.clearKeyboardProtocolNegotiationBuffer();\n\t\tif (shouldDisableKittyProtocol) {\n\t\t\t// Disable Kitty keyboard protocol first so any late key releases\n\t\t\t// do not generate new Kitty escape sequences.\n\t\t\tthis.rawWrite(\"\\x1b[<u\");\n\t\t\tthis.keyboardProtocolPushed = false;\n\t\t\tthis._kittyProtocolActive = false;\n\t\t\tsetKittyProtocolActive(false);\n\t\t}\n\t\tthis.disableModifyOtherKeys();\n\n\t\tconst previousHandler = this.inputHandler;\n\t\tthis.inputHandler = undefined;\n\n\t\tlet lastDataTime = Date.now();\n\t\tconst onData = () => {\n\t\t\tlastDataTime = Date.now();\n\t\t};\n\n\t\tprocess.stdin.on(\"data\", onData);\n\t\tconst endTime = Date.now() + maxMs;\n\n\t\ttry {\n\t\t\twhile (true) {\n\t\t\t\tconst now = Date.now();\n\t\t\t\tconst timeLeft = endTime - now;\n\t\t\t\tif (timeLeft <= 0) break;\n\t\t\t\tif (now - lastDataTime >= idleMs) break;\n\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, Math.min(idleMs, timeLeft)));\n\t\t\t}\n\t\t} finally {\n\t\t\tprocess.stdin.removeListener(\"data\", onData);\n\t\t\tthis.inputHandler = previousHandler;\n\t\t}\n\t}\n\n\tstop(): void {\n\t\tif (this.clearProgressInterval()) {\n\t\t\tthis.rawWrite(TERMINAL_PROGRESS_CLEAR_SEQUENCE);\n\t\t}\n\n\t\t// Disable bracketed paste mode\n\t\tthis.rawWrite(\"\\x1b[?2004l\");\n\n\t\tconst shouldDisableKittyProtocol = this.keyboardProtocolPushed || this._kittyProtocolActive;\n\t\tthis.clearKeyboardProtocolNegotiationBuffer();\n\n\t\t// Disable Kitty keyboard protocol if not already done by drainInput()\n\t\tif (shouldDisableKittyProtocol) {\n\t\t\tthis.rawWrite(\"\\x1b[<u\");\n\t\t\tthis.keyboardProtocolPushed = false;\n\t\t\tthis._kittyProtocolActive = false;\n\t\t\tsetKittyProtocolActive(false);\n\t\t}\n\t\tthis.disableModifyOtherKeys();\n\n\t\t// Clean up StdinBuffer\n\t\tif (this.stdinBuffer) {\n\t\t\tthis.stdinBuffer.destroy();\n\t\t\tthis.stdinBuffer = undefined;\n\t\t}\n\n\t\t// Remove event handlers\n\t\tif (this.stdinDataHandler) {\n\t\t\tprocess.stdin.removeListener(\"data\", this.stdinDataHandler);\n\t\t\tthis.stdinDataHandler = undefined;\n\t\t}\n\t\tthis.inputHandler = undefined;\n\t\tif (this.resizeHandler) {\n\t\t\tprocess.stdout.removeListener(\"resize\", this.resizeHandler);\n\t\t\tthis.resizeHandler = undefined;\n\t\t}\n\n\t\t// Pause stdin to prevent any buffered input (e.g., Ctrl+D) from being\n\t\t// re-interpreted after raw mode is disabled. This fixes a race condition\n\t\t// where Ctrl+D could close the parent shell over SSH.\n\t\tprocess.stdin.pause();\n\n\t\t// Restore raw mode state\n\t\tif (process.stdin.setRawMode) {\n\t\t\ttry {\n\t\t\t\tprocess.stdin.setRawMode(this.wasRaw);\n\t\t\t} catch (error) {\n\t\t\t\tif (!isDeadTerminalError(error)) throw error;\n\t\t\t}\n\t\t}\n\n\t\tthis.removeExternalStdoutGuard();\n\n\t\tthis.scheduleStdinErrorHandlerCleanup();\n\t}\n\n\tprivate scheduleStdinErrorHandlerCleanup(): void {\n\t\tif (!this.stdinErrorHandler || this.stdinErrorHandlerCleanupTimer) return;\n\t\t// Keep the guard armed briefly past stop(): a late PTY failure racing\n\t\t// the exit path must not crash the process after the TUI tore down.\n\t\tconst handler = this.stdinErrorHandler;\n\t\tthis.stdinErrorHandlerCleanupTimer = setTimeout(() => {\n\t\t\tthis.stdinErrorHandlerCleanupTimer = undefined;\n\t\t\tif (this.stdinErrorHandler === handler) {\n\t\t\t\tthis.stdinErrorHandler = undefined;\n\t\t\t\tunsubscribeFromStdinErrors(handler);\n\t\t\t}\n\t\t}, STDIN_ERROR_HANDLER_GRACE_MS);\n\t\tthis.stdinErrorHandlerCleanupTimer.unref();\n\t}\n\n\twrite(data: string): void {\n\t\tthis.rawWrite(data);\n\t\tif (this.writeLogPath) {\n\t\t\ttry {\n\t\t\t\tfs.appendFileSync(this.writeLogPath, data, { encoding: \"utf8\" });\n\t\t\t} catch {\n\t\t\t\t// Ignore logging errors\n\t\t\t}\n\t\t}\n\t}\n\n\tget columns(): number {\n\t\treturn process.stdout.columns || Number(process.env.COLUMNS) || 80;\n\t}\n\n\tget rows(): number {\n\t\treturn process.stdout.rows || Number(process.env.LINES) || 24;\n\t}\n\n\tmoveBy(lines: number): void {\n\t\tif (lines > 0) {\n\t\t\t// Move down\n\t\t\tthis.rawWrite(`\\x1b[${lines}B`);\n\t\t} else if (lines < 0) {\n\t\t\t// Move up\n\t\t\tthis.rawWrite(`\\x1b[${-lines}A`);\n\t\t}\n\t\t// lines === 0: no movement\n\t}\n\n\thideCursor(): void {\n\t\tthis.rawWrite(\"\\x1b[?25l\");\n\t}\n\n\tshowCursor(): void {\n\t\tthis.rawWrite(\"\\x1b[?25h\");\n\t}\n\n\tclearLine(): void {\n\t\tthis.rawWrite(\"\\x1b[K\");\n\t}\n\n\tclearFromCursor(): void {\n\t\tthis.rawWrite(\"\\x1b[J\");\n\t}\n\n\tclearScreen(): void {\n\t\tthis.rawWrite(\"\\x1b[2J\\x1b[H\"); // Clear screen and move to home (1,1)\n\t}\n\n\tsetTitle(title: string): void {\n\t\t// OSC 0;title BEL - set terminal window title. Control characters are\n\t\t// stripped so a title cannot terminate the OSC early and leak the rest\n\t\t// onto the screen.\n\t\tconst sanitizedTitle = title.replace(/[\\u0000-\\u001f\\u007f-\\u009f]/g, \"\");\n\t\tthis.rawWrite(`\\x1b]0;${sanitizedTitle}\\x07`);\n\t}\n\n\tsetProgress(active: boolean): void {\n\t\tif (active) {\n\t\t\t// OSC 9;4;3 - indeterminate progress\n\t\t\tthis.rawWrite(TERMINAL_PROGRESS_ACTIVE_SEQUENCE);\n\t\t\tif (!this.progressInterval) {\n\t\t\t\tthis.progressInterval = setInterval(() => {\n\t\t\t\t\tthis.rawWrite(TERMINAL_PROGRESS_ACTIVE_SEQUENCE);\n\t\t\t\t}, TERMINAL_PROGRESS_KEEPALIVE_MS);\n\t\t\t}\n\t\t} else {\n\t\t\tthis.clearProgressInterval();\n\t\t\t// OSC 9;4;0 - clear progress\n\t\t\tthis.rawWrite(TERMINAL_PROGRESS_CLEAR_SEQUENCE);\n\t\t}\n\t}\n\n\tprivate clearProgressInterval(): boolean {\n\t\tif (!this.progressInterval) return false;\n\t\tclearInterval(this.progressInterval);\n\t\tthis.progressInterval = undefined;\n\t\treturn true;\n\t}\n}\n"]}
1
+ {"version":3,"file":"terminal.js","sourceRoot":"","sources":["../src/terminal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAElD,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAC5C,MAAM,iCAAiC,GAAG,gBAAgB,CAAC;AAC3D,MAAM,gCAAgC,GAAG,gBAAgB,CAAC;AAC1D,MAAM,2BAA2B,GAAG,YAAY,CAAC;AACjD,MAAM,qCAAqC,GAAG,CAAC,CAAC;AAChD,MAAM,yBAAyB,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AACxE,uGAAuG;AACvG,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,4FAA4F;AAC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AC,iCAAiC,CAAC,CAAC;gBAClD,CAAC,EAAE,8BAA8B,CAAC,CAAC;YACpC,CAAC;QACF,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC7B,6BAA6B;YAC7B,IAAI,CAAC,QAAQ,CAAC,gCAAgC,CAAC,CAAC;QACjD,CAAC;IACF,CAAC;IAEO,qBAAqB;QAC5B,IAAI,CAAC,IAAI,CAAC,gBAAgB;YAAE,OAAO,KAAK,CAAC;QACzC,aAAa,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACrC,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC;QAClC,OAAO,IAAI,CAAC;IACb,CAAC;CACD","sourcesContent":["import * as fs from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport * as path from \"node:path\";\nimport { setKittyProtocolActive } from \"./keys.ts\";\nimport { isMultiplexerSession } from \"./mux.ts\";\nimport { isNativeModifierPressed } from \"./native-modifiers.ts\";\nimport { getNativeModuleCandidates } from \"./native-module-path.ts\";\nimport { StdinBuffer } from \"./stdin-buffer.ts\";\n\nconst cjsRequire = createRequire(import.meta.url);\n\nconst TERMINAL_PROGRESS_KEEPALIVE_MS = 1000;\nconst TERMINAL_PROGRESS_ACTIVE_SEQUENCE = \"\\x1b]9;4;3\\x07\";\nconst TERMINAL_PROGRESS_CLEAR_SEQUENCE = \"\\x1b]9;4;0\\x07\";\nconst NATIVE_SHIFT_ENTER_SEQUENCE = \"\\x1b[13;2u\";\nconst DESIRED_KITTY_KEYBOARD_PROTOCOL_FLAGS = 7;\nconst DEAD_TERMINAL_ERROR_CODES = new Set([\"EIO\", \"EPIPE\", \"ENOTCONN\"]);\n// Bun's macOS tty shim can report synchronous ioctl EIO as raw positive errno 5 without a string code.\nconst EIO_ERRNO = 5;\n// Bun's tty shim can also drop both properties and leave the errno only in the message text\n// (`new Error(\"setRawMode failed with errno: 5\")` - no `code`, no `errno`), so the numeric\n// fallback has to read the message. Restricted to errno values that are stable across darwin\n// and linux: EIO (5) and EPIPE (32). ENOTCONN is deliberately excluded because its number\n// differs per platform (57 on darwin, 107 on linux) and a wrong guess would swallow a live error.\nconst EPIPE_ERRNO = 32;\nconst DEAD_TERMINAL_ERRNOS = new Set([EIO_ERRNO, EPIPE_ERRNO]);\nconst ERRNO_IN_MESSAGE_PATTERN = /errno:\\s*(\\d+)/;\nconst KEYBOARD_PROTOCOL_RESPONSE_FRAGMENT_TIMEOUT_MS = 150;\nconst KITTY_KEYBOARD_PROTOCOL_QUERY = `\\x1b[>${DESIRED_KITTY_KEYBOARD_PROTOCOL_FLAGS}u\\x1b[?u\\x1b[c`;\n\nexport type KeyboardProtocolNegotiationSequence =\n\t| { type: \"kitty-flags\"; flags: number }\n\t| { type: \"device-attributes\" };\n\nexport function parseKeyboardProtocolNegotiationSequence(\n\tsequence: string,\n): KeyboardProtocolNegotiationSequence | undefined {\n\tconst kittyFlags = sequence.match(/^\\x1b\\[\\?(\\d+)u$/);\n\tif (kittyFlags) {\n\t\treturn { type: \"kitty-flags\", flags: Number.parseInt(kittyFlags[1]!, 10) };\n\t}\n\tif (/^\\x1b\\[\\?[\\d;]*c$/.test(sequence)) {\n\t\treturn { type: \"device-attributes\" };\n\t}\n\treturn undefined;\n}\n\nfunction isKeyboardProtocolNegotiationSequencePrefix(sequence: string): boolean {\n\treturn sequence === \"\\x1b[\" || /^\\x1b\\[\\?[\\d;]*$/.test(sequence);\n}\n\nexport function isAppleTerminalSession(): boolean {\n\treturn process.platform === \"darwin\" && process.env.TERM_PROGRAM === \"Apple_Terminal\";\n}\n\n/**\n * Refresh terminal dimensions on POSIX platforms by sending SIGWINCH to this process.\n * Best-effort: some environments (restricted seccomp or LSM policies) return EACCES\n * for `kill(2)`; in that case the dimensions refresh is skipped rather than crashing.\n */\nexport function refreshTerminalDimensions(): void {\n\tif (process.platform === \"win32\" || process.pid <= 0) return;\n\ttry {\n\t\tprocess.kill(process.pid, \"SIGWINCH\");\n\t} catch {\n\t\t// Signal delivery not permitted in this environment; ignore.\n\t}\n}\n\nexport function normalizeNativeShiftEnterInput(\n\tdata: string,\n\tshouldDetectNativeShiftEnter: boolean,\n\tisShiftPressed: boolean,\n): string {\n\tif (shouldDetectNativeShiftEnter && data === \"\\r\" && isShiftPressed) return NATIVE_SHIFT_ENTER_SEQUENCE;\n\treturn data;\n}\n\nexport function normalizeAppleTerminalInput(data: string, isAppleTerminal: boolean, isShiftPressed: boolean): string {\n\treturn normalizeNativeShiftEnterInput(data, isAppleTerminal, isShiftPressed);\n}\n\nexport function normalizeWarpWslShiftEnterInput(\n\tdata: string,\n\tenv: NodeJS.ProcessEnv = process.env,\n\tplatform: NodeJS.Platform = process.platform,\n\tsocketExists: (socketPath: string) => boolean = (socketPath) => {\n\t\ttry {\n\t\t\treturn fs.statSync(socketPath).isSocket();\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t},\n): string {\n\tif (data !== \"\\n\" || platform !== \"linux\") return data;\n\tif (isMultiplexerSession(env) || env.SSH_CONNECTION?.trim() || env.SSH_CLIENT?.trim() || env.SSH_TTY?.trim()) {\n\t\treturn data;\n\t}\n\tconst isWarp = Boolean(env.WARP_SESSION_ID?.trim() || env.WARP_TERMINAL_SESSION_UUID?.trim());\n\tconst interopPath = env.WSL_INTEROP?.trim();\n\tconst isWsl =\n\t\tisWarp && interopPath !== undefined && /^\\/run\\/WSL\\/\\d+_interop$/.test(interopPath) && socketExists(interopPath);\n\treturn isWarp && isWsl ? NATIVE_SHIFT_ENTER_SEQUENCE : data;\n}\n\nexport function keyboardEnhancementEnabled(): boolean {\n\tconst value = process.env.PI_TUI_KEYBOARD_PROTOCOL;\n\tif (value === undefined) return true;\n\treturn ![\"0\", \"false\", \"no\", \"off\"].includes(value.toLowerCase());\n}\n\nfunction isDeadTerminalError(error: unknown): boolean {\n\tif (!(error instanceof Error)) return false;\n\tif (\"code\" in error && typeof error.code === \"string\") return DEAD_TERMINAL_ERROR_CODES.has(error.code);\n\tif (\"errno\" in error && error.errno === EIO_ERRNO) return true;\n\tconst messageErrno = ERRNO_IN_MESSAGE_PATTERN.exec(error.message);\n\tif (!messageErrno) return false;\n\treturn DEAD_TERMINAL_ERRNOS.has(Number.parseInt(messageErrno[1]!, 10));\n}\n\nconst STDIN_ERROR_HANDLER_GRACE_MS = 250;\nconst stdinErrorSubscribers = new Set<(err: Error) => void>();\n\nexport function __stdinErrorSubscriberCountForTests(): number {\n\treturn stdinErrorSubscribers.size;\n}\nexport function __stdinErrorDispatcherInstalledForTests(): boolean {\n\treturn process.stdin.listeners(\"error\").includes(dispatchStdinError);\n}\n\n/**\n * A vanished or re-backgrounded controlling terminal fails the next stdin\n * read with EIO; that is the only stdin error this module owns. Node reports\n * it as code \"EIO\" (errno -5), Bun's macOS tty shim as a bare positive\n * errno 5 — both shapes classify. Any other stdin failure (EBADF, EPIPE, an\n * unexpected platform error) keeps its default EventEmitter propagation so it\n * stays observable instead of being downgraded to a silently ignored error.\n */\nfunction isTerminalDetachStdinError(err: Error): boolean {\n\tif ((err as NodeJS.ErrnoException).code === \"EIO\") return true;\n\tconst errno = (err as NodeJS.ErrnoException).errno;\n\treturn errno === EIO_ERRNO || errno === -EIO_ERRNO;\n}\n\nconst dispatchStdinError = (err: Error): void => {\n\tif (!isTerminalDetachStdinError(err)) {\n\t\t// Our listener must not be the reason a non-EIO error stops propagating.\n\t\t// When no other \"error\" listener exists, EventEmitter would have thrown;\n\t\t// rethrowing from inside emit() reproduces that exact contract.\n\t\tconst hasOtherListener = process.stdin.listeners(\"error\").some((listener) => listener !== dispatchStdinError);\n\t\tif (!hasOtherListener) throw err;\n\t\treturn;\n\t}\n\tfor (const subscriber of stdinErrorSubscribers) subscriber(err);\n};\n\nfunction subscribeToStdinErrors(subscriber: (err: Error) => void): void {\n\tif (stdinErrorSubscribers.size === 0) process.stdin.on(\"error\", dispatchStdinError);\n\tstdinErrorSubscribers.add(subscriber);\n}\n\nfunction unsubscribeFromStdinErrors(subscriber: (err: Error) => void): void {\n\tstdinErrorSubscribers.delete(subscriber);\n\tif (stdinErrorSubscribers.size === 0) process.stdin.removeListener(\"error\", dispatchStdinError);\n}\n\n/**\n * Minimal terminal interface for TUI\n */\nexport interface Terminal {\n\t// Start the terminal with input and resize handlers\n\tstart(onInput: (data: string) => void, onResize: () => void): void;\n\n\t// Stop the terminal and restore state\n\tstop(): void;\n\n\t/**\n\t * Drain stdin before exiting to prevent Kitty key release events from\n\t * leaking to the parent shell over slow SSH connections.\n\t * @param maxMs - Maximum time to drain (default: 1000ms)\n\t * @param idleMs - Exit early if no input arrives within this time (default: 50ms)\n\t */\n\tdrainInput(maxMs?: number, idleMs?: number): Promise<void>;\n\n\t// Write output to terminal\n\twrite(data: string): void;\n\n\t// Get terminal dimensions\n\tget columns(): number;\n\tget rows(): number;\n\n\t// Whether Kitty keyboard protocol is active\n\tget kittyProtocolActive(): boolean;\n\n\t// Cursor positioning (relative to current position)\n\tmoveBy(lines: number): void; // Move cursor up (negative) or down (positive) by N lines\n\n\t// Cursor visibility\n\thideCursor(): void; // Hide the cursor\n\tshowCursor(): void; // Show the cursor\n\n\t// Clear operations\n\tclearLine(): void; // Clear current line\n\tclearFromCursor(): void; // Clear from cursor to end of screen\n\tclearScreen(): void; // Clear entire screen and move cursor to (0,0)\n\n\t// Title operations\n\tsetTitle(title: string): void; // Set terminal window title\n\n\t// Progress indicator (OSC 9;4)\n\tsetProgress(active: boolean): void;\n}\n\nexport interface ProcessTerminalOptions {\n\t/**\n\t * When set, stdout writes not issued by this terminal are hidden from the\n\t * screen while the terminal is started and forwarded to this handler\n\t * instead. External writes (console.log, libraries) would otherwise\n\t * interleave with frames and desynchronize differential rendering.\n\t */\n\tonExternalStdoutWrite?: (text: string) => void;\n}\n\nconst DEFAULT_ESCAPE_TIMEOUT_MS = 10;\nconst DEFAULT_SSH_ESCAPE_TIMEOUT_MS = 100;\n\n/**\n * Resolve how long to wait for the rest of an escape sequence before\n * dispatching a lone ESC as the Escape key. Legacy Alt+key input is ESC plus\n * another byte, so high-latency transports need a longer reassembly window.\n */\nexport function resolveEscapeTimeoutMs(env: NodeJS.ProcessEnv = process.env): number {\n\tconst configured = Number(env.PI_TUI_ESC_TIMEOUT);\n\tif (Number.isFinite(configured) && configured > 0) {\n\t\treturn configured;\n\t}\n\tif (env.SSH_CONNECTION || env.SSH_TTY) {\n\t\treturn DEFAULT_SSH_ESCAPE_TIMEOUT_MS;\n\t}\n\treturn DEFAULT_ESCAPE_TIMEOUT_MS;\n}\n\n/**\n * Real terminal using process.stdin/stdout\n */\nexport class ProcessTerminal implements Terminal {\n\tprivate wasRaw = false;\n\tprivate onExternalStdoutWrite?: (text: string) => void;\n\tprivate originalStdoutWrite?: typeof process.stdout.write;\n\tprivate rawStdoutWrite?: (data: string) => void;\n\tprivate forwardingExternalWrite = false;\n\tprivate inputHandler?: (data: string) => void;\n\tprivate resizeHandler?: () => void;\n\tprivate _kittyProtocolActive = false;\n\tprivate _modifyOtherKeysActive = false;\n\tprivate keyboardProtocolPushed = false;\n\tprivate keyboardProtocolNegotiationBuffer = \"\";\n\tprivate keyboardProtocolBufferFlushTimer?: ReturnType<typeof setTimeout>;\n\tprivate stdinBuffer?: StdinBuffer;\n\tprivate stdinDataHandler?: (data: string | Buffer) => void;\n\tprivate stdinErrorHandler?: (err: Error) => void;\n\tprivate stdinErrorHandlerCleanupTimer?: ReturnType<typeof setTimeout>;\n\tprivate progressInterval?: ReturnType<typeof setInterval>;\n\tprivate writeLogPath = (() => {\n\t\tconst env = process.env.PI_TUI_WRITE_LOG || \"\";\n\t\tif (!env) return \"\";\n\t\ttry {\n\t\t\tif (fs.statSync(env).isDirectory()) {\n\t\t\t\tconst now = new Date();\n\t\t\t\tconst ts = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, \"0\")}-${String(now.getDate()).padStart(2, \"0\")}_${String(now.getHours()).padStart(2, \"0\")}-${String(now.getMinutes()).padStart(2, \"0\")}-${String(now.getSeconds()).padStart(2, \"0\")}`;\n\t\t\t\treturn path.join(env, `tui-${ts}-${process.pid}.log`);\n\t\t\t}\n\t\t} catch {\n\t\t\t// Not an existing directory - use as-is (file path)\n\t\t}\n\t\treturn env;\n\t})();\n\n\tconstructor(options?: ProcessTerminalOptions) {\n\t\tthis.onExternalStdoutWrite = options?.onExternalStdoutWrite;\n\t}\n\n\tget kittyProtocolActive(): boolean {\n\t\treturn this._kittyProtocolActive;\n\t}\n\n\tprivate rawWrite(data: string): void {\n\t\tif (this.rawStdoutWrite) {\n\t\t\tthis.rawStdoutWrite(data);\n\t\t\treturn;\n\t\t}\n\t\tprocess.stdout.write(data);\n\t}\n\n\tprivate installExternalStdoutGuard(): void {\n\t\tconst handler = this.onExternalStdoutWrite;\n\t\tif (!handler || this.originalStdoutWrite) {\n\t\t\treturn;\n\t\t}\n\t\tthis.originalStdoutWrite = process.stdout.write;\n\t\tconst rawWrite = process.stdout.write.bind(process.stdout);\n\t\tthis.rawStdoutWrite = rawWrite;\n\n\t\tprocess.stdout.write = ((\n\t\t\tchunk: string | Uint8Array,\n\t\t\tencodingOrCallback?: BufferEncoding | ((error?: Error | null) => void),\n\t\t\tcallback?: (error?: Error | null) => void,\n\t\t): boolean => {\n\t\t\tconst cb = typeof encodingOrCallback === \"function\" ? encodingOrCallback : callback;\n\t\t\tconst encoding = typeof encodingOrCallback === \"string\" ? encodingOrCallback : undefined;\n\t\t\tconst text = typeof chunk === \"string\" ? chunk : Buffer.from(chunk).toString(encoding);\n\t\t\tif (this.forwardingExternalWrite) {\n\t\t\t\trawWrite(text);\n\t\t\t\tcb?.(null);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tthis.forwardingExternalWrite = true;\n\t\t\ttry {\n\t\t\t\thandler(text);\n\t\t\t} catch {\n\t\t\t\trawWrite(text);\n\t\t\t} finally {\n\t\t\t\tthis.forwardingExternalWrite = false;\n\t\t\t}\n\t\t\tcb?.(null);\n\t\t\treturn true;\n\t\t}) as typeof process.stdout.write;\n\t}\n\n\tprivate removeExternalStdoutGuard(): void {\n\t\tif (!this.originalStdoutWrite) {\n\t\t\treturn;\n\t\t}\n\t\tprocess.stdout.write = this.originalStdoutWrite;\n\t\tthis.originalStdoutWrite = undefined;\n\t\tthis.rawStdoutWrite = undefined;\n\t}\n\n\tget modifyOtherKeysActive(): boolean {\n\t\treturn this._modifyOtherKeysActive;\n\t}\n\n\tstart(onInput: (data: string) => void, onResize: () => void): void {\n\t\tthis.installExternalStdoutGuard();\n\t\tthis.inputHandler = onInput;\n\t\tthis.resizeHandler = onResize;\n\n\t\t// Save previous state and enable raw mode\n\t\tthis.wasRaw = process.stdin.isRaw || false;\n\t\tif (process.stdin.setRawMode) {\n\t\t\tprocess.stdin.setRawMode(true);\n\t\t}\n\t\tprocess.stdin.resume();\n\n\t\t// stdin carries the same hazard as stdout: when the controlling PTY\n\t\t// disappears (launcher killed, tmux pane closed, SSH dropped) or this\n\t\t// pgrp loses the tty foreground, the next read fails with EIO.\n\t\t// `process.stdin` is an EventEmitter, so an unobserved \"error\" event is\n\t\t// rethrown as an uncaught exception that kills the whole agent process.\n\t\tif (this.stdinErrorHandlerCleanupTimer) {\n\t\t\tclearTimeout(this.stdinErrorHandlerCleanupTimer);\n\t\t\tthis.stdinErrorHandlerCleanupTimer = undefined;\n\t\t}\n\t\tif (!this.stdinErrorHandler) {\n\t\t\t// Swallow only: the stream stays resumable, so if this pgrp regains\n\t\t\t// the tty foreground the session keeps accepting input.\n\t\t\tthis.stdinErrorHandler = () => {};\n\t\t\tsubscribeToStdinErrors(this.stdinErrorHandler);\n\t\t}\n\n\t\t// Enable bracketed paste mode - terminal will wrap pastes in \\x1b[200~ ... \\x1b[201~\n\t\tthis.rawWrite(\"\\x1b[?2004h\");\n\n\t\t// Set up resize handler immediately\n\t\tprocess.stdout.on(\"resize\", this.resizeHandler);\n\n\t\t// Refresh terminal dimensions - they may be stale after suspend/resume\n\t\t// (SIGWINCH is lost while process is stopped). Unix only, best-effort.\n\t\trefreshTerminalDimensions();\n\n\t\t// On Windows, enable ENABLE_VIRTUAL_TERMINAL_INPUT so the console sends\n\t\t// VT escape sequences (e.g. \\x1b[Z for Shift+Tab) instead of raw console\n\t\t// events that lose modifier information. Must run AFTER setRawMode(true)\n\t\t// since that resets console mode flags.\n\t\tthis.enableWindowsVTInput();\n\n\t\t// Query Kitty keyboard protocol and fall back to modifyOtherKeys when DA confirms no Kitty response.\n\t\t// See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/\n\t\tthis.queryAndEnableKittyProtocol();\n\t}\n\n\t/**\n\t * Set up StdinBuffer to split batched input into individual sequences.\n\t * This ensures components receive single events, making matchesKey/isKeyRelease work correctly.\n\t *\n\t * Also watches for Kitty protocol response and enables it when detected.\n\t * This is done here (after stdinBuffer parsing) rather than on raw stdin\n\t * to handle the case where the response arrives split across multiple events.\n\t */\n\tprivate setupStdinBuffer(): void {\n\t\tthis.stdinBuffer = new StdinBuffer({ escapeTimeout: resolveEscapeTimeoutMs() });\n\n\t\t// Forward individual sequences to the input handler\n\t\tthis.stdinBuffer.on(\"data\", (sequence) => {\n\t\t\tconst negotiationSequence = this.readKeyboardProtocolNegotiationSequence(sequence);\n\t\t\tif (negotiationSequence === \"pending\") {\n\t\t\t\tthis.scheduleKeyboardProtocolNegotiationBufferFlush();\n\t\t\t\treturn; // Wait briefly for the rest of a split Kitty response.\n\t\t\t}\n\t\t\tif (this.handleKeyboardProtocolNegotiationSequence(negotiationSequence)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.forwardInputSequence(sequence);\n\t\t});\n\n\t\t// Re-wrap paste content with bracketed paste markers for existing editor handling\n\t\tthis.stdinBuffer.on(\"paste\", (content) => {\n\t\t\tif (this.inputHandler) {\n\t\t\t\tthis.inputHandler(`\\x1b[200~${content}\\x1b[201~`);\n\t\t\t}\n\t\t});\n\n\t\t// Handler that pipes stdin data through the buffer\n\t\tthis.stdinDataHandler = (data: string | Buffer) => {\n\t\t\tthis.stdinBuffer!.process(data);\n\t\t};\n\t}\n\n\t/**\n\t * Query terminal for Kitty keyboard protocol support and enable it if available.\n\t *\n\t * Kitty's progressive enhancement detection requires requesting the desired\n\t * flags before querying them. The trailing DA query is a sentinel supported by\n\t * terminals that do not know Kitty keyboard protocol; receiving DA before a\n\t * Kitty response enables modifyOtherKeys fallback without a startup timeout.\n\t *\n\t * The requested flags are:\n\t * - 1 = disambiguate escape codes\n\t * - 2 = report event types (press/repeat/release)\n\t * - 4 = report alternate keys (shifted key, base layout key)\n\t */\n\tprivate queryAndEnableKittyProtocol(): void {\n\t\tthis.setupStdinBuffer();\n\t\tprocess.stdin.on(\"data\", this.stdinDataHandler!);\n\t\tif (!keyboardEnhancementEnabled()) {\n\t\t\treturn;\n\t\t}\n\t\tif (process.env.TMUX !== undefined || process.env.TMUX_PANE !== undefined) {\n\t\t\tthis.enableModifyOtherKeys();\n\t\t}\n\t\tthis.keyboardProtocolPushed = true;\n\t\tthis.clearKeyboardProtocolNegotiationBuffer();\n\t\tthis.rawWrite(KITTY_KEYBOARD_PROTOCOL_QUERY);\n\t}\n\n\tprivate handleKeyboardProtocolNegotiationSequence(\n\t\tnegotiationSequence: KeyboardProtocolNegotiationSequence | undefined,\n\t): boolean {\n\t\tif (!negotiationSequence) return false;\n\t\tthis.clearKeyboardProtocolNegotiationBuffer();\n\t\tif (negotiationSequence.type === \"kitty-flags\") {\n\t\t\tif (negotiationSequence.flags !== 0) {\n\t\t\t\tthis.disableModifyOtherKeys();\n\t\t\t\tif (!this._kittyProtocolActive) {\n\t\t\t\t\tthis._kittyProtocolActive = true;\n\t\t\t\t\tsetKittyProtocolActive(true);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthis.enableModifyOtherKeys();\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tif (!this._kittyProtocolActive) {\n\t\t\tthis.enableModifyOtherKeys();\n\t\t}\n\t\treturn true;\n\t}\n\n\tprivate readKeyboardProtocolNegotiationSequence(\n\t\tsequence: string,\n\t): KeyboardProtocolNegotiationSequence | \"pending\" | undefined {\n\t\tif (this.keyboardProtocolNegotiationBuffer) {\n\t\t\tconst bufferedSequence = this.keyboardProtocolNegotiationBuffer + sequence;\n\t\t\tconst negotiationSequence = parseKeyboardProtocolNegotiationSequence(bufferedSequence);\n\t\t\tif (negotiationSequence) {\n\t\t\t\tthis.clearKeyboardProtocolNegotiationBuffer();\n\t\t\t\treturn negotiationSequence;\n\t\t\t}\n\t\t\tif (isKeyboardProtocolNegotiationSequencePrefix(bufferedSequence)) {\n\t\t\t\tthis.setKeyboardProtocolNegotiationBuffer(bufferedSequence);\n\t\t\t\treturn \"pending\";\n\t\t\t}\n\t\t\tthis.flushKeyboardProtocolNegotiationBufferAsInput();\n\t\t}\n\n\t\tconst negotiationSequence = parseKeyboardProtocolNegotiationSequence(sequence);\n\t\tif (negotiationSequence) return negotiationSequence;\n\t\tif (isKeyboardProtocolNegotiationSequencePrefix(sequence)) {\n\t\t\tthis.setKeyboardProtocolNegotiationBuffer(sequence);\n\t\t\treturn \"pending\";\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tprivate setKeyboardProtocolNegotiationBuffer(sequence: string): void {\n\t\tthis.clearKeyboardProtocolNegotiationBufferFlushTimer();\n\t\tthis.keyboardProtocolNegotiationBuffer = sequence;\n\t}\n\n\tprivate clearKeyboardProtocolNegotiationBuffer(): void {\n\t\tthis.clearKeyboardProtocolNegotiationBufferFlushTimer();\n\t\tthis.keyboardProtocolNegotiationBuffer = \"\";\n\t}\n\n\tprivate flushKeyboardProtocolNegotiationBufferAsInput(): void {\n\t\tif (!this.keyboardProtocolNegotiationBuffer) return;\n\t\tconst sequence = this.keyboardProtocolNegotiationBuffer;\n\t\tthis.clearKeyboardProtocolNegotiationBuffer();\n\t\tthis.forwardInputSequence(sequence);\n\t}\n\n\tprivate scheduleKeyboardProtocolNegotiationBufferFlush(): void {\n\t\tif (!this.keyboardProtocolNegotiationBuffer || this.keyboardProtocolBufferFlushTimer) return;\n\t\tthis.keyboardProtocolBufferFlushTimer = setTimeout(() => {\n\t\t\tthis.keyboardProtocolBufferFlushTimer = undefined;\n\t\t\tthis.flushKeyboardProtocolNegotiationBufferAsInput();\n\t\t}, KEYBOARD_PROTOCOL_RESPONSE_FRAGMENT_TIMEOUT_MS);\n\t}\n\n\tprivate clearKeyboardProtocolNegotiationBufferFlushTimer(): void {\n\t\tif (!this.keyboardProtocolBufferFlushTimer) return;\n\t\tclearTimeout(this.keyboardProtocolBufferFlushTimer);\n\t\tthis.keyboardProtocolBufferFlushTimer = undefined;\n\t}\n\n\tprivate forwardInputSequence(sequence: string): void {\n\t\tif (!this.inputHandler) return;\n\t\tconst shouldDetectNativeShiftEnter =\n\t\t\tsequence === \"\\r\" && (isAppleTerminalSession() || process.platform === \"win32\");\n\t\tconst input = normalizeNativeShiftEnterInput(\n\t\t\tsequence,\n\t\t\tshouldDetectNativeShiftEnter,\n\t\t\tshouldDetectNativeShiftEnter && isNativeModifierPressed(\"shift\"),\n\t\t);\n\t\tthis.inputHandler(input);\n\t}\n\n\tprivate enableModifyOtherKeys(): void {\n\t\tif (this._kittyProtocolActive || this._modifyOtherKeysActive) return;\n\t\tthis.rawWrite(\"\\x1b[>4;2m\");\n\t\tthis._modifyOtherKeysActive = true;\n\t}\n\n\tprivate disableModifyOtherKeys(): void {\n\t\tif (!this._modifyOtherKeysActive) return;\n\t\tthis.rawWrite(\"\\x1b[>4;0m\");\n\t\tthis._modifyOtherKeysActive = false;\n\t}\n\n\t/**\n\t * On Windows, add ENABLE_VIRTUAL_TERMINAL_INPUT (0x0200) to the stdin\n\t * console handle so the terminal sends VT sequences for modified keys\n\t * (e.g. \\x1b[Z for Shift+Tab). Without this, libuv's ReadConsoleInputW\n\t * discards modifier state and Shift+Tab arrives as plain \\t.\n\t */\n\tprivate enableWindowsVTInput(): void {\n\t\tif (process.platform !== \"win32\") return;\n\t\ttry {\n\t\t\tconst arch = process.arch;\n\t\t\tif (arch !== \"x64\" && arch !== \"arm64\") return;\n\n\t\t\t// Dynamic require so non-Windows and bundled/browser paths never load the\n\t\t\t// native helper. Installed packages resolve it from pi-tui; standalone\n\t\t\t// binaries resolve the copy next to the executable.\n\t\t\tconst nativePath = path.join(\"native\", \"win32\", \"prebuilds\", `win32-${arch}`, \"win32-console-mode.node\");\n\t\t\tfor (const modulePath of getNativeModuleCandidates(nativePath)) {\n\t\t\t\ttry {\n\t\t\t\t\tconst helper = cjsRequire(modulePath) as { enableVirtualTerminalInput?: () => boolean };\n\t\t\t\t\thelper.enableVirtualTerminalInput?.();\n\t\t\t\t\treturn;\n\t\t\t\t} catch {\n\t\t\t\t\t// Try the next possible packaging location.\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Native helper not available — Shift+Tab won't be distinguishable from Tab.\n\t\t}\n\t}\n\n\tasync drainInput(maxMs = 1000, idleMs = 50): Promise<void> {\n\t\tconst shouldDisableKittyProtocol = this.keyboardProtocolPushed || this._kittyProtocolActive;\n\t\tthis.clearKeyboardProtocolNegotiationBuffer();\n\t\tif (shouldDisableKittyProtocol) {\n\t\t\t// Disable Kitty keyboard protocol first so any late key releases\n\t\t\t// do not generate new Kitty escape sequences.\n\t\t\tthis.rawWrite(\"\\x1b[<u\");\n\t\t\tthis.keyboardProtocolPushed = false;\n\t\t\tthis._kittyProtocolActive = false;\n\t\t\tsetKittyProtocolActive(false);\n\t\t}\n\t\tthis.disableModifyOtherKeys();\n\n\t\tconst previousHandler = this.inputHandler;\n\t\tthis.inputHandler = undefined;\n\n\t\tlet lastDataTime = Date.now();\n\t\tconst onData = () => {\n\t\t\tlastDataTime = Date.now();\n\t\t};\n\n\t\tprocess.stdin.on(\"data\", onData);\n\t\tconst endTime = Date.now() + maxMs;\n\n\t\ttry {\n\t\t\twhile (true) {\n\t\t\t\tconst now = Date.now();\n\t\t\t\tconst timeLeft = endTime - now;\n\t\t\t\tif (timeLeft <= 0) break;\n\t\t\t\tif (now - lastDataTime >= idleMs) break;\n\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, Math.min(idleMs, timeLeft)));\n\t\t\t}\n\t\t} finally {\n\t\t\tprocess.stdin.removeListener(\"data\", onData);\n\t\t\tthis.inputHandler = previousHandler;\n\t\t}\n\t}\n\n\tstop(): void {\n\t\tif (this.clearProgressInterval()) {\n\t\t\tthis.rawWrite(TERMINAL_PROGRESS_CLEAR_SEQUENCE);\n\t\t}\n\n\t\t// Disable bracketed paste mode\n\t\tthis.rawWrite(\"\\x1b[?2004l\");\n\n\t\tconst shouldDisableKittyProtocol = this.keyboardProtocolPushed || this._kittyProtocolActive;\n\t\tthis.clearKeyboardProtocolNegotiationBuffer();\n\n\t\t// Disable Kitty keyboard protocol if not already done by drainInput()\n\t\tif (shouldDisableKittyProtocol) {\n\t\t\tthis.rawWrite(\"\\x1b[<u\");\n\t\t\tthis.keyboardProtocolPushed = false;\n\t\t\tthis._kittyProtocolActive = false;\n\t\t\tsetKittyProtocolActive(false);\n\t\t}\n\t\tthis.disableModifyOtherKeys();\n\n\t\t// Clean up StdinBuffer\n\t\tif (this.stdinBuffer) {\n\t\t\tthis.stdinBuffer.destroy();\n\t\t\tthis.stdinBuffer = undefined;\n\t\t}\n\n\t\t// Remove event handlers\n\t\tif (this.stdinDataHandler) {\n\t\t\tprocess.stdin.removeListener(\"data\", this.stdinDataHandler);\n\t\t\tthis.stdinDataHandler = undefined;\n\t\t}\n\t\tthis.inputHandler = undefined;\n\t\tif (this.resizeHandler) {\n\t\t\tprocess.stdout.removeListener(\"resize\", this.resizeHandler);\n\t\t\tthis.resizeHandler = undefined;\n\t\t}\n\n\t\t// Pause stdin to prevent any buffered input (e.g., Ctrl+D) from being\n\t\t// re-interpreted after raw mode is disabled. This fixes a race condition\n\t\t// where Ctrl+D could close the parent shell over SSH.\n\t\tprocess.stdin.pause();\n\n\t\t// Restore raw mode state\n\t\tif (process.stdin.setRawMode) {\n\t\t\ttry {\n\t\t\t\tprocess.stdin.setRawMode(this.wasRaw);\n\t\t\t} catch (error) {\n\t\t\t\tif (!isDeadTerminalError(error)) throw error;\n\t\t\t}\n\t\t}\n\n\t\tthis.removeExternalStdoutGuard();\n\n\t\tthis.scheduleStdinErrorHandlerCleanup();\n\t}\n\n\tprivate scheduleStdinErrorHandlerCleanup(): void {\n\t\tif (!this.stdinErrorHandler || this.stdinErrorHandlerCleanupTimer) return;\n\t\t// Keep the guard armed briefly past stop(): a late PTY failure racing\n\t\t// the exit path must not crash the process after the TUI tore down.\n\t\tconst handler = this.stdinErrorHandler;\n\t\tthis.stdinErrorHandlerCleanupTimer = setTimeout(() => {\n\t\t\tthis.stdinErrorHandlerCleanupTimer = undefined;\n\t\t\tif (this.stdinErrorHandler === handler) {\n\t\t\t\tthis.stdinErrorHandler = undefined;\n\t\t\t\tunsubscribeFromStdinErrors(handler);\n\t\t\t}\n\t\t}, STDIN_ERROR_HANDLER_GRACE_MS);\n\t\tthis.stdinErrorHandlerCleanupTimer.unref();\n\t}\n\n\twrite(data: string): void {\n\t\tthis.rawWrite(data);\n\t\tif (this.writeLogPath) {\n\t\t\ttry {\n\t\t\t\tfs.appendFileSync(this.writeLogPath, data, { encoding: \"utf8\" });\n\t\t\t} catch {\n\t\t\t\t// Ignore logging errors\n\t\t\t}\n\t\t}\n\t}\n\n\tget columns(): number {\n\t\treturn process.stdout.columns || Number(process.env.COLUMNS) || 80;\n\t}\n\n\tget rows(): number {\n\t\treturn process.stdout.rows || Number(process.env.LINES) || 24;\n\t}\n\n\tmoveBy(lines: number): void {\n\t\tif (lines > 0) {\n\t\t\t// Move down\n\t\t\tthis.rawWrite(`\\x1b[${lines}B`);\n\t\t} else if (lines < 0) {\n\t\t\t// Move up\n\t\t\tthis.rawWrite(`\\x1b[${-lines}A`);\n\t\t}\n\t\t// lines === 0: no movement\n\t}\n\n\thideCursor(): void {\n\t\tthis.rawWrite(\"\\x1b[?25l\");\n\t}\n\n\tshowCursor(): void {\n\t\tthis.rawWrite(\"\\x1b[?25h\");\n\t}\n\n\tclearLine(): void {\n\t\tthis.rawWrite(\"\\x1b[K\");\n\t}\n\n\tclearFromCursor(): void {\n\t\tthis.rawWrite(\"\\x1b[J\");\n\t}\n\n\tclearScreen(): void {\n\t\tthis.rawWrite(\"\\x1b[2J\\x1b[H\"); // Clear screen and move to home (1,1)\n\t}\n\n\tsetTitle(title: string): void {\n\t\t// OSC 0;title BEL - set terminal window title. Control characters are\n\t\t// stripped so a title cannot terminate the OSC early and leak the rest\n\t\t// onto the screen.\n\t\tconst sanitizedTitle = title.replace(/[\\u0000-\\u001f\\u007f-\\u009f]/g, \"\");\n\t\tthis.rawWrite(`\\x1b]0;${sanitizedTitle}\\x07`);\n\t}\n\n\tsetProgress(active: boolean): void {\n\t\tif (active) {\n\t\t\t// OSC 9;4;3 - indeterminate progress\n\t\t\tthis.rawWrite(TERMINAL_PROGRESS_ACTIVE_SEQUENCE);\n\t\t\tif (!this.progressInterval) {\n\t\t\t\tthis.progressInterval = setInterval(() => {\n\t\t\t\t\tthis.rawWrite(TERMINAL_PROGRESS_ACTIVE_SEQUENCE);\n\t\t\t\t}, TERMINAL_PROGRESS_KEEPALIVE_MS);\n\t\t\t}\n\t\t} else {\n\t\t\tthis.clearProgressInterval();\n\t\t\t// OSC 9;4;0 - clear progress\n\t\t\tthis.rawWrite(TERMINAL_PROGRESS_CLEAR_SEQUENCE);\n\t\t}\n\t}\n\n\tprivate clearProgressInterval(): boolean {\n\t\tif (!this.progressInterval) return false;\n\t\tclearInterval(this.progressInterval);\n\t\tthis.progressInterval = undefined;\n\t\treturn true;\n\t}\n}\n"]}
@@ -13,6 +13,8 @@ export interface TuiAltScreenOptions {
13
13
  openUrl?: (url: string) => void;
14
14
  /** Handle an unmodified secondary-button press for clipboard paste. Currently enabled on Windows only. */
15
15
  onRightClickPaste?: () => void;
16
+ /** Automatically copy selected text to the clipboard on mouse release (default: true). */
17
+ copyOnSelect?: boolean;
16
18
  /**
17
19
  * Copy selected text to the system clipboard. Return `true` on success; the caller flashes
18
20
  * an error otherwise. When omitted, the selection is copied via an OSC 52 write.
@@ -56,10 +58,17 @@ export declare class TuiAltScreen extends TuiBase implements ViewportTUI {
56
58
  private readonly searchCurrentMatchStyle;
57
59
  private readonly openUrl?;
58
60
  private readonly onRightClickPaste?;
61
+ private copyOnSelect;
59
62
  private readonly copySelection?;
60
63
  constructor(terminal: Terminal, showHardwareCursor?: boolean, logDirectory?: string, options?: TuiAltScreenOptions);
61
64
  get viewportTop(): number;
62
65
  get isFollowingOutput(): boolean;
66
+ getCopyOnSelect(): boolean;
67
+ setCopyOnSelect(enabled: boolean): void;
68
+ /** Whether the fullscreen viewport has a non-empty active text selection. */
69
+ hasActiveSelection(): boolean;
70
+ /** Copy the active fullscreen text selection, if any, using the configured selection clipboard path. */
71
+ copyActiveSelectionToClipboard(): Promise<boolean>;
63
72
  setLayoutRoot(component: Component | undefined): void;
64
73
  render(width: number): string[];
65
74
  protected getMountedRoots(): readonly Component[];
@@ -106,7 +115,9 @@ export declare class TuiAltScreen extends TuiBase implements ViewportTUI {
106
115
  private handleSelectionMouseEvent;
107
116
  private getSelectionBounds;
108
117
  private getSelectionColumns;
118
+ private getActiveSelectionText;
109
119
  private copySelectionToClipboard;
120
+ private copyTextToClipboard;
110
121
  private applySearchTextHighlight;
111
122
  private applySearchHighlights;
112
123
  private applySelectionHighlight;
@@ -1 +1 @@
1
- {"version":3,"file":"tui-alt-screen.d.ts","sourceRoot":"","sources":["../src/tui-alt-screen.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAY9C,OAAO,EACN,KAAK,SAAS,EAId,OAAO,EACP,KAAK,cAAc,EACnB,YAAY,EACZ,KAAK,WAAW,EAChB,MAAM,UAAU,CAAC;AAuGlB,MAAM,WAAW,mBAAmB;IACnC,gEAAgE;IAChE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,wFAAwF;IACxF,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,mDAAmD;IACnD,gBAAgB,CAAC,EAAE,CAAC,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iB5B,OAAO,CAAC,iBAAiB;IAOzB,OAAO,CAAC,oBAAoB;IAI5B,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,yBAAyB;IA2CjC,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,uBAAuB;IAoB/B,OAAO,CAAC,iBAAiB;IAWzB,OAAO,CAAC,sBAAsB;IAQ9B,OAAO,CAAC,gBAAgB;IAqCxB,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,oBAAoB;IAoB5B,OAAO,CAAC,aAAa;IA0BrB,OAAO,CAAC,yBAAyB;IA4BjC,OAAO,CAAC,mBAAmB;IAkB3B,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,yBAAyB;IAoEjC,OAAO,CAAC,kBAAkB;IAiB1B,OAAO,CAAC,mBAAmB;IAqB3B,OAAO,CAAC,sBAAsB;YAwBhB,wBAAwB;YAMxB,mBAAmB;IAejC,OAAO,CAAC,wBAAwB;IAoBhC,OAAO,CAAC,qBAAqB;IAkD7B,OAAO,CAAC,uBAAuB;IAiB/B,OAAO,CAAC,cAAc;IAiDtB,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,gBAAgB;cAcL,QAAQ,IAAI,IAAI;CAoEnC"}
@@ -26,6 +26,9 @@ const MAX_CACHED_OFFSCREEN_KITTY_IMAGES = 16;
26
26
  const MAX_CACHED_OFFSCREEN_KITTY_TRANSMISSION_BYTES = 32 * 1024 * 1024;
27
27
  const MAX_CACHED_OFFSCREEN_KITTY_DECODED_BYTES = 64 * 1024 * 1024;
28
28
  const DOUBLE_CLICK_INTERVAL_MS = 500;
29
+ // Regular mode delegates double-click selection to the terminal emulator. Fullscreen owns mouse selection,
30
+ // so mirror common terminal word-selection behavior by keeping paths and kebab-case tokens whole.
31
+ const TERMINAL_WORD_SELECTION_JOINERS = new Set(["/", "-"]);
29
32
  const wordSegmenter = getWordSegmenter();
30
33
  /** Alternate-screen TUI with a scrollable, application-owned viewport. */
31
34
  export class TuiAltScreen extends TuiBase {
@@ -60,6 +63,7 @@ export class TuiAltScreen extends TuiBase {
60
63
  this.searchCurrentMatchStyle = options.searchCurrentMatchStyle ?? ((text) => `\x1b[1;7m${text}\x1b[22;27m`);
61
64
  this.openUrl = options.openUrl;
62
65
  this.onRightClickPaste = options.onRightClickPaste;
66
+ this.copyOnSelect = options.copyOnSelect ?? true;
63
67
  this.copySelection = options.copySelection;
64
68
  this.addInputListener((data) => this.handleViewportInput(data));
65
69
  }
@@ -69,6 +73,23 @@ export class TuiAltScreen extends TuiBase {
69
73
  get isFollowingOutput() {
70
74
  return this.getPrimaryScrollView().isFollowingEnd;
71
75
  }
76
+ getCopyOnSelect() {
77
+ return this.copyOnSelect;
78
+ }
79
+ setCopyOnSelect(enabled) {
80
+ this.copyOnSelect = enabled;
81
+ }
82
+ /** Whether the fullscreen viewport has a non-empty active text selection. */
83
+ hasActiveSelection() {
84
+ return this.getActiveSelectionText() !== undefined;
85
+ }
86
+ /** Copy the active fullscreen text selection, if any, using the configured selection clipboard path. */
87
+ async copyActiveSelectionToClipboard() {
88
+ const text = this.getActiveSelectionText();
89
+ if (!text)
90
+ return false;
91
+ return this.copyTextToClipboard(text);
92
+ }
72
93
  setLayoutRoot(component) {
73
94
  if (this.layoutRoot === component)
74
95
  return;
@@ -661,18 +682,30 @@ export class TuiAltScreen extends TuiBase {
661
682
  }
662
683
  getWordSelection(point) {
663
684
  const line = stripTerminalSequences(this.getSelectionSourceLine(point));
685
+ const segments = [];
664
686
  let start = 0;
665
687
  for (const segment of wordSegmenter.segment(line)) {
666
688
  const end = start + visibleWidth(segment.segment);
667
- if (point.col >= start && point.col < end) {
668
- return {
669
- start: { ...point, col: start },
670
- end: { ...point, col: end, boundary: true },
671
- };
672
- }
689
+ const joiner = TERMINAL_WORD_SELECTION_JOINERS.has(segment.segment);
690
+ segments.push({ start, end, selectable: segment.isWordLike === true || joiner, joiner });
673
691
  start = end;
674
692
  }
675
- return undefined;
693
+ const clickedSegmentIndex = segments.findIndex((segment) => point.col >= segment.start && point.col < segment.end);
694
+ if (clickedSegmentIndex < 0)
695
+ return undefined;
696
+ const canJoin = (left, right) => left.selectable && right.selectable && (left.joiner || right.joiner);
697
+ let selectionStart = segments[clickedSegmentIndex].start;
698
+ let selectionEnd = segments[clickedSegmentIndex].end;
699
+ for (let index = clickedSegmentIndex; index > 0 && canJoin(segments[index - 1], segments[index]); index--) {
700
+ selectionStart = segments[index - 1].start;
701
+ }
702
+ for (let index = clickedSegmentIndex; index < segments.length - 1 && canJoin(segments[index], segments[index + 1]); index++) {
703
+ selectionEnd = segments[index + 1].end;
704
+ }
705
+ return {
706
+ start: { ...point, col: selectionStart },
707
+ end: { ...point, col: selectionEnd, boundary: true },
708
+ };
676
709
  }
677
710
  getLineSelection(point) {
678
711
  return {
@@ -807,7 +840,8 @@ export class TuiAltScreen extends TuiBase {
807
840
  this.requestRender();
808
841
  return;
809
842
  }
810
- void this.copySelectionToClipboard();
843
+ if (this.copyOnSelect)
844
+ void this.copySelectionToClipboard();
811
845
  this.requestRender();
812
846
  return;
813
847
  }
@@ -870,17 +904,17 @@ export class TuiAltScreen extends TuiBase {
870
904
  }
871
905
  return { start: Math.max(minColumn, start), end: Math.min(maxColumn, end) };
872
906
  }
873
- async copySelectionToClipboard() {
907
+ getActiveSelectionText() {
874
908
  const selection = this.getSelectionBounds();
875
909
  if (!selection)
876
- return;
910
+ return undefined;
877
911
  let sourceLines = this.previousScreen;
878
912
  if (selection.start.scrollView) {
879
913
  if (!this.currentLayout)
880
- return;
914
+ return undefined;
881
915
  const box = getScrollViewBox(this.currentLayout, selection.start.scrollView);
882
916
  if (!box?.scrollContentLines)
883
- return;
917
+ return undefined;
884
918
  sourceLines = box.scrollContentLines;
885
919
  }
886
920
  const lines = [];
@@ -890,8 +924,15 @@ export class TuiAltScreen extends TuiBase {
890
924
  lines.push(stripTerminalSequences(sliceByColumn(line, columns.start, Math.max(0, columns.end - columns.start), true)).trimEnd());
891
925
  }
892
926
  const text = lines.join("\n");
893
- if (text.length === 0)
894
- return;
927
+ return text.length === 0 ? undefined : text;
928
+ }
929
+ async copySelectionToClipboard() {
930
+ const text = this.getActiveSelectionText();
931
+ if (!text)
932
+ return false;
933
+ return this.copyTextToClipboard(text);
934
+ }
935
+ async copyTextToClipboard(text) {
895
936
  // Prefer an injected clipboard implementation (native clipboard + platform tools with a
896
937
  // verified success path) when the host app provides one. A bare OSC 52 write can show
897
938
  // "Copied!" while leaving the system clipboard untouched (e.g. macOS Terminal.app, tmux
@@ -899,10 +940,11 @@ export class TuiAltScreen extends TuiBase {
899
940
  if (this.copySelection) {
900
941
  const ok = await this.copySelection(text);
901
942
  this.flash(ok ? "Copied!" : "Copy failed");
902
- return;
943
+ return ok;
903
944
  }
904
945
  this.terminal.write(`\x1b]52;c;${Buffer.from(text).toString("base64")}\x07`);
905
946
  this.flash("Copied!");
947
+ return true;
906
948
  }
907
949
  applySearchTextHighlight(text, current) {
908
950
  const style = current ? this.searchCurrentMatchStyle : this.searchMatchStyle;