@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.
Files changed (77) hide show
  1. package/CHANGELOG.md +2219 -0
  2. package/README.md +705 -0
  3. package/dist/types/autocomplete.d.ts +116 -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 +162 -0
  8. package/dist/types/components/image.d.ts +112 -0
  9. package/dist/types/components/input.d.ts +25 -0
  10. package/dist/types/components/loader.d.ts +25 -0
  11. package/dist/types/components/markdown.d.ts +88 -0
  12. package/dist/types/components/scroll-view.d.ts +62 -0
  13. package/dist/types/components/select-list.d.ts +69 -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 +27 -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 +52 -0
  21. package/dist/types/editor-component.d.ts +38 -0
  22. package/dist/types/fuzzy.d.ts +48 -0
  23. package/dist/types/index.d.ts +32 -0
  24. package/dist/types/keybindings.d.ts +197 -0
  25. package/dist/types/keys.d.ts +210 -0
  26. package/dist/types/kill-ring.d.ts +20 -0
  27. package/dist/types/kitty-graphics.d.ts +76 -0
  28. package/dist/types/latex-block.d.ts +8 -0
  29. package/dist/types/latex-to-unicode.d.ts +50 -0
  30. package/dist/types/loop-watchdog.d.ts +44 -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 +285 -0
  35. package/dist/types/terminal.d.ts +175 -0
  36. package/dist/types/tmux.d.ts +6 -0
  37. package/dist/types/ttyid.d.ts +9 -0
  38. package/dist/types/tui.d.ts +457 -0
  39. package/dist/types/utils.d.ts +100 -0
  40. package/package.json +70 -0
  41. package/src/autocomplete.ts +1079 -0
  42. package/src/bracketed-paste.ts +123 -0
  43. package/src/components/box.ts +236 -0
  44. package/src/components/cancellable-loader.ts +40 -0
  45. package/src/components/editor.ts +3301 -0
  46. package/src/components/image.ts +460 -0
  47. package/src/components/input.ts +482 -0
  48. package/src/components/loader.ts +174 -0
  49. package/src/components/markdown.ts +3119 -0
  50. package/src/components/scroll-view.ts +227 -0
  51. package/src/components/select-list.ts +539 -0
  52. package/src/components/settings-list.ts +793 -0
  53. package/src/components/spacer.ts +32 -0
  54. package/src/components/tab-bar.ts +300 -0
  55. package/src/components/text.ts +173 -0
  56. package/src/components/truncated-text.ts +69 -0
  57. package/src/deccara.ts +314 -0
  58. package/src/desktop-notify.ts +192 -0
  59. package/src/editor-component.ts +74 -0
  60. package/src/fuzzy.ts +384 -0
  61. package/src/index.ts +51 -0
  62. package/src/keybindings.ts +346 -0
  63. package/src/keys.ts +566 -0
  64. package/src/kill-ring.ts +51 -0
  65. package/src/kitty-graphics.ts +171 -0
  66. package/src/latex-block.ts +1338 -0
  67. package/src/latex-to-unicode.ts +2017 -0
  68. package/src/loop-watchdog.ts +115 -0
  69. package/src/mouse.ts +105 -0
  70. package/src/stdin-buffer.ts +781 -0
  71. package/src/symbols.ts +26 -0
  72. package/src/terminal-capabilities.ts +1211 -0
  73. package/src/terminal.ts +1854 -0
  74. package/src/tmux.ts +14 -0
  75. package/src/ttyid.ts +84 -0
  76. package/src/tui.ts +4275 -0
  77. package/src/utils.ts +619 -0
