@asm-agent/tui 0.8.2

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.
Files changed (130) hide show
  1. package/README.md +795 -0
  2. package/dist/autocomplete.d.ts +61 -0
  3. package/dist/autocomplete.d.ts.map +1 -0
  4. package/dist/autocomplete.js +601 -0
  5. package/dist/autocomplete.js.map +1 -0
  6. package/dist/components/box.d.ts +24 -0
  7. package/dist/components/box.d.ts.map +1 -0
  8. package/dist/components/box.js +114 -0
  9. package/dist/components/box.js.map +1 -0
  10. package/dist/components/cancellable-loader.d.ts +22 -0
  11. package/dist/components/cancellable-loader.d.ts.map +1 -0
  12. package/dist/components/cancellable-loader.js +35 -0
  13. package/dist/components/cancellable-loader.js.map +1 -0
  14. package/dist/components/editor.d.ts +275 -0
  15. package/dist/components/editor.d.ts.map +1 -0
  16. package/dist/components/editor.js +1968 -0
  17. package/dist/components/editor.js.map +1 -0
  18. package/dist/components/image.d.ts +34 -0
  19. package/dist/components/image.d.ts.map +1 -0
  20. package/dist/components/image.js +96 -0
  21. package/dist/components/image.js.map +1 -0
  22. package/dist/components/input.d.ts +37 -0
  23. package/dist/components/input.d.ts.map +1 -0
  24. package/dist/components/input.js +385 -0
  25. package/dist/components/input.js.map +1 -0
  26. package/dist/components/loader.d.ts +29 -0
  27. package/dist/components/loader.d.ts.map +1 -0
  28. package/dist/components/loader.js +69 -0
  29. package/dist/components/loader.js.map +1 -0
  30. package/dist/components/markdown.d.ts +100 -0
  31. package/dist/components/markdown.d.ts.map +1 -0
  32. package/dist/components/markdown.js +773 -0
  33. package/dist/components/markdown.js.map +1 -0
  34. package/dist/components/select-list.d.ts +61 -0
  35. package/dist/components/select-list.d.ts.map +1 -0
  36. package/dist/components/select-list.js +206 -0
  37. package/dist/components/select-list.js.map +1 -0
  38. package/dist/components/settings-list.d.ts +49 -0
  39. package/dist/components/settings-list.d.ts.map +1 -0
  40. package/dist/components/settings-list.js +170 -0
  41. package/dist/components/settings-list.js.map +1 -0
  42. package/dist/components/spacer.d.ts +12 -0
  43. package/dist/components/spacer.d.ts.map +1 -0
  44. package/dist/components/spacer.js +21 -0
  45. package/dist/components/spacer.js.map +1 -0
  46. package/dist/components/text.d.ts +19 -0
  47. package/dist/components/text.d.ts.map +1 -0
  48. package/dist/components/text.js +77 -0
  49. package/dist/components/text.js.map +1 -0
  50. package/dist/components/truncated-text.d.ts +14 -0
  51. package/dist/components/truncated-text.d.ts.map +1 -0
  52. package/dist/components/truncated-text.js +44 -0
  53. package/dist/components/truncated-text.js.map +1 -0
  54. package/dist/editor-component.d.ts +51 -0
  55. package/dist/editor-component.d.ts.map +1 -0
  56. package/dist/editor-component.js +2 -0
  57. package/dist/editor-component.js.map +1 -0
  58. package/dist/fullscreen.d.ts +105 -0
  59. package/dist/fullscreen.d.ts.map +1 -0
  60. package/dist/fullscreen.js +597 -0
  61. package/dist/fullscreen.js.map +1 -0
  62. package/dist/fuzzy.d.ts +26 -0
  63. package/dist/fuzzy.d.ts.map +1 -0
  64. package/dist/fuzzy.js +114 -0
  65. package/dist/fuzzy.js.map +1 -0
  66. package/dist/index.d.ts +29 -0
  67. package/dist/index.d.ts.map +1 -0
  68. package/dist/index.js +27 -0
  69. package/dist/index.js.map +1 -0
  70. package/dist/keybindings.d.ts +239 -0
  71. package/dist/keybindings.d.ts.map +1 -0
  72. package/dist/keybindings.js +222 -0
  73. package/dist/keybindings.js.map +1 -0
  74. package/dist/keys.d.ts +184 -0
  75. package/dist/keys.d.ts.map +1 -0
  76. package/dist/keys.js +1163 -0
  77. package/dist/keys.js.map +1 -0
  78. package/dist/kill-ring.d.ts +26 -0
  79. package/dist/kill-ring.d.ts.map +1 -0
  80. package/dist/kill-ring.js +42 -0
  81. package/dist/kill-ring.js.map +1 -0
  82. package/dist/latex.d.ts +21 -0
  83. package/dist/latex.d.ts.map +1 -0
  84. package/dist/latex.js +797 -0
  85. package/dist/latex.js.map +1 -0
  86. package/dist/mouse.d.ts +24 -0
  87. package/dist/mouse.d.ts.map +1 -0
  88. package/dist/mouse.js +34 -0
  89. package/dist/mouse.js.map +1 -0
  90. package/dist/render-cache.d.ts +9 -0
  91. package/dist/render-cache.d.ts.map +1 -0
  92. package/dist/render-cache.js +23 -0
  93. package/dist/render-cache.js.map +1 -0
  94. package/dist/selection-metadata.d.ts +22 -0
  95. package/dist/selection-metadata.d.ts.map +1 -0
  96. package/dist/selection-metadata.js +141 -0
  97. package/dist/selection-metadata.js.map +1 -0
  98. package/dist/slash-command-context.d.ts +12 -0
  99. package/dist/slash-command-context.d.ts.map +1 -0
  100. package/dist/slash-command-context.js +32 -0
  101. package/dist/slash-command-context.js.map +1 -0
  102. package/dist/stdin-buffer.d.ts +50 -0
  103. package/dist/stdin-buffer.d.ts.map +1 -0
  104. package/dist/stdin-buffer.js +313 -0
  105. package/dist/stdin-buffer.js.map +1 -0
  106. package/dist/terminal-colors.d.ts +31 -0
  107. package/dist/terminal-colors.d.ts.map +1 -0
  108. package/dist/terminal-colors.js +161 -0
  109. package/dist/terminal-colors.js.map +1 -0
  110. package/dist/terminal-image.d.ts +85 -0
  111. package/dist/terminal-image.d.ts.map +1 -0
  112. package/dist/terminal-image.js +324 -0
  113. package/dist/terminal-image.js.map +1 -0
  114. package/dist/terminal.d.ts +113 -0
  115. package/dist/terminal.d.ts.map +1 -0
  116. package/dist/terminal.js +486 -0
  117. package/dist/terminal.js.map +1 -0
  118. package/dist/tui.d.ts +310 -0
  119. package/dist/tui.d.ts.map +1 -0
  120. package/dist/tui.js +1673 -0
  121. package/dist/tui.js.map +1 -0
  122. package/dist/undo-stack.d.ts +16 -0
  123. package/dist/undo-stack.d.ts.map +1 -0
  124. package/dist/undo-stack.js +26 -0
  125. package/dist/undo-stack.js.map +1 -0
  126. package/dist/utils.d.ts +98 -0
  127. package/dist/utils.d.ts.map +1 -0
  128. package/dist/utils.js +1233 -0
  129. package/dist/utils.js.map +1 -0
  130. package/package.json +52 -0
