@linxiraos/pi-tui 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -1
- package/THIRD-PARTY-NOTICES.txt +22909 -0
- package/dist/types/autocomplete.d.ts +127 -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/composer/borderless.d.ts +8 -0
- package/dist/types/components/composer/box.d.ts +2 -0
- package/dist/types/components/composer/claude.d.ts +8 -0
- package/dist/types/components/composer/field.d.ts +3 -0
- package/dist/types/components/composer/index.d.ts +9 -0
- package/dist/types/components/composer/pi.d.ts +2 -0
- package/dist/types/components/composer/rail.d.ts +3 -0
- package/dist/types/components/composer/registry.d.ts +12 -0
- package/dist/types/components/composer/rule.d.ts +7 -0
- package/dist/types/components/composer/types.d.ts +90 -0
- package/dist/types/components/editor.d.ts +213 -0
- package/dist/types/components/image.d.ts +162 -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 +86 -0
- package/dist/types/components/scroll-view.d.ts +62 -0
- package/dist/types/components/select-list.d.ts +78 -0
- package/dist/types/components/settings-list.d.ts +129 -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 +33 -0
- package/dist/types/keybindings.d.ts +202 -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 +49 -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 +338 -0
- package/dist/types/terminal.d.ts +215 -0
- package/dist/types/tmux.d.ts +6 -0
- package/dist/types/ttyid.d.ts +9 -0
- package/dist/types/tui.d.ts +332 -0
- package/dist/types/utils.d.ts +112 -0
- package/package.json +71 -68
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyboard input handling for terminal applications.
|
|
3
|
+
*
|
|
4
|
+
* Supports both legacy terminal sequences and Kitty keyboard protocol.
|
|
5
|
+
* See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/
|
|
6
|
+
* Reference: https://github.com/sst/opentui/blob/7da92b4088aebfe27b9f691c04163a48821e49fd/packages/core/src/lib/parse.keypress.ts
|
|
7
|
+
*
|
|
8
|
+
* Symbol keys are also supported, however some ctrl+symbol combos
|
|
9
|
+
* overlap with ASCII codes, e.g. ctrl+[ = ESC.
|
|
10
|
+
* See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/#legacy-ctrl-mapping-of-ascii-keys
|
|
11
|
+
* Those can still be * used for ctrl+shift combos
|
|
12
|
+
*
|
|
13
|
+
* API:
|
|
14
|
+
* - matchesKey(data, keyId) - Check if input matches a key identifier
|
|
15
|
+
* - parseKey(data) - Parse input and return the key identifier
|
|
16
|
+
* - Key - Helper object for creating typed key identifiers
|
|
17
|
+
* - setKittyProtocolActive(active) - Set global Kitty protocol state
|
|
18
|
+
* - isKittyProtocolActive() - Query global Kitty protocol state
|
|
19
|
+
*/
|
|
20
|
+
import type { KeyEventType } from "@linxiraos/pi-natives";
|
|
21
|
+
/** Whether the local process is running directly under Windows Terminal. */
|
|
22
|
+
export declare function isWindowsTerminalSession(): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Match ambiguous legacy Backspace bytes against an expected modifier mask.
|
|
25
|
+
*
|
|
26
|
+
* Windows Terminal encodes Ctrl+Backspace as raw `0x08` (BS) and plain
|
|
27
|
+
* Backspace as `0x7f` (DEL). Remote/container sessions lose terminal identity,
|
|
28
|
+
* and multiplexers (tmux/screen/Zellij) inherit `WT_SESSION` while emitting
|
|
29
|
+
* raw `0x08` for plain Backspace themselves, so the automatic heuristic is
|
|
30
|
+
* limited to direct Windows Terminal sessions. `PI_TUI_RAW_BACKSPACE_IS_CTRL=1`
|
|
31
|
+
* explicitly opts into the mapping everywhere.
|
|
32
|
+
*/
|
|
33
|
+
export declare function matchesRawBackspace(data: string, expectedModifier: number): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Set the global Kitty keyboard protocol state.
|
|
36
|
+
* Called by ProcessTerminal after detecting protocol support.
|
|
37
|
+
*/
|
|
38
|
+
export declare function setKittyProtocolActive(active: boolean): void;
|
|
39
|
+
/**
|
|
40
|
+
* Query whether Kitty keyboard protocol is currently active.
|
|
41
|
+
*/
|
|
42
|
+
export declare function isKittyProtocolActive(): boolean;
|
|
43
|
+
type Letter = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
|
|
44
|
+
type Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
45
|
+
type SymbolKey = "`" | "-" | "=" | "[" | "]" | "\\" | ";" | "'" | "," | "." | "/" | "!" | "@" | "#" | "$" | "%" | "^" | "&" | "*" | "(" | ")" | "_" | "+" | "|" | "~" | "{" | "}" | ":" | "<" | ">" | "?";
|
|
46
|
+
type SpecialKey = "escape" | "esc" | "enter" | "return" | "tab" | "space" | "backspace" | "delete" | "insert" | "clear" | "home" | "end" | "pageUp" | "pageDown" | "up" | "down" | "left" | "right" | "f1" | "f2" | "f3" | "f4" | "f5" | "f6" | "f7" | "f8" | "f9" | "f10" | "f11" | "f12";
|
|
47
|
+
type BaseKey = Letter | Digit | SymbolKey | SpecialKey;
|
|
48
|
+
type ModifierName = "ctrl" | "shift" | "alt" | "super";
|
|
49
|
+
type ModifiedKeyId<Key extends string, RemainingModifiers extends ModifierName = ModifierName> = {
|
|
50
|
+
[M in RemainingModifiers]: `${M}+${Key}` | `${M}+${ModifiedKeyId<Key, Exclude<RemainingModifiers, M>>}`;
|
|
51
|
+
}[RemainingModifiers];
|
|
52
|
+
/**
|
|
53
|
+
* Union type of all valid key identifiers.
|
|
54
|
+
* Provides autocomplete and catches typos at compile time.
|
|
55
|
+
*/
|
|
56
|
+
export type KeyId = BaseKey | ModifiedKeyId<BaseKey>;
|
|
57
|
+
/**
|
|
58
|
+
* Typed helper for constructing key identifiers with autocomplete.
|
|
59
|
+
*
|
|
60
|
+
* The runtime values are just the canonical key-name strings (so `Key.enter`
|
|
61
|
+
* is literally `"enter"`); the value of `Key` over a bag of magic strings is
|
|
62
|
+
* that each property is typed to the exact `KeyId` literal it produces and the
|
|
63
|
+
* modifier methods return precisely-typed concatenations (e.g. `Key.ctrl("c")`
|
|
64
|
+
* is `"ctrl+c"`, not just `string`). This mirrors the upstream
|
|
65
|
+
* `@mariozechner/pi-tui` `Key` export verbatim so plugins built against any
|
|
66
|
+
* scope alias (`@mariozechner`, `@earendil-works`, `@oh-my-pi`) keep working
|
|
67
|
+
* once the specifier shim remaps them to this package.
|
|
68
|
+
*/
|
|
69
|
+
export declare const Key: {
|
|
70
|
+
readonly escape: "escape";
|
|
71
|
+
readonly esc: "esc";
|
|
72
|
+
readonly enter: "enter";
|
|
73
|
+
readonly return: "return";
|
|
74
|
+
readonly tab: "tab";
|
|
75
|
+
readonly space: "space";
|
|
76
|
+
readonly backspace: "backspace";
|
|
77
|
+
readonly delete: "delete";
|
|
78
|
+
readonly insert: "insert";
|
|
79
|
+
readonly clear: "clear";
|
|
80
|
+
readonly home: "home";
|
|
81
|
+
readonly end: "end";
|
|
82
|
+
readonly pageUp: "pageUp";
|
|
83
|
+
readonly pageDown: "pageDown";
|
|
84
|
+
readonly up: "up";
|
|
85
|
+
readonly down: "down";
|
|
86
|
+
readonly left: "left";
|
|
87
|
+
readonly right: "right";
|
|
88
|
+
readonly f1: "f1";
|
|
89
|
+
readonly f2: "f2";
|
|
90
|
+
readonly f3: "f3";
|
|
91
|
+
readonly f4: "f4";
|
|
92
|
+
readonly f5: "f5";
|
|
93
|
+
readonly f6: "f6";
|
|
94
|
+
readonly f7: "f7";
|
|
95
|
+
readonly f8: "f8";
|
|
96
|
+
readonly f9: "f9";
|
|
97
|
+
readonly f10: "f10";
|
|
98
|
+
readonly f11: "f11";
|
|
99
|
+
readonly f12: "f12";
|
|
100
|
+
readonly backtick: "`";
|
|
101
|
+
readonly hyphen: "-";
|
|
102
|
+
readonly equals: "=";
|
|
103
|
+
readonly leftbracket: "[";
|
|
104
|
+
readonly rightbracket: "]";
|
|
105
|
+
readonly backslash: "\\";
|
|
106
|
+
readonly semicolon: ";";
|
|
107
|
+
readonly quote: "'";
|
|
108
|
+
readonly comma: ",";
|
|
109
|
+
readonly period: ".";
|
|
110
|
+
readonly slash: "/";
|
|
111
|
+
readonly exclamation: "!";
|
|
112
|
+
readonly at: "@";
|
|
113
|
+
readonly hash: "#";
|
|
114
|
+
readonly dollar: "$";
|
|
115
|
+
readonly percent: "%";
|
|
116
|
+
readonly caret: "^";
|
|
117
|
+
readonly ampersand: "&";
|
|
118
|
+
readonly asterisk: "*";
|
|
119
|
+
readonly leftparen: "(";
|
|
120
|
+
readonly rightparen: ")";
|
|
121
|
+
readonly underscore: "_";
|
|
122
|
+
readonly plus: "+";
|
|
123
|
+
readonly pipe: "|";
|
|
124
|
+
readonly tilde: "~";
|
|
125
|
+
readonly leftbrace: "{";
|
|
126
|
+
readonly rightbrace: "}";
|
|
127
|
+
readonly colon: ":";
|
|
128
|
+
readonly lessthan: "<";
|
|
129
|
+
readonly greaterthan: ">";
|
|
130
|
+
readonly question: "?";
|
|
131
|
+
readonly ctrl: <K extends BaseKey>(key: K) => `ctrl+${K}`;
|
|
132
|
+
readonly shift: <K extends BaseKey>(key: K) => `shift+${K}`;
|
|
133
|
+
readonly alt: <K extends BaseKey>(key: K) => `alt+${K}`;
|
|
134
|
+
readonly super: <K extends BaseKey>(key: K) => `super+${K}`;
|
|
135
|
+
readonly ctrlShift: <K extends BaseKey>(key: K) => `ctrl+shift+${K}`;
|
|
136
|
+
readonly shiftCtrl: <K extends BaseKey>(key: K) => `shift+ctrl+${K}`;
|
|
137
|
+
readonly ctrlAlt: <K extends BaseKey>(key: K) => `ctrl+alt+${K}`;
|
|
138
|
+
readonly altCtrl: <K extends BaseKey>(key: K) => `alt+ctrl+${K}`;
|
|
139
|
+
readonly shiftAlt: <K extends BaseKey>(key: K) => `shift+alt+${K}`;
|
|
140
|
+
readonly altShift: <K extends BaseKey>(key: K) => `alt+shift+${K}`;
|
|
141
|
+
readonly ctrlSuper: <K extends BaseKey>(key: K) => `ctrl+super+${K}`;
|
|
142
|
+
readonly superCtrl: <K extends BaseKey>(key: K) => `super+ctrl+${K}`;
|
|
143
|
+
readonly shiftSuper: <K extends BaseKey>(key: K) => `shift+super+${K}`;
|
|
144
|
+
readonly superShift: <K extends BaseKey>(key: K) => `super+shift+${K}`;
|
|
145
|
+
readonly altSuper: <K extends BaseKey>(key: K) => `alt+super+${K}`;
|
|
146
|
+
readonly superAlt: <K extends BaseKey>(key: K) => `super+alt+${K}`;
|
|
147
|
+
readonly ctrlShiftAlt: <K extends BaseKey>(key: K) => `ctrl+shift+alt+${K}`;
|
|
148
|
+
readonly ctrlShiftSuper: <K extends BaseKey>(key: K) => `ctrl+shift+super+${K}`;
|
|
149
|
+
};
|
|
150
|
+
interface ParsedKittySequence {
|
|
151
|
+
codepoint: number;
|
|
152
|
+
shiftedKey?: number;
|
|
153
|
+
baseLayoutKey?: number;
|
|
154
|
+
modifier: number;
|
|
155
|
+
eventType?: KeyEventType;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Check if the input is a key release event.
|
|
159
|
+
* Only meaningful when Kitty keyboard protocol with flag 2 is active.
|
|
160
|
+
* Returns false if Kitty protocol is not active.
|
|
161
|
+
*/
|
|
162
|
+
export declare function isKeyRelease(data: string): boolean;
|
|
163
|
+
/**
|
|
164
|
+
* Check if the input is a key repeat event.
|
|
165
|
+
* Only meaningful when Kitty keyboard protocol with flag 2 is active.
|
|
166
|
+
* Returns false if Kitty protocol is not active.
|
|
167
|
+
*/
|
|
168
|
+
export declare function isKeyRepeat(data: string): boolean;
|
|
169
|
+
export declare function parseKittySequence(data: string): ParsedKittySequence | null;
|
|
170
|
+
/**
|
|
171
|
+
* Extract printable text from raw terminal input.
|
|
172
|
+
*
|
|
173
|
+
* Handles Kitty CSI-u text-producing keys so text-entry components can treat
|
|
174
|
+
* keypad digits, keypad operators, and shifted symbols the same as direct character input.
|
|
175
|
+
*/
|
|
176
|
+
export declare function extractPrintableText(data: string): string | undefined;
|
|
177
|
+
/**
|
|
178
|
+
* Decode terminal input into the printable character it represents.
|
|
179
|
+
*
|
|
180
|
+
* Tries Kitty CSI-u first, then falls back to xterm modifyOtherKeys. Returns
|
|
181
|
+
* undefined for control sequences and modifier-only events.
|
|
182
|
+
*/
|
|
183
|
+
export declare function decodePrintableKey(data: string): string | undefined;
|
|
184
|
+
/**
|
|
185
|
+
* Match input data against a key identifier string.
|
|
186
|
+
*
|
|
187
|
+
* Supported key identifiers:
|
|
188
|
+
* - Single keys: "escape", "tab", "enter", "backspace", "delete", "home", "end", "space"
|
|
189
|
+
* - Arrow keys: "up", "down", "left", "right"
|
|
190
|
+
* - Ctrl combinations: "ctrl+c", "ctrl+z", etc.
|
|
191
|
+
* - Shift combinations: "shift+tab", "shift+enter"
|
|
192
|
+
* - Alt combinations: "alt+enter", "alt+backspace"
|
|
193
|
+
* - Combined modifiers: "shift+ctrl+p", "ctrl+alt+x"
|
|
194
|
+
*
|
|
195
|
+
* Use the Key helper for autocomplete: Key.ctrl("c"), Key.escape, Key.ctrlShift("p")
|
|
196
|
+
*
|
|
197
|
+
* @param data - Raw input data from terminal
|
|
198
|
+
* @param keyId - Key identifier (e.g., "ctrl+c", "escape", Key.ctrl("c"))
|
|
199
|
+
*/
|
|
200
|
+
export declare function matchesKey(data: string, keyId: KeyId): boolean;
|
|
201
|
+
/**
|
|
202
|
+
* Parse terminal input and return a normalized key identifier.
|
|
203
|
+
*
|
|
204
|
+
* Returns key names like "escape", "ctrl+c", "shift+tab", "alt+enter".
|
|
205
|
+
* Returns undefined if the input is not a recognized key sequence.
|
|
206
|
+
*
|
|
207
|
+
* @param data - Raw input data from terminal
|
|
208
|
+
*/
|
|
209
|
+
export declare function parseKey(data: string): string | undefined;
|
|
210
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare class KillRing {
|
|
2
|
+
#private;
|
|
3
|
+
/**
|
|
4
|
+
* Add text to the kill ring.
|
|
5
|
+
*
|
|
6
|
+
* @param text - The killed text to add
|
|
7
|
+
* @param opts - Push options
|
|
8
|
+
* @param opts.prepend - If accumulating, prepend (backward deletion) or append (forward deletion)
|
|
9
|
+
* @param opts.accumulate - Merge with the most recent entry instead of creating a new one
|
|
10
|
+
*/
|
|
11
|
+
push(text: string, opts: {
|
|
12
|
+
prepend: boolean;
|
|
13
|
+
accumulate?: boolean;
|
|
14
|
+
}): void;
|
|
15
|
+
/** Get most recent entry without modifying the ring. */
|
|
16
|
+
peek(): string | undefined;
|
|
17
|
+
/** Move last entry to front (for yank-pop cycling). */
|
|
18
|
+
rotate(): void;
|
|
19
|
+
get length(): number;
|
|
20
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kitty graphics: Unicode placeholder placement (`U=1` + U+10EEEE), with
|
|
3
|
+
* runtime feature state and env overrides.
|
|
4
|
+
*
|
|
5
|
+
* Unicode placeholders let a transmitted image be displayed by writing ordinary
|
|
6
|
+
* text cells — the placeholder char U+10EEEE plus row/column combining
|
|
7
|
+
* diacritics — instead of a cursor-positioned `a=p` direct placement. The image
|
|
8
|
+
* then participates in the normal text grid, so it survives horizontal slicing,
|
|
9
|
+
* reflow and overlapping draws (each cell names its own row+column, so a sliced
|
|
10
|
+
* row still maps to the correct sub-region). See kitty
|
|
11
|
+
* `docs/graphics-protocol.rst` "Unicode placeholders for relative placements".
|
|
12
|
+
*
|
|
13
|
+
* This module is intentionally free of `./terminal-capabilities` imports so the
|
|
14
|
+
* dependency stays one-way (capabilities → kitty-graphics) and no import cycle
|
|
15
|
+
* forms. Protocol gating (`imageProtocol === Kitty`) lives in the caller.
|
|
16
|
+
*/
|
|
17
|
+
/** Kitty Unicode placeholder base character (U+10EEEE, Plane 16 PUA). */
|
|
18
|
+
export declare const KITTY_PLACEHOLDER = "\uDBFB\uDEEE";
|
|
19
|
+
/** Largest row/column index expressible with the diacritic table (one cell each). */
|
|
20
|
+
export declare const KITTY_PLACEHOLDER_MAX_CELLS: number;
|
|
21
|
+
export interface KittyGraphicsFeatures {
|
|
22
|
+
/** Display images via Unicode placeholders instead of direct `a=p` placement. */
|
|
23
|
+
unicodePlaceholders: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Whether the detected terminal renders Kitty Unicode placeholders (`U=1` +
|
|
27
|
+
* U+10EEEE with row/column diacritics).
|
|
28
|
+
*
|
|
29
|
+
* Kitty and Ghostty advertise placeholder support directly. A tmux session
|
|
30
|
+
* cannot use cursor-positioned placements because the outer terminal does not
|
|
31
|
+
* know pane scroll/reflow state, so an explicit `PI_FORCE_IMAGE_PROTOCOL=kitty`
|
|
32
|
+
* also opts into placeholders there — matching `timg -pk`. Automatic tmux
|
|
33
|
+
* fallback stays off because the unknown outer terminal may render U+10EEEE as
|
|
34
|
+
* literal PUA boxes (#1877).
|
|
35
|
+
*
|
|
36
|
+
* `PI_NO_KITTY_PLACEHOLDERS=1` and `PI_KITTY_PLACEHOLDERS=0` remain hard
|
|
37
|
+
* opt-outs; `PI_KITTY_PLACEHOLDERS=1` explicitly opts in anywhere else.
|
|
38
|
+
*/
|
|
39
|
+
export declare function detectKittyUnicodePlaceholdersSupport(terminalId: string, env?: NodeJS.ProcessEnv): boolean;
|
|
40
|
+
export declare function getKittyGraphics(): Readonly<KittyGraphicsFeatures>;
|
|
41
|
+
export declare function setKittyGraphics(partial: Partial<KittyGraphicsFeatures>): void;
|
|
42
|
+
/** Whether a `columns`×`rows` placeholder grid fits within the diacritic table. */
|
|
43
|
+
export declare function kittyPlaceholdersFit(columns: number, rows: number): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Virtual placement APC (`a=p,U=1`): tells the terminal that placeholder cells
|
|
46
|
+
* carrying image id `i` should display the transmitted image, scaled to fit the
|
|
47
|
+
* `c`×`r` cell box. Re-emitting with a stable `placementId` replaces in place.
|
|
48
|
+
*/
|
|
49
|
+
export declare function encodeKittyVirtualPlacement(opts: {
|
|
50
|
+
imageId: number;
|
|
51
|
+
placementId?: number;
|
|
52
|
+
columns: number;
|
|
53
|
+
rows: number;
|
|
54
|
+
}): string;
|
|
55
|
+
/**
|
|
56
|
+
* Build the placeholder cell grid as one string per row. The image id is carried
|
|
57
|
+
* in each row's foreground color and the placement id (if any) in its underline
|
|
58
|
+
* color; every cell names its explicit row+column diacritic (robust to slicing,
|
|
59
|
+
* unlike left-inheritance). Returns exactly `rows` strings.
|
|
60
|
+
*/
|
|
61
|
+
export declare function encodeKittyPlaceholderGrid(opts: {
|
|
62
|
+
imageId: number;
|
|
63
|
+
placementId?: number;
|
|
64
|
+
columns: number;
|
|
65
|
+
rows: number;
|
|
66
|
+
}): string[];
|
|
67
|
+
/**
|
|
68
|
+
* Full placeholder render: the virtual-placement APC prefixes line 0, and every
|
|
69
|
+
* line carries placeholder cells. Returns exactly `rows` lines (no cursor moves).
|
|
70
|
+
*/
|
|
71
|
+
export declare function renderKittyPlaceholderLines(opts: {
|
|
72
|
+
imageId: number;
|
|
73
|
+
placementId?: number;
|
|
74
|
+
columns: number;
|
|
75
|
+
rows: number;
|
|
76
|
+
}): string[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render a display LaTeX math fragment to lines with full 2-D layout: stacked
|
|
3
|
+
* fractions, stretchy delimiters, matrix grids, operator limits, drawn
|
|
4
|
+
* radicals. Top-level source newlines and `\\` become vertical rows (so a
|
|
5
|
+
* `lhs =` line stays above its block). Inline math should use `latexToUnicode`
|
|
6
|
+
* instead — fractions there stay single-line.
|
|
7
|
+
*/
|
|
8
|
+
export declare function latexToBlock(src: string): string[];
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Math font command names (`\mathbf`, `\mathbb`, …) whose single brace argument
|
|
3
|
+
* restyles glyphs. Exported for the display block engine (`latex-block`), which
|
|
4
|
+
* re-wraps inline runs inside these commands when their argument contains 2-D
|
|
5
|
+
* layout (fractions, matrices) so styling survives box boundaries.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MATH_FONT_COMMANDS: ReadonlySet<string>;
|
|
8
|
+
/**
|
|
9
|
+
* Painter for a LaTeX color scope (optional model + spec, e.g. `rgb`/`1,0,0` or
|
|
10
|
+
* `red`): returns a function that paints already-rendered text with the scope's
|
|
11
|
+
* foreground, re-asserting it after embedded foreground resets so nested color
|
|
12
|
+
* runs restore to the scope color; null when the color cannot be resolved. Used
|
|
13
|
+
* by the display block engine (`latex-block`) to paint structural glyphs
|
|
14
|
+
* (fraction bars, stretched delimiters, matrix brackets) inside
|
|
15
|
+
* `\color`/`\textcolor` scopes.
|
|
16
|
+
*/
|
|
17
|
+
export declare function latexColorScope(model: string | null, spec: string): ((text: string) => string) | null;
|
|
18
|
+
/**
|
|
19
|
+
* Convert a bare LaTeX math fragment (no surrounding `$`/`\(` delimiters) to its
|
|
20
|
+
* best-effort Unicode rendering. Unknown commands degrade to their bare name;
|
|
21
|
+
* `\\` becomes a newline. Always returns a string (never throws).
|
|
22
|
+
*/
|
|
23
|
+
export declare function latexToUnicode(src: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* True when `env` is a math environment safe to auto-render without `$`/`\[`
|
|
26
|
+
* delimiters. The trailing `*` of starred variants (`align*`, `equation*`) is
|
|
27
|
+
* ignored; text-mode environments (`tabular`, `itemize`, …) return false.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isBareMathEnvironment(env: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Scan prose for math spans — `$$…$$`, `\[…\]` (display) and `$…$`, `\(…\)`
|
|
32
|
+
* (inline) — and replace each with its Unicode rendering, leaving everything
|
|
33
|
+
* else verbatim. Newlines inside a span collapse to spaces so the result stays
|
|
34
|
+
* single-line-safe.
|
|
35
|
+
*
|
|
36
|
+
* Inline `$…$` uses pandoc's anti-currency heuristics: the opener must not be
|
|
37
|
+
* followed by whitespace, the closer must not be preceded by whitespace nor
|
|
38
|
+
* followed by a digit, and `\$` is treated as a literal dollar — so "$5 and
|
|
39
|
+
* $10" is left untouched.
|
|
40
|
+
*/
|
|
41
|
+
export declare function renderMathInText(text: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* Index of the `$` that closes an inline math span opened at `open` (the index
|
|
44
|
+
* of the opening `$`), or -1 when the run is not inline math. Applies pandoc's
|
|
45
|
+
* anti-currency heuristics: the opener must not be followed by whitespace, the
|
|
46
|
+
* closer must not be preceded by whitespace nor followed by a digit, `\$` is a
|
|
47
|
+
* literal dollar, and the span may not span a newline. Shared by
|
|
48
|
+
* `renderMathInText` and the markdown math tokenizer so the rule has one home.
|
|
49
|
+
*/
|
|
50
|
+
export declare function inlineMathSpanEnd(text: string, open: number): number;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export interface LoopWatchdogOptions {
|
|
2
|
+
/** How far ahead each probe tick is scheduled, in ms. Default 250. */
|
|
3
|
+
intervalMs?: number;
|
|
4
|
+
/** A tick later than this past its deadline counts as a block. Default 250. */
|
|
5
|
+
thresholdMs?: number;
|
|
6
|
+
/** Overshoot beyond this is suppressed only when the process burned negligible CPU. Default 60_000. */
|
|
7
|
+
sleepMs?: number;
|
|
8
|
+
/** Monotonic clock source; injectable for tests. Default `performance.now`. */
|
|
9
|
+
now?: () => number;
|
|
10
|
+
/** Process CPU time in ms; injectable for tests. Default `process.cpuUsage`. */
|
|
11
|
+
cpuNow?: () => number;
|
|
12
|
+
/** Timer source; injectable for tests. Default `setTimeout`. */
|
|
13
|
+
schedule?: (cb: () => void, ms: number) => LoopWatchdogTimer;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Timer handle the watchdog arms. `cancel`, when present, is invoked on stop()
|
|
17
|
+
* so a stopped watchdog leaves no armed timer to wake the loop even once.
|
|
18
|
+
*/
|
|
19
|
+
interface LoopWatchdogTimer {
|
|
20
|
+
unref?(): void;
|
|
21
|
+
cancel?(): void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Always-on event-loop lag probe. Each tick is scheduled `intervalMs` ahead of
|
|
25
|
+
* a recorded deadline; a tick that fires `thresholdMs` past its deadline means
|
|
26
|
+
* the loop was blocked that long. The overshoot is logged once on the rising
|
|
27
|
+
* edge (one block ⇒ one line, deduped via `#wasBlocked`), tagged with the phase
|
|
28
|
+
* active during the elapsed interval via {@link takeRecentLoopPhase} — which
|
|
29
|
+
* survives the synchronous push/pop the instrumented hot paths do before this
|
|
30
|
+
* delayed tick can run — so the stall names its cause instead of "unknown".
|
|
31
|
+
*
|
|
32
|
+
* The handle is `unref`'d so the probe never keeps the process alive, and stop()
|
|
33
|
+
* cancels the armed timer when the handle exposes `cancel` (the default
|
|
34
|
+
* `setTimeout` handle does, via `clearTimeout`). The `#generation` guard remains
|
|
35
|
+
* as a fallback for injected handles that cannot cancel.
|
|
36
|
+
*
|
|
37
|
+
* A long overshoot is classified by CPU time rather than by duration. System
|
|
38
|
+
* sleep and a CPU-bound wedge both produce an arbitrarily large gap, so duration
|
|
39
|
+
* alone cannot tell them apart, and suppressing on duration discards exactly the
|
|
40
|
+
* worst stalls. Only a gap the process spent negligible CPU on is treated as
|
|
41
|
+
* sleep. CPU accounting is process-wide, so worker activity errs toward logging.
|
|
42
|
+
*/
|
|
43
|
+
export declare class LoopWatchdog {
|
|
44
|
+
#private;
|
|
45
|
+
constructor(options?: LoopWatchdogOptions);
|
|
46
|
+
start(): void;
|
|
47
|
+
stop(): void;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
@@ -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
|
+
}
|