jeopi-tui 16.2.13

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 (75) hide show
  1. package/CHANGELOG.md +1861 -0
  2. package/README.md +705 -0
  3. package/dist/types/autocomplete.d.ts +99 -0
  4. package/dist/types/bracketed-paste.d.ts +51 -0
  5. package/dist/types/components/box.d.ts +31 -0
  6. package/dist/types/components/cancellable-loader.d.ts +21 -0
  7. package/dist/types/components/editor.d.ts +155 -0
  8. package/dist/types/components/image.d.ts +112 -0
  9. package/dist/types/components/input.d.ts +23 -0
  10. package/dist/types/components/loader.d.ts +20 -0
  11. package/dist/types/components/markdown.d.ts +64 -0
  12. package/dist/types/components/scroll-view.d.ts +62 -0
  13. package/dist/types/components/select-list.d.ts +68 -0
  14. package/dist/types/components/settings-list.d.ts +123 -0
  15. package/dist/types/components/spacer.d.ts +11 -0
  16. package/dist/types/components/tab-bar.d.ts +89 -0
  17. package/dist/types/components/text.d.ts +14 -0
  18. package/dist/types/components/truncated-text.d.ts +10 -0
  19. package/dist/types/deccara.d.ts +49 -0
  20. package/dist/types/desktop-notify.d.ts +51 -0
  21. package/dist/types/editor-component.d.ts +38 -0
  22. package/dist/types/fuzzy.d.ts +32 -0
  23. package/dist/types/index.d.ts +32 -0
  24. package/dist/types/keybindings.d.ts +191 -0
  25. package/dist/types/keys.d.ts +208 -0
  26. package/dist/types/kill-ring.d.ts +20 -0
  27. package/dist/types/kitty-graphics.d.ts +79 -0
  28. package/dist/types/latex-block.d.ts +7 -0
  29. package/dist/types/latex-to-unicode.d.ts +33 -0
  30. package/dist/types/loop-watchdog.d.ts +39 -0
  31. package/dist/types/mouse.d.ts +67 -0
  32. package/dist/types/stdin-buffer.d.ts +60 -0
  33. package/dist/types/symbols.d.ts +25 -0
  34. package/dist/types/terminal-capabilities.d.ts +284 -0
  35. package/dist/types/terminal.d.ts +107 -0
  36. package/dist/types/ttyid.d.ts +9 -0
  37. package/dist/types/tui.d.ts +423 -0
  38. package/dist/types/utils.d.ts +95 -0
  39. package/package.json +73 -0
  40. package/src/autocomplete.ts +1026 -0
  41. package/src/bracketed-paste.ts +123 -0
  42. package/src/components/box.ts +194 -0
  43. package/src/components/cancellable-loader.ts +40 -0
  44. package/src/components/editor.ts +3092 -0
  45. package/src/components/image.ts +444 -0
  46. package/src/components/input.ts +474 -0
  47. package/src/components/loader.ts +103 -0
  48. package/src/components/markdown.ts +2068 -0
  49. package/src/components/scroll-view.ts +227 -0
  50. package/src/components/select-list.ts +531 -0
  51. package/src/components/settings-list.ts +793 -0
  52. package/src/components/spacer.ts +32 -0
  53. package/src/components/tab-bar.ts +300 -0
  54. package/src/components/text.ts +122 -0
  55. package/src/components/truncated-text.ts +69 -0
  56. package/src/deccara.ts +314 -0
  57. package/src/desktop-notify.ts +186 -0
  58. package/src/editor-component.ts +74 -0
  59. package/src/fuzzy.ts +356 -0
  60. package/src/index.ts +51 -0
  61. package/src/keybindings.ts +337 -0
  62. package/src/keys.ts +561 -0
  63. package/src/kill-ring.ts +51 -0
  64. package/src/kitty-graphics.ts +171 -0
  65. package/src/latex-block.ts +461 -0
  66. package/src/latex-to-unicode.ts +1994 -0
  67. package/src/loop-watchdog.ts +106 -0
  68. package/src/mouse.ts +105 -0
  69. package/src/stdin-buffer.ts +669 -0
  70. package/src/symbols.ts +26 -0
  71. package/src/terminal-capabilities.ts +1152 -0
  72. package/src/terminal.ts +1463 -0
  73. package/src/ttyid.ts +84 -0
  74. package/src/tui.ts +3901 -0
  75. package/src/utils.ts +570 -0