@@ -0,0 +1,197 @@
1
+ import { type KeyId } from "./keys.js";
2
+ /**
3
+ * Global keybinding registry.
4
+ * Downstream packages can add keybindings via declaration merging.
5
+ */
6
+ export interface Keybindings {
7
+ "tui.editor.cursorUp": true;
8
+ "tui.editor.cursorDown": true;
9
+ "tui.editor.cursorLeft": true;
10
+ "tui.editor.cursorRight": true;
11
+ "tui.editor.cursorWordLeft": true;
12
+ "tui.editor.cursorWordRight": true;
13
+ "tui.editor.cursorLineStart": true;
14
+ "tui.editor.cursorLineEnd": true;
15
+ "tui.editor.jumpForward": true;
16
+ "tui.editor.jumpBackward": true;
17
+ "tui.editor.pageUp": true;
18
+ "tui.editor.pageDown": true;
19
+ "tui.editor.deleteCharBackward": true;
20
+ "tui.editor.deleteCharForward": true;
21
+ "tui.editor.deleteWordBackward": true;
22
+ "tui.editor.deleteWordForward": true;
23
+ "tui.editor.deleteToLineStart": true;
24
+ "tui.editor.deleteToLineEnd": true;
25
+ "tui.editor.yank": true;
26
+ "tui.editor.yankPop": true;
27
+ "tui.editor.undo": true;
28
+ "tui.input.newLine": true;
29
+ "tui.input.submit": true;
30
+ "tui.input.tab": true;
31
+ "tui.input.copy": true;
32
+ "tui.select.up": true;
33
+ "tui.select.down": true;
34
+ "tui.select.pageUp": true;
35
+ "tui.select.pageDown": true;
36
+ "tui.select.confirm": true;
37
+ "tui.select.cancel": true;
38
+ }
39
+ export type Keybinding = keyof Keybindings;
40
+ export type { KeyId };
41
+ export interface KeybindingDefinition {
42
+ defaultKeys: KeyId | KeyId[];
43
+ description?: string;
44
+ }
45
+ export type KeybindingDefinitions = Record<string, KeybindingDefinition>;
46
+ export type KeybindingsConfig = Record<string, KeyId | KeyId[] | undefined>;
47
+ export declare const TUI_KEYBINDINGS: {
48
+ readonly "tui.editor.cursorUp": {
49
+ readonly defaultKeys: "up";
50
+ readonly description: "Move cursor up";
51
+ };
52
+ readonly "tui.editor.cursorDown": {
53
+ readonly defaultKeys: "down";
54
+ readonly description: "Move cursor down";
55
+ };
56
+ readonly "tui.editor.cursorLeft": {
57
+ readonly defaultKeys: ["left", "ctrl+b"];
58
+ readonly description: "Move cursor left";
59
+ };
60
+ readonly "tui.editor.cursorRight": {
61
+ readonly defaultKeys: ["right", "ctrl+f"];
62
+ readonly description: "Move cursor right";
63
+ };
64
+ readonly "tui.editor.cursorWordLeft": {
65
+ readonly defaultKeys: ["alt+left", "ctrl+left", "alt+b"];
66
+ readonly description: "Move cursor word left";
67
+ };
68
+ readonly "tui.editor.cursorWordRight": {
69
+ readonly defaultKeys: ["alt+right", "ctrl+right", "alt+f"];
70
+ readonly description: "Move cursor word right";
71
+ };
72
+ readonly "tui.editor.cursorLineStart": {
73
+ readonly defaultKeys: ["home", "ctrl+a"];
74
+ readonly description: "Move to line start";
75
+ };
76
+ readonly "tui.editor.cursorLineEnd": {
77
+ readonly defaultKeys: ["end", "ctrl+e"];
78
+ readonly description: "Move to line end";
79
+ };
80
+ readonly "tui.editor.jumpForward": {
81
+ readonly defaultKeys: "ctrl+]";
82
+ readonly description: "Jump forward to character";
83
+ };
84
+ readonly "tui.editor.jumpBackward": {
85
+ readonly defaultKeys: "ctrl+alt+]";
86
+ readonly description: "Jump backward to character";
87
+ };
88
+ readonly "tui.editor.pageUp": {
89
+ readonly defaultKeys: "pageUp";
90
+ readonly description: "Page up";
91
+ };
92
+ readonly "tui.editor.pageDown": {
93
+ readonly defaultKeys: "pageDown";
94
+ readonly description: "Page down";
95
+ };
96
+ readonly "tui.editor.deleteCharBackward": {
97
+ readonly defaultKeys: "backspace";
98
+ readonly description: "Delete character backward";
99
+ };
100
+ readonly "tui.editor.deleteCharForward": {
101
+ readonly defaultKeys: ["delete", "ctrl+d"];
102
+ readonly description: "Delete character forward";
103
+ };
104
+ readonly "tui.editor.deleteWordBackward": {
105
+ readonly defaultKeys: ["ctrl+w", "alt+backspace", "ctrl+backspace", "super+alt+backspace"];
106
+ readonly description: "Delete word backward";
107
+ };
108
+ readonly "tui.editor.deleteWordForward": {
109
+ readonly defaultKeys: ["alt+delete", "alt+d", "super+alt+delete", "super+alt+d"];
110
+ readonly description: "Delete word forward";
111
+ };
112
+ readonly "tui.editor.deleteToLineStart": {
113
+ readonly defaultKeys: "ctrl+u";
114
+ readonly description: "Delete to line start";
115
+ };
116
+ readonly "tui.editor.deleteToLineEnd": {
117
+ readonly defaultKeys: "ctrl+k";
118
+ readonly description: "Delete to line end";
119
+ };
120
+ readonly "tui.editor.yank": {
121
+ readonly defaultKeys: "ctrl+y";
122
+ readonly description: "Yank";
123
+ };
124
+ readonly "tui.editor.yankPop": {
125
+ readonly defaultKeys: "alt+y";
126
+ readonly description: "Yank pop";
127
+ };
128
+ readonly "tui.editor.undo": {
129
+ readonly defaultKeys: ["ctrl+-", "ctrl+_"];
130
+ readonly description: "Undo";
131
+ };
132
+ readonly "tui.input.newLine": {
133
+ readonly defaultKeys: ["shift+enter", "ctrl+j"];
134
+ readonly description: "Insert newline";
135
+ };
136
+ readonly "tui.input.submit": {
137
+ readonly defaultKeys: "enter";
138
+ readonly description: "Submit input";
139
+ };
140
+ readonly "tui.input.tab": {
141
+ readonly defaultKeys: "tab";
142
+ readonly description: "Tab / autocomplete";
143
+ };
144
+ readonly "tui.input.copy": {
145
+ readonly defaultKeys: "ctrl+c";
146
+ readonly description: "Copy selection";
147
+ };
148
+ readonly "tui.select.up": {
149
+ readonly defaultKeys: "up";
150
+ readonly description: "Move selection up";
151
+ };
152
+ readonly "tui.select.down": {
153
+ readonly defaultKeys: "down";
154
+ readonly description: "Move selection down";
155
+ };
156
+ readonly "tui.select.pageUp": {
157
+ readonly defaultKeys: "pageUp";
158
+ readonly description: "Selection page up";
159
+ };
160
+ readonly "tui.select.pageDown": {
161
+ readonly defaultKeys: "pageDown";
162
+ readonly description: "Selection page down";
163
+ };
164
+ readonly "tui.select.confirm": {
165
+ readonly defaultKeys: "enter";
166
+ readonly description: "Confirm selection";
167
+ };
168
+ readonly "tui.select.cancel": {
169
+ readonly defaultKeys: ["escape", "ctrl+c"];
170
+ readonly description: "Cancel selection";
171
+ };
172
+ };
173
+ export interface KeybindingConflict {
174
+ key: KeyId;
175
+ keybindings: string[];
176
+ }
177
+ export declare function canonicalKeyId(key: string): string;
178
+ export declare function addKeyAliases(keys: Set<string>, key: KeyId): void;
179
+ export declare class KeybindingsManager {
180
+ #private;
181
+ constructor(definitions: KeybindingDefinitions, userBindings?: KeybindingsConfig);
182
+ matches(data: string, keybinding: Keybinding): boolean;
183
+ /**
184
+ * Set-lookup variant of {@link matches} for hot input paths: the caller
185
+ * parses `data` once (`parseKey` + `canonicalKeyId`) and probes many
186
+ * bindings without re-parsing the raw sequence per probe.
187
+ */
188
+ matchesCanonical(canonical: string | undefined, keybinding: Keybinding): boolean;
189
+ getKeys(keybinding: Keybinding): KeyId[];
190
+ getDefinition(keybinding: Keybinding): KeybindingDefinition;
191
+ getConflicts(): KeybindingConflict[];
192
+ setUserBindings(userBindings: KeybindingsConfig): void;
193
+ getUserBindings(): KeybindingsConfig;
194
+ getResolvedBindings(): KeybindingsConfig;
195
+ }
196
+ export declare function setKeybindings(keybindings: KeybindingsManager): void;
197
+ export declare function getKeybindings(): KeybindingsManager;
@@ -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,44 @@
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 likely includes system sleep, so it is suppressed. Default 60_000. */
7
+ sleepMs?: number;
8
+ /** Monotonic clock source; injectable for tests. Default `performance.now`. */
9
+ now?: () => number;
10
+ /** Timer source; injectable for tests. Default `setTimeout`. */
11
+ schedule?: (cb: () => void, ms: number) => LoopWatchdogTimer;
12
+ }
13
+ /**
14
+ * Timer handle the watchdog arms. `cancel`, when present, is invoked on stop()
15
+ * so a stopped watchdog leaves no armed timer to wake the loop even once.
16
+ */
17
+ interface LoopWatchdogTimer {
18
+ unref?(): void;
19
+ cancel?(): void;
20
+ }
21
+ /**
22
+ * Always-on event-loop lag probe. Each tick is scheduled `intervalMs` ahead of
23
+ * a recorded deadline; a tick that fires `thresholdMs` past its deadline means
24
+ * the loop was blocked that long. The overshoot is logged once on the rising
25
+ * edge (one block ⇒ one line, deduped via `#wasBlocked`), tagged with the phase
26
+ * active during the elapsed interval via {@link takeRecentLoopPhase} — which
27
+ * survives the synchronous push/pop the instrumented hot paths do before this
28
+ * delayed tick can run — so the stall names its cause instead of "unknown".
29
+ *
30
+ * The handle is `unref`'d so the probe never keeps the process alive, and stop()
31
+ * cancels the armed timer when the handle exposes `cancel` (the default
32
+ * `setTimeout` handle does, via `clearTimeout`). The `#generation` guard remains
33
+ * as a fallback for injected handles that cannot cancel. An overshoot beyond
34
+ * `sleepMs` is treated as system sleep rather than a synchronous stall: the
35
+ * process could not have run JS during the missed interval, and one resume
36
+ * should not produce a multi-minute `ui.loop-blocked` record.
37
+ */
38
+ export declare class LoopWatchdog {
39
+ #private;
40
+ constructor(options?: LoopWatchdogOptions);
41
+ start(): void;
42
+ stop(): void;
43
+ }
44
+ export {};