@linxiraos/pi-tui 1.0.0
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.
- package/CHANGELOG.md +2219 -0
- package/README.md +705 -0
- package/dist/types/autocomplete.d.ts +116 -0
- package/dist/types/bracketed-paste.d.ts +51 -0
- package/dist/types/components/box.d.ts +31 -0
- package/dist/types/components/cancellable-loader.d.ts +21 -0
- package/dist/types/components/editor.d.ts +162 -0
- package/dist/types/components/image.d.ts +112 -0
- package/dist/types/components/input.d.ts +25 -0
- package/dist/types/components/loader.d.ts +25 -0
- package/dist/types/components/markdown.d.ts +88 -0
- package/dist/types/components/scroll-view.d.ts +62 -0
- package/dist/types/components/select-list.d.ts +69 -0
- package/dist/types/components/settings-list.d.ts +123 -0
- package/dist/types/components/spacer.d.ts +11 -0
- package/dist/types/components/tab-bar.d.ts +89 -0
- package/dist/types/components/text.d.ts +27 -0
- package/dist/types/components/truncated-text.d.ts +10 -0
- package/dist/types/deccara.d.ts +49 -0
- package/dist/types/desktop-notify.d.ts +52 -0
- package/dist/types/editor-component.d.ts +38 -0
- package/dist/types/fuzzy.d.ts +48 -0
- package/dist/types/index.d.ts +32 -0
- package/dist/types/keybindings.d.ts +197 -0
- package/dist/types/keys.d.ts +210 -0
- package/dist/types/kill-ring.d.ts +20 -0
- package/dist/types/kitty-graphics.d.ts +76 -0
- package/dist/types/latex-block.d.ts +8 -0
- package/dist/types/latex-to-unicode.d.ts +50 -0
- package/dist/types/loop-watchdog.d.ts +44 -0
- package/dist/types/mouse.d.ts +67 -0
- package/dist/types/stdin-buffer.d.ts +60 -0
- package/dist/types/symbols.d.ts +25 -0
- package/dist/types/terminal-capabilities.d.ts +285 -0
- package/dist/types/terminal.d.ts +175 -0
- package/dist/types/tmux.d.ts +6 -0
- package/dist/types/ttyid.d.ts +9 -0
- package/dist/types/tui.d.ts +457 -0
- package/dist/types/utils.d.ts +100 -0
- package/package.json +70 -0
- package/src/autocomplete.ts +1079 -0
- package/src/bracketed-paste.ts +123 -0
- package/src/components/box.ts +236 -0
- package/src/components/cancellable-loader.ts +40 -0
- package/src/components/editor.ts +3301 -0
- package/src/components/image.ts +460 -0
- package/src/components/input.ts +482 -0
- package/src/components/loader.ts +174 -0
- package/src/components/markdown.ts +3119 -0
- package/src/components/scroll-view.ts +227 -0
- package/src/components/select-list.ts +539 -0
- package/src/components/settings-list.ts +793 -0
- package/src/components/spacer.ts +32 -0
- package/src/components/tab-bar.ts +300 -0
- package/src/components/text.ts +173 -0
- package/src/components/truncated-text.ts +69 -0
- package/src/deccara.ts +314 -0
- package/src/desktop-notify.ts +192 -0
- package/src/editor-component.ts +74 -0
- package/src/fuzzy.ts +384 -0
- package/src/index.ts +51 -0
- package/src/keybindings.ts +346 -0
- package/src/keys.ts +566 -0
- package/src/kill-ring.ts +51 -0
- package/src/kitty-graphics.ts +171 -0
- package/src/latex-block.ts +1338 -0
- package/src/latex-to-unicode.ts +2017 -0
- package/src/loop-watchdog.ts +115 -0
- package/src/mouse.ts +105 -0
- package/src/stdin-buffer.ts +781 -0
- package/src/symbols.ts +26 -0
- package/src/terminal-capabilities.ts +1211 -0
- package/src/terminal.ts +1854 -0
- package/src/tmux.ts +14 -0
- package/src/ttyid.ts +84 -0
- package/src/tui.ts +4275 -0
- package/src/utils.ts +619 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SGR mouse report parsing (`\x1b[<button;col;rowM` / `…m`).
|
|
3
|
+
*
|
|
4
|
+
* Mouse tracking is enabled only while a fullscreen overlay holds the
|
|
5
|
+
* alternate screen (see tui.ts MOUSE_TRACKING_ON), so consumers are
|
|
6
|
+
* fullscreen components hit-testing against their own rendered frame:
|
|
7
|
+
* the frame paints from screen row 0, hence `row`/`col` are exposed
|
|
8
|
+
* 0-based for direct indexing into rendered lines.
|
|
9
|
+
*/
|
|
10
|
+
/** A decoded SGR mouse report. */
|
|
11
|
+
export interface SgrMouseEvent {
|
|
12
|
+
/** Raw button code (bit 32 = motion, bit 64 = wheel, low bits = button). */
|
|
13
|
+
button: number;
|
|
14
|
+
/** 0-based column of the event. */
|
|
15
|
+
col: number;
|
|
16
|
+
/** 0-based row of the event. */
|
|
17
|
+
row: number;
|
|
18
|
+
/** True for a release report (`m` suffix). */
|
|
19
|
+
release: boolean;
|
|
20
|
+
/** Wheel direction: -1 up, 1 down, null when not a wheel event. */
|
|
21
|
+
wheel: -1 | 1 | null;
|
|
22
|
+
/** True when the pointer moved (hover or drag) rather than clicked. */
|
|
23
|
+
motion: boolean;
|
|
24
|
+
/** True for a left-button press (not motion, not release, not wheel). */
|
|
25
|
+
leftClick: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Decode an SGR mouse report, or return null when `data` is not one.
|
|
29
|
+
* Callers on hot keypress paths should pre-check `data.startsWith("\x1b[<")`
|
|
30
|
+
* before paying for the regex.
|
|
31
|
+
*/
|
|
32
|
+
export declare function parseSgrMouse(data: string): SgrMouseEvent | null;
|
|
33
|
+
/** Handler invoked with a decoded SGR event; returning `false` reports unhandled. */
|
|
34
|
+
export type SgrMouseHandler = (event: SgrMouseEvent) => boolean | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Decode an SGR mouse report and forward it to `handler`. Returns `false` when
|
|
37
|
+
* `data` is not an SGR mouse report (or fails to parse), so callers can fall
|
|
38
|
+
* through to other input handling. Centralizes the repeated
|
|
39
|
+
* `data.startsWith("\x1b[<")` + `parseSgrMouse()` pattern.
|
|
40
|
+
*/
|
|
41
|
+
export declare function routeSgrMouseInput(data: string, handler: SgrMouseHandler): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Structural view of a SelectList-like target for mouse routing. Declared here
|
|
44
|
+
* (rather than importing the component) to keep this core module free of any
|
|
45
|
+
* component-to-core import cycle.
|
|
46
|
+
*/
|
|
47
|
+
export interface SelectListMouseTarget {
|
|
48
|
+
handleWheel(delta: -1 | 1): void;
|
|
49
|
+
hitTest(line: number): number | undefined;
|
|
50
|
+
setHoverIndex(index: number | null): void;
|
|
51
|
+
clickItem(index: number): void;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Route a decoded mouse event against a SelectList-like target at the given
|
|
55
|
+
* 0-based frame-local `line`. Centralizes the repeated wheel/hit-test/hover/
|
|
56
|
+
* click pattern. Returns `true` when the event was consumed.
|
|
57
|
+
*/
|
|
58
|
+
export declare function routeSelectListMouse(target: SelectListMouseTarget, event: SgrMouseEvent, line: number): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Implemented by components that accept routed mouse events at frame-local
|
|
61
|
+
* coordinates. Hosts translate screen coordinates to the component's own
|
|
62
|
+
* rendered lines before forwarding.
|
|
63
|
+
*/
|
|
64
|
+
export interface MouseRoutable {
|
|
65
|
+
/** `line`/`col` are 0-based within the component's rendered output. */
|
|
66
|
+
routeMouse(event: SgrMouseEvent, line: number, col: number): void;
|
|
67
|
+
}
|
|
@@ -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,285 @@
|
|
|
1
|
+
import type { HangulCompatibilityJamoWidth } from "./utils.js";
|
|
2
|
+
export { isInsideTmux, wrapTmuxPassthrough } from "./tmux.js";
|
|
3
|
+
export declare enum ImageProtocol {
|
|
4
|
+
Kitty = "\u001B_G",
|
|
5
|
+
Iterm2 = "\u001B]1337;File=",
|
|
6
|
+
Sixel = "\u001BPq"
|
|
7
|
+
}
|
|
8
|
+
export declare enum NotifyProtocol {
|
|
9
|
+
Bell = "\u0007",
|
|
10
|
+
Osc99 = "\u001B]99;;",
|
|
11
|
+
Osc9 = "\u001B]9;"
|
|
12
|
+
}
|
|
13
|
+
export type TerminalId = "kitty" | "ghostty" | "wezterm" | "iterm2" | "vscode" | "alacritty" | "warp" | "base" | "trueColor";
|
|
14
|
+
/** Terminal capability details used for rendering and protocol selection. */
|
|
15
|
+
export declare class TerminalInfo {
|
|
16
|
+
readonly id: TerminalId;
|
|
17
|
+
readonly imageProtocol: ImageProtocol | null;
|
|
18
|
+
readonly trueColor: boolean;
|
|
19
|
+
readonly hyperlinks: boolean;
|
|
20
|
+
readonly notifyProtocol: NotifyProtocol;
|
|
21
|
+
readonly deccara: boolean;
|
|
22
|
+
readonly supportsScreenToScrollback: boolean;
|
|
23
|
+
/** Renders the Kitty OSC 66 text-sizing protocol (scaled spans). Kitty only. */
|
|
24
|
+
readonly textSizing: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Hangul Compatibility Jamo (U+3131..=U+318E) cell width. Ghostty follows
|
|
27
|
+
* UAX#11 (2 cells); Warp paints 1; "platform" keeps the OS default
|
|
28
|
+
* (macOS narrow, otherwise UAX#11).
|
|
29
|
+
*/
|
|
30
|
+
readonly hangulJamoWidth: HangulCompatibilityJamoWidth;
|
|
31
|
+
constructor(id: TerminalId, imageProtocol: ImageProtocol | null, trueColor: boolean, hyperlinks: boolean, notifyProtocol?: NotifyProtocol, deccara?: boolean, supportsScreenToScrollback?: boolean,
|
|
32
|
+
/** Renders the Kitty OSC 66 text-sizing protocol (scaled spans). Kitty only. */
|
|
33
|
+
textSizing?: boolean,
|
|
34
|
+
/**
|
|
35
|
+
* Hangul Compatibility Jamo (U+3131..=U+318E) cell width. Ghostty follows
|
|
36
|
+
* UAX#11 (2 cells); Warp paints 1; "platform" keeps the OS default
|
|
37
|
+
* (macOS narrow, otherwise UAX#11).
|
|
38
|
+
*/
|
|
39
|
+
hangulJamoWidth?: HangulCompatibilityJamoWidth);
|
|
40
|
+
/**
|
|
41
|
+
* Mutable clone for the {@link TERMINAL} singleton: copies every field and
|
|
42
|
+
* keeps the prototype methods, so the builder and runtime setters flip
|
|
43
|
+
* runtime-resolved {@link RuntimeTerminal} capabilities in place instead of
|
|
44
|
+
* reconstructing positional constructor args.
|
|
45
|
+
*/
|
|
46
|
+
clone(): RuntimeTerminal;
|
|
47
|
+
isImageLine(line: string): boolean;
|
|
48
|
+
formatNotification(message: string | TerminalNotification): string;
|
|
49
|
+
sendNotification(message: string | TerminalNotification): void;
|
|
50
|
+
}
|
|
51
|
+
/** Detect terminal multiplexers where scrollback clearing and height-change redraws are hostile. */
|
|
52
|
+
export declare function isInsideTerminalMultiplexer(env?: NodeJS.ProcessEnv): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Whether the agent process is running inside a Zellij session. Read fresh on
|
|
55
|
+
* each call (like {@link isInsideTmux}) so a session attached/detached mid-run
|
|
56
|
+
* is observed and tests can toggle `Bun.env.ZELLIJ` per case.
|
|
57
|
+
*/
|
|
58
|
+
export declare function isInsideZellij(env?: NodeJS.ProcessEnv): boolean;
|
|
59
|
+
export declare function isNotificationSuppressed(): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Returns true when running in Windows Terminal with known SIXEL support.
|
|
62
|
+
*
|
|
63
|
+
* Windows Terminal introduced SIXEL support in preview 1.22.
|
|
64
|
+
*/
|
|
65
|
+
export declare function isWindowsTerminalPreviewSixelSupported(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Resolve an explicit user override for DEC 2026 synchronized output. Returns
|
|
68
|
+
* `false` for an opt-out, `true` for a force-on, or `null` when the user has
|
|
69
|
+
* expressed no preference. Shared by the static default and the runtime DECRQM
|
|
70
|
+
* probe so both honor the same precedence — an opt-out beats a force-on.
|
|
71
|
+
*/
|
|
72
|
+
export declare function synchronizedOutputUserOverride(env?: NodeJS.ProcessEnv): boolean | null;
|
|
73
|
+
/**
|
|
74
|
+
* Whether DEC 2026 synchronized-output wrappers should be enabled by default.
|
|
75
|
+
*
|
|
76
|
+
* Policy (highest precedence first):
|
|
77
|
+
* 1. Explicit user override (`PI_NO_SYNC_OUTPUT`/`PI_TUI_SYNC_OUTPUT=0` off,
|
|
78
|
+
* `PI_FORCE_SYNC_OUTPUT=1`/`PI_TUI_SYNC_OUTPUT=1` on).
|
|
79
|
+
* 2. Positive `TERM_FEATURES` advertisement (`Sy`) — survives SSH/mux wrapping.
|
|
80
|
+
* 3. Windows Terminal (1.24+) via `WT_SESSION`, on native win32 and the
|
|
81
|
+
* WSL/SSH-fronted host alike.
|
|
82
|
+
* 4. Known direct terminals with confirmed support. SSH does *not* disable —
|
|
83
|
+
* DEC 2026 passes through SSH when the outer terminal honors it.
|
|
84
|
+
* 5. Everything else starts off, including risky multiplexers; the runtime
|
|
85
|
+
* DECRQM probe upgrades any of them when the terminal actually reports
|
|
86
|
+
* `?2026` supported (current zellij, tmux master, foot, contour, mintty…).
|
|
87
|
+
*/
|
|
88
|
+
export declare function shouldEnableSynchronizedOutputByDefault(env?: NodeJS.ProcessEnv, terminalId?: TerminalId): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Whether the terminal applies Kitty-style DECCARA rectangular SGR changes
|
|
91
|
+
* (`CSI Pt ; Pl ; Pb ; Pr ; <sgr> $ r`) extended to background color, so large
|
|
92
|
+
* filled regions can be painted as rectangles instead of background-padded
|
|
93
|
+
* strings on every row.
|
|
94
|
+
*
|
|
95
|
+
* Verified against terminal sources rather than terminfo, because a bare
|
|
96
|
+
* `Cara`/DECCARA terminfo capability does not imply the Kitty SGR-background
|
|
97
|
+
* extension:
|
|
98
|
+
* - Kitty implements it for *all* SGR attributes including background (see
|
|
99
|
+
* kitty `docs/deccara.rst` and the `test_deccara` parser test).
|
|
100
|
+
* - Ghostty does NOT: its `CSI $ r` dispatch falls through to an "unknown CSI"
|
|
101
|
+
* warning and DECCARA/DECSACE are tracked as unsupported
|
|
102
|
+
* (ghostty-org/ghostty#632). Enabling it there would silently drop panel
|
|
103
|
+
* backgrounds, so ghostty stays on the padded-string fallback.
|
|
104
|
+
*
|
|
105
|
+
* Disabled under tmux/screen/zellij multiplexers — screen-coordinate rectangle
|
|
106
|
+
* protocols are not safe to assume through a multiplexer — and via the
|
|
107
|
+
* `PI_NO_DECCARA` kill switch. Pure helper for tests and `TERMINAL` construction.
|
|
108
|
+
*/
|
|
109
|
+
export declare function detectRectangularSgrSupport(terminalId: TerminalId, env?: NodeJS.ProcessEnv): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Resolve an explicit user override for OSC 8 hyperlinks. Returns `false` for
|
|
112
|
+
* an opt-out, `true` for a force-on, or `null` when the user has expressed no
|
|
113
|
+
* preference. Opt-out beats force-on so a kill switch is unambiguous, mirroring
|
|
114
|
+
* {@link synchronizedOutputUserOverride}.
|
|
115
|
+
*/
|
|
116
|
+
export declare function hyperlinksUserOverride(env?: NodeJS.ProcessEnv): boolean | null;
|
|
117
|
+
/**
|
|
118
|
+
* Whether OSC 8 hyperlinks should be enabled by default.
|
|
119
|
+
*
|
|
120
|
+
* Policy (highest precedence first):
|
|
121
|
+
* 1. Explicit user override (`PI_NO_HYPERLINKS=1` off, `PI_FORCE_HYPERLINKS=1`
|
|
122
|
+
* on). Opt-out wins ties.
|
|
123
|
+
* 2. Static terminal capability — terminals whose {@link TerminalInfo} marks
|
|
124
|
+
* `hyperlinks: false` (e.g. `base`) stay off unless the user forced on.
|
|
125
|
+
* 3. GNU screen's explicit session marker (`STY`) always off, even if tmux is
|
|
126
|
+
* also present: a screen layer anywhere in the path cannot forward OSC 8.
|
|
127
|
+
* 4. tmux session (`TMUX` set): enabled when tmux self-reports >= 3.4 via
|
|
128
|
+
* `TERM_PROGRAM_VERSION` (tmux 3.4 stores OSC 8 as a cell attribute and
|
|
129
|
+
* forwards it to outer terminals whose `terminal-features` include
|
|
130
|
+
* `hyperlinks`). Older or unknown versions stay off; on outer terminals
|
|
131
|
+
* without the feature configured, tmux silently drops the sequence —
|
|
132
|
+
* identical to today. Checked before the screen-family TERM heuristic
|
|
133
|
+
* because tmux's historical `default-terminal` is `screen-256color`, so
|
|
134
|
+
* `TERM=screen*` inside a tmux session must NOT short-circuit to off.
|
|
135
|
+
* 5. screen-family TERM without `TMUX` always off: screen never gained OSC 8
|
|
136
|
+
* support.
|
|
137
|
+
* 6. tmux-family TERM without `TMUX` env — unusual (e.g. inspection scripts);
|
|
138
|
+
* no version available, so off.
|
|
139
|
+
* 7. Otherwise honor the static terminal capability.
|
|
140
|
+
*/
|
|
141
|
+
export declare function shouldEnableHyperlinksByDefault(env?: NodeJS.ProcessEnv, terminalId?: TerminalId): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Warp implements the Kitty graphics protocol only on macOS/Linux; its Windows
|
|
144
|
+
* build (including Warp-hosted WSL shells) renders the same APC sequences as
|
|
145
|
+
* visible garbage. Keep platform/env injectable so the carve-out is testable
|
|
146
|
+
* without mutating `process.platform`.
|
|
147
|
+
*/
|
|
148
|
+
export declare function resolveWarpImageProtocol(platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv): ImageProtocol | null;
|
|
149
|
+
/** Resolve terminal identity from environment markers used by common emulators. */
|
|
150
|
+
export declare function detectTerminalId(env?: NodeJS.ProcessEnv): TerminalId;
|
|
151
|
+
export declare const TERMINAL_ID: TerminalId;
|
|
152
|
+
/**
|
|
153
|
+
* The process-wide {@link TERMINAL} singleton: a {@link TerminalInfo} whose
|
|
154
|
+
* post-construction capabilities — the image protocol and the probe-driven
|
|
155
|
+
* flags — are writable, so the runtime setters and tests mutate them directly
|
|
156
|
+
* instead of through an unsound cast. Every other field stays readonly.
|
|
157
|
+
*/
|
|
158
|
+
export interface RuntimeTerminal extends TerminalInfo {
|
|
159
|
+
imageProtocol: ImageProtocol | null;
|
|
160
|
+
hyperlinks: boolean;
|
|
161
|
+
deccara: boolean;
|
|
162
|
+
supportsScreenToScrollback: boolean;
|
|
163
|
+
textSizing: boolean;
|
|
164
|
+
}
|
|
165
|
+
export declare const TERMINAL: RuntimeTerminal;
|
|
166
|
+
/**
|
|
167
|
+
* Override terminal image protocol at runtime after capability probes complete.
|
|
168
|
+
*/
|
|
169
|
+
export declare function setTerminalImageProtocol(imageProtocol: ImageProtocol | null): void;
|
|
170
|
+
/**
|
|
171
|
+
* Override DECCARA rectangular-SGR capability at runtime. Used by tests to
|
|
172
|
+
* exercise the optimizer and fallback paths deterministically — the default is
|
|
173
|
+
* resolved once at import and force-disabled under the test runtime.
|
|
174
|
+
*/
|
|
175
|
+
export declare function setTerminalDeccara(enabled: boolean): void;
|
|
176
|
+
/** Override screen-to-scrollback clear support for targeted renderer tests. */
|
|
177
|
+
export declare function setTerminalScreenToScrollback(enabled: boolean): void;
|
|
178
|
+
/**
|
|
179
|
+
* Enable/disable OSC 66 text-sizing at runtime. The coding-agent calls this from
|
|
180
|
+
* the `tui.textSizing` setting (gated on the terminal's static `textSizing`
|
|
181
|
+
* capability); tests flip it directly to exercise the scaled-heading path.
|
|
182
|
+
*/
|
|
183
|
+
export declare function setTerminalTextSizing(enabled: boolean): void;
|
|
184
|
+
export declare function getTerminalInfo(terminalId: TerminalId, platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv): TerminalInfo;
|
|
185
|
+
export interface CellDimensions {
|
|
186
|
+
widthPx: number;
|
|
187
|
+
heightPx: number;
|
|
188
|
+
}
|
|
189
|
+
export interface ImageDimensions {
|
|
190
|
+
widthPx: number;
|
|
191
|
+
heightPx: number;
|
|
192
|
+
}
|
|
193
|
+
export interface ImageRenderOptions {
|
|
194
|
+
maxWidthCells?: number;
|
|
195
|
+
maxHeightCells?: number;
|
|
196
|
+
preserveAspectRatio?: boolean;
|
|
197
|
+
/**
|
|
198
|
+
* Stable Kitty image id (`i=`). When set, the image is displayed via a
|
|
199
|
+
* transmit-once + placement scheme keyed off this id instead of re-sending the
|
|
200
|
+
* base64 each frame.
|
|
201
|
+
*/
|
|
202
|
+
imageId?: number;
|
|
203
|
+
/** Stable Kitty placement id (`p=`); defaults to {@link imageId}. */
|
|
204
|
+
placementId?: number;
|
|
205
|
+
/** When true (Kitty + {@link imageId}), also return the one-time transmit sequence. */
|
|
206
|
+
includeTransmit?: boolean;
|
|
207
|
+
}
|
|
208
|
+
export declare function getCellDimensions(): CellDimensions;
|
|
209
|
+
export declare function setCellDimensions(dims: CellDimensions): void;
|
|
210
|
+
/** Transmit-and-display (`a=T`) — the self-contained form used when no stable id is available. */
|
|
211
|
+
export declare function encodeKitty(base64Data: string, options?: {
|
|
212
|
+
columns?: number;
|
|
213
|
+
rows?: number;
|
|
214
|
+
imageId?: number;
|
|
215
|
+
}): string;
|
|
216
|
+
/**
|
|
217
|
+
* Transmit image data only (`a=t`), keyed by `imageId`, without displaying it.
|
|
218
|
+
* Sent once per image; the data then persists in the terminal's store (it
|
|
219
|
+
* survives scroll-off and text clears for images with a non-zero id), so
|
|
220
|
+
* subsequent frames display it with the tiny {@link encodeKittyPlacement}
|
|
221
|
+
* sequence instead of re-sending the base64.
|
|
222
|
+
*/
|
|
223
|
+
export declare function encodeKittyTransmit(base64Data: string, imageId: number): string;
|
|
224
|
+
/**
|
|
225
|
+
* Display a previously transmitted image (`a=p`) at the cursor. `C=1` keeps
|
|
226
|
+
* the terminal cursor anchored at the placement origin so the renderer's
|
|
227
|
+
* explicit cursor movement remains the only row accounting. Carrying a stable
|
|
228
|
+
* `placementId` (`p=`) means re-emitting the sequence on a repaint *replaces*
|
|
229
|
+
* the existing placement (moving/resizing it without flicker) rather than
|
|
230
|
+
* stacking a duplicate.
|
|
231
|
+
*/
|
|
232
|
+
export declare function encodeKittyPlacement(options: {
|
|
233
|
+
imageId: number;
|
|
234
|
+
placementId?: number;
|
|
235
|
+
columns?: number;
|
|
236
|
+
rows?: number;
|
|
237
|
+
}): string;
|
|
238
|
+
/**
|
|
239
|
+
* Kitty graphics delete command for a single image id. Uses `d=I` (capital)
|
|
240
|
+
* which removes the image and every one of its placements — on screen *and* in
|
|
241
|
+
* scrollback — and frees the backing data. `q=2` suppresses the terminal reply.
|
|
242
|
+
* Text-clearing escapes (`CSI 2 J` / `CSI 3 J`) do not remove Kitty graphics, so
|
|
243
|
+
* this is the only way to actually purge a placed image.
|
|
244
|
+
*/
|
|
245
|
+
export declare function encodeKittyDeleteImage(imageId: number): string;
|
|
246
|
+
export declare function encodeITerm2(base64Data: string, options?: {
|
|
247
|
+
width?: number | string;
|
|
248
|
+
height?: number | string;
|
|
249
|
+
name?: string;
|
|
250
|
+
preserveAspectRatio?: boolean;
|
|
251
|
+
inline?: boolean;
|
|
252
|
+
}): string;
|
|
253
|
+
export declare function calculateImageRows(imageDimensions: ImageDimensions, targetWidthCells: number, cellDimensions?: CellDimensions): number;
|
|
254
|
+
export declare function getPngDimensions(base64Data: string): ImageDimensions | null;
|
|
255
|
+
export declare function getJpegDimensions(base64Data: string): ImageDimensions | null;
|
|
256
|
+
export declare function getGifDimensions(base64Data: string): ImageDimensions | null;
|
|
257
|
+
export declare function getWebpDimensions(base64Data: string): ImageDimensions | null;
|
|
258
|
+
export declare function getImageDimensions(base64Data: string, mimeType: string): ImageDimensions | null;
|
|
259
|
+
export declare function renderImage(base64Data: string, imageDimensions: ImageDimensions, options?: ImageRenderOptions): {
|
|
260
|
+
sequence?: string;
|
|
261
|
+
lines?: string[];
|
|
262
|
+
rows: number;
|
|
263
|
+
transmit?: string;
|
|
264
|
+
} | null;
|
|
265
|
+
export declare function imageFallback(mimeType: string, dimensions?: ImageDimensions, filename?: string): string;
|
|
266
|
+
/**
|
|
267
|
+
* Structured terminal notification. Rich fields are honored only by OSC 99
|
|
268
|
+
* (Kitty) once support is confirmed; other protocols and the unconfirmed Kitty
|
|
269
|
+
* path collapse to a single `title: body` line.
|
|
270
|
+
*/
|
|
271
|
+
export interface TerminalNotification {
|
|
272
|
+
title?: string;
|
|
273
|
+
body?: string;
|
|
274
|
+
id?: string;
|
|
275
|
+
type?: string | string[];
|
|
276
|
+
urgency?: "low" | "normal" | "critical";
|
|
277
|
+
iconName?: string;
|
|
278
|
+
sound?: "silent" | "system" | "info" | "warning" | "error" | "question";
|
|
279
|
+
actions?: "focus" | "report" | "focus-report" | "none";
|
|
280
|
+
expiresMs?: number;
|
|
281
|
+
}
|
|
282
|
+
/** Record the OSC 99 capability-probe result (called by ProcessTerminal). */
|
|
283
|
+
export declare function setOsc99Supported(supported: boolean): void;
|
|
284
|
+
/** True when OSC 99 structured notifications have been confirmed available. */
|
|
285
|
+
export declare function isOsc99Supported(): boolean;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Split `data` into chunks whose encoded UTF-8 byte length is no greater than
|
|
3
|
+
* `maxChunkBytes`, preferring a line boundary (`\n`) as the cut point so
|
|
4
|
+
* escape sequences (which never contain `\n`) stay intact. The TUI's
|
|
5
|
+
* full-paint buffers are line-structured (`buffer += "\r\n"` between rows),
|
|
6
|
+
* so a newline almost always exists within the window. The fallback for a
|
|
7
|
+
* buffer with no newline in range is a hard cut at the last UTF-8 code-point
|
|
8
|
+
* boundary that still fits — the ConPTY viewport bug from a single oversized
|
|
9
|
+
* write is strictly worse than a one-frame escape-sequence glitch on a
|
|
10
|
+
* buffer the renderer effectively never produces.
|
|
11
|
+
*
|
|
12
|
+
* UTF-16 code units are walked manually rather than measuring with
|
|
13
|
+
* `Buffer.byteLength` per slice candidate: each code unit's UTF-8 width is
|
|
14
|
+
* known from its value (BMP `<0x80` → 1, `<0x800` → 2, surrogate pair → 4
|
|
15
|
+
* bytes across two units, other BMP → 3), and surrogate pairs are kept
|
|
16
|
+
* together so the chunker never splits a non-BMP character.
|
|
17
|
+
*
|
|
18
|
+
* Exported for unit testing of the chunking contract; `#safeWrite` is the
|
|
19
|
+
* sole production caller.
|
|
20
|
+
*/
|
|
21
|
+
export declare function chunkForConPTY(data: string, maxChunkBytes?: number): string[];
|
|
22
|
+
/**
|
|
23
|
+
* Turns an unbounded, never-draining stdout writable buffer into a bounded
|
|
24
|
+
* disconnect signal.
|
|
25
|
+
*
|
|
26
|
+
* `process.stdout.write()` returns `false` once its buffer exceeds the stream
|
|
27
|
+
* high-water mark; the bytes stay queued and are only freed when the consumer
|
|
28
|
+
* drains (the `drain` event). While the consumer keeps up, writes are accepted
|
|
29
|
+
* and nothing accumulates. When it stalls, every subsequent write piles onto
|
|
30
|
+
* the buffer — a stalled-but-alive PTY reader never throws, so the write path
|
|
31
|
+
* has no other signal that output is going nowhere. This guard sums the bytes
|
|
32
|
+
* queued since backpressure began and reports when that backlog crosses the
|
|
33
|
+
* cap, at which point the caller treats the terminal as disconnected.
|
|
34
|
+
*
|
|
35
|
+
* Exported for unit testing; `ProcessTerminal` is the sole production user.
|
|
36
|
+
*/
|
|
37
|
+
export declare class OutputBacklogGuard {
|
|
38
|
+
#private;
|
|
39
|
+
private readonly capBytes;
|
|
40
|
+
constructor(capBytes?: number);
|
|
41
|
+
/** True once a refused write started a backlog that has not yet drained. */
|
|
42
|
+
get tracking(): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Record one `stdout.write()`: `accepted` is that call's return value and
|
|
45
|
+
* `bytes` its encoded size. Returns true when the pending backlog now
|
|
46
|
+
* exceeds the cap and the terminal should be treated as disconnected.
|
|
47
|
+
*/
|
|
48
|
+
record(accepted: boolean, bytes: number): boolean;
|
|
49
|
+
/** Called on the stdout `drain` event: the buffer emptied, backlog cleared. */
|
|
50
|
+
reset(): void;
|
|
51
|
+
}
|
|
52
|
+
/** Record alternate-screen state (called by the TUI on `?1049h`/`?1049l` writes). */
|
|
53
|
+
export declare function setAltScreenActive(active: boolean): void;
|
|
54
|
+
/**
|
|
55
|
+
* Emergency terminal restore - call this from signal/crash handlers
|
|
56
|
+
* Resets terminal state without requiring access to the ProcessTerminal instance
|
|
57
|
+
*/
|
|
58
|
+
export declare function emergencyTerminalRestore(): void;
|
|
59
|
+
/** Terminal-reported appearance (dark/light mode). */
|
|
60
|
+
export type TerminalAppearance = "dark" | "light";
|
|
61
|
+
/** Identity of an accepted explicit terminal appearance refresh request. */
|
|
62
|
+
export type TerminalAppearanceRequestToken = number;
|
|
63
|
+
export interface Terminal {
|
|
64
|
+
start(onInput: (data: string) => void, onResize: () => void, onDisconnect?: () => void): void;
|
|
65
|
+
stop(): void;
|
|
66
|
+
/**
|
|
67
|
+
* Drain stdin before exiting to prevent Kitty key release events from
|
|
68
|
+
* leaking to the parent shell over slow SSH connections.
|
|
69
|
+
* @param maxMs - Maximum time to drain (default: 1000ms)
|
|
70
|
+
* @param idleMs - Exit early if no input arrives within this time (default: 50ms)
|
|
71
|
+
*/
|
|
72
|
+
drainInput(maxMs?: number, idleMs?: number): Promise<void>;
|
|
73
|
+
write(data: string): void;
|
|
74
|
+
get columns(): number;
|
|
75
|
+
get rows(): number;
|
|
76
|
+
get kittyProtocolActive(): boolean;
|
|
77
|
+
get kittyEnableSequence(): string | null;
|
|
78
|
+
readonly keyboardEnhancementEnterSequence?: string | null;
|
|
79
|
+
readonly keyboardEnhancementExitSequence?: string | null;
|
|
80
|
+
moveBy(lines: number): void;
|
|
81
|
+
hideCursor(force?: boolean): void;
|
|
82
|
+
showCursor(force?: boolean): void;
|
|
83
|
+
clearLine(): void;
|
|
84
|
+
clearFromCursor(): void;
|
|
85
|
+
clearScreen(): void;
|
|
86
|
+
setTitle(title: string): void;
|
|
87
|
+
setProgress(active: boolean): void;
|
|
88
|
+
/**
|
|
89
|
+
* Register a callback for terminal appearance (dark/light) changes.
|
|
90
|
+
* Detection uses OSC 11 background color query with Mode 2031 as a change trigger.
|
|
91
|
+
* Fires when the detected appearance changes, including the initial detection.
|
|
92
|
+
* Subscribers registered after detection are invoked immediately with the
|
|
93
|
+
* already-detected appearance so late subscribers never miss it.
|
|
94
|
+
*/
|
|
95
|
+
onAppearanceChange(callback: (appearance: TerminalAppearance, requestToken?: TerminalAppearanceRequestToken) => void): void;
|
|
96
|
+
/**
|
|
97
|
+
* Register a callback fired for every valid OSC 11 appearance report,
|
|
98
|
+
* including reports whose classification matches the current appearance.
|
|
99
|
+
* Unlike onAppearanceChange, this does not replay an earlier report.
|
|
100
|
+
* Optional so custom Terminals built against older pi-tui versions keep working.
|
|
101
|
+
*/
|
|
102
|
+
onAppearanceReport?(callback: (appearance: TerminalAppearance, requestToken?: TerminalAppearanceRequestToken) => void): (() => void) | void;
|
|
103
|
+
/**
|
|
104
|
+
* Start a bounded OSC 11 background-color refresh cycle, driving appearance
|
|
105
|
+
* callbacks through the same parse/dedup pipeline used at startup and on Mode
|
|
106
|
+
* 2031 notifications. Direct terminals need one query; tmux needs a
|
|
107
|
+
* passthrough query to update its cache followed by one delayed direct cache
|
|
108
|
+
* read. Invoked on the user's explicit display-reset gesture so terminals
|
|
109
|
+
* without end-to-end Mode 2031 notifications pick up a light/dark switch
|
|
110
|
+
* without a restart. No periodic probes are armed.
|
|
111
|
+
*
|
|
112
|
+
* A caller-provided token must be propagated unchanged to callbacks and
|
|
113
|
+
* returned when the request is accepted. This lets callers establish ownership
|
|
114
|
+
* before implementations synchronously dispatch a cached response. Optional so
|
|
115
|
+
* custom Terminals built against older pi-tui versions keep working.
|
|
116
|
+
*/
|
|
117
|
+
refreshAppearance?(requestToken?: TerminalAppearanceRequestToken): TerminalAppearanceRequestToken | void;
|
|
118
|
+
/** The last detected terminal appearance, or undefined if not yet known. */
|
|
119
|
+
get appearance(): TerminalAppearance | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* Register a callback fired once per DEC private mode when its DECRQM support
|
|
122
|
+
* status resolves. `confirmed` is false when the terminal answered the DA1
|
|
123
|
+
* sentinel without answering DECRQM, which proves only that querying support
|
|
124
|
+
* is unavailable — not that the private mode itself is unsupported.
|
|
125
|
+
*/
|
|
126
|
+
onPrivateModeReport?(callback: (mode: number, supported: boolean, confirmed?: boolean) => void): void;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* True when stdout flows through a ConPTY pseudo-console (native win32, or
|
|
130
|
+
* Linux running under WSL where stdout still crosses into ConPTY at the
|
|
131
|
+
* `wslhost` boundary). ConPTY hosts share the per-WriteFile viewport-tracking
|
|
132
|
+
* quirks documented above and on {@link MAX_CONPTY_WRITE_CHUNK_BYTES}, so both
|
|
133
|
+
* `#safeWrite` and the renderer's post-big-paint settle gate hang off this
|
|
134
|
+
* single predicate.
|
|
135
|
+
*/
|
|
136
|
+
export declare function isConPTYHosted(): boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Real terminal using process.stdin/stdout
|
|
139
|
+
*/
|
|
140
|
+
export declare class ProcessTerminal implements Terminal {
|
|
141
|
+
#private;
|
|
142
|
+
get kittyProtocolActive(): boolean;
|
|
143
|
+
get kittyEnableSequence(): string | null;
|
|
144
|
+
get keyboardEnhancementEnterSequence(): string | null;
|
|
145
|
+
get keyboardEnhancementExitSequence(): string | null;
|
|
146
|
+
get appearance(): TerminalAppearance | undefined;
|
|
147
|
+
onAppearanceChange(callback: (appearance: TerminalAppearance, requestToken?: TerminalAppearanceRequestToken) => void): void;
|
|
148
|
+
onAppearanceReport(callback: (appearance: TerminalAppearance, requestToken?: TerminalAppearanceRequestToken) => void): () => void;
|
|
149
|
+
/**
|
|
150
|
+
* Re-query the terminal background through the startup DA1-sentinel FIFO,
|
|
151
|
+
* pending/queued gating, parsing, dedup, and appearance callbacks. Inside
|
|
152
|
+
* tmux, only this explicit path first passes an OSC 11 query to the outer
|
|
153
|
+
* terminal, waits briefly for tmux to consume the response into its cache,
|
|
154
|
+
* then reads that cache with a direct query. The outer query deliberately has
|
|
155
|
+
* no DA1 sentinel: multiplexers can decode a fragmented DA1 response as a key
|
|
156
|
+
* sequence and leak the remaining bytes into the editor. Startup and Mode 2031
|
|
157
|
+
* probes remain direct. Suppressed while inactive, headless, or after teardown.
|
|
158
|
+
*/
|
|
159
|
+
refreshAppearance(requestToken?: TerminalAppearanceRequestToken): TerminalAppearanceRequestToken | void;
|
|
160
|
+
onPrivateModeReport(callback: (mode: number, supported: boolean, confirmed?: boolean) => void): void;
|
|
161
|
+
start(onInput: (data: string) => void, onResize: () => void, onDisconnect?: () => void): void;
|
|
162
|
+
drainInput(maxMs?: number, idleMs?: number): Promise<void>;
|
|
163
|
+
stop(): void;
|
|
164
|
+
write(data: string): void;
|
|
165
|
+
get columns(): number;
|
|
166
|
+
get rows(): number;
|
|
167
|
+
moveBy(lines: number): void;
|
|
168
|
+
hideCursor(force?: boolean): void;
|
|
169
|
+
showCursor(force?: boolean): void;
|
|
170
|
+
clearLine(): void;
|
|
171
|
+
clearFromCursor(): void;
|
|
172
|
+
clearScreen(): void;
|
|
173
|
+
setTitle(title: string): void;
|
|
174
|
+
setProgress(active: boolean): void;
|
|
175
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Whether the process is running inside a tmux session. */
|
|
2
|
+
export declare function isInsideTmux(env?: NodeJS.ProcessEnv): boolean;
|
|
3
|
+
/** Wrap a control sequence in tmux's DCS passthrough envelope. */
|
|
4
|
+
export declare function wrapTmuxPassthrough(payload: string): string;
|
|
5
|
+
/** Pass a control sequence through tmux, leaving direct-terminal output unchanged. */
|
|
6
|
+
export declare function wrapTmuxPassthroughIfNeeded(payload: string, env?: NodeJS.ProcessEnv): string;
|
|
@@ -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;
|