@ny4n/tui 0.0.0-stage → 1.0.1

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 (205) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +948 -2
  3. package/dist/alt-screen-search.d.ts +46 -0
  4. package/dist/alt-screen-search.d.ts.map +1 -0
  5. package/dist/alt-screen-search.js +282 -0
  6. package/dist/alt-screen-search.js.map +1 -0
  7. package/dist/autocomplete.d.ts +57 -0
  8. package/dist/autocomplete.d.ts.map +1 -0
  9. package/dist/autocomplete.js +693 -0
  10. package/dist/autocomplete.js.map +1 -0
  11. package/dist/colors.d.ts +73 -0
  12. package/dist/colors.d.ts.map +1 -0
  13. package/dist/colors.js +273 -0
  14. package/dist/colors.js.map +1 -0
  15. package/dist/components/alt-screen-flash.d.ts +13 -0
  16. package/dist/components/alt-screen-flash.d.ts.map +1 -0
  17. package/dist/components/alt-screen-flash.js +37 -0
  18. package/dist/components/alt-screen-flash.js.map +1 -0
  19. package/dist/components/box.d.ts +25 -0
  20. package/dist/components/box.d.ts.map +1 -0
  21. package/dist/components/box.js +138 -0
  22. package/dist/components/box.js.map +1 -0
  23. package/dist/components/cancellable-loader.d.ts +22 -0
  24. package/dist/components/cancellable-loader.d.ts.map +1 -0
  25. package/dist/components/cancellable-loader.js +35 -0
  26. package/dist/components/cancellable-loader.js.map +1 -0
  27. package/dist/components/editor.d.ts +260 -0
  28. package/dist/components/editor.d.ts.map +1 -0
  29. package/dist/components/editor.js +2044 -0
  30. package/dist/components/editor.js.map +1 -0
  31. package/dist/components/h-stack.d.ts +7 -0
  32. package/dist/components/h-stack.d.ts.map +1 -0
  33. package/dist/components/h-stack.js +43 -0
  34. package/dist/components/h-stack.js.map +1 -0
  35. package/dist/components/image.d.ts +40 -0
  36. package/dist/components/image.d.ts.map +1 -0
  37. package/dist/components/image.js +123 -0
  38. package/dist/components/image.js.map +1 -0
  39. package/dist/components/input.d.ts +48 -0
  40. package/dist/components/input.d.ts.map +1 -0
  41. package/dist/components/input.js +417 -0
  42. package/dist/components/input.js.map +1 -0
  43. package/dist/components/loader.d.ts +33 -0
  44. package/dist/components/loader.d.ts.map +1 -0
  45. package/dist/components/loader.js +76 -0
  46. package/dist/components/loader.js.map +1 -0
  47. package/dist/components/markdown.d.ts +104 -0
  48. package/dist/components/markdown.d.ts.map +1 -0
  49. package/dist/components/markdown.js +821 -0
  50. package/dist/components/markdown.js.map +1 -0
  51. package/dist/components/mouse-region.d.ts +12 -0
  52. package/dist/components/mouse-region.d.ts.map +1 -0
  53. package/dist/components/mouse-region.js +21 -0
  54. package/dist/components/mouse-region.js.map +1 -0
  55. package/dist/components/scroll-view.d.ts +59 -0
  56. package/dist/components/scroll-view.d.ts.map +1 -0
  57. package/dist/components/scroll-view.js +195 -0
  58. package/dist/components/scroll-view.js.map +1 -0
  59. package/dist/components/select-list.d.ts +53 -0
  60. package/dist/components/select-list.d.ts.map +1 -0
  61. package/dist/components/select-list.js +206 -0
  62. package/dist/components/select-list.js.map +1 -0
  63. package/dist/components/settings-list.d.ts +60 -0
  64. package/dist/components/settings-list.d.ts.map +1 -0
  65. package/dist/components/settings-list.js +252 -0
  66. package/dist/components/settings-list.js.map +1 -0
  67. package/dist/components/spacer.d.ts +12 -0
  68. package/dist/components/spacer.d.ts.map +1 -0
  69. package/dist/components/spacer.js +23 -0
  70. package/dist/components/spacer.js.map +1 -0
  71. package/dist/components/stack.d.ts +32 -0
  72. package/dist/components/stack.d.ts.map +1 -0
  73. package/dist/components/stack.js +111 -0
  74. package/dist/components/stack.js.map +1 -0
  75. package/dist/components/text.d.ts +20 -0
  76. package/dist/components/text.d.ts.map +1 -0
  77. package/dist/components/text.js +95 -0
  78. package/dist/components/text.js.map +1 -0
  79. package/dist/components/truncated-text.d.ts +13 -0
  80. package/dist/components/truncated-text.d.ts.map +1 -0
  81. package/dist/components/truncated-text.js +51 -0
  82. package/dist/components/truncated-text.js.map +1 -0
  83. package/dist/components/v-stack.d.ts +8 -0
  84. package/dist/components/v-stack.d.ts.map +1 -0
  85. package/dist/components/v-stack.js +26 -0
  86. package/dist/components/v-stack.js.map +1 -0
  87. package/dist/editor-component.d.ts +39 -0
  88. package/dist/editor-component.d.ts.map +1 -0
  89. package/dist/editor-component.js +2 -0
  90. package/dist/editor-component.js.map +1 -0
  91. package/dist/fuzzy.d.ts +16 -0
  92. package/dist/fuzzy.d.ts.map +1 -0
  93. package/dist/fuzzy.js +111 -0
  94. package/dist/fuzzy.js.map +1 -0
  95. package/dist/index.d.ts +37 -0
  96. package/dist/index.d.ts.map +1 -0
  97. package/dist/index.js +50 -0
  98. package/dist/index.js.map +1 -0
  99. package/dist/keybindings.d.ts +273 -0
  100. package/dist/keybindings.d.ts.map +1 -0
  101. package/dist/keybindings.js +233 -0
  102. package/dist/keybindings.js.map +1 -0
  103. package/dist/keys.d.ts +184 -0
  104. package/dist/keys.d.ts.map +1 -0
  105. package/dist/keys.js +1206 -0
  106. package/dist/keys.js.map +1 -0
  107. package/dist/kill-ring.d.ts +28 -0
  108. package/dist/kill-ring.d.ts.map +1 -0
  109. package/dist/kill-ring.js +44 -0
  110. package/dist/kill-ring.js.map +1 -0
  111. package/dist/latex.d.ts +10 -0
  112. package/dist/latex.d.ts.map +1 -0
  113. package/dist/latex.js +1378 -0
  114. package/dist/latex.js.map +1 -0
  115. package/dist/layout-node.d.ts +40 -0
  116. package/dist/layout-node.d.ts.map +1 -0
  117. package/dist/layout-node.js +6 -0
  118. package/dist/layout-node.js.map +1 -0
  119. package/dist/layout.d.ts +42 -0
  120. package/dist/layout.d.ts.map +1 -0
  121. package/dist/layout.js +344 -0
  122. package/dist/layout.js.map +1 -0
  123. package/dist/native-modifiers.d.ts +4 -0
  124. package/dist/native-modifiers.d.ts.map +1 -0
  125. package/dist/native-modifiers.js +13 -0
  126. package/dist/native-modifiers.js.map +1 -0
  127. package/dist/native-module-path.d.ts +7 -0
  128. package/dist/native-module-path.d.ts.map +1 -0
  129. package/dist/native-module-path.js +19 -0
  130. package/dist/native-module-path.js.map +1 -0
  131. package/dist/native-platform.d.ts +20 -0
  132. package/dist/native-platform.d.ts.map +1 -0
  133. package/dist/native-platform.js +42 -0
  134. package/dist/native-platform.js.map +1 -0
  135. package/dist/oklab.d.ts +43 -0
  136. package/dist/oklab.d.ts.map +1 -0
  137. package/dist/oklab.js +210 -0
  138. package/dist/oklab.js.map +1 -0
  139. package/dist/program-status.d.ts +23 -0
  140. package/dist/program-status.d.ts.map +1 -0
  141. package/dist/program-status.js +43 -0
  142. package/dist/program-status.js.map +1 -0
  143. package/dist/stdin-buffer.d.ts +56 -0
  144. package/dist/stdin-buffer.d.ts.map +1 -0
  145. package/dist/stdin-buffer.js +366 -0
  146. package/dist/stdin-buffer.js.map +1 -0
  147. package/dist/terminal-colors.d.ts +27 -0
  148. package/dist/terminal-colors.d.ts.map +1 -0
  149. package/dist/terminal-colors.js +64 -0
  150. package/dist/terminal-colors.js.map +1 -0
  151. package/dist/terminal-image.d.ts +123 -0
  152. package/dist/terminal-image.d.ts.map +1 -0
  153. package/dist/terminal-image.js +603 -0
  154. package/dist/terminal-image.js.map +1 -0
  155. package/dist/terminal.d.ts +143 -0
  156. package/dist/terminal.d.ts.map +1 -0
  157. package/dist/terminal.js +493 -0
  158. package/dist/terminal.js.map +1 -0
  159. package/dist/tui-alt-screen.d.ts +168 -0
  160. package/dist/tui-alt-screen.d.ts.map +1 -0
  161. package/dist/tui-alt-screen.js +1552 -0
  162. package/dist/tui-alt-screen.js.map +1 -0
  163. package/dist/tui-main-screen.d.ts +39 -0
  164. package/dist/tui-main-screen.d.ts.map +1 -0
  165. package/dist/tui-main-screen.js +595 -0
  166. package/dist/tui-main-screen.js.map +1 -0
  167. package/dist/tui.d.ts +398 -0
  168. package/dist/tui.d.ts.map +1 -0
  169. package/dist/tui.js +1096 -0
  170. package/dist/tui.js.map +1 -0
  171. package/dist/undo-stack.d.ts +17 -0
  172. package/dist/undo-stack.d.ts.map +1 -0
  173. package/dist/undo-stack.js +25 -0
  174. package/dist/undo-stack.js.map +1 -0
  175. package/dist/utils.d.ts +107 -0
  176. package/dist/utils.d.ts.map +1 -0
  177. package/dist/utils.js +1263 -0
  178. package/dist/utils.js.map +1 -0
  179. package/dist/wheel-scroll.d.ts +23 -0
  180. package/dist/wheel-scroll.d.ts.map +1 -0
  181. package/dist/wheel-scroll.js +73 -0
  182. package/dist/wheel-scroll.js.map +1 -0
  183. package/dist/word-navigation.d.ts +25 -0
  184. package/dist/word-navigation.d.ts.map +1 -0
  185. package/dist/word-navigation.js +96 -0
  186. package/dist/word-navigation.js.map +1 -0
  187. package/native/clipboard.h +208 -0
  188. package/native/darwin/README.md +22 -0
  189. package/native/darwin/build.sh +69 -0
  190. package/native/darwin/prebuilds/darwin-arm64/darwin-platform.node +0 -0
  191. package/native/darwin/prebuilds/darwin-x64/darwin-platform.node +0 -0
  192. package/native/darwin/src/darwin-platform.m +132 -0
  193. package/native/linux/README.md +23 -0
  194. package/native/linux/build.sh +65 -0
  195. package/native/linux/prebuilds/linux-arm64/linux-platform-x11.node +0 -0
  196. package/native/linux/prebuilds/linux-x64/linux-platform-x11.node +0 -0
  197. package/native/linux/src/clipboard-worker.h +70 -0
  198. package/native/linux/src/linux-platform-x11.c +274 -0
  199. package/native/napi.h +91 -0
  200. package/native/win32/README.md +31 -0
  201. package/native/win32/build.mjs +232 -0
  202. package/native/win32/prebuilds/win32-arm64/win32-platform.node +0 -0
  203. package/native/win32/prebuilds/win32-x64/win32-platform.node +0 -0
  204. package/native/win32/src/win32-platform.c +241 -0
  205. package/package.json +61 -5