@@ -0,0 +1 @@
1
+ {"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GAAG,IAAI,CAS1B;IAED,UAAU,IAAI,IAAI,CAEjB;IAED,UAAU,IAAI,IAAI,CAEjB;IAED,SAAS,IAAI,IAAI,CAEhB;IAED,eAAe,IAAI,IAAI,CAEtB;IAED,WAAW,IAAI,IAAI,CAElB;IAED,cAAc,IAAI,IAAI,CASrB;IAED,cAAc,IAAI,IAAI,CAErB;IAED,OAAO,CAAC,gBAAgB;IAWxB,IAAI,eAAe,IAAI,OAAO,CAE7B;IAED,OAAO,CAAC,2BAA2B;IAInC,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAMvC;IAED,IAAI,mBAAmB,IAAI,OAAO,CAEjC;IAED,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAG5B;IAED,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAcjC;IAED,OAAO,CAAC,qBAAqB;CAM7B","sourcesContent":["import * as fs from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport * as path from \"node:path\";\nimport { setKittyProtocolActive } from \"./keys.js\";\nimport { StdinBuffer } from \"./stdin-buffer.js\";\nimport {\n\tparseOscColorResponse,\n\tQUERY_DEFAULT_BACKGROUND,\n\tQUERY_DEFAULT_FOREGROUND,\n\ttype Rgb,\n\tsetDefaultTerminalColors,\n} from \"./terminal-colors.js\";\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\";\n\n// A preserved alternate screen is adopted by the next ProcessTerminal during in-process handoff.\nlet pendingAltScreenHandoff: symbol | undefined;\n\ninterface PendingInputHandoff {\n\ttoken: symbol;\n\twasRaw: boolean;\n\tdiscardHandler: (data: string) => void;\n}\n\n// Keep stdin raw and drain input while a preserved fullscreen frame waits for\n// the next in-process TUI. Worker-backed session attach can make this handoff\n// noticeably longer; restoring cooked mode during the gap makes arrow escape\n// sequences echo into the preserved frame.\nlet pendingInputHandoff: PendingInputHandoff | undefined;\n\nfunction consumeAltScreenHandoff(): boolean {\n\tif (!pendingAltScreenHandoff) {\n\t\treturn false;\n\t}\n\tpendingAltScreenHandoff = undefined;\n\treturn true;\n}\n\nfunction beginInputHandoff(token: symbol, wasRaw: boolean): void {\n\tconst inheritedWasRaw = pendingInputHandoff?.wasRaw ?? wasRaw;\n\tif (pendingInputHandoff) {\n\t\tprocess.stdin.removeListener(\"data\", pendingInputHandoff.discardHandler);\n\t}\n\tconst discardHandler = (_data: string) => {};\n\tpendingInputHandoff = { token, wasRaw: inheritedWasRaw, discardHandler };\n\tprocess.stdin.on(\"data\", discardHandler);\n\tprocess.stdin.resume();\n}\n\nfunction consumeInputHandoff(): boolean | undefined {\n\tconst handoff = pendingInputHandoff;\n\tif (!handoff) {\n\t\treturn undefined;\n\t}\n\tprocess.stdin.removeListener(\"data\", handoff.discardHandler);\n\tpendingInputHandoff = undefined;\n\treturn handoff.wasRaw;\n}\n\nfunction cancelInputHandoff(token: symbol): void {\n\tconst handoff = pendingInputHandoff;\n\tif (!handoff || handoff.token !== token) {\n\t\treturn;\n\t}\n\tprocess.stdin.removeListener(\"data\", handoff.discardHandler);\n\tpendingInputHandoff = undefined;\n\tprocess.stdin.pause();\n\tif (process.stdin.setRawMode) {\n\t\tprocess.stdin.setRawMode(handoff.wasRaw);\n\t}\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(options?: TerminalStopOptions): 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// Alternate screen buffer. The primary screen (and its scrollback) is left\n\t// untouched while the alt screen is active, so a full-screen view can be\n\t// shown and dismissed without disturbing the transcript history.\n\tenterAltScreen(): void;\n\tleaveAltScreen(): void;\n\tget altScreenActive(): boolean;\n\n\t// SGR mouse tracking (?1000 + ?1006); motion tracking is deliberately never\n\t// enabled so native drag-selection keeps working.\n\tsetMouseTracking(enabled: boolean): void;\n\tget mouseTrackingActive(): boolean;\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 TerminalStopOptions {\n\tpreserveAltScreen?: boolean;\n}\n\n/**\n * Real terminal using process.stdin/stdout\n */\nexport class ProcessTerminal implements Terminal {\n\tprivate wasRaw = false;\n\tprivate started = false;\n\tprivate inputHandler?: (data: string) => void;\n\tprivate resizeHandler?: () => void;\n\tprivate _kittyProtocolActive = false;\n\tprivate _modifyOtherKeysActive = false;\n\tprivate readonly altScreenHandoffToken = Symbol(\"altScreenHandoff\");\n\tprivate _altScreenActive = consumeAltScreenHandoff();\n\tprivate _mouseTrackingActive = false;\n\tprivate stdinBuffer?: StdinBuffer;\n\tprivate stdinDataHandler?: (data: string) => void;\n\tprivate keyboardProtocolFallbackTimer?: ReturnType<typeof setTimeout>;\n\tprivate progressInterval?: ReturnType<typeof setInterval>;\n\tprivate defaultColorProbe?: {\n\t\tforeground?: Rgb;\n\t\tbackground?: Rgb;\n\t\ttimeout: ReturnType<typeof setTimeout>;\n\t};\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\tget kittyProtocolActive(): boolean {\n\t\treturn this._kittyProtocolActive;\n\t}\n\n\tstart(onInput: (data: string) => void, onResize: () => void): void {\n\t\tthis.started = true;\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 = consumeInputHandoff() ?? process.stdin.isRaw ?? false;\n\t\tif (process.stdin.setRawMode) {\n\t\t\tprocess.stdin.setRawMode(true);\n\t\t}\n\t\tprocess.stdin.setEncoding(\"utf8\");\n\t\tprocess.stdin.resume();\n\n\t\t// Enable bracketed paste mode - terminal will wrap pastes in \\x1b[200~ ... \\x1b[201~\n\t\tprocess.stdout.write(\"\\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 and enable Kitty keyboard protocol\n\t\t// The query handler intercepts input temporarily, then installs the user's handler\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({ timeout: 10 });\n\n\t\t// Kitty protocol response pattern: \\x1b[?<flags>u\n\t\tconst kittyResponsePattern = /^\\x1b\\[\\?(\\d+)u$/;\n\n\t\t// Forward individual sequences to the input handler\n\t\tthis.stdinBuffer.on(\"data\", (sequence) => {\n\t\t\tif (this.handleDefaultColorProbeResponse(sequence)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Check for Kitty protocol response (only if not already enabled)\n\t\t\tif (!this._kittyProtocolActive) {\n\t\t\t\tconst match = sequence.match(kittyResponsePattern);\n\t\t\t\tif (match) {\n\t\t\t\t\tthis.clearKeyboardProtocolFallbackTimer();\n\t\t\t\t\tthis._kittyProtocolActive = true;\n\t\t\t\t\tsetKittyProtocolActive(true);\n\n\t\t\t\t\t// Enable Kitty keyboard protocol (push flags)\n\t\t\t\t\t// Flag 1 = disambiguate escape codes\n\t\t\t\t\t// Flag 2 = report event types (press/repeat/release)\n\t\t\t\t\t// Flag 4 = report alternate keys (shifted key, base layout key)\n\t\t\t\t\t// Base layout key enables shortcuts to work with non-Latin keyboard layouts\n\t\t\t\t\tprocess.stdout.write(\"\\x1b[>7u\");\n\t\t\t\t\treturn; // Don't forward protocol response to TUI\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this.inputHandler) {\n\t\t\t\tthis.inputHandler(sequence);\n\t\t\t}\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) => {\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 if available.\n\t *\n\t * Sends CSI ? u to query current flags. If terminal responds with CSI ? <flags> u,\n\t * it supports the protocol and we enable it with CSI > 1 u.\n\t *\n\t * If no Kitty response arrives shortly after startup, fall back to enabling\n\t * xterm modifyOtherKeys mode 2. This is needed for tmux, which can forward\n\t * modified enter keys as CSI-u when extended-keys is enabled, but may not\n\t * answer the Kitty protocol query.\n\t *\n\t * The response is detected in setupStdinBuffer's data handler, which properly\n\t * handles the case where the response arrives split across multiple stdin events.\n\t */\n\tprivate queryAndEnableKittyProtocol(): void {\n\t\tthis.setupStdinBuffer();\n\t\tprocess.stdin.on(\"data\", this.stdinDataHandler!);\n\t\tthis.queryDefaultTerminalColors();\n\t\tprocess.stdout.write(\"\\x1b[?u\");\n\t\tthis.clearKeyboardProtocolFallbackTimer();\n\t\tthis.keyboardProtocolFallbackTimer = setTimeout(() => {\n\t\t\tthis.keyboardProtocolFallbackTimer = undefined;\n\t\t\tif (!this._kittyProtocolActive && !this._modifyOtherKeysActive) {\n\t\t\t\tprocess.stdout.write(\"\\x1b[>4;2m\");\n\t\t\t\tthis._modifyOtherKeysActive = true;\n\t\t\t}\n\t\t}, 150);\n\t}\n\n\tprivate clearKeyboardProtocolFallbackTimer(): void {\n\t\tif (!this.keyboardProtocolFallbackTimer) {\n\t\t\treturn;\n\t\t}\n\t\tclearTimeout(this.keyboardProtocolFallbackTimer);\n\t\tthis.keyboardProtocolFallbackTimer = undefined;\n\t}\n\n\tprivate queryDefaultTerminalColors(): void {\n\t\tif (process.stdin.isTTY !== true || process.stdout.isTTY !== true) {\n\t\t\treturn;\n\t\t}\n\t\tthis.finishDefaultColorProbe();\n\t\tthis.defaultColorProbe = {\n\t\t\ttimeout: setTimeout(() => this.finishDefaultColorProbe(), 100),\n\t\t};\n\t\tprocess.stdout.write(QUERY_DEFAULT_FOREGROUND);\n\t\tprocess.stdout.write(QUERY_DEFAULT_BACKGROUND);\n\t}\n\n\tprivate handleDefaultColorProbeResponse(sequence: string): boolean {\n\t\tconst response = parseOscColorResponse(sequence);\n\t\tif (!response) {\n\t\t\treturn false;\n\t\t}\n\t\tif (!this.defaultColorProbe) {\n\t\t\treturn true;\n\t\t}\n\n\t\tthis.defaultColorProbe[response.kind] = response.rgb;\n\t\tif (this.defaultColorProbe.foreground && this.defaultColorProbe.background) {\n\t\t\tthis.finishDefaultColorProbe();\n\t\t}\n\t\treturn true;\n\t}\n\n\tprivate finishDefaultColorProbe(): void {\n\t\tif (!this.defaultColorProbe) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { foreground, background, timeout } = this.defaultColorProbe;\n\t\tclearTimeout(timeout);\n\t\tthis.defaultColorProbe = undefined;\n\t\tif (foreground && background) {\n\t\t\tsetDefaultTerminalColors({ foreground, background });\n\t\t\tthis.resizeHandler?.();\n\t\t}\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\t// Dynamic require to avoid bundling koffi's 74MB of cross-platform\n\t\t\t// native binaries into every compiled binary. Koffi is only needed\n\t\t\t// on Windows for VT input support.\n\t\t\tconst koffi = cjsRequire(\"koffi\");\n\t\t\tconst k32 = koffi.load(\"kernel32.dll\");\n\t\t\tconst GetStdHandle = k32.func(\"void* __stdcall GetStdHandle(int)\");\n\t\t\tconst GetConsoleMode = k32.func(\"bool __stdcall GetConsoleMode(void*, _Out_ uint32_t*)\");\n\t\t\tconst SetConsoleMode = k32.func(\"bool __stdcall SetConsoleMode(void*, uint32_t)\");\n\n\t\t\tconst STD_INPUT_HANDLE = -10;\n\t\t\tconst ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200;\n\t\t\tconst handle = GetStdHandle(STD_INPUT_HANDLE);\n\t\t\tconst mode = new Uint32Array(1);\n\t\t\tGetConsoleMode(handle, mode);\n\t\t\tSetConsoleMode(handle, mode[0]! | ENABLE_VIRTUAL_TERMINAL_INPUT);\n\t\t} catch {\n\t\t\t// koffi 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\tif (this._kittyProtocolActive) {\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\tprocess.stdout.write(\"\\x1b[<u\");\n\t\t\tthis._kittyProtocolActive = false;\n\t\t\tsetKittyProtocolActive(false);\n\t\t}\n\t\tif (this._modifyOtherKeysActive) {\n\t\t\tprocess.stdout.write(\"\\x1b[>4;0m\");\n\t\t\tthis._modifyOtherKeysActive = false;\n\t\t}\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(options: TerminalStopOptions = {}): void {\n\t\tconst wasStarted = this.started;\n\t\tthis.started = false;\n\t\tthis.finishDefaultColorProbe();\n\t\tthis.clearKeyboardProtocolFallbackTimer();\n\n\t\tif (this.clearProgressInterval()) {\n\t\t\tprocess.stdout.write(TERMINAL_PROGRESS_CLEAR_SEQUENCE);\n\t\t}\n\n\t\tif (this._mouseTrackingActive) {\n\t\t\tprocess.stdout.write(\"\\x1b[?1006l\\x1b[?1002l\");\n\t\t\tthis._mouseTrackingActive = false;\n\t\t}\n\t\tif (this._altScreenActive) {\n\t\t\tif (options.preserveAltScreen) {\n\t\t\t\tpendingAltScreenHandoff = this.altScreenHandoffToken;\n\t\t\t\tthis._altScreenActive = false;\n\t\t\t} else {\n\t\t\t\tthis.releaseAltScreen();\n\t\t\t}\n\t\t} else if (!options.preserveAltScreen) {\n\t\t\tthis.releaseAltScreen();\n\t\t}\n\n\t\t// Disable bracketed paste mode\n\t\tprocess.stdout.write(\"\\x1b[?2004l\");\n\n\t\t// Disable Kitty keyboard protocol if not already done by drainInput()\n\t\tif (this._kittyProtocolActive) {\n\t\t\tprocess.stdout.write(\"\\x1b[<u\");\n\t\t\tthis._kittyProtocolActive = false;\n\t\t\tsetKittyProtocolActive(false);\n\t\t}\n\t\tif (this._modifyOtherKeysActive) {\n\t\t\tprocess.stdout.write(\"\\x1b[>4;0m\");\n\t\t\tthis._modifyOtherKeysActive = false;\n\t\t}\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\tif (options.preserveAltScreen && wasStarted) {\n\t\t\tbeginInputHandoff(this.altScreenHandoffToken, this.wasRaw);\n\t\t} else {\n\t\t\t// Pause stdin to prevent any buffered input (e.g., Ctrl+D) from being\n\t\t\t// re-interpreted after raw mode is disabled. This fixes a race condition\n\t\t\t// where Ctrl+D could close the parent shell over SSH.\n\t\t\tprocess.stdin.pause();\n\n\t\t\t// Restore raw mode state\n\t\t\tif (process.stdin.setRawMode) {\n\t\t\t\tprocess.stdin.setRawMode(this.wasRaw);\n\t\t\t}\n\t\t}\n\t}\n\n\twrite(data: string): void {\n\t\tprocess.stdout.write(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\tprocess.stdout.write(`\\x1b[${lines}B`);\n\t\t} else if (lines < 0) {\n\t\t\t// Move up\n\t\t\tprocess.stdout.write(`\\x1b[${-lines}A`);\n\t\t}\n\t\t// lines === 0: no movement\n\t}\n\n\thideCursor(): void {\n\t\tprocess.stdout.write(\"\\x1b[?25l\");\n\t}\n\n\tshowCursor(): void {\n\t\tprocess.stdout.write(\"\\x1b[?25h\");\n\t}\n\n\tclearLine(): void {\n\t\tprocess.stdout.write(\"\\x1b[K\");\n\t}\n\n\tclearFromCursor(): void {\n\t\tprocess.stdout.write(\"\\x1b[J\");\n\t}\n\n\tclearScreen(): void {\n\t\tprocess.stdout.write(\"\\x1b[2J\\x1b[H\"); // Clear screen and move to home (1,1)\n\t}\n\n\tenterAltScreen(): void {\n\t\tif (this._altScreenActive) return;\n\t\tif (this.ownsPendingAltScreenHandoff()) {\n\t\t\tpendingAltScreenHandoff = undefined;\n\t\t\tthis._altScreenActive = true;\n\t\t\treturn;\n\t\t}\n\t\tthis._altScreenActive = true;\n\t\tthis.write(\"\\x1b[?1049h\");\n\t}\n\n\tleaveAltScreen(): void {\n\t\tthis.releaseAltScreen();\n\t}\n\n\tprivate releaseAltScreen(): void {\n\t\tconst ownsPendingHandoff = this.ownsPendingAltScreenHandoff();\n\t\tif (!this._altScreenActive && !ownsPendingHandoff) return;\n\t\tthis._altScreenActive = false;\n\t\tif (ownsPendingHandoff) {\n\t\t\tpendingAltScreenHandoff = undefined;\n\t\t\tcancelInputHandoff(this.altScreenHandoffToken);\n\t\t}\n\t\tthis.write(\"\\x1b[?1049l\");\n\t}\n\n\tget altScreenActive(): boolean {\n\t\treturn this._altScreenActive;\n\t}\n\n\tprivate ownsPendingAltScreenHandoff(): boolean {\n\t\treturn pendingAltScreenHandoff === this.altScreenHandoffToken;\n\t}\n\n\tsetMouseTracking(enabled: boolean): void {\n\t\tif (enabled === this._mouseTrackingActive) return;\n\t\tthis._mouseTrackingActive = enabled;\n\t\t// ?1002 (button-event tracking) reports drag motion for in-app selection\n\t\t// but not hover, keeping passive mouse movement unreported.\n\t\tthis.write(enabled ? \"\\x1b[?1002h\\x1b[?1006h\" : \"\\x1b[?1006l\\x1b[?1002l\");\n\t}\n\n\tget mouseTrackingActive(): boolean {\n\t\treturn this._mouseTrackingActive;\n\t}\n\n\tsetTitle(title: string): void {\n\t\t// OSC 0;title BEL - set terminal window title\n\t\tprocess.stdout.write(`\\x1b]0;${title}\\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\tprocess.stdout.write(TERMINAL_PROGRESS_ACTIVE_SEQUENCE);\n\t\t\tif (!this.progressInterval) {\n\t\t\t\tthis.progressInterval = setInterval(() => {\n\t\t\t\t\tprocess.stdout.write(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\tprocess.stdout.write(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"]}
@@ -0,0 +1,486 @@
1
+ import * as fs from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import * as path from "node:path";
4
+ import { setKittyProtocolActive } from "./keys.js";
5
+ import { StdinBuffer } from "./stdin-buffer.js";
6
+ import { parseOscColorResponse, QUERY_DEFAULT_BACKGROUND, QUERY_DEFAULT_FOREGROUND, setDefaultTerminalColors, } from "./terminal-colors.js";
7
+ const cjsRequire = createRequire(import.meta.url);
8
+ const TERMINAL_PROGRESS_KEEPALIVE_MS = 1000;
9
+ const TERMINAL_PROGRESS_ACTIVE_SEQUENCE = "\x1b]9;4;3\x07";
10
+ const TERMINAL_PROGRESS_CLEAR_SEQUENCE = "\x1b]9;4;0;\x07";
11
+ // A preserved alternate screen is adopted by the next ProcessTerminal during in-process handoff.
12
+ let pendingAltScreenHandoff;
13
+ // Keep stdin raw and drain input while a preserved fullscreen frame waits for
14
+ // the next in-process TUI. Worker-backed session attach can make this handoff
15
+ // noticeably longer; restoring cooked mode during the gap makes arrow escape
16
+ // sequences echo into the preserved frame.
17
+ let pendingInputHandoff;
18
+ function consumeAltScreenHandoff() {
19
+ if (!pendingAltScreenHandoff) {
20
+ return false;
21
+ }
22
+ pendingAltScreenHandoff = undefined;
23
+ return true;
24
+ }
25
+ function beginInputHandoff(token, wasRaw) {
26
+ const inheritedWasRaw = pendingInputHandoff?.wasRaw ?? wasRaw;
27
+ if (pendingInputHandoff) {
28
+ process.stdin.removeListener("data", pendingInputHandoff.discardHandler);
29
+ }
30
+ const discardHandler = (_data) => { };
31
+ pendingInputHandoff = { token, wasRaw: inheritedWasRaw, discardHandler };
32
+ process.stdin.on("data", discardHandler);
33
+ process.stdin.resume();
34
+ }
35
+ function consumeInputHandoff() {
36
+ const handoff = pendingInputHandoff;
37
+ if (!handoff) {
38
+ return undefined;
39
+ }
40
+ process.stdin.removeListener("data", handoff.discardHandler);
41
+ pendingInputHandoff = undefined;
42
+ return handoff.wasRaw;
43
+ }
44
+ function cancelInputHandoff(token) {
45
+ const handoff = pendingInputHandoff;
46
+ if (!handoff || handoff.token !== token) {
47
+ return;
48
+ }
49
+ process.stdin.removeListener("data", handoff.discardHandler);
50
+ pendingInputHandoff = undefined;
51
+ process.stdin.pause();
52
+ if (process.stdin.setRawMode) {
53
+ process.stdin.setRawMode(handoff.wasRaw);
54
+ }
55
+ }
56
+ /**
57
+ * Real terminal using process.stdin/stdout
58
+ */
59
+ export class ProcessTerminal {
60
+ wasRaw = false;
61
+ started = false;
62
+ inputHandler;
63
+ resizeHandler;
64
+ _kittyProtocolActive = false;
65
+ _modifyOtherKeysActive = false;
66
+ altScreenHandoffToken = Symbol("altScreenHandoff");
67
+ _altScreenActive = consumeAltScreenHandoff();
68
+ _mouseTrackingActive = false;
69
+ stdinBuffer;
70
+ stdinDataHandler;
71
+ keyboardProtocolFallbackTimer;
72
+ progressInterval;
73
+ defaultColorProbe;
74
+ writeLogPath = (() => {
75
+ const env = process.env.PI_TUI_WRITE_LOG || "";
76
+ if (!env)
77
+ return "";
78
+ try {
79
+ if (fs.statSync(env).isDirectory()) {
80
+ const now = new Date();
81
+ const 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")}`;
82
+ return path.join(env, `tui-${ts}-${process.pid}.log`);
83
+ }
84
+ }
85
+ catch {
86
+ // Not an existing directory - use as-is (file path)
87
+ }
88
+ return env;
89
+ })();
90
+ get kittyProtocolActive() {
91
+ return this._kittyProtocolActive;
92
+ }
93
+ start(onInput, onResize) {
94
+ this.started = true;
95
+ this.inputHandler = onInput;
96
+ this.resizeHandler = onResize;
97
+ // Save previous state and enable raw mode
98
+ this.wasRaw = consumeInputHandoff() ?? process.stdin.isRaw ?? false;
99
+ if (process.stdin.setRawMode) {
100
+ process.stdin.setRawMode(true);
101
+ }
102
+ process.stdin.setEncoding("utf8");
103
+ process.stdin.resume();
104
+ // Enable bracketed paste mode - terminal will wrap pastes in \x1b[200~ ... \x1b[201~
105
+ process.stdout.write("\x1b[?2004h");
106
+ // Set up resize handler immediately
107
+ process.stdout.on("resize", this.resizeHandler);
108
+ // Refresh terminal dimensions - they may be stale after suspend/resume
109
+ // (SIGWINCH is lost while process is stopped). Unix only.
110
+ if (process.platform !== "win32") {
111
+ process.kill(process.pid, "SIGWINCH");
112
+ }
113
+ // On Windows, enable ENABLE_VIRTUAL_TERMINAL_INPUT so the console sends
114
+ // VT escape sequences (e.g. \x1b[Z for Shift+Tab) instead of raw console
115
+ // events that lose modifier information. Must run AFTER setRawMode(true)
116
+ // since that resets console mode flags.
117
+ this.enableWindowsVTInput();
118
+ // Query and enable Kitty keyboard protocol
119
+ // The query handler intercepts input temporarily, then installs the user's handler
120
+ // See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/
121
+ this.queryAndEnableKittyProtocol();
122
+ }
123
+ /**
124
+ * Set up StdinBuffer to split batched input into individual sequences.
125
+ * This ensures components receive single events, making matchesKey/isKeyRelease work correctly.
126
+ *
127
+ * Also watches for Kitty protocol response and enables it when detected.
128
+ * This is done here (after stdinBuffer parsing) rather than on raw stdin
129
+ * to handle the case where the response arrives split across multiple events.
130
+ */
131
+ setupStdinBuffer() {
132
+ this.stdinBuffer = new StdinBuffer({ timeout: 10 });
133
+ // Kitty protocol response pattern: \x1b[?<flags>u
134
+ const kittyResponsePattern = /^\x1b\[\?(\d+)u$/;
135
+ // Forward individual sequences to the input handler
136
+ this.stdinBuffer.on("data", (sequence) => {
137
+ if (this.handleDefaultColorProbeResponse(sequence)) {
138
+ return;
139
+ }
140
+ // Check for Kitty protocol response (only if not already enabled)
141
+ if (!this._kittyProtocolActive) {
142
+ const match = sequence.match(kittyResponsePattern);
143
+ if (match) {
144
+ this.clearKeyboardProtocolFallbackTimer();
145
+ this._kittyProtocolActive = true;
146
+ setKittyProtocolActive(true);
147
+ // Enable Kitty keyboard protocol (push flags)
148
+ // Flag 1 = disambiguate escape codes
149
+ // Flag 2 = report event types (press/repeat/release)
150
+ // Flag 4 = report alternate keys (shifted key, base layout key)
151
+ // Base layout key enables shortcuts to work with non-Latin keyboard layouts
152
+ process.stdout.write("\x1b[>7u");
153
+ return; // Don't forward protocol response to TUI
154
+ }
155
+ }
156
+ if (this.inputHandler) {
157
+ this.inputHandler(sequence);
158
+ }
159
+ });
160
+ // Re-wrap paste content with bracketed paste markers for existing editor handling
161
+ this.stdinBuffer.on("paste", (content) => {
162
+ if (this.inputHandler) {
163
+ this.inputHandler(`\x1b[200~${content}\x1b[201~`);
164
+ }
165
+ });
166
+ // Handler that pipes stdin data through the buffer
167
+ this.stdinDataHandler = (data) => {
168
+ this.stdinBuffer.process(data);
169
+ };
170
+ }
171
+ /**
172
+ * Query terminal for Kitty keyboard protocol support and enable if available.
173
+ *
174
+ * Sends CSI ? u to query current flags. If terminal responds with CSI ? <flags> u,
175
+ * it supports the protocol and we enable it with CSI > 1 u.
176
+ *
177
+ * If no Kitty response arrives shortly after startup, fall back to enabling
178
+ * xterm modifyOtherKeys mode 2. This is needed for tmux, which can forward
179
+ * modified enter keys as CSI-u when extended-keys is enabled, but may not
180
+ * answer the Kitty protocol query.
181
+ *
182
+ * The response is detected in setupStdinBuffer's data handler, which properly
183
+ * handles the case where the response arrives split across multiple stdin events.
184
+ */
185
+ queryAndEnableKittyProtocol() {
186
+ this.setupStdinBuffer();
187
+ process.stdin.on("data", this.stdinDataHandler);
188
+ this.queryDefaultTerminalColors();
189
+ process.stdout.write("\x1b[?u");
190
+ this.clearKeyboardProtocolFallbackTimer();
191
+ this.keyboardProtocolFallbackTimer = setTimeout(() => {
192
+ this.keyboardProtocolFallbackTimer = undefined;
193
+ if (!this._kittyProtocolActive && !this._modifyOtherKeysActive) {
194
+ process.stdout.write("\x1b[>4;2m");
195
+ this._modifyOtherKeysActive = true;
196
+ }
197
+ }, 150);
198
+ }
199
+ clearKeyboardProtocolFallbackTimer() {
200
+ if (!this.keyboardProtocolFallbackTimer) {
201
+ return;
202
+ }
203
+ clearTimeout(this.keyboardProtocolFallbackTimer);
204
+ this.keyboardProtocolFallbackTimer = undefined;
205
+ }
206
+ queryDefaultTerminalColors() {
207
+ if (process.stdin.isTTY !== true || process.stdout.isTTY !== true) {
208
+ return;
209
+ }
210
+ this.finishDefaultColorProbe();
211
+ this.defaultColorProbe = {
212
+ timeout: setTimeout(() => this.finishDefaultColorProbe(), 100),
213
+ };
214
+ process.stdout.write(QUERY_DEFAULT_FOREGROUND);
215
+ process.stdout.write(QUERY_DEFAULT_BACKGROUND);
216
+ }
217
+ handleDefaultColorProbeResponse(sequence) {
218
+ const response = parseOscColorResponse(sequence);
219
+ if (!response) {
220
+ return false;
221
+ }
222
+ if (!this.defaultColorProbe) {
223
+ return true;
224
+ }
225
+ this.defaultColorProbe[response.kind] = response.rgb;
226
+ if (this.defaultColorProbe.foreground && this.defaultColorProbe.background) {
227
+ this.finishDefaultColorProbe();
228
+ }
229
+ return true;
230
+ }
231
+ finishDefaultColorProbe() {
232
+ if (!this.defaultColorProbe) {
233
+ return;
234
+ }
235
+ const { foreground, background, timeout } = this.defaultColorProbe;
236
+ clearTimeout(timeout);
237
+ this.defaultColorProbe = undefined;
238
+ if (foreground && background) {
239
+ setDefaultTerminalColors({ foreground, background });
240
+ this.resizeHandler?.();
241
+ }
242
+ }
243
+ /**
244
+ * On Windows, add ENABLE_VIRTUAL_TERMINAL_INPUT (0x0200) to the stdin
245
+ * console handle so the terminal sends VT sequences for modified keys
246
+ * (e.g. \x1b[Z for Shift+Tab). Without this, libuv's ReadConsoleInputW
247
+ * discards modifier state and Shift+Tab arrives as plain \t.
248
+ */
249
+ enableWindowsVTInput() {
250
+ if (process.platform !== "win32")
251
+ return;
252
+ try {
253
+ // Dynamic require to avoid bundling koffi's 74MB of cross-platform
254
+ // native binaries into every compiled binary. Koffi is only needed
255
+ // on Windows for VT input support.
256
+ const koffi = cjsRequire("koffi");
257
+ const k32 = koffi.load("kernel32.dll");
258
+ const GetStdHandle = k32.func("void* __stdcall GetStdHandle(int)");
259
+ const GetConsoleMode = k32.func("bool __stdcall GetConsoleMode(void*, _Out_ uint32_t*)");
260
+ const SetConsoleMode = k32.func("bool __stdcall SetConsoleMode(void*, uint32_t)");
261
+ const STD_INPUT_HANDLE = -10;
262
+ const ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200;
263
+ const handle = GetStdHandle(STD_INPUT_HANDLE);
264
+ const mode = new Uint32Array(1);
265
+ GetConsoleMode(handle, mode);
266
+ SetConsoleMode(handle, mode[0] | ENABLE_VIRTUAL_TERMINAL_INPUT);
267
+ }
268
+ catch {
269
+ // koffi not available — Shift+Tab won't be distinguishable from Tab
270
+ }
271
+ }
272
+ async drainInput(maxMs = 1000, idleMs = 50) {
273
+ if (this._kittyProtocolActive) {
274
+ // Disable Kitty keyboard protocol first so any late key releases
275
+ // do not generate new Kitty escape sequences.
276
+ process.stdout.write("\x1b[<u");
277
+ this._kittyProtocolActive = false;
278
+ setKittyProtocolActive(false);
279
+ }
280
+ if (this._modifyOtherKeysActive) {
281
+ process.stdout.write("\x1b[>4;0m");
282
+ this._modifyOtherKeysActive = false;
283
+ }
284
+ const previousHandler = this.inputHandler;
285
+ this.inputHandler = undefined;
286
+ let lastDataTime = Date.now();
287
+ const onData = () => {
288
+ lastDataTime = Date.now();
289
+ };
290
+ process.stdin.on("data", onData);
291
+ const endTime = Date.now() + maxMs;
292
+ try {
293
+ while (true) {
294
+ const now = Date.now();
295
+ const timeLeft = endTime - now;
296
+ if (timeLeft <= 0)
297
+ break;
298
+ if (now - lastDataTime >= idleMs)
299
+ break;
300
+ await new Promise((resolve) => setTimeout(resolve, Math.min(idleMs, timeLeft)));
301
+ }
302
+ }
303
+ finally {
304
+ process.stdin.removeListener("data", onData);
305
+ this.inputHandler = previousHandler;
306
+ }
307
+ }
308
+ stop(options = {}) {
309
+ const wasStarted = this.started;
310
+ this.started = false;
311
+ this.finishDefaultColorProbe();
312
+ this.clearKeyboardProtocolFallbackTimer();
313
+ if (this.clearProgressInterval()) {
314
+ process.stdout.write(TERMINAL_PROGRESS_CLEAR_SEQUENCE);
315
+ }
316
+ if (this._mouseTrackingActive) {
317
+ process.stdout.write("\x1b[?1006l\x1b[?1002l");
318
+ this._mouseTrackingActive = false;
319
+ }
320
+ if (this._altScreenActive) {
321
+ if (options.preserveAltScreen) {
322
+ pendingAltScreenHandoff = this.altScreenHandoffToken;
323
+ this._altScreenActive = false;
324
+ }
325
+ else {
326
+ this.releaseAltScreen();
327
+ }
328
+ }
329
+ else if (!options.preserveAltScreen) {
330
+ this.releaseAltScreen();
331
+ }
332
+ // Disable bracketed paste mode
333
+ process.stdout.write("\x1b[?2004l");
334
+ // Disable Kitty keyboard protocol if not already done by drainInput()
335
+ if (this._kittyProtocolActive) {
336
+ process.stdout.write("\x1b[<u");
337
+ this._kittyProtocolActive = false;
338
+ setKittyProtocolActive(false);
339
+ }
340
+ if (this._modifyOtherKeysActive) {
341
+ process.stdout.write("\x1b[>4;0m");
342
+ this._modifyOtherKeysActive = false;
343
+ }
344
+ // Clean up StdinBuffer
345
+ if (this.stdinBuffer) {
346
+ this.stdinBuffer.destroy();
347
+ this.stdinBuffer = undefined;
348
+ }
349
+ // Remove event handlers
350
+ if (this.stdinDataHandler) {
351
+ process.stdin.removeListener("data", this.stdinDataHandler);
352
+ this.stdinDataHandler = undefined;
353
+ }
354
+ this.inputHandler = undefined;
355
+ if (this.resizeHandler) {
356
+ process.stdout.removeListener("resize", this.resizeHandler);
357
+ this.resizeHandler = undefined;
358
+ }
359
+ if (options.preserveAltScreen && wasStarted) {
360
+ beginInputHandoff(this.altScreenHandoffToken, this.wasRaw);
361
+ }
362
+ else {
363
+ // Pause stdin to prevent any buffered input (e.g., Ctrl+D) from being
364
+ // re-interpreted after raw mode is disabled. This fixes a race condition
365
+ // where Ctrl+D could close the parent shell over SSH.
366
+ process.stdin.pause();
367
+ // Restore raw mode state
368
+ if (process.stdin.setRawMode) {
369
+ process.stdin.setRawMode(this.wasRaw);
370
+ }
371
+ }
372
+ }
373
+ write(data) {
374
+ process.stdout.write(data);
375
+ if (this.writeLogPath) {
376
+ try {
377
+ fs.appendFileSync(this.writeLogPath, data, { encoding: "utf8" });
378
+ }
379
+ catch {
380
+ // Ignore logging errors
381
+ }
382
+ }
383
+ }
384
+ get columns() {
385
+ return process.stdout.columns || Number(process.env.COLUMNS) || 80;
386
+ }
387
+ get rows() {
388
+ return process.stdout.rows || Number(process.env.LINES) || 24;
389
+ }
390
+ moveBy(lines) {
391
+ if (lines > 0) {
392
+ // Move down
393
+ process.stdout.write(`\x1b[${lines}B`);
394
+ }
395
+ else if (lines < 0) {
396
+ // Move up
397
+ process.stdout.write(`\x1b[${-lines}A`);
398
+ }
399
+ // lines === 0: no movement
400
+ }
401
+ hideCursor() {
402
+ process.stdout.write("\x1b[?25l");
403
+ }
404
+ showCursor() {
405
+ process.stdout.write("\x1b[?25h");
406
+ }
407
+ clearLine() {
408
+ process.stdout.write("\x1b[K");
409
+ }
410
+ clearFromCursor() {
411
+ process.stdout.write("\x1b[J");
412
+ }
413
+ clearScreen() {
414
+ process.stdout.write("\x1b[2J\x1b[H"); // Clear screen and move to home (1,1)
415
+ }
416
+ enterAltScreen() {
417
+ if (this._altScreenActive)
418
+ return;
419
+ if (this.ownsPendingAltScreenHandoff()) {
420
+ pendingAltScreenHandoff = undefined;
421
+ this._altScreenActive = true;
422
+ return;
423
+ }
424
+ this._altScreenActive = true;
425
+ this.write("\x1b[?1049h");
426
+ }
427
+ leaveAltScreen() {
428
+ this.releaseAltScreen();
429
+ }
430
+ releaseAltScreen() {
431
+ const ownsPendingHandoff = this.ownsPendingAltScreenHandoff();
432
+ if (!this._altScreenActive && !ownsPendingHandoff)
433
+ return;
434
+ this._altScreenActive = false;
435
+ if (ownsPendingHandoff) {
436
+ pendingAltScreenHandoff = undefined;
437
+ cancelInputHandoff(this.altScreenHandoffToken);
438
+ }
439
+ this.write("\x1b[?1049l");
440
+ }
441
+ get altScreenActive() {
442
+ return this._altScreenActive;
443
+ }
444
+ ownsPendingAltScreenHandoff() {
445
+ return pendingAltScreenHandoff === this.altScreenHandoffToken;
446
+ }
447
+ setMouseTracking(enabled) {
448
+ if (enabled === this._mouseTrackingActive)
449
+ return;
450
+ this._mouseTrackingActive = enabled;
451
+ // ?1002 (button-event tracking) reports drag motion for in-app selection
452
+ // but not hover, keeping passive mouse movement unreported.
453
+ this.write(enabled ? "\x1b[?1002h\x1b[?1006h" : "\x1b[?1006l\x1b[?1002l");
454
+ }
455
+ get mouseTrackingActive() {
456
+ return this._mouseTrackingActive;
457
+ }
458
+ setTitle(title) {
459
+ // OSC 0;title BEL - set terminal window title
460
+ process.stdout.write(`\x1b]0;${title}\x07`);
461
+ }
462
+ setProgress(active) {
463
+ if (active) {
464
+ // OSC 9;4;3 - indeterminate progress
465
+ process.stdout.write(TERMINAL_PROGRESS_ACTIVE_SEQUENCE);
466
+ if (!this.progressInterval) {
467
+ this.progressInterval = setInterval(() => {
468
+ process.stdout.write(TERMINAL_PROGRESS_ACTIVE_SEQUENCE);
469
+ }, TERMINAL_PROGRESS_KEEPALIVE_MS);
470
+ }
471
+ }
472
+ else {
473
+ this.clearProgressInterval();
474
+ // OSC 9;4;0 - clear progress
475
+ process.stdout.write(TERMINAL_PROGRESS_CLEAR_SEQUENCE);
476
+ }
477
+ }
478
+ clearProgressInterval() {
479
+ if (!this.progressInterval)
480
+ return false;
481
+ clearInterval(this.progressInterval);
482
+ this.progressInterval = undefined;
483
+ return true;
484
+ }
485
+ }
486
+ //# sourceMappingURL=terminal.js.map
@@ -0,0 +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,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EACN,qBAAqB,EACrB,wBAAwB,EACxB,wBAAwB,EAExB,wBAAwB,GACxB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAElD,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAC5C,MAAM,iCAAiC,GAAG,gBAAgB,CAAC;AAC3D,MAAM,gCAAgC,GAAG,iBAAiB,CAAC;AAE3D,iGAAiG;AACjG,IAAI,uBAA2C,CAAC;AAQhD,8EAA8E;AAC9E,8EAA8E;AAC9E,6EAA6E;AAC7E,2CAA2C;AAC3C,IAAI,mBAAoD,CAAC;AAEzD,SAAS,uBAAuB,GAAY;IAC3C,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACd,CAAC;I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cesContent":["import * as fs from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport * as path from \"node:path\";\nimport { setKittyProtocolActive } from \"./keys.js\";\nimport { StdinBuffer } from \"./stdin-buffer.js\";\nimport {\n\tparseOscColorResponse,\n\tQUERY_DEFAULT_BACKGROUND,\n\tQUERY_DEFAULT_FOREGROUND,\n\ttype Rgb,\n\tsetDefaultTerminalColors,\n} from \"./terminal-colors.js\";\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\";\n\n// A preserved alternate screen is adopted by the next ProcessTerminal during in-process handoff.\nlet pendingAltScreenHandoff: symbol | undefined;\n\ninterface PendingInputHandoff {\n\ttoken: symbol;\n\twasRaw: boolean;\n\tdiscardHandler: (data: string) => void;\n}\n\n// Keep stdin raw and drain input while a preserved fullscreen frame waits for\n// the next in-process TUI. Worker-backed session attach can make this handoff\n// noticeably longer; restoring cooked mode during the gap makes arrow escape\n// sequences echo into the preserved frame.\nlet pendingInputHandoff: PendingInputHandoff | undefined;\n\nfunction consumeAltScreenHandoff(): boolean {\n\tif (!pendingAltScreenHandoff) {\n\t\treturn false;\n\t}\n\tpendingAltScreenHandoff = undefined;\n\treturn true;\n}\n\nfunction beginInputHandoff(token: symbol, wasRaw: boolean): void {\n\tconst inheritedWasRaw = pendingInputHandoff?.wasRaw ?? wasRaw;\n\tif (pendingInputHandoff) {\n\t\tprocess.stdin.removeListener(\"data\", pendingInputHandoff.discardHandler);\n\t}\n\tconst discardHandler = (_data: string) => {};\n\tpendingInputHandoff = { token, wasRaw: inheritedWasRaw, discardHandler };\n\tprocess.stdin.on(\"data\", discardHandler);\n\tprocess.stdin.resume();\n}\n\nfunction consumeInputHandoff(): boolean | undefined {\n\tconst handoff = pendingInputHandoff;\n\tif (!handoff) {\n\t\treturn undefined;\n\t}\n\tprocess.stdin.removeListener(\"data\", handoff.discardHandler);\n\tpendingInputHandoff = undefined;\n\treturn handoff.wasRaw;\n}\n\nfunction cancelInputHandoff(token: symbol): void {\n\tconst handoff = pendingInputHandoff;\n\tif (!handoff || handoff.token !== token) {\n\t\treturn;\n\t}\n\tprocess.stdin.removeListener(\"data\", handoff.discardHandler);\n\tpendingInputHandoff = undefined;\n\tprocess.stdin.pause();\n\tif (process.stdin.setRawMode) {\n\t\tprocess.stdin.setRawMode(handoff.wasRaw);\n\t}\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(options?: TerminalStopOptions): 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// Alternate screen buffer. The primary screen (and its scrollback) is left\n\t// untouched while the alt screen is active, so a full-screen view can be\n\t// shown and dismissed without disturbing the transcript history.\n\tenterAltScreen(): void;\n\tleaveAltScreen(): void;\n\tget altScreenActive(): boolean;\n\n\t// SGR mouse tracking (?1000 + ?1006); motion tracking is deliberately never\n\t// enabled so native drag-selection keeps working.\n\tsetMouseTracking(enabled: boolean): void;\n\tget mouseTrackingActive(): boolean;\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 TerminalStopOptions {\n\tpreserveAltScreen?: boolean;\n}\n\n/**\n * Real terminal using process.stdin/stdout\n */\nexport class ProcessTerminal implements Terminal {\n\tprivate wasRaw = false;\n\tprivate started = false;\n\tprivate inputHandler?: (data: string) => void;\n\tprivate resizeHandler?: () => void;\n\tprivate _kittyProtocolActive = false;\n\tprivate _modifyOtherKeysActive = false;\n\tprivate readonly altScreenHandoffToken = Symbol(\"altScreenHandoff\");\n\tprivate _altScreenActive = consumeAltScreenHandoff();\n\tprivate _mouseTrackingActive = false;\n\tprivate stdinBuffer?: StdinBuffer;\n\tprivate stdinDataHandler?: (data: string) => void;\n\tprivate keyboardProtocolFallbackTimer?: ReturnType<typeof setTimeout>;\n\tprivate progressInterval?: ReturnType<typeof setInterval>;\n\tprivate defaultColorProbe?: {\n\t\tforeground?: Rgb;\n\t\tbackground?: Rgb;\n\t\ttimeout: ReturnType<typeof setTimeout>;\n\t};\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\tget kittyProtocolActive(): boolean {\n\t\treturn this._kittyProtocolActive;\n\t}\n\n\tstart(onInput: (data: string) => void, onResize: () => void): void {\n\t\tthis.started = true;\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 = consumeInputHandoff() ?? process.stdin.isRaw ?? false;\n\t\tif (process.stdin.setRawMode) {\n\t\t\tprocess.stdin.setRawMode(true);\n\t\t}\n\t\tprocess.stdin.setEncoding(\"utf8\");\n\t\tprocess.stdin.resume();\n\n\t\t// Enable bracketed paste mode - terminal will wrap pastes in \\x1b[200~ ... \\x1b[201~\n\t\tprocess.stdout.write(\"\\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 and enable Kitty keyboard protocol\n\t\t// The query handler intercepts input temporarily, then installs the user's handler\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({ timeout: 10 });\n\n\t\t// Kitty protocol response pattern: \\x1b[?<flags>u\n\t\tconst kittyResponsePattern = /^\\x1b\\[\\?(\\d+)u$/;\n\n\t\t// Forward individual sequences to the input handler\n\t\tthis.stdinBuffer.on(\"data\", (sequence) => {\n\t\t\tif (this.handleDefaultColorProbeResponse(sequence)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Check for Kitty protocol response (only if not already enabled)\n\t\t\tif (!this._kittyProtocolActive) {\n\t\t\t\tconst match = sequence.match(kittyResponsePattern);\n\t\t\t\tif (match) {\n\t\t\t\t\tthis.clearKeyboardProtocolFallbackTimer();\n\t\t\t\t\tthis._kittyProtocolActive = true;\n\t\t\t\t\tsetKittyProtocolActive(true);\n\n\t\t\t\t\t// Enable Kitty keyboard protocol (push flags)\n\t\t\t\t\t// Flag 1 = disambiguate escape codes\n\t\t\t\t\t// Flag 2 = report event types (press/repeat/release)\n\t\t\t\t\t// Flag 4 = report alternate keys (shifted key, base layout key)\n\t\t\t\t\t// Base layout key enables shortcuts to work with non-Latin keyboard layouts\n\t\t\t\t\tprocess.stdout.write(\"\\x1b[>7u\");\n\t\t\t\t\treturn; // Don't forward protocol response to TUI\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this.inputHandler) {\n\t\t\t\tthis.inputHandler(sequence);\n\t\t\t}\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) => {\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 if available.\n\t *\n\t * Sends CSI ? u to query current flags. If terminal responds with CSI ? <flags> u,\n\t * it supports the protocol and we enable it with CSI > 1 u.\n\t *\n\t * If no Kitty response arrives shortly after startup, fall back to enabling\n\t * xterm modifyOtherKeys mode 2. This is needed for tmux, which can forward\n\t * modified enter keys as CSI-u when extended-keys is enabled, but may not\n\t * answer the Kitty protocol query.\n\t *\n\t * The response is detected in setupStdinBuffer's data handler, which properly\n\t * handles the case where the response arrives split across multiple stdin events.\n\t */\n\tprivate queryAndEnableKittyProtocol(): void {\n\t\tthis.setupStdinBuffer();\n\t\tprocess.stdin.on(\"data\", this.stdinDataHandler!);\n\t\tthis.queryDefaultTerminalColors();\n\t\tprocess.stdout.write(\"\\x1b[?u\");\n\t\tthis.clearKeyboardProtocolFallbackTimer();\n\t\tthis.keyboardProtocolFallbackTimer = setTimeout(() => {\n\t\t\tthis.keyboardProtocolFallbackTimer = undefined;\n\t\t\tif (!this._kittyProtocolActive && !this._modifyOtherKeysActive) {\n\t\t\t\tprocess.stdout.write(\"\\x1b[>4;2m\");\n\t\t\t\tthis._modifyOtherKeysActive = true;\n\t\t\t}\n\t\t}, 150);\n\t}\n\n\tprivate clearKeyboardProtocolFallbackTimer(): void {\n\t\tif (!this.keyboardProtocolFallbackTimer) {\n\t\t\treturn;\n\t\t}\n\t\tclearTimeout(this.keyboardProtocolFallbackTimer);\n\t\tthis.keyboardProtocolFallbackTimer = undefined;\n\t}\n\n\tprivate queryDefaultTerminalColors(): void {\n\t\tif (process.stdin.isTTY !== true || process.stdout.isTTY !== true) {\n\t\t\treturn;\n\t\t}\n\t\tthis.finishDefaultColorProbe();\n\t\tthis.defaultColorProbe = {\n\t\t\ttimeout: setTimeout(() => this.finishDefaultColorProbe(), 100),\n\t\t};\n\t\tprocess.stdout.write(QUERY_DEFAULT_FOREGROUND);\n\t\tprocess.stdout.write(QUERY_DEFAULT_BACKGROUND);\n\t}\n\n\tprivate handleDefaultColorProbeResponse(sequence: string): boolean {\n\t\tconst response = parseOscColorResponse(sequence);\n\t\tif (!response) {\n\t\t\treturn false;\n\t\t}\n\t\tif (!this.defaultColorProbe) {\n\t\t\treturn true;\n\t\t}\n\n\t\tthis.defaultColorProbe[response.kind] = response.rgb;\n\t\tif (this.defaultColorProbe.foreground && this.defaultColorProbe.background) {\n\t\t\tthis.finishDefaultColorProbe();\n\t\t}\n\t\treturn true;\n\t}\n\n\tprivate finishDefaultColorProbe(): void {\n\t\tif (!this.defaultColorProbe) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { foreground, background, timeout } = this.defaultColorProbe;\n\t\tclearTimeout(timeout);\n\t\tthis.defaultColorProbe = undefined;\n\t\tif (foreground && background) {\n\t\t\tsetDefaultTerminalColors({ foreground, background });\n\t\t\tthis.resizeHandler?.();\n\t\t}\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\t// Dynamic require to avoid bundling koffi's 74MB of cross-platform\n\t\t\t// native binaries into every compiled binary. Koffi is only needed\n\t\t\t// on Windows for VT input support.\n\t\t\tconst koffi = cjsRequire(\"koffi\");\n\t\t\tconst k32 = koffi.load(\"kernel32.dll\");\n\t\t\tconst GetStdHandle = k32.func(\"void* __stdcall GetStdHandle(int)\");\n\t\t\tconst GetConsoleMode = k32.func(\"bool __stdcall GetConsoleMode(void*, _Out_ uint32_t*)\");\n\t\t\tconst SetConsoleMode = k32.func(\"bool __stdcall SetConsoleMode(void*, uint32_t)\");\n\n\t\t\tconst STD_INPUT_HANDLE = -10;\n\t\t\tconst ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200;\n\t\t\tconst handle = GetStdHandle(STD_INPUT_HANDLE);\n\t\t\tconst mode = new Uint32Array(1);\n\t\t\tGetConsoleMode(handle, mode);\n\t\t\tSetConsoleMode(handle, mode[0]! | ENABLE_VIRTUAL_TERMINAL_INPUT);\n\t\t} catch {\n\t\t\t// koffi 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\tif (this._kittyProtocolActive) {\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\tprocess.stdout.write(\"\\x1b[<u\");\n\t\t\tthis._kittyProtocolActive = false;\n\t\t\tsetKittyProtocolActive(false);\n\t\t}\n\t\tif (this._modifyOtherKeysActive) {\n\t\t\tprocess.stdout.write(\"\\x1b[>4;0m\");\n\t\t\tthis._modifyOtherKeysActive = false;\n\t\t}\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(options: TerminalStopOptions = {}): void {\n\t\tconst wasStarted = this.started;\n\t\tthis.started = false;\n\t\tthis.finishDefaultColorProbe();\n\t\tthis.clearKeyboardProtocolFallbackTimer();\n\n\t\tif (this.clearProgressInterval()) {\n\t\t\tprocess.stdout.write(TERMINAL_PROGRESS_CLEAR_SEQUENCE);\n\t\t}\n\n\t\tif (this._mouseTrackingActive) {\n\t\t\tprocess.stdout.write(\"\\x1b[?1006l\\x1b[?1002l\");\n\t\t\tthis._mouseTrackingActive = false;\n\t\t}\n\t\tif (this._altScreenActive) {\n\t\t\tif (options.preserveAltScreen) {\n\t\t\t\tpendingAltScreenHandoff = this.altScreenHandoffToken;\n\t\t\t\tthis._altScreenActive = false;\n\t\t\t} else {\n\t\t\t\tthis.releaseAltScreen();\n\t\t\t}\n\t\t} else if (!options.preserveAltScreen) {\n\t\t\tthis.releaseAltScreen();\n\t\t}\n\n\t\t// Disable bracketed paste mode\n\t\tprocess.stdout.write(\"\\x1b[?2004l\");\n\n\t\t// Disable Kitty keyboard protocol if not already done by drainInput()\n\t\tif (this._kittyProtocolActive) {\n\t\t\tprocess.stdout.write(\"\\x1b[<u\");\n\t\t\tthis._kittyProtocolActive = false;\n\t\t\tsetKittyProtocolActive(false);\n\t\t}\n\t\tif (this._modifyOtherKeysActive) {\n\t\t\tprocess.stdout.write(\"\\x1b[>4;0m\");\n\t\t\tthis._modifyOtherKeysActive = false;\n\t\t}\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\tif (options.preserveAltScreen && wasStarted) {\n\t\t\tbeginInputHandoff(this.altScreenHandoffToken, this.wasRaw);\n\t\t} else {\n\t\t\t// Pause stdin to prevent any buffered input (e.g., Ctrl+D) from being\n\t\t\t// re-interpreted after raw mode is disabled. This fixes a race condition\n\t\t\t// where Ctrl+D could close the parent shell over SSH.\n\t\t\tprocess.stdin.pause();\n\n\t\t\t// Restore raw mode state\n\t\t\tif (process.stdin.setRawMode) {\n\t\t\t\tprocess.stdin.setRawMode(this.wasRaw);\n\t\t\t}\n\t\t}\n\t}\n\n\twrite(data: string): void {\n\t\tprocess.stdout.write(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\tprocess.stdout.write(`\\x1b[${lines}B`);\n\t\t} else if (lines < 0) {\n\t\t\t// Move up\n\t\t\tprocess.stdout.write(`\\x1b[${-lines}A`);\n\t\t}\n\t\t// lines === 0: no movement\n\t}\n\n\thideCursor(): void {\n\t\tprocess.stdout.write(\"\\x1b[?25l\");\n\t}\n\n\tshowCursor(): void {\n\t\tprocess.stdout.write(\"\\x1b[?25h\");\n\t}\n\n\tclearLine(): void {\n\t\tprocess.stdout.write(\"\\x1b[K\");\n\t}\n\n\tclearFromCursor(): void {\n\t\tprocess.stdout.write(\"\\x1b[J\");\n\t}\n\n\tclearScreen(): void {\n\t\tprocess.stdout.write(\"\\x1b[2J\\x1b[H\"); // Clear screen and move to home (1,1)\n\t}\n\n\tenterAltScreen(): void {\n\t\tif (this._altScreenActive) return;\n\t\tif (this.ownsPendingAltScreenHandoff()) {\n\t\t\tpendingAltScreenHandoff = undefined;\n\t\t\tthis._altScreenActive = true;\n\t\t\treturn;\n\t\t}\n\t\tthis._altScreenActive = true;\n\t\tthis.write(\"\\x1b[?1049h\");\n\t}\n\n\tleaveAltScreen(): void {\n\t\tthis.releaseAltScreen();\n\t}\n\n\tprivate releaseAltScreen(): void {\n\t\tconst ownsPendingHandoff = this.ownsPendingAltScreenHandoff();\n\t\tif (!this._altScreenActive && !ownsPendingHandoff) return;\n\t\tthis._altScreenActive = false;\n\t\tif (ownsPendingHandoff) {\n\t\t\tpendingAltScreenHandoff = undefined;\n\t\t\tcancelInputHandoff(this.altScreenHandoffToken);\n\t\t}\n\t\tthis.write(\"\\x1b[?1049l\");\n\t}\n\n\tget altScreenActive(): boolean {\n\t\treturn this._altScreenActive;\n\t}\n\n\tprivate ownsPendingAltScreenHandoff(): boolean {\n\t\treturn pendingAltScreenHandoff === this.altScreenHandoffToken;\n\t}\n\n\tsetMouseTracking(enabled: boolean): void {\n\t\tif (enabled === this._mouseTrackingActive) return;\n\t\tthis._mouseTrackingActive = enabled;\n\t\t// ?1002 (button-event tracking) reports drag motion for in-app selection\n\t\t// but not hover, keeping passive mouse movement unreported.\n\t\tthis.write(enabled ? \"\\x1b[?1002h\\x1b[?1006h\" : \"\\x1b[?1006l\\x1b[?1002l\");\n\t}\n\n\tget mouseTrackingActive(): boolean {\n\t\treturn this._mouseTrackingActive;\n\t}\n\n\tsetTitle(title: string): void {\n\t\t// OSC 0;title BEL - set terminal window title\n\t\tprocess.stdout.write(`\\x1b]0;${title}\\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\tprocess.stdout.write(TERMINAL_PROGRESS_ACTIVE_SEQUENCE);\n\t\t\tif (!this.progressInterval) {\n\t\t\t\tthis.progressInterval = setInterval(() => {\n\t\t\t\t\tprocess.stdout.write(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\tprocess.stdout.write(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"]}