@sayknow-cli/tui 0.3.6 → 0.3.8
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/dist/types/animation-scheduler.d.ts +13 -0
- package/dist/types/autocomplete.d.ts +83 -0
- package/dist/types/bracketed-paste.d.ts +26 -0
- package/dist/types/components/box.d.ts +20 -0
- package/dist/types/components/cancellable-loader.d.ts +21 -0
- package/dist/types/components/editor.d.ts +126 -0
- package/dist/types/components/image.d.ts +16 -0
- package/dist/types/components/input.d.ts +16 -0
- package/dist/types/components/loader.d.ts +23 -0
- package/dist/types/components/markdown.d.ts +77 -0
- package/dist/types/components/select-list.d.ts +46 -0
- package/dist/types/components/settings-list.d.ts +39 -0
- package/dist/types/components/spacer.d.ts +11 -0
- package/dist/types/components/tab-bar.d.ts +56 -0
- package/dist/types/components/text.d.ts +13 -0
- package/dist/types/components/truncated-text.d.ts +10 -0
- package/dist/types/editor-component.d.ts +36 -0
- package/dist/types/fuzzy.d.ts +15 -0
- package/dist/types/index.d.ts +27 -0
- package/dist/types/keybindings.d.ts +201 -0
- package/dist/types/keys.d.ts +208 -0
- package/dist/types/kill-ring.d.ts +27 -0
- package/dist/types/metrics.d.ts +85 -0
- package/dist/types/stdin-buffer.d.ts +50 -0
- package/dist/types/symbols.d.ts +23 -0
- package/dist/types/terminal-capabilities.d.ts +75 -0
- package/dist/types/terminal.d.ts +88 -0
- package/dist/types/ttyid.d.ts +9 -0
- package/dist/types/tui.d.ts +206 -0
- package/dist/types/utils.d.ts +87 -0
- package/package.json +10 -9
- package/src/animation-scheduler.ts +99 -0
- package/src/autocomplete.ts +119 -96
- package/src/components/editor.ts +310 -128
- package/src/components/input.ts +2 -1
- package/src/components/loader.ts +36 -37
- package/src/components/markdown.ts +79 -2
- package/src/components/select-list.ts +8 -1
- package/src/index.ts +1 -0
- package/src/stdin-buffer.ts +89 -11
- package/src/terminal.ts +44 -8
- package/src/tui.ts +362 -64
- package/src/utils.ts +77 -11
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export declare enum ImageProtocol {
|
|
2
|
+
Kitty = "\u001B_G",
|
|
3
|
+
Iterm2 = "\u001B]1337;File=",
|
|
4
|
+
Sixel = "\u001BPq"
|
|
5
|
+
}
|
|
6
|
+
export declare enum NotifyProtocol {
|
|
7
|
+
Bell = "\u0007",
|
|
8
|
+
Osc99 = "\u001B]99;;",
|
|
9
|
+
Osc9 = "\u001B]9;"
|
|
10
|
+
}
|
|
11
|
+
export type TerminalId = "kitty" | "ghostty" | "wezterm" | "iterm2" | "vscode" | "alacritty" | "base" | "trueColor";
|
|
12
|
+
/** Terminal capability details used for rendering and protocol selection. */
|
|
13
|
+
export declare class TerminalInfo {
|
|
14
|
+
readonly id: TerminalId;
|
|
15
|
+
readonly imageProtocol: ImageProtocol | null;
|
|
16
|
+
readonly trueColor: boolean;
|
|
17
|
+
readonly hyperlinks: boolean;
|
|
18
|
+
readonly notifyProtocol: NotifyProtocol;
|
|
19
|
+
constructor(id: TerminalId, imageProtocol: ImageProtocol | null, trueColor: boolean, hyperlinks: boolean, notifyProtocol?: NotifyProtocol);
|
|
20
|
+
isImageLine(line: string): boolean;
|
|
21
|
+
formatNotification(message: string): string;
|
|
22
|
+
sendNotification(message: string): void;
|
|
23
|
+
}
|
|
24
|
+
export declare function isNotificationSuppressed(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Returns true when running in Windows Terminal with known SIXEL support.
|
|
27
|
+
*
|
|
28
|
+
* Windows Terminal introduced SIXEL support in preview 1.22.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isWindowsTerminalPreviewSixelSupported(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): boolean;
|
|
31
|
+
export declare const TERMINAL_ID: TerminalId;
|
|
32
|
+
export declare const TERMINAL: TerminalInfo;
|
|
33
|
+
/**
|
|
34
|
+
* Override terminal image protocol at runtime after capability probes complete.
|
|
35
|
+
*/
|
|
36
|
+
export declare function setTerminalImageProtocol(imageProtocol: ImageProtocol | null): void;
|
|
37
|
+
export declare function getTerminalInfo(terminalId: TerminalId): TerminalInfo;
|
|
38
|
+
export interface CellDimensions {
|
|
39
|
+
widthPx: number;
|
|
40
|
+
heightPx: number;
|
|
41
|
+
}
|
|
42
|
+
export interface ImageDimensions {
|
|
43
|
+
widthPx: number;
|
|
44
|
+
heightPx: number;
|
|
45
|
+
}
|
|
46
|
+
export interface ImageRenderOptions {
|
|
47
|
+
maxWidthCells?: number;
|
|
48
|
+
maxHeightCells?: number;
|
|
49
|
+
preserveAspectRatio?: boolean;
|
|
50
|
+
}
|
|
51
|
+
export declare function getCellDimensions(): CellDimensions;
|
|
52
|
+
export declare function setCellDimensions(dims: CellDimensions): void;
|
|
53
|
+
export declare function encodeKitty(base64Data: string, options?: {
|
|
54
|
+
columns?: number;
|
|
55
|
+
rows?: number;
|
|
56
|
+
imageId?: number;
|
|
57
|
+
}): string;
|
|
58
|
+
export declare function encodeITerm2(base64Data: string, options?: {
|
|
59
|
+
width?: number | string;
|
|
60
|
+
height?: number | string;
|
|
61
|
+
name?: string;
|
|
62
|
+
preserveAspectRatio?: boolean;
|
|
63
|
+
inline?: boolean;
|
|
64
|
+
}): string;
|
|
65
|
+
export declare function calculateImageRows(imageDimensions: ImageDimensions, targetWidthCells: number, cellDimensions?: CellDimensions): number;
|
|
66
|
+
export declare function getPngDimensions(base64Data: string): ImageDimensions | null;
|
|
67
|
+
export declare function getJpegDimensions(base64Data: string): ImageDimensions | null;
|
|
68
|
+
export declare function getGifDimensions(base64Data: string): ImageDimensions | null;
|
|
69
|
+
export declare function getWebpDimensions(base64Data: string): ImageDimensions | null;
|
|
70
|
+
export declare function getImageDimensions(base64Data: string, mimeType: string): ImageDimensions | null;
|
|
71
|
+
export declare function renderImage(base64Data: string, imageDimensions: ImageDimensions, options?: ImageRenderOptions): {
|
|
72
|
+
sequence: string;
|
|
73
|
+
rows: number;
|
|
74
|
+
} | null;
|
|
75
|
+
export declare function imageFallback(mimeType: string, dimensions?: ImageDimensions, filename?: string): string;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether SKC may reprogram the keyboard with enhanced input protocols
|
|
3
|
+
* (the Kitty keyboard protocol and the xterm modifyOtherKeys fallback).
|
|
4
|
+
*
|
|
5
|
+
* Enabled by default. Set `SKC_TUI_KEYBOARD_PROTOCOL=0` to leave the keyboard in
|
|
6
|
+
* its default mode. Some terminals — notably Android Termius — break IME
|
|
7
|
+
* composition (e.g. Korean/Hangul syllable composition) while these enhanced
|
|
8
|
+
* modes are active, committing every intermediate composing jamo/syllable
|
|
9
|
+
* instead of only the final character. Disabling the protocol restores normal
|
|
10
|
+
* IME behavior, matching how other TUIs that leave the keyboard untouched render
|
|
11
|
+
* Korean correctly.
|
|
12
|
+
*/
|
|
13
|
+
export declare function keyboardEnhancementEnabled(): boolean;
|
|
14
|
+
/** Error codes for terminal/pipe write failures that should never crash the process. */
|
|
15
|
+
export declare function isBenignTerminalWriteError(err: unknown): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Emergency terminal restore - call this from signal/crash handlers
|
|
18
|
+
* Resets terminal state without requiring access to the ProcessTerminal instance
|
|
19
|
+
*/
|
|
20
|
+
export declare function emergencyTerminalRestore(): void;
|
|
21
|
+
/** Terminal-reported appearance (dark/light mode). */
|
|
22
|
+
export type TerminalAppearance = "dark" | "light";
|
|
23
|
+
export interface Terminal {
|
|
24
|
+
start(onInput: (data: string) => void, onResize: () => void): void;
|
|
25
|
+
stop(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Drain stdin before exiting to prevent Kitty key release events from
|
|
28
|
+
* leaking to the parent shell over slow SSH connections.
|
|
29
|
+
* @param maxMs - Maximum time to drain (default: 1000ms)
|
|
30
|
+
* @param idleMs - Exit early if no input arrives within this time (default: 50ms)
|
|
31
|
+
*/
|
|
32
|
+
drainInput(maxMs?: number, idleMs?: number): Promise<void>;
|
|
33
|
+
write(data: string): void;
|
|
34
|
+
get available(): boolean;
|
|
35
|
+
get columns(): number;
|
|
36
|
+
get rows(): number;
|
|
37
|
+
get kittyProtocolActive(): boolean;
|
|
38
|
+
moveBy(lines: number): void;
|
|
39
|
+
hideCursor(): void;
|
|
40
|
+
showCursor(): void;
|
|
41
|
+
clearLine(): void;
|
|
42
|
+
clearFromCursor(): void;
|
|
43
|
+
clearScreen(): void;
|
|
44
|
+
setTitle(title: string): void;
|
|
45
|
+
setProgress(active: boolean): void;
|
|
46
|
+
/**
|
|
47
|
+
* Register a callback for terminal appearance (dark/light) changes.
|
|
48
|
+
* Detection uses OSC 11 background color query with Mode 2031 as a change trigger.
|
|
49
|
+
* Fires when the detected appearance changes, including the initial detection.
|
|
50
|
+
*/
|
|
51
|
+
onAppearanceChange(callback: (appearance: TerminalAppearance) => void): void;
|
|
52
|
+
/** The last detected terminal appearance, or undefined if not yet known. */
|
|
53
|
+
get appearance(): TerminalAppearance | undefined;
|
|
54
|
+
}
|
|
55
|
+
interface TerminalSizeStream {
|
|
56
|
+
columns?: number;
|
|
57
|
+
rows?: number;
|
|
58
|
+
getWindowSize?: () => [number, number] | number[];
|
|
59
|
+
}
|
|
60
|
+
export declare function resolveTerminalColumns(stream?: TerminalSizeStream, envColumns?: string | undefined): number;
|
|
61
|
+
export declare function resolveTerminalRows(stream?: TerminalSizeStream, envRows?: string | undefined): number;
|
|
62
|
+
/**
|
|
63
|
+
* Real terminal using process.stdin/stdout
|
|
64
|
+
*/
|
|
65
|
+
export declare class ProcessTerminal implements Terminal {
|
|
66
|
+
#private;
|
|
67
|
+
get kittyProtocolActive(): boolean;
|
|
68
|
+
get appearance(): TerminalAppearance | undefined;
|
|
69
|
+
onAppearanceChange(callback: (appearance: TerminalAppearance) => void): void;
|
|
70
|
+
start(onInput: (data: string) => void, onResize: () => void): void;
|
|
71
|
+
drainInput(maxMs?: number, idleMs?: number): Promise<void>;
|
|
72
|
+
stop(): void;
|
|
73
|
+
write(data: string): void;
|
|
74
|
+
/** Invoked by the durable module-level stdout write guard (see installStdoutWriteGuard). */
|
|
75
|
+
markStdoutUnavailable(err: unknown): void;
|
|
76
|
+
get available(): boolean;
|
|
77
|
+
get columns(): number;
|
|
78
|
+
get rows(): number;
|
|
79
|
+
moveBy(lines: number): void;
|
|
80
|
+
hideCursor(): void;
|
|
81
|
+
showCursor(): void;
|
|
82
|
+
clearLine(): void;
|
|
83
|
+
clearFromCursor(): void;
|
|
84
|
+
clearScreen(): void;
|
|
85
|
+
setTitle(title: string): void;
|
|
86
|
+
setProgress(active: boolean): void;
|
|
87
|
+
}
|
|
88
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Resolve the TTY device path for stdin (fd 0) via POSIX `ttyname(3)`. */
|
|
2
|
+
export declare function getTtyPath(): string | null;
|
|
3
|
+
/**
|
|
4
|
+
* Get a stable identifier for the current terminal.
|
|
5
|
+
* Uses the TTY device path (e.g., /dev/pts/3), falling back to environment
|
|
6
|
+
* variables for terminal multiplexers or terminal emulators.
|
|
7
|
+
* Returns null if no terminal can be identified (e.g., piped input).
|
|
8
|
+
*/
|
|
9
|
+
export declare function getTerminalId(): string | null;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import type { Terminal } from "./terminal";
|
|
2
|
+
import { visibleWidth } from "./utils";
|
|
3
|
+
type InputListenerResult = {
|
|
4
|
+
consume?: boolean;
|
|
5
|
+
data?: string;
|
|
6
|
+
} | undefined;
|
|
7
|
+
type InputListener = (data: string) => InputListenerResult;
|
|
8
|
+
/**
|
|
9
|
+
* Component interface - all components must implement this
|
|
10
|
+
*/
|
|
11
|
+
export interface Component {
|
|
12
|
+
/**
|
|
13
|
+
* Render the component to lines for the given viewport width
|
|
14
|
+
* @param width - Current viewport width
|
|
15
|
+
* @returns Array of strings, each representing a line
|
|
16
|
+
*/
|
|
17
|
+
render(width: number): string[];
|
|
18
|
+
/**
|
|
19
|
+
* Optional handler for keyboard input when component has focus
|
|
20
|
+
*/
|
|
21
|
+
handleInput?(data: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* If true, component receives key release events (Kitty protocol).
|
|
24
|
+
* Default is false - release events are filtered out.
|
|
25
|
+
*/
|
|
26
|
+
wantsKeyRelease?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Invalidate any cached rendering state.
|
|
29
|
+
* Called when theme changes or when component needs to re-render from scratch.
|
|
30
|
+
*/
|
|
31
|
+
invalidate(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Optional cleanup hook. Called once when the component is permanently
|
|
34
|
+
* removed from the tree via removeChild/clear/dispose. Implementations MUST
|
|
35
|
+
* be idempotent. Components meant to be re-added should be detached, not
|
|
36
|
+
* removed/cleared.
|
|
37
|
+
*/
|
|
38
|
+
dispose?(): void;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Interface for components that can receive focus and display a hardware cursor.
|
|
42
|
+
* When focused, the component should emit CURSOR_MARKER at the cursor position
|
|
43
|
+
* in its render output. TUI will find this marker and position the hardware
|
|
44
|
+
* cursor there for proper IME candidate window positioning.
|
|
45
|
+
*/
|
|
46
|
+
export interface Focusable {
|
|
47
|
+
/** Set by TUI when focus changes. Component should emit CURSOR_MARKER when true. */
|
|
48
|
+
focused: boolean;
|
|
49
|
+
}
|
|
50
|
+
/** Type guard to check if a component implements Focusable */
|
|
51
|
+
export declare function isFocusable(component: Component | null): component is Component & Focusable;
|
|
52
|
+
/**
|
|
53
|
+
* Cursor position marker - APC (Application Program Command) sequence.
|
|
54
|
+
* This is a zero-width escape sequence that terminals ignore.
|
|
55
|
+
* Components emit this at the cursor position when focused.
|
|
56
|
+
* TUI finds and strips this marker, then positions the hardware cursor there.
|
|
57
|
+
*/
|
|
58
|
+
export declare const CURSOR_MARKER = "\u001B_pi:c\u0007";
|
|
59
|
+
export { visibleWidth };
|
|
60
|
+
/**
|
|
61
|
+
* Anchor position for overlays
|
|
62
|
+
*/
|
|
63
|
+
export type OverlayAnchor = "center" | "top-left" | "top-right" | "bottom-left" | "bottom-right" | "top-center" | "bottom-center" | "left-center" | "right-center";
|
|
64
|
+
/**
|
|
65
|
+
* Margin configuration for overlays
|
|
66
|
+
*/
|
|
67
|
+
export interface OverlayMargin {
|
|
68
|
+
top?: number;
|
|
69
|
+
right?: number;
|
|
70
|
+
bottom?: number;
|
|
71
|
+
left?: number;
|
|
72
|
+
}
|
|
73
|
+
/** Value that can be absolute (number) or percentage (string like "50%") */
|
|
74
|
+
export type SizeValue = number | `${number}%`;
|
|
75
|
+
/**
|
|
76
|
+
* Options for overlay positioning and sizing.
|
|
77
|
+
* Values can be absolute numbers or percentage strings (e.g., "50%").
|
|
78
|
+
*/
|
|
79
|
+
export interface OverlayOptions {
|
|
80
|
+
/** Width in columns, or percentage of terminal width (e.g., "50%") */
|
|
81
|
+
width?: SizeValue;
|
|
82
|
+
/** Minimum width in columns */
|
|
83
|
+
minWidth?: number;
|
|
84
|
+
/** Maximum height in rows, or percentage of terminal height (e.g., "50%") */
|
|
85
|
+
maxHeight?: SizeValue;
|
|
86
|
+
/** Anchor point for positioning (default: 'center') */
|
|
87
|
+
anchor?: OverlayAnchor;
|
|
88
|
+
/** Horizontal offset from anchor position (positive = right) */
|
|
89
|
+
offsetX?: number;
|
|
90
|
+
/** Vertical offset from anchor position (positive = down) */
|
|
91
|
+
offsetY?: number;
|
|
92
|
+
/** Row position: absolute number, or percentage (e.g., "25%" = 25% from top) */
|
|
93
|
+
row?: SizeValue;
|
|
94
|
+
/** Column position: absolute number, or percentage (e.g., "50%" = centered horizontally) */
|
|
95
|
+
col?: SizeValue;
|
|
96
|
+
/** Margin from terminal edges. Number applies to all sides. */
|
|
97
|
+
margin?: OverlayMargin | number;
|
|
98
|
+
/**
|
|
99
|
+
* Control overlay visibility based on terminal dimensions.
|
|
100
|
+
* If provided, overlay is only rendered when this returns true.
|
|
101
|
+
* Called each render cycle with current terminal dimensions.
|
|
102
|
+
*/
|
|
103
|
+
visible?: (termWidth: number, termHeight: number) => boolean;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Handle returned by showOverlay for controlling the overlay
|
|
107
|
+
*/
|
|
108
|
+
export interface OverlayHandle {
|
|
109
|
+
/** Permanently remove the overlay (cannot be shown again) */
|
|
110
|
+
hide(): void;
|
|
111
|
+
/** Temporarily hide or show the overlay */
|
|
112
|
+
setHidden(hidden: boolean): void;
|
|
113
|
+
/** Check if overlay is temporarily hidden */
|
|
114
|
+
isHidden(): boolean;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Container - a component that contains other components
|
|
118
|
+
*/
|
|
119
|
+
export declare class Container implements Component {
|
|
120
|
+
#private;
|
|
121
|
+
children: Component[];
|
|
122
|
+
addChild(component: Component): void;
|
|
123
|
+
removeChild(component: Component): void;
|
|
124
|
+
/** Remove a child without disposing it (for detach-then-readd reuse). */
|
|
125
|
+
detachChild(component: Component): void;
|
|
126
|
+
clear(): void;
|
|
127
|
+
/** Remove all children without disposing them (for detach-then-readd reuse). */
|
|
128
|
+
detachAll(): void;
|
|
129
|
+
dispose(): void;
|
|
130
|
+
invalidate(): void;
|
|
131
|
+
render(width: number): string[];
|
|
132
|
+
}
|
|
133
|
+
type TuiRenderCounterSnapshot = {
|
|
134
|
+
debugRedrawEnvReads: number;
|
|
135
|
+
debugRedrawAppendWrites: number;
|
|
136
|
+
differentialGuardVisibleWidthCalls: number;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* TUI - Main class for managing terminal UI with differential rendering
|
|
140
|
+
*/
|
|
141
|
+
export declare class TUI extends Container {
|
|
142
|
+
#private;
|
|
143
|
+
terminal: Terminal;
|
|
144
|
+
/** Global callback for debug key (Shift+Ctrl+D). Called before input is forwarded to focused component. */
|
|
145
|
+
onDebug?: () => void;
|
|
146
|
+
static resetRenderCountersForTest(): void;
|
|
147
|
+
static getRenderCountersForTest(): TuiRenderCounterSnapshot;
|
|
148
|
+
overlayStack: {
|
|
149
|
+
component: Component;
|
|
150
|
+
options?: OverlayOptions;
|
|
151
|
+
preFocus: Component | null;
|
|
152
|
+
hidden: boolean;
|
|
153
|
+
}[];
|
|
154
|
+
constructor(terminal: Terminal, showHardwareCursor?: boolean);
|
|
155
|
+
dispose(): void;
|
|
156
|
+
get fullRedraws(): number;
|
|
157
|
+
getShowHardwareCursor(): boolean;
|
|
158
|
+
setShowHardwareCursor(enabled: boolean): void;
|
|
159
|
+
getClearOnShrink(): boolean;
|
|
160
|
+
/**
|
|
161
|
+
* Set whether to trigger full re-render when content shrinks.
|
|
162
|
+
* When true (default), empty rows are cleared when content shrinks.
|
|
163
|
+
* When false, empty rows remain (reduces redraws on slower terminals).
|
|
164
|
+
*/
|
|
165
|
+
setClearOnShrink(enabled: boolean): void;
|
|
166
|
+
setFocus(component: Component | null): void;
|
|
167
|
+
setBottomPinnedComponent(component: Component | null): void;
|
|
168
|
+
scrollViewportPages(direction: -1 | 1): boolean;
|
|
169
|
+
followLiveViewport(): boolean;
|
|
170
|
+
/**
|
|
171
|
+
* Show an overlay component with configurable positioning and sizing.
|
|
172
|
+
* Returns a handle to control the overlay's visibility.
|
|
173
|
+
*/
|
|
174
|
+
showOverlay(component: Component, options?: OverlayOptions): OverlayHandle;
|
|
175
|
+
/** Hide the topmost overlay and restore previous focus. */
|
|
176
|
+
hideOverlay(): void;
|
|
177
|
+
/** Check if there are any visible overlays */
|
|
178
|
+
hasOverlay(): boolean;
|
|
179
|
+
invalidate(): void;
|
|
180
|
+
start(): void;
|
|
181
|
+
get terminalAvailable(): boolean;
|
|
182
|
+
addInputListener(listener: InputListener): () => void;
|
|
183
|
+
removeInputListener(listener: InputListener): void;
|
|
184
|
+
stop(): void;
|
|
185
|
+
/**
|
|
186
|
+
* Viewport-repaint-aware resize render request.
|
|
187
|
+
*
|
|
188
|
+
* A forced full redraw (`requestRender(true)`) resets `#previousWidth`/`#previousHeight`
|
|
189
|
+
* to -1, which makes `#doRender` treat the frame as a width change and fall into the
|
|
190
|
+
* `fullRender` path. In terminal multiplexers that path skips the scrollback-clearing
|
|
191
|
+
* `3J` escape (users navigate scrollback history), so replaying every transcript line
|
|
192
|
+
* piles it back on top of scrollback — the "top of screen scrolls down to the prompt at
|
|
193
|
+
* high speed" resize storm. Windows Terminal can also visibly jump to the
|
|
194
|
+
* transcript top during streaming redraws, so viewport-repaint sessions keep
|
|
195
|
+
* force off and let `#doRender` repaint only the live viewport. Set
|
|
196
|
+
* `PI_TUI_LEGACY_MULTIPLEXER_FULL_RENDER=1` to restore the legacy tmux redraw.
|
|
197
|
+
*/
|
|
198
|
+
requestResizeRender(): void;
|
|
199
|
+
requestRender(force?: boolean, source?: string): void;
|
|
200
|
+
getLineRenderCacheStats(): {
|
|
201
|
+
normalizationSize: number;
|
|
202
|
+
truncationSize: number;
|
|
203
|
+
normalizationLimit: number;
|
|
204
|
+
truncationLimit: number;
|
|
205
|
+
};
|
|
206
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Ellipsis, type ExtractSegmentsResult, type SliceResult } from "@sayknow-cli/natives";
|
|
2
|
+
export { Ellipsis } from "@sayknow-cli/natives";
|
|
3
|
+
export { getDefaultTabWidth, getIndentation } from "@sayknow-cli/utils";
|
|
4
|
+
/** Test-only performance counters for advisory baseline tests. */
|
|
5
|
+
export declare const __textHelperPerfCounters: {
|
|
6
|
+
truncateToWidthCalls: number;
|
|
7
|
+
wrapTextWithAnsiCalls: number;
|
|
8
|
+
truncateLinesToWidthCalls: number;
|
|
9
|
+
visibleWidthsCalls: number;
|
|
10
|
+
reset(): void;
|
|
11
|
+
};
|
|
12
|
+
export declare function invalidateTabWidthCache(): void;
|
|
13
|
+
export declare function isPrintableAscii(text: string): boolean;
|
|
14
|
+
export declare function sliceWithWidth(line: string, startCol: number, length: number, strict?: boolean | null): SliceResult;
|
|
15
|
+
export declare function truncateToWidth(text: string, maxWidth: number, ellipsisKind?: Ellipsis | null, pad?: boolean | null): string;
|
|
16
|
+
export declare function truncateLinesToWidth(lines: readonly string[], maxWidth: number, ellipsisKind?: Ellipsis | null, pad?: boolean | null): string[];
|
|
17
|
+
export declare function wrapTextWithAnsi(text: string, width: number): string[];
|
|
18
|
+
export declare function extractSegments(line: string, beforeEnd: number, afterStart: number, afterLen: number, strictAfter: boolean): ExtractSegmentsResult;
|
|
19
|
+
/**
|
|
20
|
+
* Tab width in columns for `file`, using `process.cwd()` as the project root for relative paths.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getIndentationNoescape(file?: string): number;
|
|
23
|
+
export declare function replaceTabs(text: string, file?: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Returns a string of n spaces. Uses a pre-allocated buffer for efficiency.
|
|
26
|
+
*/
|
|
27
|
+
export declare function padding(n: number): string;
|
|
28
|
+
/**
|
|
29
|
+
* Get the shared grapheme segmenter instance.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getSegmenter(): Intl.Segmenter;
|
|
32
|
+
export declare function visibleWidthRaw(str: string): number;
|
|
33
|
+
/**
|
|
34
|
+
* Calculate the visible width of a string in terminal columns.
|
|
35
|
+
*/
|
|
36
|
+
export declare function visibleWidth(str: string): number;
|
|
37
|
+
export declare function visibleWidthsNative(lines: readonly string[]): number[];
|
|
38
|
+
export declare function visibleWidths(lines: readonly string[]): number[];
|
|
39
|
+
/**
|
|
40
|
+
* Normalize text for terminal output without changing logical editor content.
|
|
41
|
+
* Some terminals render canonically decomposed Hangul jamo or precomposed
|
|
42
|
+
* Thai/Lao AM vowels inconsistently during differential repaint. Emit a stable
|
|
43
|
+
* terminal form while keeping the component/source strings unchanged.
|
|
44
|
+
*/
|
|
45
|
+
export declare function normalizeTerminalOutput(str: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Check if a character is whitespace.
|
|
48
|
+
*/
|
|
49
|
+
export declare function isWhitespaceChar(char: string): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Check if a character is punctuation.
|
|
52
|
+
*/
|
|
53
|
+
export declare function isPunctuationChar(char: string): boolean;
|
|
54
|
+
export type WordNavKind = "whitespace" | "delimiter" | "cjk" | "word" | "other";
|
|
55
|
+
/**
|
|
56
|
+
* Coarse Unicode-aware character classification for word navigation (Option/Alt + Left/Right).
|
|
57
|
+
* This intentionally avoids language-specific word segmentation for predictability across scripts.
|
|
58
|
+
*/
|
|
59
|
+
export declare function getWordNavKind(grapheme: string): WordNavKind;
|
|
60
|
+
export declare function isWordNavJoiner(grapheme: string): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Move the cursor one "word" to the left using Unicode-aware coarse navigation.
|
|
63
|
+
*
|
|
64
|
+
* Returns a new cursor index in the range [0, text.length].
|
|
65
|
+
*/
|
|
66
|
+
export declare function moveWordLeft(text: string, cursor: number): number;
|
|
67
|
+
/**
|
|
68
|
+
* Move the cursor one "word" to the right using Unicode-aware coarse navigation.
|
|
69
|
+
*
|
|
70
|
+
* Returns a new cursor index in the range [0, text.length].
|
|
71
|
+
*/
|
|
72
|
+
export declare function moveWordRight(text: string, cursor: number): number;
|
|
73
|
+
/**
|
|
74
|
+
* Apply background color to a line, padding to full width.
|
|
75
|
+
*
|
|
76
|
+
* @param line - Line of text (may contain ANSI codes)
|
|
77
|
+
* @param width - Total width to pad to
|
|
78
|
+
* @param bgFn - Background color function
|
|
79
|
+
* @returns Line with background applied and padded to width
|
|
80
|
+
*/
|
|
81
|
+
export declare function applyBackgroundToLine(line: string, width: number, bgFn: (text: string) => string): string;
|
|
82
|
+
/**
|
|
83
|
+
* Extract a range of visible columns from a line. Handles ANSI codes and wide chars.
|
|
84
|
+
*
|
|
85
|
+
* @param strict - If true, exclude wide chars at boundary that would extend past the range
|
|
86
|
+
*/
|
|
87
|
+
export declare function sliceByColumn(line: string, startCol: number, length: number, strict?: boolean): string;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@sayknow-cli/tui",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.8",
|
|
5
5
|
"description": "Terminal User Interface library with differential rendering for efficient text-based applications",
|
|
6
|
-
"homepage": "https://
|
|
6
|
+
"homepage": "https://sayknow-cli.com",
|
|
7
7
|
"author": "jaybeyond",
|
|
8
8
|
"contributors": [
|
|
9
9
|
"Mario Zechner"
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"cli"
|
|
28
28
|
],
|
|
29
29
|
"main": "./src/index.ts",
|
|
30
|
-
"types": "./
|
|
30
|
+
"types": "./dist/types/index.d.ts",
|
|
31
31
|
"scripts": {
|
|
32
32
|
"check": "biome check . && bun run check:types",
|
|
33
33
|
"check:types": "tsgo -p tsconfig.json --noEmit",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"fmt": "biome format --write ."
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@sayknow-cli/natives": "0.3.
|
|
42
|
-
"@sayknow-cli/utils": "0.3.
|
|
41
|
+
"@sayknow-cli/natives": "0.3.8",
|
|
42
|
+
"@sayknow-cli/utils": "0.3.8",
|
|
43
43
|
"lru-cache": "11.3.6",
|
|
44
44
|
"marked": "^18.0.3"
|
|
45
45
|
},
|
|
@@ -53,19 +53,20 @@
|
|
|
53
53
|
"files": [
|
|
54
54
|
"src",
|
|
55
55
|
"README.md",
|
|
56
|
-
"CHANGELOG.md"
|
|
56
|
+
"CHANGELOG.md",
|
|
57
|
+
"dist/types"
|
|
57
58
|
],
|
|
58
59
|
"exports": {
|
|
59
60
|
".": {
|
|
60
|
-
"types": "./
|
|
61
|
+
"types": "./dist/types/index.d.ts",
|
|
61
62
|
"import": "./src/index.ts"
|
|
62
63
|
},
|
|
63
64
|
"./*": {
|
|
64
|
-
"types": "./
|
|
65
|
+
"types": "./dist/types/*.d.ts",
|
|
65
66
|
"import": "./src/*.ts"
|
|
66
67
|
},
|
|
67
68
|
"./components/*": {
|
|
68
|
-
"types": "./
|
|
69
|
+
"types": "./dist/types/components/*.d.ts",
|
|
69
70
|
"import": "./src/components/*.ts"
|
|
70
71
|
},
|
|
71
72
|
"./*.js": "./src/*.ts"
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export type AnimationCadence = 16 | 80;
|
|
2
|
+
|
|
3
|
+
type TimerHandle = ReturnType<typeof setInterval>;
|
|
4
|
+
type AnimationCallback = (now: number) => void;
|
|
5
|
+
|
|
6
|
+
interface CadenceBucket {
|
|
7
|
+
callbacks: Set<AnimationCallback>;
|
|
8
|
+
timer?: TimerHandle;
|
|
9
|
+
startedTimers: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const buckets = new Map<AnimationCadence, CadenceBucket>();
|
|
13
|
+
|
|
14
|
+
function getBucket(cadence: AnimationCadence): CadenceBucket {
|
|
15
|
+
let bucket = buckets.get(cadence);
|
|
16
|
+
if (!bucket) {
|
|
17
|
+
bucket = { callbacks: new Set(), startedTimers: 0 };
|
|
18
|
+
buckets.set(cadence, bucket);
|
|
19
|
+
}
|
|
20
|
+
return bucket;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function startBucket(cadence: AnimationCadence, bucket: CadenceBucket): void {
|
|
24
|
+
if (bucket.timer) return;
|
|
25
|
+
bucket.timer = setInterval(() => {
|
|
26
|
+
const now = performance.now();
|
|
27
|
+
// Snapshot so re-entrant register/unregister during a tick is safe, and
|
|
28
|
+
// isolate each callback so one throwing registrant cannot starve siblings
|
|
29
|
+
// or surface as an uncaught exception that kills the shared timer.
|
|
30
|
+
for (const callback of [...bucket.callbacks]) {
|
|
31
|
+
try {
|
|
32
|
+
callback(now);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
console.error("[animation-scheduler] callback threw:", err);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}, cadence);
|
|
38
|
+
bucket.startedTimers += 1;
|
|
39
|
+
bucket.timer?.unref?.();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function stopBucket(bucket: CadenceBucket): void {
|
|
43
|
+
if (!bucket.timer) return;
|
|
44
|
+
clearInterval(bucket.timer);
|
|
45
|
+
bucket.timer = undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface AnimationRegistration {
|
|
49
|
+
unregister(): void;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function registerAnimationCallback(
|
|
53
|
+
callback: AnimationCallback,
|
|
54
|
+
cadence: AnimationCadence = 80,
|
|
55
|
+
): AnimationRegistration {
|
|
56
|
+
const bucket = getBucket(cadence);
|
|
57
|
+
bucket.callbacks.add(callback);
|
|
58
|
+
startBucket(cadence, bucket);
|
|
59
|
+
let registered = true;
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
unregister(): void {
|
|
63
|
+
if (!registered) return;
|
|
64
|
+
registered = false;
|
|
65
|
+
bucket.callbacks.delete(callback);
|
|
66
|
+
if (bucket.callbacks.size === 0) stopBucket(bucket);
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const __animationSchedulerTestHooks = {
|
|
72
|
+
getActiveTimerCount(cadence?: AnimationCadence): number {
|
|
73
|
+
if (cadence !== undefined) return getBucket(cadence).timer ? 1 : 0;
|
|
74
|
+
let count = 0;
|
|
75
|
+
for (const bucket of buckets.values()) {
|
|
76
|
+
if (bucket.timer) count += 1;
|
|
77
|
+
}
|
|
78
|
+
return count;
|
|
79
|
+
},
|
|
80
|
+
getRegistrantCount(cadence?: AnimationCadence): number {
|
|
81
|
+
if (cadence !== undefined) return getBucket(cadence).callbacks.size;
|
|
82
|
+
let count = 0;
|
|
83
|
+
for (const bucket of buckets.values()) count += bucket.callbacks.size;
|
|
84
|
+
return count;
|
|
85
|
+
},
|
|
86
|
+
getStartedTimerCount(cadence?: AnimationCadence): number {
|
|
87
|
+
if (cadence !== undefined) return getBucket(cadence).startedTimers;
|
|
88
|
+
let count = 0;
|
|
89
|
+
for (const bucket of buckets.values()) count += bucket.startedTimers;
|
|
90
|
+
return count;
|
|
91
|
+
},
|
|
92
|
+
reset(): void {
|
|
93
|
+
for (const bucket of buckets.values()) {
|
|
94
|
+
stopBucket(bucket);
|
|
95
|
+
bucket.callbacks.clear();
|
|
96
|
+
bucket.startedTimers = 0;
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
};
|