@@ -0,0 +1,493 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ import { setKittyProtocolActive } from "./keys.js";
4
+ import { isNativeModifierPressed } from "./native-modifiers.js";
5
+ import { getNativePlatformHelper } from "./native-platform.js";
6
+ import { formatProgramStatus, isProgramStatusReply, PROGRAM_STATUS_QUERY, } from "./program-status.js";
7
+ import { StdinBuffer } from "./stdin-buffer.js";
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
+ const NATIVE_SHIFT_ENTER_SEQUENCE = "\x1b[13;2u";
12
+ const DESIRED_KITTY_KEYBOARD_PROTOCOL_FLAGS = 7;
13
+ const KEYBOARD_PROTOCOL_RESPONSE_FRAGMENT_TIMEOUT_MS = 150;
14
+ const KITTY_KEYBOARD_PROTOCOL_QUERY = `\x1b[>${DESIRED_KITTY_KEYBOARD_PROTOCOL_FLAGS}u\x1b[?u`;
15
+ const DEVICE_ATTRIBUTES_QUERY = "\x1b[c";
16
+ export function parseKeyboardProtocolNegotiationSequence(sequence) {
17
+ const kittyFlags = sequence.match(/^\x1b\[\?(\d+)u$/);
18
+ if (kittyFlags) {
19
+ return { type: "kitty-flags", flags: Number.parseInt(kittyFlags[1], 10) };
20
+ }
21
+ if (/^\x1b\[\?[\d;]*c$/.test(sequence)) {
22
+ return { type: "device-attributes" };
23
+ }
24
+ return undefined;
25
+ }
26
+ function isKeyboardProtocolNegotiationSequencePrefix(sequence) {
27
+ return sequence === "\x1b[" || /^\x1b\[\?[\d;]*$/.test(sequence);
28
+ }
29
+ export function isAppleTerminalSession() {
30
+ return process.platform === "darwin" && process.env.TERM_PROGRAM === "Apple_Terminal";
31
+ }
32
+ /**
33
+ * Refresh terminal dimensions on POSIX platforms by sending SIGWINCH to this process.
34
+ * Best-effort: some environments (restricted seccomp or LSM policies) return EACCES
35
+ * for `kill(2)`; in that case the dimensions refresh is skipped rather than crashing.
36
+ */
37
+ export function refreshTerminalDimensions() {
38
+ if (process.platform === "win32" || process.pid <= 0)
39
+ return;
40
+ try {
41
+ process.kill(process.pid, "SIGWINCH");
42
+ }
43
+ catch {
44
+ // Signal delivery not permitted in this environment; ignore.
45
+ }
46
+ }
47
+ export function normalizeNativeShiftEnterInput(data, shouldDetectNativeShiftEnter, isShiftPressed) {
48
+ if (shouldDetectNativeShiftEnter && data === "\r" && isShiftPressed)
49
+ return NATIVE_SHIFT_ENTER_SEQUENCE;
50
+ return data;
51
+ }
52
+ export function normalizeAppleTerminalInput(data, isAppleTerminal, isShiftPressed) {
53
+ return normalizeNativeShiftEnterInput(data, isAppleTerminal, isShiftPressed);
54
+ }
55
+ const DEFAULT_ESCAPE_TIMEOUT_MS = 10;
56
+ const DEFAULT_SSH_ESCAPE_TIMEOUT_MS = 100;
57
+ /**
58
+ * Resolve how long to wait for the rest of an escape sequence before
59
+ * dispatching a lone ESC as the Escape key. Legacy Alt+key input is ESC plus
60
+ * another byte, so high-latency transports need a longer reassembly window.
61
+ */
62
+ export function resolveEscapeTimeoutMs(env = process.env) {
63
+ const configured = Number(env.NYAN_TUI_ESC_TIMEOUT);
64
+ if (Number.isFinite(configured) && configured > 0) {
65
+ return configured;
66
+ }
67
+ if (env.SSH_CONNECTION || env.SSH_TTY) {
68
+ return DEFAULT_SSH_ESCAPE_TIMEOUT_MS;
69
+ }
70
+ return DEFAULT_ESCAPE_TIMEOUT_MS;
71
+ }
72
+ /**
73
+ * Real terminal using process.stdin/stdout
74
+ */
75
+ export class ProcessTerminal {
76
+ wasRaw = false;
77
+ inputHandler;
78
+ resizeHandler;
79
+ _kittyProtocolActive = false;
80
+ _modifyOtherKeysActive = false;
81
+ keyboardProtocolPushed = false;
82
+ /** DA1 replies owed to keyboard protocol queries. Later DA1 replies answer other queries and are forwarded. */
83
+ pendingKeyboardProtocolDeviceAttributes = 0;
84
+ keyboardProtocolNegotiationBuffer = "";
85
+ keyboardProtocolBufferFlushTimer;
86
+ stdinBuffer;
87
+ stdinDataHandler;
88
+ progressInterval;
89
+ /** Latest program status, kept across stop() so start() can report it again. */
90
+ programStatus;
91
+ /** Whether the terminal confirmed OSC 7501 support since the last start(), or `NYAN_PROGRAM_STATUS=1`. */
92
+ programStatusSupported = false;
93
+ /** The support query was sent and its DA1 sentinel has not arrived yet. */
94
+ programStatusQueryPending = false;
95
+ writeLogPath = (() => {
96
+ const env = process.env.NYAN_TUI_WRITE_LOG || "";
97
+ if (!env)
98
+ return "";
99
+ try {
100
+ if (fs.statSync(env).isDirectory()) {
101
+ const now = new Date();
102
+ 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")}`;
103
+ return path.join(env, `tui-${ts}-${process.pid}.log`);
104
+ }
105
+ }
106
+ catch {
107
+ // Not an existing directory - use as-is (file path)
108
+ }
109
+ return env;
110
+ })();
111
+ get kittyProtocolActive() {
112
+ return this._kittyProtocolActive;
113
+ }
114
+ get modifyOtherKeysActive() {
115
+ return this._modifyOtherKeysActive;
116
+ }
117
+ start(onInput, onResize) {
118
+ this.inputHandler = onInput;
119
+ this.resizeHandler = onResize;
120
+ // Save previous state and enable raw mode
121
+ this.wasRaw = process.stdin.isRaw || false;
122
+ if (process.stdin.setRawMode) {
123
+ process.stdin.setRawMode(true);
124
+ }
125
+ process.stdin.setEncoding("utf8");
126
+ process.stdin.resume();
127
+ // Enable bracketed paste mode - terminal will wrap pastes in \x1b[200~ ... \x1b[201~
128
+ process.stdout.write("\x1b[?2004h");
129
+ // Set up resize handler immediately
130
+ process.stdout.on("resize", this.resizeHandler);
131
+ // Refresh terminal dimensions - they may be stale after suspend/resume
132
+ // (SIGWINCH is lost while process is stopped). Unix only, best-effort.
133
+ refreshTerminalDimensions();
134
+ // On Windows, enable ENABLE_VIRTUAL_TERMINAL_INPUT so the console sends
135
+ // VT escape sequences (e.g. \x1b[Z for Shift+Tab) instead of raw console
136
+ // events that lose modifier information. Must run AFTER setRawMode(true)
137
+ // since that resets console mode flags.
138
+ this.enableWindowsVTInput();
139
+ // Query Kitty keyboard protocol and fall back to modifyOtherKeys when DA confirms no Kitty response.
140
+ // See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/
141
+ this.queryAndEnableKittyProtocol();
142
+ }
143
+ /**
144
+ * Set up StdinBuffer to split batched input into individual sequences.
145
+ * This ensures components receive single events, making matchesKey/isKeyRelease work correctly.
146
+ *
147
+ * Also watches for Kitty protocol response and enables it when detected.
148
+ * This is done here (after stdinBuffer parsing) rather than on raw stdin
149
+ * to handle the case where the response arrives split across multiple events.
150
+ */
151
+ setupStdinBuffer() {
152
+ this.stdinBuffer = new StdinBuffer({ escapeTimeout: resolveEscapeTimeoutMs() });
153
+ // Forward individual sequences to the input handler
154
+ this.stdinBuffer.on("data", (sequence) => {
155
+ if (isProgramStatusReply(sequence)) {
156
+ if (this.programStatusQueryPending) {
157
+ this.programStatusQueryPending = false;
158
+ this.programStatusSupported = true;
159
+ this.writeProgramStatus();
160
+ }
161
+ return;
162
+ }
163
+ const negotiation = this.readKeyboardProtocolNegotiationSequence(sequence);
164
+ if (negotiation === "pending") {
165
+ this.scheduleKeyboardProtocolNegotiationBufferFlush();
166
+ return; // Wait briefly for the rest of a split Kitty response.
167
+ }
168
+ if (negotiation && this.handleKeyboardProtocolNegotiationSequence(negotiation.parsed)) {
169
+ return;
170
+ }
171
+ this.forwardInputSequence(negotiation?.sequence ?? sequence);
172
+ });
173
+ // Re-wrap paste content with bracketed paste markers for existing editor handling
174
+ this.stdinBuffer.on("paste", (content) => {
175
+ if (this.inputHandler) {
176
+ this.inputHandler(`\x1b[200~${content}\x1b[201~`);
177
+ }
178
+ });
179
+ // Handler that pipes stdin data through the buffer
180
+ this.stdinDataHandler = (data) => {
181
+ this.stdinBuffer.process(data);
182
+ };
183
+ }
184
+ /**
185
+ * Query terminal for Kitty keyboard protocol support and enable it if available.
186
+ *
187
+ * Kitty's progressive enhancement detection requires requesting the desired
188
+ * flags before querying them. The trailing DA query is a sentinel supported by
189
+ * terminals that do not know Kitty keyboard protocol; receiving DA before a
190
+ * Kitty response enables modifyOtherKeys fallback without a startup timeout.
191
+ *
192
+ * The requested flags are:
193
+ * - 1 = disambiguate escape codes
194
+ * - 2 = report event types (press/repeat/release)
195
+ * - 4 = report alternate keys (shifted key, base layout key)
196
+ *
197
+ * The OSC 7501 program status query shares the DA sentinel: a terminal that supports it replies
198
+ * before DA. `NYAN_PROGRAM_STATUS=1` or `0` skips the query.
199
+ */
200
+ queryAndEnableKittyProtocol() {
201
+ this.setupStdinBuffer();
202
+ process.stdin.on("data", this.stdinDataHandler);
203
+ this.keyboardProtocolPushed = true;
204
+ this.pendingKeyboardProtocolDeviceAttributes += 1;
205
+ this.clearKeyboardProtocolNegotiationBuffer();
206
+ const programStatusOverride = process.env.NYAN_PROGRAM_STATUS;
207
+ this.programStatusSupported = programStatusOverride === "1";
208
+ this.programStatusQueryPending = programStatusOverride !== "1" && programStatusOverride !== "0";
209
+ const programStatusQuery = this.programStatusQueryPending ? PROGRAM_STATUS_QUERY : "";
210
+ process.stdout.write(`${KITTY_KEYBOARD_PROTOCOL_QUERY}${programStatusQuery}${DEVICE_ATTRIBUTES_QUERY}`);
211
+ this.writeProgramStatus();
212
+ }
213
+ handleKeyboardProtocolNegotiationSequence(negotiationSequence) {
214
+ this.clearKeyboardProtocolNegotiationBuffer();
215
+ if (negotiationSequence.type === "device-attributes") {
216
+ if (this.pendingKeyboardProtocolDeviceAttributes === 0)
217
+ return false;
218
+ this.pendingKeyboardProtocolDeviceAttributes -= 1;
219
+ // The last owed DA answers the latest query, which got no program status reply first. Earlier DA
220
+ // replies belong to queries from before a restart.
221
+ if (this.pendingKeyboardProtocolDeviceAttributes === 0)
222
+ this.programStatusQueryPending = false;
223
+ }
224
+ if (negotiationSequence.type === "kitty-flags") {
225
+ if (negotiationSequence.flags !== 0) {
226
+ this.disableModifyOtherKeys();
227
+ if (!this._kittyProtocolActive) {
228
+ this._kittyProtocolActive = true;
229
+ setKittyProtocolActive(true);
230
+ }
231
+ }
232
+ else {
233
+ this.enableModifyOtherKeys();
234
+ }
235
+ return true;
236
+ }
237
+ if (!this._kittyProtocolActive) {
238
+ this.enableModifyOtherKeys();
239
+ }
240
+ return true;
241
+ }
242
+ /** Returns the parsed negotiation reply with its full (possibly reassembled) sequence. */
243
+ readKeyboardProtocolNegotiationSequence(sequence) {
244
+ if (this.keyboardProtocolNegotiationBuffer) {
245
+ const bufferedSequence = this.keyboardProtocolNegotiationBuffer + sequence;
246
+ const negotiationSequence = parseKeyboardProtocolNegotiationSequence(bufferedSequence);
247
+ if (negotiationSequence) {
248
+ this.clearKeyboardProtocolNegotiationBuffer();
249
+ return { parsed: negotiationSequence, sequence: bufferedSequence };
250
+ }
251
+ if (isKeyboardProtocolNegotiationSequencePrefix(bufferedSequence)) {
252
+ this.setKeyboardProtocolNegotiationBuffer(bufferedSequence);
253
+ return "pending";
254
+ }
255
+ this.flushKeyboardProtocolNegotiationBufferAsInput();
256
+ }
257
+ const negotiationSequence = parseKeyboardProtocolNegotiationSequence(sequence);
258
+ if (negotiationSequence)
259
+ return { parsed: negotiationSequence, sequence };
260
+ if (isKeyboardProtocolNegotiationSequencePrefix(sequence)) {
261
+ this.setKeyboardProtocolNegotiationBuffer(sequence);
262
+ return "pending";
263
+ }
264
+ return undefined;
265
+ }
266
+ setKeyboardProtocolNegotiationBuffer(sequence) {
267
+ this.clearKeyboardProtocolNegotiationBufferFlushTimer();
268
+ this.keyboardProtocolNegotiationBuffer = sequence;
269
+ }
270
+ clearKeyboardProtocolNegotiationBuffer() {
271
+ this.clearKeyboardProtocolNegotiationBufferFlushTimer();
272
+ this.keyboardProtocolNegotiationBuffer = "";
273
+ }
274
+ flushKeyboardProtocolNegotiationBufferAsInput() {
275
+ if (!this.keyboardProtocolNegotiationBuffer)
276
+ return;
277
+ const sequence = this.keyboardProtocolNegotiationBuffer;
278
+ this.clearKeyboardProtocolNegotiationBuffer();
279
+ this.forwardInputSequence(sequence);
280
+ }
281
+ scheduleKeyboardProtocolNegotiationBufferFlush() {
282
+ if (!this.keyboardProtocolNegotiationBuffer || this.keyboardProtocolBufferFlushTimer)
283
+ return;
284
+ this.keyboardProtocolBufferFlushTimer = setTimeout(() => {
285
+ this.keyboardProtocolBufferFlushTimer = undefined;
286
+ this.flushKeyboardProtocolNegotiationBufferAsInput();
287
+ }, KEYBOARD_PROTOCOL_RESPONSE_FRAGMENT_TIMEOUT_MS);
288
+ }
289
+ clearKeyboardProtocolNegotiationBufferFlushTimer() {
290
+ if (!this.keyboardProtocolBufferFlushTimer)
291
+ return;
292
+ clearTimeout(this.keyboardProtocolBufferFlushTimer);
293
+ this.keyboardProtocolBufferFlushTimer = undefined;
294
+ }
295
+ forwardInputSequence(sequence) {
296
+ if (!this.inputHandler)
297
+ return;
298
+ const shouldDetectNativeShiftEnter = sequence === "\r" && (isAppleTerminalSession() || process.platform === "win32");
299
+ const input = normalizeNativeShiftEnterInput(sequence, shouldDetectNativeShiftEnter, shouldDetectNativeShiftEnter && isNativeModifierPressed("shift"));
300
+ this.inputHandler(input);
301
+ }
302
+ enableModifyOtherKeys() {
303
+ if (this._kittyProtocolActive || this._modifyOtherKeysActive)
304
+ return;
305
+ process.stdout.write("\x1b[>4;2m");
306
+ this._modifyOtherKeysActive = true;
307
+ }
308
+ disableModifyOtherKeys() {
309
+ if (!this._modifyOtherKeysActive)
310
+ return;
311
+ process.stdout.write("\x1b[>4;0m");
312
+ this._modifyOtherKeysActive = false;
313
+ }
314
+ /**
315
+ * On Windows, add ENABLE_VIRTUAL_TERMINAL_INPUT (0x0200) to the stdin
316
+ * console handle so the terminal sends VT sequences for modified keys
317
+ * (e.g. \x1b[Z for Shift+Tab). Without this, libuv's ReadConsoleInputW
318
+ * discards modifier state and Shift+Tab arrives as plain \t.
319
+ */
320
+ enableWindowsVTInput() {
321
+ if (process.platform !== "win32")
322
+ return;
323
+ try {
324
+ getNativePlatformHelper()?.enableVirtualTerminalInput?.();
325
+ }
326
+ catch {
327
+ // Native helper not available — Shift+Tab won't be distinguishable from Tab.
328
+ }
329
+ }
330
+ async drainInput(maxMs = 1000, idleMs = 50) {
331
+ const shouldDisableKittyProtocol = this.keyboardProtocolPushed || this._kittyProtocolActive;
332
+ this.clearKeyboardProtocolNegotiationBuffer();
333
+ if (shouldDisableKittyProtocol) {
334
+ // Disable Kitty keyboard protocol first so any late key releases
335
+ // do not generate new Kitty escape sequences.
336
+ process.stdout.write("\x1b[<u");
337
+ this.keyboardProtocolPushed = false;
338
+ this._kittyProtocolActive = false;
339
+ setKittyProtocolActive(false);
340
+ }
341
+ this.disableModifyOtherKeys();
342
+ const previousHandler = this.inputHandler;
343
+ this.inputHandler = undefined;
344
+ let lastDataTime = Date.now();
345
+ const onData = () => {
346
+ lastDataTime = Date.now();
347
+ };
348
+ process.stdin.on("data", onData);
349
+ const endTime = Date.now() + maxMs;
350
+ try {
351
+ while (true) {
352
+ const now = Date.now();
353
+ const timeLeft = endTime - now;
354
+ if (timeLeft <= 0)
355
+ break;
356
+ if (now - lastDataTime >= idleMs)
357
+ break;
358
+ await new Promise((resolve) => setTimeout(resolve, Math.min(idleMs, timeLeft)));
359
+ }
360
+ }
361
+ finally {
362
+ process.stdin.removeListener("data", onData);
363
+ this.inputHandler = previousHandler;
364
+ }
365
+ }
366
+ stop() {
367
+ if (this.clearProgressInterval()) {
368
+ process.stdout.write(TERMINAL_PROGRESS_CLEAR_SEQUENCE);
369
+ }
370
+ // Remove the status while stopped, for example after exit or while suspended. start() reports it again.
371
+ if (this.programStatusSupported && this.programStatus) {
372
+ process.stdout.write(formatProgramStatus({ state: "clear" }));
373
+ }
374
+ this.programStatusSupported = false;
375
+ this.programStatusQueryPending = false;
376
+ // Disable bracketed paste mode
377
+ process.stdout.write("\x1b[?2004l");
378
+ const shouldDisableKittyProtocol = this.keyboardProtocolPushed || this._kittyProtocolActive;
379
+ this.clearKeyboardProtocolNegotiationBuffer();
380
+ // Disable Kitty keyboard protocol if not already done by drainInput()
381
+ if (shouldDisableKittyProtocol) {
382
+ process.stdout.write("\x1b[<u");
383
+ this.keyboardProtocolPushed = false;
384
+ this._kittyProtocolActive = false;
385
+ setKittyProtocolActive(false);
386
+ }
387
+ this.disableModifyOtherKeys();
388
+ // Clean up StdinBuffer
389
+ if (this.stdinBuffer) {
390
+ this.stdinBuffer.destroy();
391
+ this.stdinBuffer = undefined;
392
+ }
393
+ // Remove event handlers
394
+ if (this.stdinDataHandler) {
395
+ process.stdin.removeListener("data", this.stdinDataHandler);
396
+ this.stdinDataHandler = undefined;
397
+ }
398
+ this.inputHandler = undefined;
399
+ if (this.resizeHandler) {
400
+ process.stdout.removeListener("resize", this.resizeHandler);
401
+ this.resizeHandler = undefined;
402
+ }
403
+ // Pause stdin to prevent any buffered input (e.g., Ctrl+D) from being
404
+ // re-interpreted after raw mode is disabled. This fixes a race condition
405
+ // where Ctrl+D could close the parent shell over SSH.
406
+ process.stdin.pause();
407
+ // Restore raw mode state
408
+ if (process.stdin.setRawMode) {
409
+ process.stdin.setRawMode(this.wasRaw);
410
+ }
411
+ }
412
+ write(data) {
413
+ process.stdout.write(data);
414
+ if (this.writeLogPath) {
415
+ try {
416
+ fs.appendFileSync(this.writeLogPath, data, { encoding: "utf8" });
417
+ }
418
+ catch {
419
+ // Ignore logging errors
420
+ }
421
+ }
422
+ }
423
+ get columns() {
424
+ return process.stdout.columns || Number(process.env.COLUMNS) || 80;
425
+ }
426
+ get rows() {
427
+ return process.stdout.rows || Number(process.env.LINES) || 24;
428
+ }
429
+ moveBy(lines) {
430
+ if (lines > 0) {
431
+ // Move down
432
+ process.stdout.write(`\x1b[${lines}B`);
433
+ }
434
+ else if (lines < 0) {
435
+ // Move up
436
+ process.stdout.write(`\x1b[${-lines}A`);
437
+ }
438
+ // lines === 0: no movement
439
+ }
440
+ hideCursor() {
441
+ process.stdout.write("\x1b[?25l");
442
+ }
443
+ showCursor() {
444
+ process.stdout.write("\x1b[?25h");
445
+ }
446
+ clearLine() {
447
+ process.stdout.write("\x1b[K");
448
+ }
449
+ clearFromCursor() {
450
+ process.stdout.write("\x1b[J");
451
+ }
452
+ clearScreen() {
453
+ process.stdout.write("\x1b[2J\x1b[H"); // Clear screen and move to home (1,1)
454
+ }
455
+ setTitle(title) {
456
+ // OSC 0;title BEL - set terminal window title
457
+ process.stdout.write(`\x1b]0;${title}\x07`);
458
+ }
459
+ setProgramStatus(status) {
460
+ this.programStatus = status.state === "clear" ? undefined : status;
461
+ if (this.programStatusSupported)
462
+ process.stdout.write(formatProgramStatus(status));
463
+ }
464
+ writeProgramStatus() {
465
+ if (this.programStatusSupported && this.programStatus) {
466
+ process.stdout.write(formatProgramStatus(this.programStatus));
467
+ }
468
+ }
469
+ setProgress(active) {
470
+ if (active) {
471
+ // OSC 9;4;3 - indeterminate progress
472
+ process.stdout.write(TERMINAL_PROGRESS_ACTIVE_SEQUENCE);
473
+ if (!this.progressInterval) {
474
+ this.progressInterval = setInterval(() => {
475
+ process.stdout.write(TERMINAL_PROGRESS_ACTIVE_SEQUENCE);
476
+ }, TERMINAL_PROGRESS_KEEPALIVE_MS);
477
+ }
478
+ }
479
+ else {
480
+ this.clearProgressInterval();
481
+ // OSC 9;4;0 - clear progress
482
+ process.stdout.write(TERMINAL_PROGRESS_CLEAR_SEQUENCE);
483
+ }
484
+ }
485
+ clearProgressInterval() {
486
+ if (!this.progressInterval)
487
+ return false;
488
+ clearInterval(this.progressInterval);
489
+ this.progressInterval = undefined;
490
+ return true;
491
+ }
492
+ }
493
+ //# 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,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EACN,mBAAmB,EACnB,oBAAoB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CAAC,GAAG,EAAE;oBACxC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;gBACzD,CAAC,EAAE,8BAA8B,CAAC,CAAC;YACpC,CAAC;QACF,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC7B,6BAA6B;YAC7B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACxD,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 * as path from \"node:path\";\nimport { setKittyProtocolActive } from \"./keys.ts\";\nimport { isNativeModifierPressed } from \"./native-modifiers.ts\";\nimport { getNativePlatformHelper } from \"./native-platform.ts\";\nimport {\n\tformatProgramStatus,\n\tisProgramStatusReply,\n\tPROGRAM_STATUS_QUERY,\n\ttype ProgramStatus,\n} from \"./program-status.ts\";\nimport { StdinBuffer } from \"./stdin-buffer.ts\";\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 KEYBOARD_PROTOCOL_RESPONSE_FRAGMENT_TIMEOUT_MS = 150;\nconst KITTY_KEYBOARD_PROTOCOL_QUERY = `\\x1b[>${DESIRED_KITTY_KEYBOARD_PROTOCOL_FLAGS}u\\x1b[?u`;\nconst DEVICE_ATTRIBUTES_QUERY = \"\\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\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\t/**\n\t * Report what the program is doing (OSC 7501). Sent only to terminals that support it; the latest\n\t * status is re-sent when support is confirmed or the terminal restarts.\n\t */\n\tsetProgramStatus(status: ProgramStatus): 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.NYAN_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 inputHandler?: (data: string) => void;\n\tprivate resizeHandler?: () => void;\n\tprivate _kittyProtocolActive = false;\n\tprivate _modifyOtherKeysActive = false;\n\tprivate keyboardProtocolPushed = false;\n\t/** DA1 replies owed to keyboard protocol queries. Later DA1 replies answer other queries and are forwarded. */\n\tprivate pendingKeyboardProtocolDeviceAttributes = 0;\n\tprivate keyboardProtocolNegotiationBuffer = \"\";\n\tprivate keyboardProtocolBufferFlushTimer?: ReturnType<typeof setTimeout>;\n\tprivate stdinBuffer?: StdinBuffer;\n\tprivate stdinDataHandler?: (data: string) => void;\n\tprivate progressInterval?: ReturnType<typeof setInterval>;\n\t/** Latest program status, kept across stop() so start() can report it again. */\n\tprivate programStatus?: ProgramStatus;\n\t/** Whether the terminal confirmed OSC 7501 support since the last start(), or `NYAN_PROGRAM_STATUS=1`. */\n\tprivate programStatusSupported = false;\n\t/** The support query was sent and its DA1 sentinel has not arrived yet. */\n\tprivate programStatusQueryPending = false;\n\tprivate writeLogPath = (() => {\n\t\tconst env = process.env.NYAN_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\tget modifyOtherKeysActive(): boolean {\n\t\treturn this._modifyOtherKeysActive;\n\t}\n\n\tstart(onInput: (data: string) => void, onResize: () => void): void {\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.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, 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\tif (isProgramStatusReply(sequence)) {\n\t\t\t\tif (this.programStatusQueryPending) {\n\t\t\t\t\tthis.programStatusQueryPending = false;\n\t\t\t\t\tthis.programStatusSupported = true;\n\t\t\t\t\tthis.writeProgramStatus();\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst negotiation = this.readKeyboardProtocolNegotiationSequence(sequence);\n\t\t\tif (negotiation === \"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 (negotiation && this.handleKeyboardProtocolNegotiationSequence(negotiation.parsed)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.forwardInputSequence(negotiation?.sequence ?? 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) => {\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\t * The OSC 7501 program status query shares the DA sentinel: a terminal that supports it replies\n\t * before DA. `NYAN_PROGRAM_STATUS=1` or `0` skips the query.\n\t */\n\tprivate queryAndEnableKittyProtocol(): void {\n\t\tthis.setupStdinBuffer();\n\t\tprocess.stdin.on(\"data\", this.stdinDataHandler!);\n\t\tthis.keyboardProtocolPushed = true;\n\t\tthis.pendingKeyboardProtocolDeviceAttributes += 1;\n\t\tthis.clearKeyboardProtocolNegotiationBuffer();\n\t\tconst programStatusOverride = process.env.NYAN_PROGRAM_STATUS;\n\t\tthis.programStatusSupported = programStatusOverride === \"1\";\n\t\tthis.programStatusQueryPending = programStatusOverride !== \"1\" && programStatusOverride !== \"0\";\n\t\tconst programStatusQuery = this.programStatusQueryPending ? PROGRAM_STATUS_QUERY : \"\";\n\t\tprocess.stdout.write(`${KITTY_KEYBOARD_PROTOCOL_QUERY}${programStatusQuery}${DEVICE_ATTRIBUTES_QUERY}`);\n\t\tthis.writeProgramStatus();\n\t}\n\n\tprivate handleKeyboardProtocolNegotiationSequence(\n\t\tnegotiationSequence: KeyboardProtocolNegotiationSequence,\n\t): boolean {\n\t\tthis.clearKeyboardProtocolNegotiationBuffer();\n\t\tif (negotiationSequence.type === \"device-attributes\") {\n\t\t\tif (this.pendingKeyboardProtocolDeviceAttributes === 0) return false;\n\t\t\tthis.pendingKeyboardProtocolDeviceAttributes -= 1;\n\t\t\t// The last owed DA answers the latest query, which got no program status reply first. Earlier DA\n\t\t\t// replies belong to queries from before a restart.\n\t\t\tif (this.pendingKeyboardProtocolDeviceAttributes === 0) this.programStatusQueryPending = false;\n\t\t}\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\t/** Returns the parsed negotiation reply with its full (possibly reassembled) sequence. */\n\tprivate readKeyboardProtocolNegotiationSequence(\n\t\tsequence: string,\n\t): { parsed: KeyboardProtocolNegotiationSequence; sequence: string } | \"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 { parsed: negotiationSequence, sequence: bufferedSequence };\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 { parsed: negotiationSequence, sequence };\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\tprocess.stdout.write(\"\\x1b[>4;2m\");\n\t\tthis._modifyOtherKeysActive = true;\n\t}\n\n\tprivate disableModifyOtherKeys(): void {\n\t\tif (!this._modifyOtherKeysActive) return;\n\t\tprocess.stdout.write(\"\\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\tgetNativePlatformHelper()?.enableVirtualTerminalInput?.();\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\tprocess.stdout.write(\"\\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\tprocess.stdout.write(TERMINAL_PROGRESS_CLEAR_SEQUENCE);\n\t\t}\n\t\t// Remove the status while stopped, for example after exit or while suspended. start() reports it again.\n\t\tif (this.programStatusSupported && this.programStatus) {\n\t\t\tprocess.stdout.write(formatProgramStatus({ state: \"clear\" }));\n\t\t}\n\t\tthis.programStatusSupported = false;\n\t\tthis.programStatusQueryPending = false;\n\n\t\t// Disable bracketed paste mode\n\t\tprocess.stdout.write(\"\\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\tprocess.stdout.write(\"\\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\tprocess.stdin.setRawMode(this.wasRaw);\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\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\tsetProgramStatus(status: ProgramStatus): void {\n\t\tthis.programStatus = status.state === \"clear\" ? undefined : status;\n\t\tif (this.programStatusSupported) process.stdout.write(formatProgramStatus(status));\n\t}\n\n\tprivate writeProgramStatus(): void {\n\t\tif (this.programStatusSupported && this.programStatus) {\n\t\t\tprocess.stdout.write(formatProgramStatus(this.programStatus));\n\t\t}\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"]}