@@ -0,0 +1,60 @@
1
+ /**
2
+ * StdinBuffer buffers input and emits complete sequences.
3
+ *
4
+ * This is necessary because stdin data events can arrive in partial chunks,
5
+ * especially for escape sequences like mouse events. Without buffering,
6
+ * partial sequences can be misinterpreted as regular keypresses.
7
+ *
8
+ * For example, the mouse SGR sequence `\x1b[<35;20;5m` might arrive as:
9
+ * - Event 1: `\x1b`
10
+ * - Event 2: `[<35`
11
+ * - Event 3: `;20;5m`
12
+ *
13
+ * The buffer accumulates these until a complete sequence is detected.
14
+ * Call the `process()` method to feed input data.
15
+ *
16
+ * Based on code from OpenTUI (https://github.com/anomalyco/opentui)
17
+ * MIT License - Copyright (c) 2025 opentui
18
+ */
19
+ import { EventEmitter } from "events";
20
+ export type StdinBufferOptions = {
21
+ /**
22
+ * Maximum time to wait for sequence completion (default: 75ms).
23
+ * After this time, a genuinely incomplete escape is flushed.
24
+ */
25
+ timeout?: number;
26
+ /**
27
+ * Maximum extra time (default: 150ms) an unambiguous escape partial — an
28
+ * SGR mouse prefix, or any dangling escape while the kitty keyboard
29
+ * protocol is active — is held past `timeout` waiting for its tail.
30
+ */
31
+ partialHoldTimeout?: number;
32
+ /**
33
+ * Paste-mode inactivity watchdog (default: 1000ms). If no input arrives for
34
+ * this long while waiting for the bracketed-paste end marker, the paste is
35
+ * assumed truncated: accumulated bytes are delivered and input recovers.
36
+ */
37
+ pasteTimeout?: number;
38
+ /**
39
+ * Paste-mode byte cap (default: 64 MiB). Exceeding it aborts paste mode the
40
+ * same way, bounding memory when the end marker never arrives.
41
+ */
42
+ pasteByteLimit?: number;
43
+ };
44
+ export type StdinBufferEventMap = {
45
+ data: [string];
46
+ paste: [string];
47
+ };
48
+ /**
49
+ * Buffers stdin input and emits complete sequences via the 'data' event.
50
+ * Handles partial escape sequences that arrive across multiple chunks.
51
+ */
52
+ export declare class StdinBuffer extends EventEmitter<StdinBufferEventMap> {
53
+ #private;
54
+ constructor(options?: StdinBufferOptions);
55
+ process(data: string | Buffer): void;
56
+ flush(): string[];
57
+ clear(): void;
58
+ getBuffer(): string;
59
+ destroy(): void;
60
+ }
@@ -0,0 +1,25 @@
1
+ export interface BoxSymbols {
2
+ topLeft: string;
3
+ topRight: string;
4
+ bottomLeft: string;
5
+ bottomRight: string;
6
+ horizontal: string;
7
+ vertical: string;
8
+ teeDown: string;
9
+ teeUp: string;
10
+ teeLeft: string;
11
+ teeRight: string;
12
+ cross: string;
13
+ }
14
+ export interface SymbolTheme {
15
+ cursor: string;
16
+ inputCursor: string;
17
+ boxRound: Omit<BoxSymbols, "teeDown" | "teeUp" | "teeLeft" | "teeRight" | "cross">;
18
+ boxSharp: BoxSymbols;
19
+ table: BoxSymbols;
20
+ quoteBorder: string;
21
+ hrChar: string;
22
+ /** Chip glyph drawn (painted with the referenced color) before inline hex colors. */
23
+ colorSwatch?: string;
24
+ spinnerFrames: string[];
25
+ }
@@ -0,0 +1,284 @@
1
+ export declare enum ImageProtocol {
2
+ Kitty = "\u001B_G",
3
+ Iterm2 = "\u001B]1337;File=",
4
+ Sixel = "\u001BPq"
5
+ }
6
+ export declare enum NotifyProtocol {
7
+ Bell = "\u0007",
8
+ Osc99 = "\u001B]99;;",
9
+ Osc9 = "\u001B]9;"
10
+ }
11
+ export type TerminalId = "kitty" | "ghostty" | "wezterm" | "iterm2" | "vscode" | "alacritty" | "warp" | "base" | "trueColor";
12
+ /** Terminal capability details used for rendering and protocol selection. */
13
+ export declare class TerminalInfo {
14
+ readonly id: TerminalId;
15
+ readonly imageProtocol: ImageProtocol | null;
16
+ readonly trueColor: boolean;
17
+ readonly hyperlinks: boolean;
18
+ readonly notifyProtocol: NotifyProtocol;
19
+ readonly deccara: boolean;
20
+ readonly supportsScreenToScrollback: boolean;
21
+ /** Renders the Kitty OSC 66 text-sizing protocol (scaled spans). Kitty only. */
22
+ readonly textSizing: boolean;
23
+ constructor(id: TerminalId, imageProtocol: ImageProtocol | null, trueColor: boolean, hyperlinks: boolean, notifyProtocol?: NotifyProtocol, deccara?: boolean, supportsScreenToScrollback?: boolean,
24
+ /** Renders the Kitty OSC 66 text-sizing protocol (scaled spans). Kitty only. */
25
+ textSizing?: boolean);
26
+ /**
27
+ * Mutable clone for the {@link TERMINAL} singleton: copies every field and
28
+ * keeps the prototype methods, so the builder and runtime setters flip
29
+ * runtime-resolved {@link RuntimeTerminal} capabilities in place instead of
30
+ * reconstructing positional constructor args.
31
+ */
32
+ clone(): RuntimeTerminal;
33
+ isImageLine(line: string): boolean;
34
+ formatNotification(message: string | TerminalNotification): string;
35
+ sendNotification(message: string | TerminalNotification): void;
36
+ }
37
+ /**
38
+ * Whether the agent process is running inside a tmux session. Read fresh on
39
+ * each call so tests can toggle `Bun.env.TMUX` per case without re-importing
40
+ * the module and so a tmux session attached/detached mid-run is observed.
41
+ */
42
+ export declare function isInsideTmux(env?: NodeJS.ProcessEnv): boolean;
43
+ /** Detect terminal multiplexers where scrollback clearing and height-change redraws are hostile. */
44
+ export declare function isInsideTerminalMultiplexer(env?: NodeJS.ProcessEnv): boolean;
45
+ /**
46
+ * Wrap a control-sequence payload in tmux's DCS passthrough envelope. Each
47
+ * ESC byte inside `payload` is doubled per tmux's escape rules. tmux strips
48
+ * the envelope and forwards the unwrapped payload to the outer terminal only
49
+ * when the user opts in with `set -g allow-passthrough on`; otherwise tmux
50
+ * silently consumes the envelope, which is identical to the pre-wrap baseline
51
+ * (tmux already swallowed the bare OSC).
52
+ *
53
+ * Used by `TerminalInfo.sendNotification` and the OSC 99 capability probe in
54
+ * `terminal.ts` to keep notifications alive for terminals that understand
55
+ * OSC 9 / OSC 99 (kitty, ghostty, wezterm, iterm2) when running under tmux.
56
+ */
57
+ export declare function wrapTmuxPassthrough(payload: string): string;
58
+ export declare function isNotificationSuppressed(): boolean;
59
+ /**
60
+ * Returns true when running in Windows Terminal with known SIXEL support.
61
+ *
62
+ * Windows Terminal introduced SIXEL support in preview 1.22.
63
+ */
64
+ export declare function isWindowsTerminalPreviewSixelSupported(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): boolean;
65
+ /**
66
+ * Resolve an explicit user override for DEC 2026 synchronized output. Returns
67
+ * `false` for an opt-out, `true` for a force-on, or `null` when the user has
68
+ * expressed no preference. Shared by the static default and the runtime DECRQM
69
+ * probe so both honor the same precedence — an opt-out beats a force-on.
70
+ */
71
+ export declare function synchronizedOutputUserOverride(env?: NodeJS.ProcessEnv): boolean | null;
72
+ /**
73
+ * Whether DEC 2026 synchronized-output wrappers should be enabled by default.
74
+ *
75
+ * Policy (highest precedence first):
76
+ * 1. Explicit user override (`PI_NO_SYNC_OUTPUT`/`PI_TUI_SYNC_OUTPUT=0` off,
77
+ * `PI_FORCE_SYNC_OUTPUT=1`/`PI_TUI_SYNC_OUTPUT=1` on).
78
+ * 2. Positive `TERM_FEATURES` advertisement (`Sy`) — survives SSH/mux wrapping.
79
+ * 3. Windows Terminal (1.24+) via `WT_SESSION`, on native win32 and the
80
+ * WSL/SSH-fronted host alike.
81
+ * 4. Known direct terminals with confirmed support. SSH does *not* disable —
82
+ * DEC 2026 passes through SSH when the outer terminal honors it.
83
+ * 5. Everything else starts off, including risky multiplexers; the runtime
84
+ * DECRQM probe upgrades any of them when the terminal actually reports
85
+ * `?2026` supported (current zellij, tmux master, foot, contour, mintty…).
86
+ */
87
+ export declare function shouldEnableSynchronizedOutputByDefault(env?: NodeJS.ProcessEnv, terminalId?: TerminalId): boolean;
88
+ /**
89
+ * Whether the terminal applies Kitty-style DECCARA rectangular SGR changes
90
+ * (`CSI Pt ; Pl ; Pb ; Pr ; <sgr> $ r`) extended to background color, so large
91
+ * filled regions can be painted as rectangles instead of background-padded
92
+ * strings on every row.
93
+ *
94
+ * Verified against terminal sources rather than terminfo, because a bare
95
+ * `Cara`/DECCARA terminfo capability does not imply the Kitty SGR-background
96
+ * extension:
97
+ * - Kitty implements it for *all* SGR attributes including background (see
98
+ * kitty `docs/deccara.rst` and the `test_deccara` parser test).
99
+ * - Ghostty does NOT: its `CSI $ r` dispatch falls through to an "unknown CSI"
100
+ * warning and DECCARA/DECSACE are tracked as unsupported
101
+ * (ghostty-org/ghostty#632). Enabling it there would silently drop panel
102
+ * backgrounds, so ghostty stays on the padded-string fallback.
103
+ *
104
+ * Disabled under tmux/screen/zellij multiplexers — screen-coordinate rectangle
105
+ * protocols are not safe to assume through a multiplexer — and via the
106
+ * `PI_NO_DECCARA` kill switch. Pure helper for tests and `TERMINAL` construction.
107
+ */
108
+ export declare function detectRectangularSgrSupport(terminalId: TerminalId, env?: NodeJS.ProcessEnv): boolean;
109
+ /**
110
+ * Resolve an explicit user override for OSC 8 hyperlinks. Returns `false` for
111
+ * an opt-out, `true` for a force-on, or `null` when the user has expressed no
112
+ * preference. Opt-out beats force-on so a kill switch is unambiguous, mirroring
113
+ * {@link synchronizedOutputUserOverride}.
114
+ */
115
+ export declare function hyperlinksUserOverride(env?: NodeJS.ProcessEnv): boolean | null;
116
+ /**
117
+ * Whether OSC 8 hyperlinks should be enabled by default.
118
+ *
119
+ * Policy (highest precedence first):
120
+ * 1. Explicit user override (`PI_NO_HYPERLINKS=1` off, `PI_FORCE_HYPERLINKS=1`
121
+ * on). Opt-out wins ties.
122
+ * 2. Static terminal capability — terminals whose {@link TerminalInfo} marks
123
+ * `hyperlinks: false` (e.g. `base`) stay off unless the user forced on.
124
+ * 3. GNU screen's explicit session marker (`STY`) always off, even if tmux is
125
+ * also present: a screen layer anywhere in the path cannot forward OSC 8.
126
+ * 4. tmux session (`TMUX` set): enabled when tmux self-reports >= 3.4 via
127
+ * `TERM_PROGRAM_VERSION` (tmux 3.4 stores OSC 8 as a cell attribute and
128
+ * forwards it to outer terminals whose `terminal-features` include
129
+ * `hyperlinks`). Older or unknown versions stay off; on outer terminals
130
+ * without the feature configured, tmux silently drops the sequence —
131
+ * identical to today. Checked before the screen-family TERM heuristic
132
+ * because tmux's historical `default-terminal` is `screen-256color`, so
133
+ * `TERM=screen*` inside a tmux session must NOT short-circuit to off.
134
+ * 5. screen-family TERM without `TMUX` always off: screen never gained OSC 8
135
+ * support.
136
+ * 6. tmux-family TERM without `TMUX` env — unusual (e.g. inspection scripts);
137
+ * no version available, so off.
138
+ * 7. Otherwise honor the static terminal capability.
139
+ */
140
+ export declare function shouldEnableHyperlinksByDefault(env?: NodeJS.ProcessEnv, terminalId?: TerminalId): boolean;
141
+ /**
142
+ * Warp implements the Kitty graphics protocol only on macOS/Linux; its Windows
143
+ * build (including Warp-hosted WSL shells) renders the same APC sequences as
144
+ * visible garbage. Keep platform/env injectable so the carve-out is testable
145
+ * without mutating `process.platform`.
146
+ */
147
+ export declare function resolveWarpImageProtocol(platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv): ImageProtocol | null;
148
+ /** Resolve terminal identity from environment markers used by common emulators. */
149
+ export declare function detectTerminalId(env?: NodeJS.ProcessEnv): TerminalId;
150
+ export declare const TERMINAL_ID: TerminalId;
151
+ /**
152
+ * The process-wide {@link TERMINAL} singleton: a {@link TerminalInfo} whose
153
+ * post-construction capabilities — the image protocol and the probe-driven
154
+ * flags — are writable, so the runtime setters and tests mutate them directly
155
+ * instead of through an unsound cast. Every other field stays readonly.
156
+ */
157
+ export interface RuntimeTerminal extends TerminalInfo {
158
+ imageProtocol: ImageProtocol | null;
159
+ hyperlinks: boolean;
160
+ deccara: boolean;
161
+ supportsScreenToScrollback: boolean;
162
+ textSizing: boolean;
163
+ }
164
+ export declare const TERMINAL: RuntimeTerminal;
165
+ /**
166
+ * Override terminal image protocol at runtime after capability probes complete.
167
+ */
168
+ export declare function setTerminalImageProtocol(imageProtocol: ImageProtocol | null): void;
169
+ /**
170
+ * Override DECCARA rectangular-SGR capability at runtime. Used by tests to
171
+ * exercise the optimizer and fallback paths deterministically — the default is
172
+ * resolved once at import and force-disabled under the test runtime.
173
+ */
174
+ export declare function setTerminalDeccara(enabled: boolean): void;
175
+ /** Override screen-to-scrollback clear support for targeted renderer tests. */
176
+ export declare function setTerminalScreenToScrollback(enabled: boolean): void;
177
+ /**
178
+ * Enable/disable OSC 66 text-sizing at runtime. The coding-agent calls this from
179
+ * the `tui.textSizing` setting (gated on the terminal's static `textSizing`
180
+ * capability); tests flip it directly to exercise the scaled-heading path.
181
+ */
182
+ export declare function setTerminalTextSizing(enabled: boolean): void;
183
+ export declare function getTerminalInfo(terminalId: TerminalId, platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv): TerminalInfo;
184
+ export interface CellDimensions {
185
+ widthPx: number;
186
+ heightPx: number;
187
+ }
188
+ export interface ImageDimensions {
189
+ widthPx: number;
190
+ heightPx: number;
191
+ }
192
+ export interface ImageRenderOptions {
193
+ maxWidthCells?: number;
194
+ maxHeightCells?: number;
195
+ preserveAspectRatio?: boolean;
196
+ /**
197
+ * Stable Kitty image id (`i=`). When set, the image is displayed via a
198
+ * transmit-once + placement scheme keyed off this id instead of re-sending the
199
+ * base64 each frame.
200
+ */
201
+ imageId?: number;
202
+ /** Stable Kitty placement id (`p=`); defaults to {@link imageId}. */
203
+ placementId?: number;
204
+ /** When true (Kitty + {@link imageId}), also return the one-time transmit sequence. */
205
+ includeTransmit?: boolean;
206
+ }
207
+ export declare function getCellDimensions(): CellDimensions;
208
+ export declare function setCellDimensions(dims: CellDimensions): void;
209
+ /** Transmit-and-display (`a=T`) — the self-contained form used when no stable id is available. */
210
+ export declare function encodeKitty(base64Data: string, options?: {
211
+ columns?: number;
212
+ rows?: number;
213
+ imageId?: number;
214
+ }): string;
215
+ /**
216
+ * Transmit image data only (`a=t`), keyed by `imageId`, without displaying it.
217
+ * Sent once per image; the data then persists in the terminal's store (it
218
+ * survives scroll-off and text clears for images with a non-zero id), so
219
+ * subsequent frames display it with the tiny {@link encodeKittyPlacement}
220
+ * sequence instead of re-sending the base64.
221
+ */
222
+ export declare function encodeKittyTransmit(base64Data: string, imageId: number): string;
223
+ /**
224
+ * Display a previously transmitted image (`a=p`) at the cursor. `C=1` keeps
225
+ * the terminal cursor anchored at the placement origin so the renderer's
226
+ * explicit cursor movement remains the only row accounting. Carrying a stable
227
+ * `placementId` (`p=`) means re-emitting the sequence on a repaint *replaces*
228
+ * the existing placement (moving/resizing it without flicker) rather than
229
+ * stacking a duplicate.
230
+ */
231
+ export declare function encodeKittyPlacement(options: {
232
+ imageId: number;
233
+ placementId?: number;
234
+ columns?: number;
235
+ rows?: number;
236
+ }): string;
237
+ /**
238
+ * Kitty graphics delete command for a single image id. Uses `d=I` (capital)
239
+ * which removes the image and every one of its placements — on screen *and* in
240
+ * scrollback — and frees the backing data. `q=2` suppresses the terminal reply.
241
+ * Text-clearing escapes (`CSI 2 J` / `CSI 3 J`) do not remove Kitty graphics, so
242
+ * this is the only way to actually purge a placed image.
243
+ */
244
+ export declare function encodeKittyDeleteImage(imageId: number): string;
245
+ export declare function encodeITerm2(base64Data: string, options?: {
246
+ width?: number | string;
247
+ height?: number | string;
248
+ name?: string;
249
+ preserveAspectRatio?: boolean;
250
+ inline?: boolean;
251
+ }): string;
252
+ export declare function calculateImageRows(imageDimensions: ImageDimensions, targetWidthCells: number, cellDimensions?: CellDimensions): number;
253
+ export declare function getPngDimensions(base64Data: string): ImageDimensions | null;
254
+ export declare function getJpegDimensions(base64Data: string): ImageDimensions | null;
255
+ export declare function getGifDimensions(base64Data: string): ImageDimensions | null;
256
+ export declare function getWebpDimensions(base64Data: string): ImageDimensions | null;
257
+ export declare function getImageDimensions(base64Data: string, mimeType: string): ImageDimensions | null;
258
+ export declare function renderImage(base64Data: string, imageDimensions: ImageDimensions, options?: ImageRenderOptions): {
259
+ sequence?: string;
260
+ lines?: string[];
261
+ rows: number;
262
+ transmit?: string;
263
+ } | null;
264
+ export declare function imageFallback(mimeType: string, dimensions?: ImageDimensions, filename?: string): string;
265
+ /**
266
+ * Structured terminal notification. Rich fields are honored only by OSC 99
267
+ * (Kitty) once support is confirmed; other protocols and the unconfirmed Kitty
268
+ * path collapse to a single `title: body` line.
269
+ */
270
+ export interface TerminalNotification {
271
+ title?: string;
272
+ body?: string;
273
+ id?: string;
274
+ type?: string | string[];
275
+ urgency?: "low" | "normal" | "critical";
276
+ iconName?: string;
277
+ sound?: "silent" | "system" | "info" | "warning" | "error" | "question";
278
+ actions?: "focus" | "report" | "focus-report" | "none";
279
+ expiresMs?: number;
280
+ }
281
+ /** Record the OSC 99 capability-probe result (called by ProcessTerminal). */
282
+ export declare function setOsc99Supported(supported: boolean): void;
283
+ /** True when OSC 99 structured notifications have been confirmed available. */
284
+ export declare function isOsc99Supported(): boolean;
@@ -0,0 +1,107 @@
1
+ import { type HangulCompatibilityJamoWidth } from "./utils";
2
+ export declare function resolveHangulCompatibilityJamoWidthFromTerminalIdentity(env?: NodeJS.ProcessEnv): HangulCompatibilityJamoWidth;
3
+ /**
4
+ * Split `data` into chunks whose encoded UTF-8 byte length is no greater than
5
+ * `maxChunkBytes`, preferring a line boundary (`\n`) as the cut point so
6
+ * escape sequences (which never contain `\n`) stay intact. The TUI's
7
+ * full-paint buffers are line-structured (`buffer += "\r\n"` between rows),
8
+ * so a newline almost always exists within the window. The fallback for a
9
+ * buffer with no newline in range is a hard cut at the last UTF-8 code-point
10
+ * boundary that still fits — the ConPTY viewport bug from a single oversized
11
+ * write is strictly worse than a one-frame escape-sequence glitch on a
12
+ * buffer the renderer effectively never produces.
13
+ *
14
+ * UTF-16 code units are walked manually rather than measuring with
15
+ * `Buffer.byteLength` per slice candidate: each code unit's UTF-8 width is
16
+ * known from its value (BMP `<0x80` → 1, `<0x800` → 2, surrogate pair → 4
17
+ * bytes across two units, other BMP → 3), and surrogate pairs are kept
18
+ * together so the chunker never splits a non-BMP character.
19
+ *
20
+ * Exported for unit testing of the chunking contract; `#safeWrite` is the
21
+ * sole production caller.
22
+ */
23
+ export declare function chunkForConPTY(data: string, maxChunkBytes?: number): string[];
24
+ /** Record alternate-screen state (called by the TUI on `?1049h`/`?1049l` writes). */
25
+ export declare function setAltScreenActive(active: boolean): void;
26
+ /**
27
+ * Emergency terminal restore - call this from signal/crash handlers
28
+ * Resets terminal state without requiring access to the ProcessTerminal instance
29
+ */
30
+ export declare function emergencyTerminalRestore(): void;
31
+ /** Terminal-reported appearance (dark/light mode). */
32
+ export type TerminalAppearance = "dark" | "light";
33
+ export interface Terminal {
34
+ start(onInput: (data: string) => void, onResize: () => void): void;
35
+ stop(): void;
36
+ /**
37
+ * Drain stdin before exiting to prevent Kitty key release events from
38
+ * leaking to the parent shell over slow SSH connections.
39
+ * @param maxMs - Maximum time to drain (default: 1000ms)
40
+ * @param idleMs - Exit early if no input arrives within this time (default: 50ms)
41
+ */
42
+ drainInput(maxMs?: number, idleMs?: number): Promise<void>;
43
+ write(data: string): void;
44
+ get columns(): number;
45
+ get rows(): number;
46
+ get kittyProtocolActive(): boolean;
47
+ get kittyEnableSequence(): string | null;
48
+ readonly keyboardEnhancementEnterSequence?: string | null;
49
+ readonly keyboardEnhancementExitSequence?: string | null;
50
+ moveBy(lines: number): void;
51
+ hideCursor(): void;
52
+ showCursor(): void;
53
+ clearLine(): void;
54
+ clearFromCursor(): void;
55
+ clearScreen(): void;
56
+ setTitle(title: string): void;
57
+ setProgress(active: boolean): void;
58
+ /**
59
+ * Register a callback for terminal appearance (dark/light) changes.
60
+ * Detection uses OSC 11 background color query with Mode 2031 as a change trigger.
61
+ * Fires when the detected appearance changes, including the initial detection.
62
+ */
63
+ onAppearanceChange(callback: (appearance: TerminalAppearance) => void): void;
64
+ /** The last detected terminal appearance, or undefined if not yet known. */
65
+ get appearance(): TerminalAppearance | undefined;
66
+ /**
67
+ * Register a callback fired once per DEC private mode when its DECRQM support
68
+ * status resolves. Optional: only real terminals implement capability probing.
69
+ */
70
+ onPrivateModeReport?(callback: (mode: number, supported: boolean) => void): void;
71
+ }
72
+ /**
73
+ * True when stdout flows through a ConPTY pseudo-console (native win32, or
74
+ * Linux running under WSL where stdout still crosses into ConPTY at the
75
+ * `wslhost` boundary). ConPTY hosts share the per-WriteFile viewport-tracking
76
+ * quirks documented above and on {@link MAX_CONPTY_WRITE_CHUNK_BYTES}, so both
77
+ * `#safeWrite` and the renderer's post-big-paint settle gate hang off this
78
+ * single predicate.
79
+ */
80
+ export declare function isConPTYHosted(): boolean;
81
+ /**
82
+ * Real terminal using process.stdin/stdout
83
+ */
84
+ export declare class ProcessTerminal implements Terminal {
85
+ #private;
86
+ get kittyProtocolActive(): boolean;
87
+ get kittyEnableSequence(): string | null;
88
+ get keyboardEnhancementEnterSequence(): string | null;
89
+ get keyboardEnhancementExitSequence(): string | null;
90
+ get appearance(): TerminalAppearance | undefined;
91
+ onAppearanceChange(callback: (appearance: TerminalAppearance) => void): void;
92
+ onPrivateModeReport(callback: (mode: number, supported: boolean) => void): void;
93
+ start(onInput: (data: string) => void, onResize: () => void): void;
94
+ drainInput(maxMs?: number, idleMs?: number): Promise<void>;
95
+ stop(): void;
96
+ write(data: string): void;
97
+ get columns(): number;
98
+ get rows(): number;
99
+ moveBy(lines: number): void;
100
+ hideCursor(): void;
101
+ showCursor(): void;
102
+ clearLine(): void;
103
+ clearFromCursor(): void;
104
+ clearScreen(): void;
105
+ setTitle(title: string): void;
106
+ setProgress(active: boolean): void;
107
+ }
@@ -0,0 +1,9 @@
1
+ /** Resolve the TTY device path for stdin (fd 0) via POSIX `ttyname(3)`. */
2
+ export declare function getTtyPath(): string | null;
3
+ /**
4
+ * Get a stable identifier for the current terminal.
5
+ * Uses the TTY device path (e.g., /dev/pts/3), falling back to environment
6
+ * variables for terminal multiplexers or terminal emulators.
7
+ * Returns null if no terminal can be identified (e.g., piped input).
8
+ */
9
+ export declare function getTerminalId(): string | null;