@flyingrobots/bijou-tui 0.9.0 → 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/dist/accordion.d.ts +46 -5
- package/dist/accordion.d.ts.map +1 -1
- package/dist/accordion.js +41 -5
- package/dist/accordion.js.map +1 -1
- package/dist/animate.d.ts +30 -0
- package/dist/animate.d.ts.map +1 -1
- package/dist/animate.js +33 -0
- package/dist/animate.js.map +1 -1
- package/dist/browsable-list.d.ts +67 -4
- package/dist/browsable-list.d.ts.map +1 -1
- package/dist/browsable-list.js +49 -4
- package/dist/browsable-list.js.map +1 -1
- package/dist/canvas.d.ts +42 -0
- package/dist/canvas.d.ts.map +1 -0
- package/dist/canvas.js +41 -0
- package/dist/canvas.js.map +1 -0
- package/dist/command-palette.d.ts +67 -6
- package/dist/command-palette.d.ts.map +1 -1
- package/dist/command-palette.js +67 -6
- package/dist/command-palette.js.map +1 -1
- package/dist/commands.d.ts +32 -3
- package/dist/commands.d.ts.map +1 -1
- package/dist/commands.js +32 -3
- package/dist/commands.js.map +1 -1
- package/dist/driver.d.ts +14 -0
- package/dist/driver.d.ts.map +1 -1
- package/dist/driver.js +7 -0
- package/dist/driver.js.map +1 -1
- package/dist/eventbus.d.ts +49 -9
- package/dist/eventbus.d.ts.map +1 -1
- package/dist/eventbus.js +22 -4
- package/dist/eventbus.js.map +1 -1
- package/dist/file-picker.d.ts +56 -4
- package/dist/file-picker.d.ts.map +1 -1
- package/dist/file-picker.js +52 -4
- package/dist/file-picker.js.map +1 -1
- package/dist/flex.d.ts +17 -0
- package/dist/flex.d.ts.map +1 -1
- package/dist/flex.js +106 -12
- package/dist/flex.js.map +1 -1
- package/dist/help.d.ts +16 -1
- package/dist/help.d.ts.map +1 -1
- package/dist/help.js +13 -0
- package/dist/help.js.map +1 -1
- package/dist/index.d.ts +12 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/inputstack.d.ts +32 -4
- package/dist/inputstack.d.ts.map +1 -1
- package/dist/inputstack.js +11 -0
- package/dist/inputstack.js.map +1 -1
- package/dist/keybindings.d.ts +106 -14
- package/dist/keybindings.d.ts.map +1 -1
- package/dist/keybindings.js +28 -2
- package/dist/keybindings.js.map +1 -1
- package/dist/keys.d.ts +29 -3
- package/dist/keys.d.ts.map +1 -1
- package/dist/keys.js +73 -2
- package/dist/keys.js.map +1 -1
- package/dist/layout.d.ts +26 -0
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +25 -1
- package/dist/layout.js.map +1 -1
- package/dist/navigable-table.d.ts +48 -4
- package/dist/navigable-table.d.ts.map +1 -1
- package/dist/navigable-table.js +44 -4
- package/dist/navigable-table.js.map +1 -1
- package/dist/overlay.d.ts +110 -3
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +87 -7
- package/dist/overlay.js.map +1 -1
- package/dist/pager.d.ts +66 -7
- package/dist/pager.d.ts.map +1 -1
- package/dist/pager.js +56 -7
- package/dist/pager.js.map +1 -1
- package/dist/panels.d.ts +55 -0
- package/dist/panels.d.ts.map +1 -1
- package/dist/panels.js +11 -0
- package/dist/panels.js.map +1 -1
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +24 -3
- package/dist/runtime.js.map +1 -1
- package/dist/screen.d.ts +37 -3
- package/dist/screen.d.ts.map +1 -1
- package/dist/screen.js +37 -3
- package/dist/screen.js.map +1 -1
- package/dist/spring.d.ts +56 -7
- package/dist/spring.d.ts.map +1 -1
- package/dist/spring.js +44 -7
- package/dist/spring.js.map +1 -1
- package/dist/status-bar.d.ts +15 -2
- package/dist/status-bar.d.ts.map +1 -1
- package/dist/status-bar.js +9 -0
- package/dist/status-bar.js.map +1 -1
- package/dist/timeline.d.ts +68 -5
- package/dist/timeline.d.ts.map +1 -1
- package/dist/timeline.js +33 -0
- package/dist/timeline.js.map +1 -1
- package/dist/types.d.ts +102 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +30 -2
- package/dist/types.js.map +1 -1
- package/dist/viewport.d.ts +74 -14
- package/dist/viewport.d.ts.map +1 -1
- package/dist/viewport.js +82 -60
- package/dist/viewport.js.map +1 -1
- package/package.json +2 -2
package/dist/types.d.ts
CHANGED
|
@@ -1,35 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core type definitions for the bijou-tui framework.
|
|
3
|
+
*
|
|
4
|
+
* Define the message types (key, resize, mouse), TEA application interface,
|
|
5
|
+
* command abstraction, and runtime options used throughout bijou-tui.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
1
9
|
import type { BijouContext } from '@flyingrobots/bijou';
|
|
10
|
+
/** Represent a keyboard input event with key name and modifier flags. */
|
|
2
11
|
export interface KeyMsg {
|
|
12
|
+
/** Discriminant tag identifying this as a keyboard message. */
|
|
3
13
|
readonly type: 'key';
|
|
14
|
+
/** Key name (e.g. `"a"`, `"enter"`, `"up"`, `"space"`). */
|
|
4
15
|
readonly key: string;
|
|
16
|
+
/** Whether the Ctrl modifier was held. */
|
|
5
17
|
readonly ctrl: boolean;
|
|
18
|
+
/** Whether the Alt/Option modifier was held. */
|
|
6
19
|
readonly alt: boolean;
|
|
20
|
+
/** Whether the Shift modifier was held. */
|
|
7
21
|
readonly shift: boolean;
|
|
8
22
|
}
|
|
23
|
+
/** Represent a terminal resize event with new dimensions. */
|
|
9
24
|
export interface ResizeMsg {
|
|
25
|
+
/** Discriminant tag identifying this as a resize message. */
|
|
10
26
|
readonly type: 'resize';
|
|
27
|
+
/** New terminal width in columns. */
|
|
11
28
|
readonly columns: number;
|
|
29
|
+
/** New terminal height in rows. */
|
|
12
30
|
readonly rows: number;
|
|
13
31
|
}
|
|
14
|
-
/**
|
|
32
|
+
/** Mouse button identifier. `"none"` is used for scroll and motion events without a button. */
|
|
33
|
+
export type MouseButton = 'left' | 'middle' | 'right' | 'none';
|
|
34
|
+
/** Mouse action type including press, release, move, and scroll directions. */
|
|
35
|
+
export type MouseAction = 'press' | 'release' | 'move' | 'scroll-up' | 'scroll-down';
|
|
36
|
+
/** Represent a mouse input event with button, action, position, and modifiers. */
|
|
37
|
+
export interface MouseMsg {
|
|
38
|
+
/** Discriminant tag identifying this as a mouse message. */
|
|
39
|
+
readonly type: 'mouse';
|
|
40
|
+
/** Which mouse button is involved (or `"none"` for scroll/motion). */
|
|
41
|
+
readonly button: MouseButton;
|
|
42
|
+
/** The mouse action performed. */
|
|
43
|
+
readonly action: MouseAction;
|
|
44
|
+
/** 0-based column position. */
|
|
45
|
+
readonly col: number;
|
|
46
|
+
/** 0-based row position. */
|
|
47
|
+
readonly row: number;
|
|
48
|
+
/** Whether the Shift modifier was held. */
|
|
49
|
+
readonly shift: boolean;
|
|
50
|
+
/** Whether the Alt/Option modifier was held. */
|
|
51
|
+
readonly alt: boolean;
|
|
52
|
+
/** Whether the Ctrl modifier was held. */
|
|
53
|
+
readonly ctrl: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Narrow an unknown message to {@link KeyMsg}.
|
|
57
|
+
*
|
|
58
|
+
* @param msg - Value to test.
|
|
59
|
+
* @returns `true` if `msg` is a `KeyMsg`.
|
|
60
|
+
*/
|
|
15
61
|
export declare function isKeyMsg(msg: unknown): msg is KeyMsg;
|
|
16
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* Narrow an unknown message to {@link ResizeMsg}.
|
|
64
|
+
*
|
|
65
|
+
* @param msg - Value to test.
|
|
66
|
+
* @returns `true` if `msg` is a `ResizeMsg`.
|
|
67
|
+
*/
|
|
17
68
|
export declare function isResizeMsg(msg: unknown): msg is ResizeMsg;
|
|
69
|
+
/**
|
|
70
|
+
* Narrow an unknown message to {@link MouseMsg}.
|
|
71
|
+
*
|
|
72
|
+
* @param msg - Value to test.
|
|
73
|
+
* @returns `true` if `msg` is a `MouseMsg`.
|
|
74
|
+
*/
|
|
75
|
+
export declare function isMouseMsg(msg: unknown): msg is MouseMsg;
|
|
76
|
+
/** Sentinel symbol signaling that the application should quit. */
|
|
18
77
|
export declare const QUIT: unique symbol;
|
|
78
|
+
/** The type of the {@link QUIT} sentinel symbol. */
|
|
19
79
|
export type QuitSignal = typeof QUIT;
|
|
20
80
|
/**
|
|
21
|
-
* A side
|
|
22
|
-
*
|
|
81
|
+
* A side-effect function that can emit messages back to the application.
|
|
82
|
+
*
|
|
83
|
+
* Receive an `emit` callback for dispatching intermediate messages during
|
|
84
|
+
* execution. Resolve to a final message, a {@link QuitSignal}, or `void`.
|
|
85
|
+
*
|
|
86
|
+
* @template M - Application message type.
|
|
23
87
|
*/
|
|
24
88
|
export type Cmd<M> = (emit: (msg: M) => void) => Promise<M | QuitSignal | void>;
|
|
89
|
+
/**
|
|
90
|
+
* TEA (The Elm Architecture) application interface.
|
|
91
|
+
*
|
|
92
|
+
* Define the three core functions: `init` for initial state, `update` for
|
|
93
|
+
* state transitions, and `view` for rendering.
|
|
94
|
+
*
|
|
95
|
+
* @template Model - Application state type.
|
|
96
|
+
* @template M - Custom application message type (defaults to `never`).
|
|
97
|
+
*/
|
|
25
98
|
export interface App<Model, M = never> {
|
|
99
|
+
/**
|
|
100
|
+
* Return the initial model and startup commands.
|
|
101
|
+
*
|
|
102
|
+
* @returns A tuple of `[initialModel, startupCommands]`.
|
|
103
|
+
*/
|
|
26
104
|
init(): [Model, Cmd<M>[]];
|
|
27
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Handle a message and return the updated model with commands.
|
|
107
|
+
*
|
|
108
|
+
* @param msg - Incoming message (key, resize, mouse, or custom).
|
|
109
|
+
* @param model - Current application state.
|
|
110
|
+
* @returns A tuple of `[updatedModel, commands]`.
|
|
111
|
+
*/
|
|
112
|
+
update(msg: KeyMsg | ResizeMsg | MouseMsg | M, model: Model): [Model, Cmd<M>[]];
|
|
113
|
+
/**
|
|
114
|
+
* Render the current model as a string for terminal display.
|
|
115
|
+
*
|
|
116
|
+
* @param model - Current application state.
|
|
117
|
+
* @returns Rendered string output.
|
|
118
|
+
*/
|
|
28
119
|
view(model: Model): string;
|
|
29
120
|
}
|
|
121
|
+
/** Configuration options for the TEA runtime. */
|
|
30
122
|
export interface RunOptions {
|
|
123
|
+
/** Enter the alternate screen buffer on startup. */
|
|
31
124
|
altScreen?: boolean;
|
|
125
|
+
/** Hide the cursor on startup. */
|
|
32
126
|
hideCursor?: boolean;
|
|
127
|
+
/** Enable mouse input (SGR mode). Default: false. */
|
|
128
|
+
mouse?: boolean;
|
|
129
|
+
/** Bijou context providing I/O and runtime ports. */
|
|
33
130
|
ctx?: BijouContext;
|
|
34
131
|
}
|
|
35
132
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAIxD,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAID,2CAA2C;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAIxD,yEAAyE;AACzE,MAAM,WAAW,MAAM;IACrB,+DAA+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AAC;CACpB"}
|
package/dist/types.js
CHANGED
|
@@ -1,12 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core type definitions for the bijou-tui framework.
|
|
3
|
+
*
|
|
4
|
+
* Define the message types (key, resize, mouse), TEA application interface,
|
|
5
|
+
* command abstraction, and runtime options used throughout bijou-tui.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
1
9
|
// --- Type guards ---
|
|
2
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Narrow an unknown message to {@link KeyMsg}.
|
|
12
|
+
*
|
|
13
|
+
* @param msg - Value to test.
|
|
14
|
+
* @returns `true` if `msg` is a `KeyMsg`.
|
|
15
|
+
*/
|
|
3
16
|
export function isKeyMsg(msg) {
|
|
4
17
|
return typeof msg === 'object' && msg !== null && 'type' in msg && msg.type === 'key';
|
|
5
18
|
}
|
|
6
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Narrow an unknown message to {@link ResizeMsg}.
|
|
21
|
+
*
|
|
22
|
+
* @param msg - Value to test.
|
|
23
|
+
* @returns `true` if `msg` is a `ResizeMsg`.
|
|
24
|
+
*/
|
|
7
25
|
export function isResizeMsg(msg) {
|
|
8
26
|
return typeof msg === 'object' && msg !== null && 'type' in msg && msg.type === 'resize';
|
|
9
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Narrow an unknown message to {@link MouseMsg}.
|
|
30
|
+
*
|
|
31
|
+
* @param msg - Value to test.
|
|
32
|
+
* @returns `true` if `msg` is a `MouseMsg`.
|
|
33
|
+
*/
|
|
34
|
+
export function isMouseMsg(msg) {
|
|
35
|
+
return typeof msg === 'object' && msg !== null && 'type' in msg && msg.type === 'mouse';
|
|
36
|
+
}
|
|
10
37
|
// --- Commands ---
|
|
38
|
+
/** Sentinel symbol signaling that the application should quit. */
|
|
11
39
|
export const QUIT = Symbol('QUIT');
|
|
12
40
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA0DH,sBAAsB;AAEtB;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAY;IACnC,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,MAAM,IAAI,GAAG,IAAK,GAAc,CAAC,IAAI,KAAK,KAAK,CAAC;AACpG,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,MAAM,IAAI,GAAG,IAAK,GAAiB,CAAC,IAAI,KAAK,QAAQ,CAAC;AAC1G,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,GAAY;IACrC,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,MAAM,IAAI,GAAG,IAAK,GAAgB,CAAC,IAAI,KAAK,OAAO,CAAC;AACxG,CAAC;AAED,mBAAmB;AAEnB,kEAAkE;AAClE,MAAM,CAAC,MAAM,IAAI,GAAkB,MAAM,CAAC,MAAM,CAAC,CAAC"}
|
package/dist/viewport.d.ts
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
* Renders a visible window into content that may be larger than the
|
|
5
5
|
* available screen space, with optional scrollbar indicator.
|
|
6
6
|
*/
|
|
7
|
+
import { clipToWidth as coreClipToWidth } from '@flyingrobots/bijou';
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for rendering a scrollable viewport window.
|
|
10
|
+
*/
|
|
7
11
|
export interface ViewportOptions {
|
|
8
12
|
/** Visible width in columns. Content lines longer than this are clipped. */
|
|
9
13
|
readonly width: number;
|
|
@@ -18,6 +22,9 @@ export interface ViewportOptions {
|
|
|
18
22
|
/** Show a scrollbar track on the right edge. Default: true. */
|
|
19
23
|
readonly showScrollbar?: boolean;
|
|
20
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Immutable snapshot of scroll position and bounds for a viewport.
|
|
27
|
+
*/
|
|
21
28
|
export interface ScrollState {
|
|
22
29
|
/** Current vertical scroll offset. */
|
|
23
30
|
readonly y: number;
|
|
@@ -32,12 +39,21 @@ export interface ScrollState {
|
|
|
32
39
|
/** Number of visible lines (viewport height). */
|
|
33
40
|
readonly visibleLines: number;
|
|
34
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Strip all SGR ANSI escape sequences from a string.
|
|
44
|
+
*
|
|
45
|
+
* @param str - Input string possibly containing ANSI escapes.
|
|
46
|
+
* @returns Plain text with all ANSI color/style sequences removed.
|
|
47
|
+
*/
|
|
35
48
|
export declare function stripAnsi(str: string): string;
|
|
36
49
|
/**
|
|
37
50
|
* Compute the terminal display width of a string.
|
|
38
51
|
*
|
|
39
52
|
* Grapheme-cluster aware: handles emoji, CJK (2 columns), ZWJ sequences,
|
|
40
53
|
* skin tones, flag pairs, and combining marks correctly.
|
|
54
|
+
*
|
|
55
|
+
* @param str - Input string (may contain ANSI escapes).
|
|
56
|
+
* @returns Display width in terminal columns.
|
|
41
57
|
*/
|
|
42
58
|
export declare function visibleLength(str: string): number;
|
|
43
59
|
/**
|
|
@@ -45,60 +61,104 @@ export declare function visibleLength(str: string): number;
|
|
|
45
61
|
* Grapheme-cluster aware: won't split multi-codepoint sequences.
|
|
46
62
|
* Appends a reset sequence if the string was clipped mid-style.
|
|
47
63
|
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
64
|
+
* Re-exported from `@flyingrobots/bijou` core for backward compatibility.
|
|
65
|
+
*
|
|
66
|
+
* @param str - Input string (may contain ANSI escapes).
|
|
67
|
+
* @param maxWidth - Maximum visible width in terminal columns.
|
|
68
|
+
* @returns Clipped string, at most `maxWidth` columns wide.
|
|
50
69
|
*/
|
|
51
|
-
export declare
|
|
70
|
+
export declare const clipToWidth: typeof coreClipToWidth;
|
|
52
71
|
/**
|
|
53
72
|
* Extract a visible-column substring from an ANSI-styled string.
|
|
54
|
-
*
|
|
55
|
-
* Grapheme-cluster aware.
|
|
73
|
+
* Return characters between visible columns [startCol, endCol).
|
|
74
|
+
* Grapheme-cluster aware. Preserve any active ANSI styles seen before startCol.
|
|
56
75
|
*
|
|
57
|
-
* O(n): pre-
|
|
76
|
+
* O(n): pre-segment stripped text once, then walk the original string
|
|
58
77
|
* with a grapheme pointer instead of re-segmenting per character.
|
|
78
|
+
*
|
|
79
|
+
* @param str - ANSI-styled input string.
|
|
80
|
+
* @param startCol - Start visible column (inclusive, 0-based).
|
|
81
|
+
* @param endCol - End visible column (exclusive).
|
|
82
|
+
* @returns Substring spanning the requested visible columns with ANSI styles preserved.
|
|
59
83
|
*/
|
|
60
84
|
export declare function sliceAnsi(str: string, startCol: number, endCol: number): string;
|
|
61
85
|
/**
|
|
62
86
|
* Render a scrollable viewport into content.
|
|
63
87
|
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
88
|
+
* Return a string with exactly `height` lines, each at most `width`
|
|
89
|
+
* visible columns wide (including optional scrollbar when enabled).
|
|
90
|
+
*
|
|
91
|
+
* @param options - Viewport configuration including dimensions, content, and scroll offsets.
|
|
92
|
+
* @returns Rendered viewport string with lines joined by newlines.
|
|
66
93
|
*/
|
|
67
94
|
export declare function viewport(options: ViewportOptions): string;
|
|
68
95
|
/**
|
|
69
96
|
* Create initial scroll state for content within a viewport.
|
|
97
|
+
*
|
|
98
|
+
* @param content - Full content string (newline-delimited).
|
|
99
|
+
* @param viewportHeight - Visible height in rows.
|
|
100
|
+
* @param viewportWidth - Visible width in columns (used to compute maxX).
|
|
101
|
+
* @returns Initial scroll state positioned at top-left (y=0, x=0).
|
|
70
102
|
*/
|
|
71
103
|
export declare function createScrollState(content: string, viewportHeight: number, viewportWidth?: number): ScrollState;
|
|
72
104
|
/**
|
|
73
|
-
* Scroll by a relative amount
|
|
105
|
+
* Scroll vertically by a relative amount, clamping to valid range.
|
|
106
|
+
*
|
|
107
|
+
* @param state - Current scroll state.
|
|
108
|
+
* @param dy - Relative vertical offset (positive = down, negative = up).
|
|
109
|
+
* @returns New scroll state with updated y position.
|
|
74
110
|
*/
|
|
75
111
|
export declare function scrollBy(state: ScrollState, dy: number): ScrollState;
|
|
76
112
|
/**
|
|
77
|
-
* Scroll to an absolute position
|
|
113
|
+
* Scroll vertically to an absolute position, clamping to valid range.
|
|
114
|
+
*
|
|
115
|
+
* @param state - Current scroll state.
|
|
116
|
+
* @param y - Absolute vertical offset (0-based line index).
|
|
117
|
+
* @returns New scroll state with updated y position.
|
|
78
118
|
*/
|
|
79
119
|
export declare function scrollTo(state: ScrollState, y: number): ScrollState;
|
|
80
120
|
/**
|
|
81
|
-
* Scroll horizontally by a relative amount
|
|
121
|
+
* Scroll horizontally by a relative amount, clamping to valid range.
|
|
122
|
+
*
|
|
123
|
+
* @param state - Current scroll state.
|
|
124
|
+
* @param dx - Relative horizontal offset (positive = right, negative = left).
|
|
125
|
+
* @returns New scroll state with updated x position.
|
|
82
126
|
*/
|
|
83
127
|
export declare function scrollByX(state: ScrollState, dx: number): ScrollState;
|
|
84
128
|
/**
|
|
85
|
-
* Scroll horizontally to an absolute position
|
|
129
|
+
* Scroll horizontally to an absolute position, clamping to valid range.
|
|
130
|
+
*
|
|
131
|
+
* @param state - Current scroll state.
|
|
132
|
+
* @param x - Absolute horizontal offset (0-based column index).
|
|
133
|
+
* @returns New scroll state with updated x position.
|
|
86
134
|
*/
|
|
87
135
|
export declare function scrollToX(state: ScrollState, x: number): ScrollState;
|
|
88
136
|
/**
|
|
89
|
-
* Scroll to the top.
|
|
137
|
+
* Scroll to the top (y = 0).
|
|
138
|
+
*
|
|
139
|
+
* @param state - Current scroll state.
|
|
140
|
+
* @returns New scroll state positioned at the top.
|
|
90
141
|
*/
|
|
91
142
|
export declare function scrollToTop(state: ScrollState): ScrollState;
|
|
92
143
|
/**
|
|
93
|
-
* Scroll to the bottom.
|
|
144
|
+
* Scroll to the bottom (y = maxY).
|
|
145
|
+
*
|
|
146
|
+
* @param state - Current scroll state.
|
|
147
|
+
* @returns New scroll state positioned at the bottom.
|
|
94
148
|
*/
|
|
95
149
|
export declare function scrollToBottom(state: ScrollState): ScrollState;
|
|
96
150
|
/**
|
|
97
151
|
* Page down (scroll by one viewport height).
|
|
152
|
+
*
|
|
153
|
+
* @param state - Current scroll state.
|
|
154
|
+
* @returns New scroll state scrolled down by `visibleLines` rows.
|
|
98
155
|
*/
|
|
99
156
|
export declare function pageDown(state: ScrollState): ScrollState;
|
|
100
157
|
/**
|
|
101
158
|
* Page up (scroll by one viewport height).
|
|
159
|
+
*
|
|
160
|
+
* @param state - Current scroll state.
|
|
161
|
+
* @returns New scroll state scrolled up by `visibleLines` rows.
|
|
102
162
|
*/
|
|
103
163
|
export declare function pageUp(state: ScrollState): ScrollState;
|
|
104
164
|
//# sourceMappingURL=viewport.d.ts.map
|
package/dist/viewport.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viewport.d.ts","sourceRoot":"","sources":["../src/viewport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"viewport.d.ts","sourceRoot":"","sources":["../src/viewport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAyD,WAAW,IAAI,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAM5H;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,4EAA4E;IAC5E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,8BAA8B;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,mEAAmE;IACnE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,+DAA+D;IAC/D,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,mEAAmE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QAAQ,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,GAAG,WAAW,CAEnE;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,GAAG,WAAW,CAErE;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,GAAG,WAAW,CAEpE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW,CAE3D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW,CAE9D;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW,CAExD;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW,CAEtD"}
|
package/dist/viewport.js
CHANGED
|
@@ -4,11 +4,18 @@
|
|
|
4
4
|
* Renders a visible window into content that may be larger than the
|
|
5
5
|
* available screen space, with optional scrollbar indicator.
|
|
6
6
|
*/
|
|
7
|
-
import { graphemeWidth, graphemeClusterWidth, segmentGraphemes } from '@flyingrobots/bijou';
|
|
7
|
+
import { graphemeWidth, graphemeClusterWidth, segmentGraphemes, clipToWidth as coreClipToWidth } from '@flyingrobots/bijou';
|
|
8
8
|
// ---------------------------------------------------------------------------
|
|
9
9
|
// ANSI helpers
|
|
10
10
|
// ---------------------------------------------------------------------------
|
|
11
|
+
/** Pattern matching SGR-style ANSI escape sequences. */
|
|
11
12
|
const ANSI_RE = /\x1b\[[0-9;]*m/g;
|
|
13
|
+
/**
|
|
14
|
+
* Strip all SGR ANSI escape sequences from a string.
|
|
15
|
+
*
|
|
16
|
+
* @param str - Input string possibly containing ANSI escapes.
|
|
17
|
+
* @returns Plain text with all ANSI color/style sequences removed.
|
|
18
|
+
*/
|
|
12
19
|
export function stripAnsi(str) {
|
|
13
20
|
return str.replace(ANSI_RE, '');
|
|
14
21
|
}
|
|
@@ -17,6 +24,9 @@ export function stripAnsi(str) {
|
|
|
17
24
|
*
|
|
18
25
|
* Grapheme-cluster aware: handles emoji, CJK (2 columns), ZWJ sequences,
|
|
19
26
|
* skin tones, flag pairs, and combining marks correctly.
|
|
27
|
+
*
|
|
28
|
+
* @param str - Input string (may contain ANSI escapes).
|
|
29
|
+
* @returns Display width in terminal columns.
|
|
20
30
|
*/
|
|
21
31
|
export function visibleLength(str) {
|
|
22
32
|
return graphemeWidth(str);
|
|
@@ -26,62 +36,25 @@ export function visibleLength(str) {
|
|
|
26
36
|
* Grapheme-cluster aware: won't split multi-codepoint sequences.
|
|
27
37
|
* Appends a reset sequence if the string was clipped mid-style.
|
|
28
38
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
39
|
+
* Re-exported from `@flyingrobots/bijou` core for backward compatibility.
|
|
40
|
+
*
|
|
41
|
+
* @param str - Input string (may contain ANSI escapes).
|
|
42
|
+
* @param maxWidth - Maximum visible width in terminal columns.
|
|
43
|
+
* @returns Clipped string, at most `maxWidth` columns wide.
|
|
31
44
|
*/
|
|
32
|
-
export
|
|
33
|
-
const stripped = stripAnsi(str);
|
|
34
|
-
const graphemes = segmentGraphemes(stripped);
|
|
35
|
-
let result = '';
|
|
36
|
-
let visible = 0;
|
|
37
|
-
let inEscape = false;
|
|
38
|
-
let escBuf = '';
|
|
39
|
-
let hasStyle = false;
|
|
40
|
-
let gi = 0;
|
|
41
|
-
let i = 0;
|
|
42
|
-
while (i < str.length) {
|
|
43
|
-
const ch = str[i];
|
|
44
|
-
if (ch === '\x1b') {
|
|
45
|
-
inEscape = true;
|
|
46
|
-
escBuf = ch;
|
|
47
|
-
i++;
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
if (inEscape) {
|
|
51
|
-
escBuf += ch;
|
|
52
|
-
if (ch === 'm') {
|
|
53
|
-
inEscape = false;
|
|
54
|
-
result += escBuf;
|
|
55
|
-
escBuf = '';
|
|
56
|
-
hasStyle = true;
|
|
57
|
-
}
|
|
58
|
-
i++;
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
// Visible character — consume next pre-segmented grapheme
|
|
62
|
-
if (gi >= graphemes.length)
|
|
63
|
-
break;
|
|
64
|
-
const grapheme = graphemes[gi];
|
|
65
|
-
const gWidth = graphemeClusterWidth(grapheme);
|
|
66
|
-
if (visible + gWidth > maxWidth) {
|
|
67
|
-
if (hasStyle)
|
|
68
|
-
result += '\x1b[0m';
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
result += grapheme;
|
|
72
|
-
visible += gWidth;
|
|
73
|
-
gi++;
|
|
74
|
-
i += grapheme.length;
|
|
75
|
-
}
|
|
76
|
-
return result;
|
|
77
|
-
}
|
|
45
|
+
export const clipToWidth = coreClipToWidth;
|
|
78
46
|
/**
|
|
79
47
|
* Extract a visible-column substring from an ANSI-styled string.
|
|
80
|
-
*
|
|
81
|
-
* Grapheme-cluster aware.
|
|
48
|
+
* Return characters between visible columns [startCol, endCol).
|
|
49
|
+
* Grapheme-cluster aware. Preserve any active ANSI styles seen before startCol.
|
|
82
50
|
*
|
|
83
|
-
* O(n): pre-
|
|
51
|
+
* O(n): pre-segment stripped text once, then walk the original string
|
|
84
52
|
* with a grapheme pointer instead of re-segmenting per character.
|
|
53
|
+
*
|
|
54
|
+
* @param str - ANSI-styled input string.
|
|
55
|
+
* @param startCol - Start visible column (inclusive, 0-based).
|
|
56
|
+
* @param endCol - End visible column (exclusive).
|
|
57
|
+
* @returns Substring spanning the requested visible columns with ANSI styles preserved.
|
|
85
58
|
*/
|
|
86
59
|
export function sliceAnsi(str, startCol, endCol) {
|
|
87
60
|
const stripped = stripAnsi(str);
|
|
@@ -151,8 +124,21 @@ export function sliceAnsi(str, startCol, endCol) {
|
|
|
151
124
|
// ---------------------------------------------------------------------------
|
|
152
125
|
// Scrollbar rendering
|
|
153
126
|
// ---------------------------------------------------------------------------
|
|
127
|
+
/** Character used for the scrollbar track (unfilled portion). */
|
|
154
128
|
const SCROLLBAR_TRACK = '│';
|
|
129
|
+
/** Character used for the scrollbar thumb (filled portion). */
|
|
155
130
|
const SCROLLBAR_THUMB = '█';
|
|
131
|
+
/**
|
|
132
|
+
* Render a vertical scrollbar as an array of single-character strings.
|
|
133
|
+
*
|
|
134
|
+
* Thumb size is proportional to the visible fraction of content.
|
|
135
|
+
* Return an array of spaces when all content fits within the viewport.
|
|
136
|
+
*
|
|
137
|
+
* @param viewportHeight - Height of the viewport in rows.
|
|
138
|
+
* @param totalLines - Total number of content lines.
|
|
139
|
+
* @param scrollY - Current vertical scroll offset.
|
|
140
|
+
* @returns Array of length `viewportHeight`, each element a single scrollbar character.
|
|
141
|
+
*/
|
|
156
142
|
function renderScrollbar(viewportHeight, totalLines, scrollY) {
|
|
157
143
|
if (totalLines <= viewportHeight) {
|
|
158
144
|
// No scrolling needed — empty gutter
|
|
@@ -176,8 +162,11 @@ function renderScrollbar(viewportHeight, totalLines, scrollY) {
|
|
|
176
162
|
/**
|
|
177
163
|
* Render a scrollable viewport into content.
|
|
178
164
|
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
165
|
+
* Return a string with exactly `height` lines, each at most `width`
|
|
166
|
+
* visible columns wide (including optional scrollbar when enabled).
|
|
167
|
+
*
|
|
168
|
+
* @param options - Viewport configuration including dimensions, content, and scroll offsets.
|
|
169
|
+
* @returns Rendered viewport string with lines joined by newlines.
|
|
181
170
|
*/
|
|
182
171
|
export function viewport(options) {
|
|
183
172
|
const { width, height, content, scrollY = 0, scrollX = 0, showScrollbar = true, } = options;
|
|
@@ -219,6 +208,11 @@ export function viewport(options) {
|
|
|
219
208
|
// ---------------------------------------------------------------------------
|
|
220
209
|
/**
|
|
221
210
|
* Create initial scroll state for content within a viewport.
|
|
211
|
+
*
|
|
212
|
+
* @param content - Full content string (newline-delimited).
|
|
213
|
+
* @param viewportHeight - Visible height in rows.
|
|
214
|
+
* @param viewportWidth - Visible width in columns (used to compute maxX).
|
|
215
|
+
* @returns Initial scroll state positioned at top-left (y=0, x=0).
|
|
222
216
|
*/
|
|
223
217
|
export function createScrollState(content, viewportHeight, viewportWidth) {
|
|
224
218
|
const lines = content.split('\n');
|
|
@@ -243,50 +237,78 @@ export function createScrollState(content, viewportHeight, viewportWidth) {
|
|
|
243
237
|
};
|
|
244
238
|
}
|
|
245
239
|
/**
|
|
246
|
-
* Scroll by a relative amount
|
|
240
|
+
* Scroll vertically by a relative amount, clamping to valid range.
|
|
241
|
+
*
|
|
242
|
+
* @param state - Current scroll state.
|
|
243
|
+
* @param dy - Relative vertical offset (positive = down, negative = up).
|
|
244
|
+
* @returns New scroll state with updated y position.
|
|
247
245
|
*/
|
|
248
246
|
export function scrollBy(state, dy) {
|
|
249
247
|
const y = Math.max(0, Math.min(state.y + dy, state.maxY));
|
|
250
248
|
return { ...state, y };
|
|
251
249
|
}
|
|
252
250
|
/**
|
|
253
|
-
* Scroll to an absolute position
|
|
251
|
+
* Scroll vertically to an absolute position, clamping to valid range.
|
|
252
|
+
*
|
|
253
|
+
* @param state - Current scroll state.
|
|
254
|
+
* @param y - Absolute vertical offset (0-based line index).
|
|
255
|
+
* @returns New scroll state with updated y position.
|
|
254
256
|
*/
|
|
255
257
|
export function scrollTo(state, y) {
|
|
256
258
|
return { ...state, y: Math.max(0, Math.min(y, state.maxY)) };
|
|
257
259
|
}
|
|
258
260
|
/**
|
|
259
|
-
* Scroll horizontally by a relative amount
|
|
261
|
+
* Scroll horizontally by a relative amount, clamping to valid range.
|
|
262
|
+
*
|
|
263
|
+
* @param state - Current scroll state.
|
|
264
|
+
* @param dx - Relative horizontal offset (positive = right, negative = left).
|
|
265
|
+
* @returns New scroll state with updated x position.
|
|
260
266
|
*/
|
|
261
267
|
export function scrollByX(state, dx) {
|
|
262
268
|
return { ...state, x: Math.max(0, Math.min(state.x + dx, state.maxX)) };
|
|
263
269
|
}
|
|
264
270
|
/**
|
|
265
|
-
* Scroll horizontally to an absolute position
|
|
271
|
+
* Scroll horizontally to an absolute position, clamping to valid range.
|
|
272
|
+
*
|
|
273
|
+
* @param state - Current scroll state.
|
|
274
|
+
* @param x - Absolute horizontal offset (0-based column index).
|
|
275
|
+
* @returns New scroll state with updated x position.
|
|
266
276
|
*/
|
|
267
277
|
export function scrollToX(state, x) {
|
|
268
278
|
return { ...state, x: Math.max(0, Math.min(x, state.maxX)) };
|
|
269
279
|
}
|
|
270
280
|
/**
|
|
271
|
-
* Scroll to the top.
|
|
281
|
+
* Scroll to the top (y = 0).
|
|
282
|
+
*
|
|
283
|
+
* @param state - Current scroll state.
|
|
284
|
+
* @returns New scroll state positioned at the top.
|
|
272
285
|
*/
|
|
273
286
|
export function scrollToTop(state) {
|
|
274
287
|
return { ...state, y: 0 };
|
|
275
288
|
}
|
|
276
289
|
/**
|
|
277
|
-
* Scroll to the bottom.
|
|
290
|
+
* Scroll to the bottom (y = maxY).
|
|
291
|
+
*
|
|
292
|
+
* @param state - Current scroll state.
|
|
293
|
+
* @returns New scroll state positioned at the bottom.
|
|
278
294
|
*/
|
|
279
295
|
export function scrollToBottom(state) {
|
|
280
296
|
return { ...state, y: state.maxY };
|
|
281
297
|
}
|
|
282
298
|
/**
|
|
283
299
|
* Page down (scroll by one viewport height).
|
|
300
|
+
*
|
|
301
|
+
* @param state - Current scroll state.
|
|
302
|
+
* @returns New scroll state scrolled down by `visibleLines` rows.
|
|
284
303
|
*/
|
|
285
304
|
export function pageDown(state) {
|
|
286
305
|
return scrollBy(state, state.visibleLines);
|
|
287
306
|
}
|
|
288
307
|
/**
|
|
289
308
|
* Page up (scroll by one viewport height).
|
|
309
|
+
*
|
|
310
|
+
* @param state - Current scroll state.
|
|
311
|
+
* @returns New scroll state scrolled up by `visibleLines` rows.
|
|
290
312
|
*/
|
|
291
313
|
export function pageUp(state) {
|
|
292
314
|
return scrollBy(state, -state.visibleLines);
|
package/dist/viewport.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viewport.js","sourceRoot":"","sources":["../src/viewport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"viewport.js","sourceRoot":"","sources":["../src/viewport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,WAAW,IAAI,eAAe,EAAE,MAAM,qBAAqB,CAAC;AA0C5H,8EAA8E;AAC9E,eAAe;AACf,8EAA8E;AAE9E,wDAAwD;AACxD,MAAM,OAAO,GAAG,iBAAiB,CAAC;AAElC;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AAClC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,eAAe,CAAC;AAE3C;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW,EAAE,QAAgB,EAAE,MAAc;IACrE,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;IAChC,MAAM,SAAS,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAE7C,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,UAAU,GAAG,EAAE,CAAC;IACpB,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,IAAI,QAAQ,GAAG,KAAK,CAAC;IAC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S,CAAC,KAAkB,EAAE,EAAU;IACtD,OAAO,EAAE,GAAG,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;AAC1E,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,KAAkB,EAAE,CAAS;IACrD,OAAO,EAAE,GAAG,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;AAC/D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,KAAkB;IAC5C,OAAO,EAAE,GAAG,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAC5B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAkB;IAC/C,OAAO,EAAE,GAAG,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;AACrC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAkB;IACzC,OAAO,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,KAAkB;IACvC,OAAO,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;AAC9C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flyingrobots/bijou-tui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "TEA runtime for terminal UIs — model/update/view with keyboard input, alt screen, and layout helpers.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"lint": "tsc --noEmit"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@flyingrobots/bijou": "0.
|
|
27
|
+
"@flyingrobots/bijou": "1.0.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^22.0.0",
|