@prometheus-ai/tui 0.5.3 → 0.5.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/autocomplete.d.ts +3 -1
- package/dist/types/components/box.d.ts +1 -1
- package/dist/types/components/editor.d.ts +35 -2
- package/dist/types/components/image.d.ts +22 -3
- package/dist/types/components/input.d.ts +6 -1
- package/dist/types/components/loader.d.ts +9 -2
- package/dist/types/components/markdown.d.ts +3 -1
- package/dist/types/components/scroll-view.d.ts +23 -1
- package/dist/types/components/select-list.d.ts +19 -1
- package/dist/types/components/settings-list.d.ts +87 -7
- package/dist/types/components/spacer.d.ts +1 -1
- package/dist/types/components/tab-bar.d.ts +37 -4
- package/dist/types/components/text.d.ts +2 -2
- package/dist/types/components/truncated-text.d.ts +1 -1
- package/dist/types/fuzzy.d.ts +10 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/keybindings.d.ts +5 -3
- package/dist/types/keys.d.ts +1 -1
- package/dist/types/kill-ring.d.ts +0 -7
- package/dist/types/kitty-graphics.d.ts +16 -31
- package/dist/types/loop-watchdog.d.ts +39 -0
- package/dist/types/mouse.d.ts +41 -0
- package/dist/types/stdin-buffer.d.ts +17 -0
- package/dist/types/terminal-capabilities.d.ts +74 -18
- package/dist/types/terminal.d.ts +34 -36
- package/dist/types/tui.d.ts +191 -79
- package/dist/types/utils.d.ts +5 -2
- package/package.json +4 -4
- package/src/autocomplete.ts +79 -65
- package/src/components/box.ts +43 -63
- package/src/components/editor.ts +471 -136
- package/src/components/image.ts +85 -9
- package/src/components/input.ts +12 -3
- package/src/components/loader.ts +35 -21
- package/src/components/markdown.ts +174 -53
- package/src/components/scroll-view.ts +63 -2
- package/src/components/select-list.ts +233 -38
- package/src/components/settings-list.ts +626 -64
- package/src/components/spacer.ts +9 -5
- package/src/components/tab-bar.ts +153 -28
- package/src/components/text.ts +6 -2
- package/src/components/truncated-text.ts +10 -2
- package/src/fuzzy.ts +214 -59
- package/src/index.ts +3 -1
- package/src/keybindings.ts +72 -14
- package/src/keys.ts +1 -1
- package/src/kill-ring.ts +5 -0
- package/src/kitty-graphics.ts +2 -101
- package/src/loop-watchdog.ts +106 -0
- package/src/mouse.ts +55 -0
- package/src/stdin-buffer.ts +291 -81
- package/src/terminal-capabilities.ts +206 -168
- package/src/terminal.ts +367 -110
- package/src/tui.ts +2102 -1729
- package/src/utils.ts +92 -60
package/src/components/box.ts
CHANGED
|
@@ -2,7 +2,9 @@ import type { Component } from "../tui";
|
|
|
2
2
|
import { applyBackgroundToLine, padding, visibleWidth } from "../utils";
|
|
3
3
|
|
|
4
4
|
type Cache = {
|
|
5
|
-
|
|
5
|
+
width: number;
|
|
6
|
+
bgSample: string | undefined;
|
|
7
|
+
childLines: (readonly string[])[];
|
|
6
8
|
result: string[];
|
|
7
9
|
};
|
|
8
10
|
|
|
@@ -63,24 +65,6 @@ export class Box implements Component {
|
|
|
63
65
|
this.#cached = undefined;
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
static #tmp = new Uint32Array(2);
|
|
67
|
-
#computeCacheKey(width: number, childLines: string[], bgSample: string | undefined): bigint | number {
|
|
68
|
-
Box.#tmp[0] = width;
|
|
69
|
-
Box.#tmp[1] = childLines.length;
|
|
70
|
-
let h = Bun.hash(Box.#tmp);
|
|
71
|
-
for (const line of childLines) {
|
|
72
|
-
h = Bun.hash(line, h);
|
|
73
|
-
}
|
|
74
|
-
if (bgSample) {
|
|
75
|
-
h = Bun.hash(bgSample, h);
|
|
76
|
-
}
|
|
77
|
-
return h;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
#matchCache(cacheKey: bigint | number): boolean {
|
|
81
|
-
return this.#cached?.key === cacheKey;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
68
|
invalidate(): void {
|
|
85
69
|
this.#invalidateCache();
|
|
86
70
|
for (const child of this.children) {
|
|
@@ -88,58 +72,54 @@ export class Box implements Component {
|
|
|
88
72
|
}
|
|
89
73
|
}
|
|
90
74
|
|
|
91
|
-
render(width: number): string[] {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
75
|
+
render(width: number): readonly string[] {
|
|
76
|
+
const children = this.children;
|
|
77
|
+
const count = children.length;
|
|
96
78
|
const contentWidth = Math.max(1, width - this.#paddingX * 2);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
// Render all children
|
|
100
|
-
const childLines: string[] = [];
|
|
101
|
-
for (const child of this.children) {
|
|
102
|
-
const lines = child.render(contentWidth);
|
|
103
|
-
for (const line of lines) {
|
|
104
|
-
childLines.push(leftPad + line);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (childLines.length === 0) {
|
|
109
|
-
return [];
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Check if bgFn output changed by sampling
|
|
79
|
+
// bgFn output can change without the function reference changing (theme
|
|
80
|
+
// mutation); sample it so a silent palette swap still misses the cache.
|
|
113
81
|
const bgSample = this.#bgFn ? this.#bgFn("test") : undefined;
|
|
114
82
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
//
|
|
118
|
-
|
|
119
|
-
|
|
83
|
+
// Render every child every frame (renders may carry side effects); the
|
|
84
|
+
// memo only skips re-deriving the padded/background rows. Per the
|
|
85
|
+
// Component render contract, identical child array references prove the
|
|
86
|
+
// content is unchanged.
|
|
87
|
+
const cached = this.#cached;
|
|
88
|
+
let unchanged =
|
|
89
|
+
cached !== undefined &&
|
|
90
|
+
cached.width === width &&
|
|
91
|
+
cached.bgSample === bgSample &&
|
|
92
|
+
cached.childLines.length === count;
|
|
93
|
+
const childLines: (readonly string[])[] = new Array(count);
|
|
94
|
+
let contentRows = 0;
|
|
95
|
+
for (let i = 0; i < count; i++) {
|
|
96
|
+
const lines = children[i]!.render(contentWidth);
|
|
97
|
+
childLines[i] = lines;
|
|
98
|
+
contentRows += lines.length;
|
|
99
|
+
if (unchanged && cached!.childLines[i] !== lines) unchanged = false;
|
|
120
100
|
}
|
|
101
|
+
if (unchanged) return cached!.result;
|
|
121
102
|
|
|
122
|
-
// Apply background and padding
|
|
123
103
|
const result: string[] = [];
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
104
|
+
if (contentRows > 0) {
|
|
105
|
+
const leftPad = padding(this.#paddingX);
|
|
106
|
+
// Top padding
|
|
107
|
+
for (let i = 0; i < this.#paddingY; i++) {
|
|
108
|
+
result.push(this.#applyBg("", width));
|
|
109
|
+
}
|
|
110
|
+
// Content
|
|
111
|
+
for (const lines of childLines) {
|
|
112
|
+
for (const line of lines) {
|
|
113
|
+
result.push(this.#applyBg(leftPad + line, width));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// Bottom padding
|
|
117
|
+
for (let i = 0; i < this.#paddingY; i++) {
|
|
118
|
+
result.push(this.#applyBg("", width));
|
|
119
|
+
}
|
|
138
120
|
}
|
|
139
121
|
|
|
140
|
-
|
|
141
|
-
this.#cached = { key: cacheKey, result };
|
|
142
|
-
|
|
122
|
+
this.#cached = { width, bgSample, childLines, result };
|
|
143
123
|
return result;
|
|
144
124
|
}
|
|
145
125
|
|