@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,457 @@
|
|
|
1
|
+
import { ImageBudget } from "./components/image.js";
|
|
2
|
+
import { type Terminal } from "./terminal.js";
|
|
3
|
+
import { visibleWidth } from "./utils.js";
|
|
4
|
+
type InputListenerResult = {
|
|
5
|
+
consume?: boolean;
|
|
6
|
+
data?: string;
|
|
7
|
+
} | undefined;
|
|
8
|
+
type InputListener = (data: string) => InputListenerResult;
|
|
9
|
+
type StartListener = () => void;
|
|
10
|
+
export interface RenderTimer {
|
|
11
|
+
cancel(): void;
|
|
12
|
+
}
|
|
13
|
+
export interface RenderScheduler {
|
|
14
|
+
now(): number;
|
|
15
|
+
scheduleImmediate(callback: () => void): void;
|
|
16
|
+
scheduleRender(callback: () => void, delayMs: number): RenderTimer;
|
|
17
|
+
}
|
|
18
|
+
export interface TUIOptions {
|
|
19
|
+
renderScheduler?: RenderScheduler;
|
|
20
|
+
}
|
|
21
|
+
export interface TUIStartOptions {
|
|
22
|
+
/** Clear saved native scrollback before the first paint. */
|
|
23
|
+
clearScrollback?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Component interface - all components must implement this
|
|
27
|
+
*
|
|
28
|
+
* Render contract: the returned array (and its rows) belongs to the component.
|
|
29
|
+
* Callers MUST NOT mutate it — components are allowed to return a cached array
|
|
30
|
+
* and will return the exact same reference for as long as their rendered
|
|
31
|
+
* content is unchanged. Conversely, a component MUST return a fresh array
|
|
32
|
+
* reference whenever its content changed; reference equality across two
|
|
33
|
+
* render() calls is the engine's proof that the rows are byte-identical
|
|
34
|
+
* (containers memoize their concatenation on it, and the TUI derives the
|
|
35
|
+
* frame's stable prefix from it). A component that mutates a previously
|
|
36
|
+
* returned array in place must implement {@link RenderStablePrefix} to declare
|
|
37
|
+
* which leading rows survived.
|
|
38
|
+
*/
|
|
39
|
+
export interface Component {
|
|
40
|
+
/**
|
|
41
|
+
* Render the component to an array of physical rows at the given width.
|
|
42
|
+
* The result is component-owned and `readonly` to the caller; an unchanged
|
|
43
|
+
* component may (and should) return the same array reference it returned
|
|
44
|
+
* last time.
|
|
45
|
+
*/
|
|
46
|
+
render(width: number): readonly string[];
|
|
47
|
+
/**
|
|
48
|
+
* Optional handler for keyboard input when component has focus
|
|
49
|
+
*/
|
|
50
|
+
handleInput?(data: string): void;
|
|
51
|
+
/**
|
|
52
|
+
* If true, component receives key release events (Kitty protocol).
|
|
53
|
+
* Default is false - release events are filtered out.
|
|
54
|
+
*/
|
|
55
|
+
wantsKeyRelease?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Optional hook to invalidate any cached rendering state.
|
|
58
|
+
* Called when theme changes or when component needs to re-render from scratch.
|
|
59
|
+
*/
|
|
60
|
+
invalidate?(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Optional hook to set whether this component ignores tight layout mode.
|
|
63
|
+
*/
|
|
64
|
+
setIgnoreTight?(ignore: boolean): any;
|
|
65
|
+
/**
|
|
66
|
+
* Optional teardown. Called when the component is permanently removed from
|
|
67
|
+
* the live tree (e.g. a transcript reset). Release timers, intervals, and
|
|
68
|
+
* subscriptions here. Must be idempotent. Containers propagate dispose to
|
|
69
|
+
* their children; leaf components without resources may omit it.
|
|
70
|
+
*/
|
|
71
|
+
dispose?(): void;
|
|
72
|
+
}
|
|
73
|
+
/** Lets an overlay root delegate keyboard focus to components it owns. */
|
|
74
|
+
export interface OverlayFocusOwner {
|
|
75
|
+
/** Returns true when `component` is a focus target inside this overlay. */
|
|
76
|
+
ownsOverlayFocusTarget(component: Component): boolean;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Component seam for append-only native-scrollback commits. A component whose
|
|
80
|
+
* rendered rows can still change reports, after each render, the local line
|
|
81
|
+
* index where that mutable suffix begins. Rows above the boundary are declared
|
|
82
|
+
* FINAL — byte-stable at the current width for the component's lifetime — and
|
|
83
|
+
* commit to native scrollback as exact, audited content. Rows at/after the
|
|
84
|
+
* boundary repaint in place inside the visible window; when they scroll above
|
|
85
|
+
* the window top they normally commit as frozen visual snapshots.
|
|
86
|
+
*
|
|
87
|
+
* A viewport-pinned region opts out of those mutable snapshot commits. Its
|
|
88
|
+
* offscreen mutable rows are virtually clipped until the boundary advances;
|
|
89
|
+
* use this for fixed-height dashboards whose frames replace each other rather
|
|
90
|
+
* than append. A root that reports no seam commits everything that scrolls as
|
|
91
|
+
* final (shell semantics).
|
|
92
|
+
*
|
|
93
|
+
* When several root children report a seam in the same frame, the topmost one
|
|
94
|
+
* defines the boundary and pinning policy: commits are prefix-only, so
|
|
95
|
+
* everything below the first seam is already excluded.
|
|
96
|
+
*/
|
|
97
|
+
export interface NativeScrollbackLiveRegion {
|
|
98
|
+
getNativeScrollbackLiveRegionStart(): number | undefined;
|
|
99
|
+
/** Keeps the mutable suffix viewport-local instead of recording frozen snapshots. */
|
|
100
|
+
isNativeScrollbackLiveRegionPinned?(): boolean;
|
|
101
|
+
}
|
|
102
|
+
export interface NativeScrollbackCommittedRows {
|
|
103
|
+
setNativeScrollbackCommittedRows(rows: number): void;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* A component that discards rows after they enter native scrollback implements
|
|
107
|
+
* this hook so a destructive full replay can rehydrate its complete frame.
|
|
108
|
+
*/
|
|
109
|
+
export interface NativeScrollbackReplay {
|
|
110
|
+
prepareNativeScrollbackReplay(): void;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Opt-in stability report for components that mutate their returned render
|
|
114
|
+
* array in place across frames (instead of returning a fresh array per
|
|
115
|
+
* change). The engine reads it right after the component's `render()` returns:
|
|
116
|
+
* the report counts the leading rows of the just-returned array that are
|
|
117
|
+
* byte-identical to the array state the reader last observed. The engine uses
|
|
118
|
+
* it to reuse the composed frame's prefix — skipping marker extraction, line
|
|
119
|
+
* preparation, and the committed-prefix audit for those rows.
|
|
120
|
+
*
|
|
121
|
+
* Contract:
|
|
122
|
+
* - Reading CONSUMES the report: it re-bases the baseline to the current
|
|
123
|
+
* array state. The accumulated count therefore covers every render since
|
|
124
|
+
* the previous read, so out-of-band `render()` calls between engine frames
|
|
125
|
+
* (an exporter walking the tree) can only lower the report, never inflate
|
|
126
|
+
* it past what the engine actually has.
|
|
127
|
+
* - An implementer that cannot prove stability for a frame must lower the
|
|
128
|
+
* accumulated count to 0 for that render.
|
|
129
|
+
* - Rows at or beyond the report may have been mutated in place; rows before
|
|
130
|
+
* it must be the identical string values at the identical indices.
|
|
131
|
+
*/
|
|
132
|
+
export interface RenderStablePrefix {
|
|
133
|
+
getRenderStablePrefixRows(): number;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Opt-in fast path for composing only the visible tail of a tall component
|
|
137
|
+
* during a terminal resize. A drag emits a SIGWINCH burst, and the width
|
|
138
|
+
* changes on every event: a full compose re-lays-out (and, for markdown,
|
|
139
|
+
* re-lexes) the entire transcript per event — O(history) work that is
|
|
140
|
+
* discarded the instant the next event arrives. While the resize is in flight
|
|
141
|
+
* the engine paints only the viewport, so it asks each tall root child for at
|
|
142
|
+
* most `maxRows` rows from the bottom of its render at `width` and skips
|
|
143
|
+
* composing everything above the fold. The authoritative full paint replays
|
|
144
|
+
* once the drag settles (see {@link TUI} resize handling).
|
|
145
|
+
*
|
|
146
|
+
* Contract:
|
|
147
|
+
* - Returns the BOTTOM rows of the component's full render at `width`, in
|
|
148
|
+
* top-to-bottom order, capped at `maxRows` (fewer when the component is
|
|
149
|
+
* shorter). The rows MUST be byte-identical to the corresponding tail of
|
|
150
|
+
* what `render(width)` would have returned, modulo a one-row separator at
|
|
151
|
+
* the very top edge (a transient frame the settle paint overwrites).
|
|
152
|
+
* - MUST NOT mutate any persistent full-compose state: the next `render()`
|
|
153
|
+
* (the settle paint) has to reconcile exactly as if the tail render never
|
|
154
|
+
* happened. Warming pure per-width render caches is fine and desirable.
|
|
155
|
+
*/
|
|
156
|
+
export interface ViewportTailProvider {
|
|
157
|
+
renderViewportTail(width: number, maxRows: number): readonly string[];
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Interface for components that can receive focus and display a cursor.
|
|
161
|
+
* When focused, the component should emit CURSOR_MARKER at the cursor position
|
|
162
|
+
* in its render output. TUI will find this marker and position the hardware
|
|
163
|
+
* cursor there for proper IME candidate window positioning.
|
|
164
|
+
*
|
|
165
|
+
* Components that can switch between terminal-cursor and software-cursor
|
|
166
|
+
* rendering expose `setUseTerminalCursor`; TUI keeps that mode in sync with
|
|
167
|
+
* its resolved hardware-cursor preference whenever focus or the preference
|
|
168
|
+
* changes.
|
|
169
|
+
*/
|
|
170
|
+
export interface Focusable {
|
|
171
|
+
/** Set by TUI when focus changes. Component should emit CURSOR_MARKER when true. */
|
|
172
|
+
focused: boolean;
|
|
173
|
+
/** Set by TUI when hardware cursor rendering is enabled or disabled. */
|
|
174
|
+
setUseTerminalCursor?(useTerminalCursor: boolean): void;
|
|
175
|
+
}
|
|
176
|
+
/** Options for scheduling a TUI render. */
|
|
177
|
+
export interface RenderRequestOptions {
|
|
178
|
+
/** Clear terminal scrollback for intentional transcript replacement. */
|
|
179
|
+
clearScrollback?: boolean;
|
|
180
|
+
}
|
|
181
|
+
/** Type guard to check if a component implements Focusable */
|
|
182
|
+
export declare function isFocusable(component: Component | null): component is Component & Focusable;
|
|
183
|
+
/**
|
|
184
|
+
* Cursor position marker - APC (Application Program Command) sequence.
|
|
185
|
+
* This is a zero-width escape sequence that terminals ignore.
|
|
186
|
+
* Components emit this at the cursor position when focused.
|
|
187
|
+
* TUI finds and strips this marker, then positions the hardware cursor there.
|
|
188
|
+
*/
|
|
189
|
+
export declare const CURSOR_MARKER = "\u001B_pi:c\u0007";
|
|
190
|
+
export { visibleWidth };
|
|
191
|
+
/**
|
|
192
|
+
* Anchor position for overlays
|
|
193
|
+
*/
|
|
194
|
+
export type OverlayAnchor = "center" | "top-left" | "top-right" | "bottom-left" | "bottom-right" | "top-center" | "bottom-center" | "left-center" | "right-center";
|
|
195
|
+
/**
|
|
196
|
+
* Margin configuration for overlays
|
|
197
|
+
*/
|
|
198
|
+
export interface OverlayMargin {
|
|
199
|
+
top?: number;
|
|
200
|
+
right?: number;
|
|
201
|
+
bottom?: number;
|
|
202
|
+
left?: number;
|
|
203
|
+
}
|
|
204
|
+
/** Value that can be absolute (number) or percentage (string like "50%") */
|
|
205
|
+
export type SizeValue = number | `${number}%`;
|
|
206
|
+
/**
|
|
207
|
+
* Options for overlay positioning and sizing.
|
|
208
|
+
* Values can be absolute numbers or percentage strings (e.g., "50%").
|
|
209
|
+
*/
|
|
210
|
+
export interface OverlayOptions {
|
|
211
|
+
/** Width in columns, or percentage of terminal width (e.g., "50%") */
|
|
212
|
+
width?: SizeValue;
|
|
213
|
+
/** Minimum width in columns */
|
|
214
|
+
minWidth?: number;
|
|
215
|
+
/** Maximum height in rows, or percentage of terminal height (e.g., "50%") */
|
|
216
|
+
maxHeight?: SizeValue;
|
|
217
|
+
/** Anchor point for positioning (default: 'center') */
|
|
218
|
+
anchor?: OverlayAnchor;
|
|
219
|
+
/** Horizontal offset from anchor position (positive = right) */
|
|
220
|
+
offsetX?: number;
|
|
221
|
+
/** Vertical offset from anchor position (positive = down) */
|
|
222
|
+
offsetY?: number;
|
|
223
|
+
/** Row position: absolute number, or percentage (e.g., "25%" = 25% from top) */
|
|
224
|
+
row?: SizeValue;
|
|
225
|
+
/** Column position: absolute number, or percentage (e.g., "50%" = centered horizontally) */
|
|
226
|
+
col?: SizeValue;
|
|
227
|
+
/** Margin from terminal edges. Number applies to all sides. */
|
|
228
|
+
margin?: OverlayMargin | number;
|
|
229
|
+
/**
|
|
230
|
+
* Control overlay visibility based on terminal dimensions.
|
|
231
|
+
* If provided, overlay is only rendered when this returns true.
|
|
232
|
+
* Called each render cycle with current terminal dimensions.
|
|
233
|
+
*/
|
|
234
|
+
visible?: (termWidth: number, termHeight: number) => boolean;
|
|
235
|
+
/**
|
|
236
|
+
* Borrow the terminal's alternate screen buffer for this overlay's lifetime
|
|
237
|
+
* (vim/less idiom). While the topmost visible overlay sets this, the engine
|
|
238
|
+
* paints only the modal on the alt screen and emits no ED3 / scrollback
|
|
239
|
+
* bytes, so the transcript on the normal screen stays untouched and is not
|
|
240
|
+
* scrollable behind the modal. Defaults off — all other overlays are
|
|
241
|
+
* unchanged and still draw over the transcript on the normal screen.
|
|
242
|
+
*/
|
|
243
|
+
fullscreen?: boolean;
|
|
244
|
+
/**
|
|
245
|
+
* Enable terminal mouse reporting while fullscreen. Defaults on; disable it
|
|
246
|
+
* when native terminal text selection takes precedence over pointer events.
|
|
247
|
+
*/
|
|
248
|
+
mouseTracking?: boolean;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Handle returned by showOverlay for controlling the overlay
|
|
252
|
+
*/
|
|
253
|
+
export interface OverlayHandle {
|
|
254
|
+
/** Permanently remove the overlay (cannot be shown again) */
|
|
255
|
+
hide(): void;
|
|
256
|
+
/** Temporarily hide or show the overlay */
|
|
257
|
+
setHidden(hidden: boolean): void;
|
|
258
|
+
/** Check if overlay is temporarily hidden */
|
|
259
|
+
isHidden(): boolean;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Container - a component that contains other components
|
|
263
|
+
*/
|
|
264
|
+
export declare class Container implements Component, NativeScrollbackCommittedRows, NativeScrollbackReplay {
|
|
265
|
+
#private;
|
|
266
|
+
children: Component[];
|
|
267
|
+
setIgnoreTight(ignore: boolean): this;
|
|
268
|
+
addChild(component: Component): void;
|
|
269
|
+
removeChild(component: Component): void;
|
|
270
|
+
clear(): void;
|
|
271
|
+
/** Dispose every child, then detach it from this container. */
|
|
272
|
+
disposeChildren(): void;
|
|
273
|
+
invalidate(): void;
|
|
274
|
+
/**
|
|
275
|
+
* Propagate teardown to children. Call when the container's children are
|
|
276
|
+
* being permanently discarded (not when they are detached for reuse — use
|
|
277
|
+
* {@link clear} for that). Idempotent per child via each child's own dispose.
|
|
278
|
+
*/
|
|
279
|
+
dispose(): void;
|
|
280
|
+
/**
|
|
281
|
+
* Split the committed prefix from the container's most recently rendered
|
|
282
|
+
* rows across its children. The memoized child arrays are the exact geometry
|
|
283
|
+
* that produced that frame; when the child list was invalidated or rebuilt,
|
|
284
|
+
* there is no safe old-to-new coordinate mapping, so propagation waits for
|
|
285
|
+
* the next render/post-emit publication.
|
|
286
|
+
*/
|
|
287
|
+
setNativeScrollbackCommittedRows(rows: number): void;
|
|
288
|
+
/** Recursively discard layout locks that are meaningful only to the old tape. */
|
|
289
|
+
prepareNativeScrollbackReplay(): void;
|
|
290
|
+
render(width: number): readonly string[];
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Merge runs of byte-adjacent SGR sequences (`CSI [0-9;:]* m`) into one. Only
|
|
294
|
+
* CSI-SGR sequences are touched; text, cursor moves, OSC, hyperlinks and image
|
|
295
|
+
* payloads pass through verbatim. Returns the original reference when nothing
|
|
296
|
+
* merges, so SGR-light lines incur only a single `indexOf` scan.
|
|
297
|
+
*/
|
|
298
|
+
export declare function coalesceAdjacentSgr(line: string): string;
|
|
299
|
+
/**
|
|
300
|
+
* Decide whether `frame` still aligns with the committed prefix, and where to
|
|
301
|
+
* re-anchor the commit index when it does not. Returns the resync row index,
|
|
302
|
+
* or -1 when no resync is needed.
|
|
303
|
+
*
|
|
304
|
+
* Zones (verifiedTo ≤ finalTo ≤ prefix.length):
|
|
305
|
+
* [0, verifiedTo) VERIFIED exact rows — sampled with tolerance.
|
|
306
|
+
* [verifiedTo, finalTo) NEWLY-FINAL rows — frozen visual snapshots whose
|
|
307
|
+
* source just became declared-final (the block finalized / a barrier
|
|
308
|
+
* cleared). Hard-scanned in FULL with no tolerance: any content change
|
|
309
|
+
* (a pending header settling, a preview replaced by its result, a tail
|
|
310
|
+
* shifting up after a barrier removal) re-anchors so the engine can
|
|
311
|
+
* erase-and-replay history with the final content exactly once (or, on
|
|
312
|
+
* ED3-unsafe multiplexers, recommit it below the frozen snapshot —
|
|
313
|
+
* duplication, never loss) instead of committing it nowhere and
|
|
314
|
+
* painting it nowhere.
|
|
315
|
+
* [finalTo, prefix.length) FROZEN visual snapshots of still-live rows —
|
|
316
|
+
* exempt: their drift is expected (a collapsing preview, a ticking
|
|
317
|
+
* progress tree) and must never spray re-anchors mid-run.
|
|
318
|
+
*
|
|
319
|
+
* The verified zone's sampled check exploits the asymmetry between the two
|
|
320
|
+
* mutation classes: an in-place edit/restyle disturbs only the touched rows
|
|
321
|
+
* (alignment below stays intact; the stale copy in history is the accepted
|
|
322
|
+
* artifact), while an insertion/deletion shifts EVERY row below it. Up to 8
|
|
323
|
+
* non-blank rows within the last 24 verified rows are compared SGR-stripped
|
|
324
|
+
* (theme changes stay quiet), tolerating a SINGLE mismatch. The tolerance is
|
|
325
|
+
* load-bearing for roots that report NO seam: an animated row already in
|
|
326
|
+
* history would otherwise re-anchor on every glyph tick.
|
|
327
|
+
*
|
|
328
|
+
* Highly repetitive tails (identical filler rows) can mask a shift in the tail
|
|
329
|
+
* sample, in which case the skipped rows are content-identical to the committed
|
|
330
|
+
* ones — observationally harmless. Exported for the render-stress harness, whose
|
|
331
|
+
* shadow commit ledger must mirror the engine's law exactly.
|
|
332
|
+
*/
|
|
333
|
+
export declare function findCommittedPrefixResync(frame: readonly string[], prefix: readonly string[], verifiedTo?: number, finalTo?: number): number;
|
|
334
|
+
/**
|
|
335
|
+
* TUI - Main class for managing terminal UI with differential rendering
|
|
336
|
+
*/
|
|
337
|
+
export declare class TUI extends Container {
|
|
338
|
+
#private;
|
|
339
|
+
terminal: Terminal;
|
|
340
|
+
/** Global callback for debug key (Shift+Ctrl+D). Called before input is forwarded to focused component. */
|
|
341
|
+
onDebug?: () => void;
|
|
342
|
+
overlayStack: {
|
|
343
|
+
component: Component;
|
|
344
|
+
options?: OverlayOptions;
|
|
345
|
+
preFocus: Component | null;
|
|
346
|
+
hidden: boolean;
|
|
347
|
+
}[];
|
|
348
|
+
constructor(terminal: Terminal, showHardwareCursor?: boolean, options?: TUIOptions);
|
|
349
|
+
render(width: number): readonly string[];
|
|
350
|
+
get fullRedraws(): number;
|
|
351
|
+
/**
|
|
352
|
+
* Transient viewport-only paints emitted by the non-multiplexer resize fast
|
|
353
|
+
* path. These never touch native scrollback or the commit ledger, so they
|
|
354
|
+
* are counted apart from {@link fullRedraws}.
|
|
355
|
+
*/
|
|
356
|
+
get resizeViewportPaints(): number;
|
|
357
|
+
/** Whether a non-multiplexer resize drag is currently in flight. */
|
|
358
|
+
get resizeViewportActive(): boolean;
|
|
359
|
+
/** Shared budget that caps how many inline images render as live graphics. */
|
|
360
|
+
get imageBudget(): ImageBudget;
|
|
361
|
+
/**
|
|
362
|
+
* Set how many inline images stay live graphics before older ones fall back
|
|
363
|
+
* to text (`0` disables the cap). Older images are hidden via a graphics purge
|
|
364
|
+
* plus a full redraw on the frame after a new image exceeds the cap.
|
|
365
|
+
*/
|
|
366
|
+
setMaxInlineImages(cap: number): void;
|
|
367
|
+
/** Delete every tracked Kitty image from the terminal graphics store. */
|
|
368
|
+
clearInlineImages(): void;
|
|
369
|
+
/**
|
|
370
|
+
* Get whether scrollback divergence rebuild is enabled.
|
|
371
|
+
*/
|
|
372
|
+
getScrollbackRebuild(): boolean;
|
|
373
|
+
/**
|
|
374
|
+
* Enable or disable scrollback divergence rebuild (default off).
|
|
375
|
+
* When enabled, the engine will erase and replay the terminal's
|
|
376
|
+
* scrollback (using ED3 / alt buffer / scrollback replay) to avoid
|
|
377
|
+
* duplicate blocks when a block's final form replaces its live preview.
|
|
378
|
+
*/
|
|
379
|
+
setScrollbackRebuild(enabled: boolean): void;
|
|
380
|
+
getShowHardwareCursor(): boolean;
|
|
381
|
+
setShowHardwareCursor(enabled: boolean): void;
|
|
382
|
+
/**
|
|
383
|
+
* Whether DEC 2026 synchronized-output wrappers are currently emitted around
|
|
384
|
+
* paints. Starts from conservative terminal/env detection and is reconciled at
|
|
385
|
+
* runtime against the terminal's DECRQM mode-2026 report — enabled on a
|
|
386
|
+
* positive report, disabled on a negative one.
|
|
387
|
+
*/
|
|
388
|
+
get synchronizedOutput(): boolean;
|
|
389
|
+
setFocus(component: Component | null): void;
|
|
390
|
+
/** Component currently receiving keyboard input, if any. */
|
|
391
|
+
getFocused(): Component | null;
|
|
392
|
+
/**
|
|
393
|
+
* Show an overlay component with configurable positioning and sizing.
|
|
394
|
+
* Returns a handle to control the overlay's visibility.
|
|
395
|
+
*/
|
|
396
|
+
showOverlay(component: Component, options?: OverlayOptions): OverlayHandle;
|
|
397
|
+
/** Hide the topmost overlay and restore previous focus. */
|
|
398
|
+
hideOverlay(): void;
|
|
399
|
+
/** Check if there are any visible overlays */
|
|
400
|
+
hasOverlay(): boolean;
|
|
401
|
+
invalidate(): void;
|
|
402
|
+
start(options?: TUIStartOptions): void;
|
|
403
|
+
addStartListener(listener: StartListener): () => void;
|
|
404
|
+
addInputListener(listener: InputListener): () => void;
|
|
405
|
+
removeInputListener(listener: InputListener): void;
|
|
406
|
+
stop(): void;
|
|
407
|
+
/**
|
|
408
|
+
* Force an immediate full replay of the current frame, including native
|
|
409
|
+
* scrollback. This is the keyboard-accessible equivalent of the resize reset:
|
|
410
|
+
* no queued diff frame or terminal scrollback probe can downgrade it to a
|
|
411
|
+
* viewport-only repaint.
|
|
412
|
+
*
|
|
413
|
+
* Invalidates every component first so the replay reflects current state. A
|
|
414
|
+
* geometry-driven reset thaws frozen scrollback snapshots implicitly (the new
|
|
415
|
+
* width misses every cached snapshot), but a same-width reset would otherwise
|
|
416
|
+
* replay stale snapshots — leaving host-frozen blocks (e.g. a transcript whose
|
|
417
|
+
* committed rows are immutable on ED3-risk terminals) showing pre-mutation
|
|
418
|
+
* content. Invalidation is the generic signal those containers use to retire
|
|
419
|
+
* their snapshots, which is exactly what a user-driven display reset wants.
|
|
420
|
+
*/
|
|
421
|
+
resetDisplay(): void;
|
|
422
|
+
requestRender(force?: boolean, options?: RenderRequestOptions): void;
|
|
423
|
+
/**
|
|
424
|
+
* Opt `component` into subtree-only renders when input leaves focus stable.
|
|
425
|
+
*
|
|
426
|
+
* The host must explicitly request renders for every sibling mutated by the
|
|
427
|
+
* component's input callbacks. Components without this opt-in retain the
|
|
428
|
+
* legacy full-root render after input.
|
|
429
|
+
*/
|
|
430
|
+
enableScopedInputRender(component: Component): void;
|
|
431
|
+
/**
|
|
432
|
+
* Schedule a render on behalf of `component` after a self-contained change
|
|
433
|
+
* (spinner frame, blink) that cannot have affected any other component.
|
|
434
|
+
*
|
|
435
|
+
* When every request since the last frame is component-scoped and the
|
|
436
|
+
* frame is otherwise quiet — no resize or geometry change, no overlays, no
|
|
437
|
+
* live inline images, no forced repaint, unchanged root child list — the
|
|
438
|
+
* next compose re-renders only the root subtrees containing the requesting
|
|
439
|
+
* components and reuses the previous frame's rows (and seam reports) for
|
|
440
|
+
* every other root child, skipping the full component-tree walk that makes
|
|
441
|
+
* long transcripts expensive to repaint at animation rate. Any concurrent
|
|
442
|
+
* full request or unsafe condition downgrades the frame to a normal full
|
|
443
|
+
* compose, so this is never less correct than `requestRender()` — only
|
|
444
|
+
* cheaper.
|
|
445
|
+
*/
|
|
446
|
+
requestComponentRender(component: Component): void;
|
|
447
|
+
/**
|
|
448
|
+
* Rewrite a quiet, visible component segment directly.
|
|
449
|
+
*
|
|
450
|
+
* Loader-style animation changes one already-positioned segment at a fixed
|
|
451
|
+
* size. When the current frame geometry is still valid, rewrite just those
|
|
452
|
+
* rows and update the diff baseline instead of scheduling a full render
|
|
453
|
+
* cycle. Unsafe states fall back to `requestComponentRender()`, preserving
|
|
454
|
+
* the ordinary renderer as the correctness path.
|
|
455
|
+
*/
|
|
456
|
+
requestDirectWrite(component: Component): void;
|
|
457
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Ellipsis, type ExtractSegmentsResult, type SliceResult } from "@linxiraos/pi-natives";
|
|
2
|
+
export { Ellipsis } from "@linxiraos/pi-natives";
|
|
3
|
+
export { DEFAULT_TAB_WIDTH } from "@linxiraos/pi-utils";
|
|
4
|
+
export type HangulCompatibilityJamoWidth = "platform" | "unicode" | 1 | 2;
|
|
5
|
+
export declare function getHangulCompatibilityJamoWidth(): HangulCompatibilityJamoWidth;
|
|
6
|
+
export declare function getWidthConfigEpoch(): number;
|
|
7
|
+
/** Publish exact per-line visible widths for a rendered lines array. */
|
|
8
|
+
export declare function publishLineWidths(lines: readonly string[], widths: readonly number[]): void;
|
|
9
|
+
/** Exact per-line visible widths for an unchanged `lines` array under the current width config. */
|
|
10
|
+
export declare function getPublishedLineWidths(lines: readonly string[]): readonly number[] | undefined;
|
|
11
|
+
export declare function setHangulCompatibilityJamoWidth(width: HangulCompatibilityJamoWidth): boolean;
|
|
12
|
+
export declare function resetHangulCompatibilityJamoWidthForTests(): void;
|
|
13
|
+
export type TextSizingScale = 1 | 2 | 3;
|
|
14
|
+
export type TextSizingVerticalAlign = "top" | "bottom" | "center";
|
|
15
|
+
export type TextSizingHorizontalAlign = "left" | "right" | "center";
|
|
16
|
+
export interface TextSizingOptions {
|
|
17
|
+
scale?: TextSizingScale;
|
|
18
|
+
widthCells?: number;
|
|
19
|
+
verticalAlign?: TextSizingVerticalAlign;
|
|
20
|
+
horizontalAlign?: TextSizingHorizontalAlign;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Encode a plain-text span using Kitty's OSC 66 text-sizing protocol. The TUI
|
|
24
|
+
* emits only safe UTF-8 payloads and ST terminators so its ANSI parser and the
|
|
25
|
+
* terminal agree on span boundaries.
|
|
26
|
+
*/
|
|
27
|
+
export declare function encodeTextSized(text: string, options?: TextSizingOptions): string;
|
|
28
|
+
export declare function sliceWithWidth(line: string, startCol: number, length: number, strict?: boolean | null): SliceResult;
|
|
29
|
+
export declare function truncateToWidth(text: string, maxWidth: number, ellipsisKind?: Ellipsis | null | "", pad?: boolean | null): string;
|
|
30
|
+
export declare function wrapTextWithAnsi(text: string, width: number): string[];
|
|
31
|
+
export declare function extractSegments(line: string, beforeEnd: number, afterStart: number, afterLen: number, strictAfter: boolean): ExtractSegmentsResult;
|
|
32
|
+
export declare function replaceTabs(text: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Returns a string of n spaces. Uses a pre-allocated buffer for efficiency.
|
|
35
|
+
*/
|
|
36
|
+
export declare function padding(n: number): string;
|
|
37
|
+
/**
|
|
38
|
+
* Get the shared grapheme segmenter instance.
|
|
39
|
+
*/
|
|
40
|
+
export declare function getSegmenter(): Intl.Segmenter;
|
|
41
|
+
/**
|
|
42
|
+
* Visible width of a string in terminal columns, excluding ANSI/OSC escapes.
|
|
43
|
+
*
|
|
44
|
+
* `Bun.stringWidth` does the heavy lifting (UAX#11 width tables + ANSI/OSC
|
|
45
|
+
* stripping); this adds the two corrections it omits — tabs (expanded to
|
|
46
|
+
* `tabWidth` cells) and OSC 66 text-sizing payloads (scaled by `s=`).
|
|
47
|
+
*/
|
|
48
|
+
export declare function visibleWidth(str: string): number;
|
|
49
|
+
/**
|
|
50
|
+
* Normalize text for terminal output without changing logical editor content.
|
|
51
|
+
* Some terminals render precomposed Thai/Lao AM vowels inconsistently during
|
|
52
|
+
* differential repaint. Their compatibility decompositions have the same cell
|
|
53
|
+
* width but avoid stale-cell artifacts in terminal renderers.
|
|
54
|
+
*/
|
|
55
|
+
export declare function normalizeTerminalOutput(str: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* Check if a character is whitespace.
|
|
58
|
+
*/
|
|
59
|
+
export declare function isWhitespaceChar(char: string): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Check if a character is punctuation.
|
|
62
|
+
*/
|
|
63
|
+
export declare function isPunctuationChar(char: string): boolean;
|
|
64
|
+
export type WordNavKind = "whitespace" | "delimiter" | "cjk" | "word" | "other";
|
|
65
|
+
/**
|
|
66
|
+
* Coarse Unicode-aware character classification for word navigation (Option/Alt + Left/Right).
|
|
67
|
+
* This intentionally avoids language-specific word segmentation for predictability across scripts.
|
|
68
|
+
*/
|
|
69
|
+
export declare function getWordNavKind(grapheme: string): WordNavKind;
|
|
70
|
+
export declare function isWordNavJoiner(grapheme: string): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Move the cursor one "word" to the left using Unicode-aware coarse navigation.
|
|
73
|
+
*
|
|
74
|
+
* Returns a new cursor index in the range [0, text.length].
|
|
75
|
+
*/
|
|
76
|
+
export declare function moveWordLeft(text: string, cursor: number): number;
|
|
77
|
+
/**
|
|
78
|
+
* Move the cursor one "word" to the right using Unicode-aware coarse navigation.
|
|
79
|
+
*
|
|
80
|
+
* Returns a new cursor index in the range [0, text.length].
|
|
81
|
+
*/
|
|
82
|
+
export declare function moveWordRight(text: string, cursor: number): number;
|
|
83
|
+
/**
|
|
84
|
+
* Apply background color to a line, padding to full width.
|
|
85
|
+
*
|
|
86
|
+
* @param line - Line of text (may contain ANSI codes)
|
|
87
|
+
* @param width - Total width to pad to
|
|
88
|
+
* @param bgFn - Background color function
|
|
89
|
+
* @returns Line with background applied and padded to width
|
|
90
|
+
*/
|
|
91
|
+
export declare function applyBackgroundToLine(line: string, width: number, bgFn: (text: string) => string): string;
|
|
92
|
+
/**
|
|
93
|
+
* Extract a range of visible columns from a line. Handles ANSI codes and wide chars.
|
|
94
|
+
*
|
|
95
|
+
* @param strict - If true, exclude wide chars at boundary that would extend past the range
|
|
96
|
+
*/
|
|
97
|
+
export declare function sliceByColumn(line: string, startCol: number, length: number, strict?: boolean): string;
|
|
98
|
+
export declare function setTuiTight(tight: boolean): void;
|
|
99
|
+
export declare function isTuiTight(): boolean;
|
|
100
|
+
export declare function getPaddingX(basePadding: number): number;
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "module",
|
|
3
|
+
"name": "@linxiraos/pi-tui",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "Terminal User Interface library with differential rendering for efficient text-based applications",
|
|
6
|
+
"homepage": "https://linxira-os.github.io",
|
|
7
|
+
"author": "Can Boluk",
|
|
8
|
+
"contributors": [
|
|
9
|
+
"Mario Zechner"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/Linxira-OS/linxira-zeta.git",
|
|
15
|
+
"directory": "packages/tui"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/can1357/oh-my-pi/issues"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"tui",
|
|
22
|
+
"terminal",
|
|
23
|
+
"ui",
|
|
24
|
+
"text-editor",
|
|
25
|
+
"differential-rendering",
|
|
26
|
+
"typescript",
|
|
27
|
+
"cli"
|
|
28
|
+
],
|
|
29
|
+
"main": "./src/index.ts",
|
|
30
|
+
"types": "./dist/types/index.d.ts",
|
|
31
|
+
"scripts": {
|
|
32
|
+
"check": "biome check . && bun run check:types",
|
|
33
|
+
"check:types": "tsgo -p tsconfig.json --noEmit",
|
|
34
|
+
"lint": "biome lint .",
|
|
35
|
+
"test": "bun test --parallel test/*.test.ts",
|
|
36
|
+
"fix": "biome check --write --unsafe .",
|
|
37
|
+
"fmt": "biome format --write ."
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@linxiraos/pi-natives": "1.0.0",
|
|
41
|
+
"@linxiraos/pi-utils": "1.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"ghostty-web": "^0.4.0"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"bun": ">=1.3.14"
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"src",
|
|
51
|
+
"README.md",
|
|
52
|
+
"CHANGELOG.md",
|
|
53
|
+
"dist/types"
|
|
54
|
+
],
|
|
55
|
+
"exports": {
|
|
56
|
+
".": {
|
|
57
|
+
"types": "./dist/types/index.d.ts",
|
|
58
|
+
"import": "./src/index.ts"
|
|
59
|
+
},
|
|
60
|
+
"./*": {
|
|
61
|
+
"types": "./dist/types/*.d.ts",
|
|
62
|
+
"import": "./src/*.ts"
|
|
63
|
+
},
|
|
64
|
+
"./components/*": {
|
|
65
|
+
"types": "./dist/types/components/*.d.ts",
|
|
66
|
+
"import": "./src/components/*.ts"
|
|
67
|
+
},
|
|
68
|
+
"./*.js": "./src/*.ts"
|
|
69
|
+
}
|
|
70
|
+
}
|