@profullstack/hqtui 0.1.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/README.md +144 -0
- package/dist/ansi.d.ts +42 -0
- package/dist/ansi.d.ts.map +1 -0
- package/dist/ansi.js +66 -0
- package/dist/ansi.js.map +1 -0
- package/dist/app.d.ts +128 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +296 -0
- package/dist/app.js.map +1 -0
- package/dist/buffer.d.ts +50 -0
- package/dist/buffer.d.ts.map +1 -0
- package/dist/buffer.js +184 -0
- package/dist/buffer.js.map +1 -0
- package/dist/capabilities.d.ts +36 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +93 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/color.d.ts +47 -0
- package/dist/color.d.ts.map +1 -0
- package/dist/color.js +176 -0
- package/dist/color.js.map +1 -0
- package/dist/diff.d.ts +39 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +203 -0
- package/dist/diff.js.map +1 -0
- package/dist/graphics/blocks.d.ts +26 -0
- package/dist/graphics/blocks.d.ts.map +1 -0
- package/dist/graphics/blocks.js +49 -0
- package/dist/graphics/blocks.js.map +1 -0
- package/dist/graphics/braille.d.ts +33 -0
- package/dist/graphics/braille.d.ts.map +1 -0
- package/dist/graphics/braille.js +166 -0
- package/dist/graphics/braille.js.map +1 -0
- package/dist/graphics/index.d.ts +4 -0
- package/dist/graphics/index.d.ts.map +1 -0
- package/dist/graphics/index.js +4 -0
- package/dist/graphics/index.js.map +1 -0
- package/dist/graphics/plot.d.ts +91 -0
- package/dist/graphics/plot.d.ts.map +1 -0
- package/dist/graphics/plot.js +291 -0
- package/dist/graphics/plot.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/input.d.ts +62 -0
- package/dist/input.d.ts.map +1 -0
- package/dist/input.js +245 -0
- package/dist/input.js.map +1 -0
- package/dist/layout.d.ts +51 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +163 -0
- package/dist/layout.js.map +1 -0
- package/dist/surface.d.ts +81 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +181 -0
- package/dist/surface.js.map +1 -0
- package/dist/terminal.d.ts +63 -0
- package/dist/terminal.d.ts.map +1 -0
- package/dist/terminal.js +189 -0
- package/dist/terminal.js.map +1 -0
- package/dist/testing.d.ts +71 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +171 -0
- package/dist/testing.js.map +1 -0
- package/dist/theme.d.ts +58 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +238 -0
- package/dist/theme.js.map +1 -0
- package/dist/ui.d.ts +194 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +439 -0
- package/dist/ui.js.map +1 -0
- package/dist/unicode.d.ts +36 -0
- package/dist/unicode.d.ts.map +1 -0
- package/dist/unicode.js +221 -0
- package/dist/unicode.js.map +1 -0
- package/dist/widgets/controls.d.ts +95 -0
- package/dist/widgets/controls.d.ts.map +1 -0
- package/dist/widgets/controls.js +231 -0
- package/dist/widgets/controls.js.map +1 -0
- package/dist/widgets/index.d.ts +5 -0
- package/dist/widgets/index.d.ts.map +1 -0
- package/dist/widgets/index.js +5 -0
- package/dist/widgets/index.js.map +1 -0
- package/dist/widgets/meters.d.ts +100 -0
- package/dist/widgets/meters.d.ts.map +1 -0
- package/dist/widgets/meters.js +209 -0
- package/dist/widgets/meters.js.map +1 -0
- package/dist/widgets/table.d.ts +92 -0
- package/dist/widgets/table.d.ts.map +1 -0
- package/dist/widgets/table.js +228 -0
- package/dist/widgets/table.js.map +1 -0
- package/dist/widgets/text.d.ts +64 -0
- package/dist/widgets/text.d.ts.map +1 -0
- package/dist/widgets/text.js +123 -0
- package/dist/widgets/text.js.map +1 -0
- package/package.json +56 -0
package/dist/app.js
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { FrameBuffer } from "./buffer.js";
|
|
2
|
+
import { Encoder } from "./diff.js";
|
|
3
|
+
import { ansi } from "./ansi.js";
|
|
4
|
+
import { Terminal, emergencyRestore } from "./terminal.js";
|
|
5
|
+
import { resolveTheme, themes } from "./theme.js";
|
|
6
|
+
import { Surface, createSurface } from "./surface.js";
|
|
7
|
+
import { Container } from "./ui.js";
|
|
8
|
+
import { matchKey } from "./input.js";
|
|
9
|
+
/**
|
|
10
|
+
* The application: owns the terminal, both framebuffers, the scheduler and the
|
|
11
|
+
* event loop. Everything else in the library is reachable from here.
|
|
12
|
+
*/
|
|
13
|
+
export class App {
|
|
14
|
+
terminal;
|
|
15
|
+
capabilities;
|
|
16
|
+
theme;
|
|
17
|
+
current;
|
|
18
|
+
previous;
|
|
19
|
+
encoder;
|
|
20
|
+
renderFn = () => { };
|
|
21
|
+
options;
|
|
22
|
+
listeners = new Map();
|
|
23
|
+
running = false;
|
|
24
|
+
dirty = true;
|
|
25
|
+
forceRepaint = true;
|
|
26
|
+
timer = null;
|
|
27
|
+
startedAt = 0;
|
|
28
|
+
frameCount = 0;
|
|
29
|
+
lastFrameAt = 0;
|
|
30
|
+
exitResolve = null;
|
|
31
|
+
focusIndex = 0;
|
|
32
|
+
focusCount = 0;
|
|
33
|
+
focusActions = [];
|
|
34
|
+
hits = [];
|
|
35
|
+
overlays = [];
|
|
36
|
+
lastStats = { frame: 0, renderMs: 0, changedCells: 0, dirtyRows: 0, bytes: 0, fps: 0 };
|
|
37
|
+
constructor(options = {}) {
|
|
38
|
+
this.options = options;
|
|
39
|
+
this.terminal = new Terminal(options);
|
|
40
|
+
this.capabilities = this.terminal.capabilities;
|
|
41
|
+
this.theme = resolveTheme(options.theme);
|
|
42
|
+
const { columns, rows } = this.terminal.size();
|
|
43
|
+
this.current = new FrameBuffer(columns, rows);
|
|
44
|
+
this.previous = new FrameBuffer(columns, rows);
|
|
45
|
+
this.encoder = new Encoder({
|
|
46
|
+
colors: this.capabilities.colors,
|
|
47
|
+
monochrome: options.monochrome ?? this.capabilities.colors === "none",
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
get width() {
|
|
51
|
+
return this.current.width;
|
|
52
|
+
}
|
|
53
|
+
get height() {
|
|
54
|
+
return this.current.height;
|
|
55
|
+
}
|
|
56
|
+
/** Stats for the most recent frame. */
|
|
57
|
+
get stats() {
|
|
58
|
+
return this.lastStats;
|
|
59
|
+
}
|
|
60
|
+
/** Register the view. Called on every frame; keep it pure and cheap. */
|
|
61
|
+
render(fn) {
|
|
62
|
+
this.renderFn = fn;
|
|
63
|
+
this.dirty = true;
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
/** Ask for a redraw. The scheduler coalesces repeated calls into one frame. */
|
|
67
|
+
invalidate() {
|
|
68
|
+
this.dirty = true;
|
|
69
|
+
}
|
|
70
|
+
/** Force a full repaint, e.g. after another process wrote to the terminal. */
|
|
71
|
+
redraw() {
|
|
72
|
+
this.forceRepaint = true;
|
|
73
|
+
this.dirty = true;
|
|
74
|
+
}
|
|
75
|
+
setTheme(theme) {
|
|
76
|
+
this.theme = resolveTheme(theme);
|
|
77
|
+
this.redraw();
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
on(event, listener) {
|
|
81
|
+
let set = this.listeners.get(event);
|
|
82
|
+
if (!set) {
|
|
83
|
+
set = new Set();
|
|
84
|
+
this.listeners.set(event, set);
|
|
85
|
+
}
|
|
86
|
+
set.add(listener);
|
|
87
|
+
return () => set.delete(listener);
|
|
88
|
+
}
|
|
89
|
+
emit(event, value) {
|
|
90
|
+
const set = this.listeners.get(event);
|
|
91
|
+
if (!set)
|
|
92
|
+
return;
|
|
93
|
+
for (const listener of set)
|
|
94
|
+
listener(value);
|
|
95
|
+
}
|
|
96
|
+
/** Move keyboard focus. Wraps around. */
|
|
97
|
+
focusNext(delta = 1) {
|
|
98
|
+
if (this.focusCount === 0)
|
|
99
|
+
return;
|
|
100
|
+
this.focusIndex = (this.focusIndex + delta + this.focusCount) % this.focusCount;
|
|
101
|
+
this.dirty = true;
|
|
102
|
+
}
|
|
103
|
+
/** Activate the focused control, as Enter does. */
|
|
104
|
+
activateFocused() {
|
|
105
|
+
this.focusActions[this.focusIndex]?.();
|
|
106
|
+
this.dirty = true;
|
|
107
|
+
}
|
|
108
|
+
/** Start the loop. Resolves when the app exits. */
|
|
109
|
+
async start() {
|
|
110
|
+
if (this.running)
|
|
111
|
+
return;
|
|
112
|
+
this.running = true;
|
|
113
|
+
this.startedAt = Date.now();
|
|
114
|
+
this.terminal.enter();
|
|
115
|
+
this.terminal.onInput((event) => this.handleInput(event));
|
|
116
|
+
this.terminal.onResizeEvent(({ columns, rows }) => {
|
|
117
|
+
this.current.resize(columns, rows);
|
|
118
|
+
this.previous.resize(columns, rows);
|
|
119
|
+
this.forceRepaint = true;
|
|
120
|
+
this.dirty = true;
|
|
121
|
+
this.emit("resize", { width: columns, height: rows });
|
|
122
|
+
this.frame();
|
|
123
|
+
});
|
|
124
|
+
const fps = this.targetFps();
|
|
125
|
+
const interval = Math.max(8, Math.floor(1000 / fps));
|
|
126
|
+
this.frame();
|
|
127
|
+
this.timer = setInterval(() => {
|
|
128
|
+
if (this.options.alwaysRender || this.dirty)
|
|
129
|
+
this.frame();
|
|
130
|
+
}, interval);
|
|
131
|
+
this.timer.unref?.();
|
|
132
|
+
await new Promise((resolve) => {
|
|
133
|
+
this.exitResolve = resolve;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
targetFps() {
|
|
137
|
+
const base = this.options.fps ?? 30;
|
|
138
|
+
if (this.capabilities.ssh)
|
|
139
|
+
return Math.min(base, this.options.remoteFps ?? 15);
|
|
140
|
+
return base;
|
|
141
|
+
}
|
|
142
|
+
/** Stop the loop and restore the terminal. */
|
|
143
|
+
stop() {
|
|
144
|
+
if (!this.running)
|
|
145
|
+
return;
|
|
146
|
+
this.running = false;
|
|
147
|
+
if (this.timer)
|
|
148
|
+
clearInterval(this.timer);
|
|
149
|
+
this.timer = null;
|
|
150
|
+
this.terminal.restore();
|
|
151
|
+
this.emit("exit", undefined);
|
|
152
|
+
this.exitResolve?.();
|
|
153
|
+
this.exitResolve = null;
|
|
154
|
+
}
|
|
155
|
+
/** Alias for `stop()`, matching what users type in their key handlers. */
|
|
156
|
+
quit() {
|
|
157
|
+
this.stop();
|
|
158
|
+
}
|
|
159
|
+
handleInput(event) {
|
|
160
|
+
if (event.type === "key") {
|
|
161
|
+
const quitKeys = this.options.quitKeys ?? ["ctrl+c", "q"];
|
|
162
|
+
if (quitKeys.some((k) => matchKey(event, k))) {
|
|
163
|
+
this.emit("key", event);
|
|
164
|
+
this.stop();
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (this.options.focusNavigation !== false) {
|
|
168
|
+
if (event.name === "tab") {
|
|
169
|
+
this.focusNext(event.shift ? -1 : 1);
|
|
170
|
+
}
|
|
171
|
+
else if (event.name === "enter" || event.name === "space") {
|
|
172
|
+
this.activateFocused();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
this.emit("key", event);
|
|
176
|
+
this.dirty = true;
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (event.type === "mouse") {
|
|
180
|
+
this.dispatchMouse(event);
|
|
181
|
+
this.emit("mouse", event);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (event.type === "paste") {
|
|
185
|
+
this.emit("paste", event);
|
|
186
|
+
this.dirty = true;
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
this.emit("focus", event);
|
|
190
|
+
}
|
|
191
|
+
dispatchMouse(event) {
|
|
192
|
+
// Later regions are drawn on top, so hit-test in reverse.
|
|
193
|
+
for (let i = this.hits.length - 1; i >= 0; i--) {
|
|
194
|
+
const hit = this.hits[i];
|
|
195
|
+
const r = hit.rect;
|
|
196
|
+
if (event.x < r.x || event.y < r.y || event.x >= r.x + r.width || event.y >= r.y + r.height)
|
|
197
|
+
continue;
|
|
198
|
+
if (event.action === "scroll")
|
|
199
|
+
hit.onScroll?.(event.scroll);
|
|
200
|
+
else if (event.action === "press")
|
|
201
|
+
hit.onClick?.(event.x - r.x, event.y - r.y, event.button);
|
|
202
|
+
else if (event.action === "move")
|
|
203
|
+
hit.onHover?.(event.x - r.x, event.y - r.y);
|
|
204
|
+
this.dirty = true;
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/** Build one frame and push the difference to the terminal. */
|
|
209
|
+
frame() {
|
|
210
|
+
const started = performance.now();
|
|
211
|
+
this.dirty = false;
|
|
212
|
+
const size = this.terminal.size();
|
|
213
|
+
if (size.columns !== this.current.width || size.rows !== this.current.height) {
|
|
214
|
+
this.current.resize(size.columns, size.rows);
|
|
215
|
+
this.previous.resize(size.columns, size.rows);
|
|
216
|
+
this.forceRepaint = true;
|
|
217
|
+
}
|
|
218
|
+
this.current.clear(this.options.paintBackground === false ? undefined : this.theme.background, this.theme.foreground);
|
|
219
|
+
this.hits = [];
|
|
220
|
+
this.overlays = [];
|
|
221
|
+
this.focusActions = [];
|
|
222
|
+
let focusCursor = 0;
|
|
223
|
+
const ctx = {
|
|
224
|
+
theme: this.theme,
|
|
225
|
+
capabilities: this.capabilities,
|
|
226
|
+
width: this.current.width,
|
|
227
|
+
height: this.current.height,
|
|
228
|
+
frame: this.frameCount,
|
|
229
|
+
elapsed: Date.now() - this.startedAt,
|
|
230
|
+
focusIndex: this.focusIndex,
|
|
231
|
+
registerFocus: (action) => {
|
|
232
|
+
const index = focusCursor++;
|
|
233
|
+
if (action)
|
|
234
|
+
this.focusActions[index] = action;
|
|
235
|
+
return { index, focused: index === this.focusIndex };
|
|
236
|
+
},
|
|
237
|
+
hit: (region) => this.hits.push(region),
|
|
238
|
+
overlay: (draw) => this.overlays.push(draw),
|
|
239
|
+
invalidate: () => this.invalidate(),
|
|
240
|
+
};
|
|
241
|
+
const root = createSurface(this.current, this.theme);
|
|
242
|
+
const container = new Container(root, ctx, "column");
|
|
243
|
+
this.renderFn({
|
|
244
|
+
ui: container,
|
|
245
|
+
theme: this.theme,
|
|
246
|
+
capabilities: this.capabilities,
|
|
247
|
+
width: this.current.width,
|
|
248
|
+
height: this.current.height,
|
|
249
|
+
frame: this.frameCount,
|
|
250
|
+
elapsed: ctx.elapsed,
|
|
251
|
+
focus: this.focusIndex,
|
|
252
|
+
app: this,
|
|
253
|
+
});
|
|
254
|
+
container.flush();
|
|
255
|
+
for (const overlay of this.overlays)
|
|
256
|
+
overlay(root);
|
|
257
|
+
this.focusCount = Math.max(focusCursor, 0);
|
|
258
|
+
if (this.focusCount > 0 && this.focusIndex >= this.focusCount)
|
|
259
|
+
this.focusIndex = 0;
|
|
260
|
+
const result = this.encoder.encode(this.previous, this.current, this.forceRepaint);
|
|
261
|
+
this.forceRepaint = false;
|
|
262
|
+
let output = result.output;
|
|
263
|
+
if (output.length > 0) {
|
|
264
|
+
if (this.capabilities.synchronizedOutput)
|
|
265
|
+
output = ansi.beginSync + output + ansi.endSync;
|
|
266
|
+
this.terminal.write(output);
|
|
267
|
+
}
|
|
268
|
+
this.previous.copyFrom(this.current);
|
|
269
|
+
const now = performance.now();
|
|
270
|
+
const stats = {
|
|
271
|
+
frame: this.frameCount++,
|
|
272
|
+
renderMs: now - started,
|
|
273
|
+
changedCells: result.changedCells,
|
|
274
|
+
dirtyRows: result.dirtyRows,
|
|
275
|
+
bytes: output.length,
|
|
276
|
+
fps: this.lastFrameAt ? 1000 / Math.max(1, now - this.lastFrameAt) : 0,
|
|
277
|
+
};
|
|
278
|
+
this.lastFrameAt = now;
|
|
279
|
+
this.lastStats = stats;
|
|
280
|
+
this.emit("frame", stats);
|
|
281
|
+
return stats;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Create an app. Every option has a sensible default: dark theme, mouse on,
|
|
286
|
+
* 30fps, alternate screen, terminal restored no matter how the process dies.
|
|
287
|
+
*
|
|
288
|
+
* const app = await createApp();
|
|
289
|
+
* app.render(({ ui }) => ui.panel({ title: "Hello" }, p => p.text("Hi")));
|
|
290
|
+
* await app.start();
|
|
291
|
+
*/
|
|
292
|
+
export async function createApp(options = {}) {
|
|
293
|
+
return new App(options);
|
|
294
|
+
}
|
|
295
|
+
export { emergencyRestore, themes };
|
|
296
|
+
//# sourceMappingURL=app.js.map
|
package/dist/app.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAwB,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjF,OAAO,EAA8B,YAAY,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,SAAS,EAA8D,MAAM,SAAS,CAAC;AAEhG,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AA0DtC;;;GAGG;AACH,MAAM,OAAO,GAAG;IACL,QAAQ,CAAW;IACnB,YAAY,CAAe;IACpC,KAAK,CAAQ;IAEL,OAAO,CAAc;IACrB,QAAQ,CAAc;IACtB,OAAO,CAAU;IACjB,QAAQ,GAAa,GAAG,EAAE,GAAE,CAAC,CAAC;IAC9B,OAAO,CAAa;IACpB,SAAS,GAAG,IAAI,GAAG,EAA+C,CAAC;IAEnE,OAAO,GAAG,KAAK,CAAC;IAChB,KAAK,GAAG,IAAI,CAAC;IACb,YAAY,GAAG,IAAI,CAAC;IACpB,KAAK,GAA0B,IAAI,CAAC;IACpC,SAAS,GAAG,CAAC,CAAC;IACd,UAAU,GAAG,CAAC,CAAC;IACf,WAAW,GAA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QAAQ,EAAE,GAAG,GAAG,OAAO;YACvB,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,KAAK,EAAE,MAAM,CAAC,MAAM;YACpB,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;SACvE,CAAC;QACF,IAAI,CAAC,WAAW,GAAG,GAAG,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QACvB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,UAAsB,EAAE;IACtD,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;AAC1B,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,CAAC"}
|
package/dist/buffer.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type Color } from "./color.ts";
|
|
2
|
+
/** Style attribute bits packed into the cell's 16-bit attribute slot. */
|
|
3
|
+
export declare const Attr: {
|
|
4
|
+
readonly None: 0;
|
|
5
|
+
readonly Bold: number;
|
|
6
|
+
readonly Dim: number;
|
|
7
|
+
readonly Italic: number;
|
|
8
|
+
readonly Underline: number;
|
|
9
|
+
readonly Blink: number;
|
|
10
|
+
readonly Reverse: number;
|
|
11
|
+
readonly Strike: number;
|
|
12
|
+
};
|
|
13
|
+
export type Attributes = number;
|
|
14
|
+
export interface Style {
|
|
15
|
+
fg?: Color;
|
|
16
|
+
bg?: Color;
|
|
17
|
+
attrs?: Attributes;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The screen is one grid of cells, not a tree of widgets. Four parallel typed
|
|
21
|
+
* arrays keep a frame allocation-free: no object is created per cell, ever.
|
|
22
|
+
*/
|
|
23
|
+
export declare class FrameBuffer {
|
|
24
|
+
width: number;
|
|
25
|
+
height: number;
|
|
26
|
+
chars: Uint32Array;
|
|
27
|
+
fg: Uint32Array;
|
|
28
|
+
bg: Uint32Array;
|
|
29
|
+
attrs: Uint16Array;
|
|
30
|
+
constructor(width: number, height: number);
|
|
31
|
+
/** Resize in place, reusing the existing allocation when it is large enough. */
|
|
32
|
+
resize(width: number, height: number): void;
|
|
33
|
+
index(x: number, y: number): number;
|
|
34
|
+
clear(fill?: Color, fg?: Color): void;
|
|
35
|
+
inBounds(x: number, y: number): boolean;
|
|
36
|
+
/** Write one already-decoded cell value. Returns columns consumed. */
|
|
37
|
+
setCell(x: number, y: number, value: number, style?: Style): number;
|
|
38
|
+
/** Write text left to right. Returns the number of columns written. */
|
|
39
|
+
write(x: number, y: number, text: string, style?: Style, maxWidth?: number): number;
|
|
40
|
+
fillRect(x: number, y: number, w: number, h: number, ch?: number, style?: Style): void;
|
|
41
|
+
/** Restyle a region without touching its characters. */
|
|
42
|
+
styleRect(x: number, y: number, w: number, h: number, style: Style): void;
|
|
43
|
+
/** Copy another buffer's contents into this one (same dimensions assumed). */
|
|
44
|
+
copyFrom(other: FrameBuffer): void;
|
|
45
|
+
/** Plain text of one row, for tests and headless rendering. */
|
|
46
|
+
rowText(y: number): string;
|
|
47
|
+
/** Whole buffer as plain text. */
|
|
48
|
+
toText(trimEnd?: boolean): string;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=buffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer.d.ts","sourceRoot":"","sources":["../src/buffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAGvD,yEAAyE;AACzE,eAAO,MAAM,IAAI;;;;;;;;;CASP,CAAC;AAEX,MAAM,MAAM,UAAU,GA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,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI;IAezE,8EAA8E;IAC9E,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAQlC,+DAA+D;IAC/D,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM;IAW1B,kCAAkC;IAClC,MAAM,CAAC,OAAO,UAAO,GAAG,MAAM;CAQ/B"}
|
package/dist/buffer.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { DEFAULT_COLOR } from "./color.js";
|
|
2
|
+
import { CONTINUATION, cellWidth, graphemes, cellText } from "./unicode.js";
|
|
3
|
+
/** Style attribute bits packed into the cell's 16-bit attribute slot. */
|
|
4
|
+
export const Attr = {
|
|
5
|
+
None: 0,
|
|
6
|
+
Bold: 1 << 0,
|
|
7
|
+
Dim: 1 << 1,
|
|
8
|
+
Italic: 1 << 2,
|
|
9
|
+
Underline: 1 << 3,
|
|
10
|
+
Blink: 1 << 4,
|
|
11
|
+
Reverse: 1 << 5,
|
|
12
|
+
Strike: 1 << 6,
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The screen is one grid of cells, not a tree of widgets. Four parallel typed
|
|
16
|
+
* arrays keep a frame allocation-free: no object is created per cell, ever.
|
|
17
|
+
*/
|
|
18
|
+
export class FrameBuffer {
|
|
19
|
+
width;
|
|
20
|
+
height;
|
|
21
|
+
chars;
|
|
22
|
+
fg;
|
|
23
|
+
bg;
|
|
24
|
+
attrs;
|
|
25
|
+
constructor(width, height) {
|
|
26
|
+
this.width = Math.max(0, width | 0);
|
|
27
|
+
this.height = Math.max(0, height | 0);
|
|
28
|
+
const n = this.width * this.height;
|
|
29
|
+
this.chars = new Uint32Array(n);
|
|
30
|
+
this.fg = new Uint32Array(n);
|
|
31
|
+
this.bg = new Uint32Array(n);
|
|
32
|
+
this.attrs = new Uint16Array(n);
|
|
33
|
+
this.clear();
|
|
34
|
+
}
|
|
35
|
+
/** Resize in place, reusing the existing allocation when it is large enough. */
|
|
36
|
+
resize(width, height) {
|
|
37
|
+
const w = Math.max(0, width | 0);
|
|
38
|
+
const h = Math.max(0, height | 0);
|
|
39
|
+
if (w === this.width && h === this.height)
|
|
40
|
+
return;
|
|
41
|
+
const n = w * h;
|
|
42
|
+
if (n > this.chars.length) {
|
|
43
|
+
this.chars = new Uint32Array(n);
|
|
44
|
+
this.fg = new Uint32Array(n);
|
|
45
|
+
this.bg = new Uint32Array(n);
|
|
46
|
+
this.attrs = new Uint16Array(n);
|
|
47
|
+
}
|
|
48
|
+
this.width = w;
|
|
49
|
+
this.height = h;
|
|
50
|
+
this.clear();
|
|
51
|
+
}
|
|
52
|
+
index(x, y) {
|
|
53
|
+
return y * this.width + x;
|
|
54
|
+
}
|
|
55
|
+
clear(fill = DEFAULT_COLOR, fg = DEFAULT_COLOR) {
|
|
56
|
+
const n = this.width * this.height;
|
|
57
|
+
this.chars.fill(32, 0, n);
|
|
58
|
+
this.fg.fill(fg, 0, n);
|
|
59
|
+
this.bg.fill(fill, 0, n);
|
|
60
|
+
this.attrs.fill(0, 0, n);
|
|
61
|
+
}
|
|
62
|
+
inBounds(x, y) {
|
|
63
|
+
return x >= 0 && y >= 0 && x < this.width && y < this.height;
|
|
64
|
+
}
|
|
65
|
+
/** Write one already-decoded cell value. Returns columns consumed. */
|
|
66
|
+
setCell(x, y, value, style) {
|
|
67
|
+
if (!this.inBounds(x, y))
|
|
68
|
+
return 0;
|
|
69
|
+
const w = cellWidth(value);
|
|
70
|
+
const i = this.index(x, y);
|
|
71
|
+
// Overwriting the tail of a wide char to our left would orphan it; blank it.
|
|
72
|
+
if (this.chars[i] === CONTINUATION && x > 0)
|
|
73
|
+
this.chars[i - 1] = 32;
|
|
74
|
+
this.chars[i] = value;
|
|
75
|
+
if (style) {
|
|
76
|
+
if (style.fg !== undefined)
|
|
77
|
+
this.fg[i] = style.fg;
|
|
78
|
+
if (style.bg !== undefined)
|
|
79
|
+
this.bg[i] = style.bg;
|
|
80
|
+
if (style.attrs !== undefined)
|
|
81
|
+
this.attrs[i] = style.attrs;
|
|
82
|
+
}
|
|
83
|
+
if (w === 2) {
|
|
84
|
+
if (x + 1 < this.width) {
|
|
85
|
+
const j = i + 1;
|
|
86
|
+
this.chars[j] = CONTINUATION;
|
|
87
|
+
if (style) {
|
|
88
|
+
if (style.fg !== undefined)
|
|
89
|
+
this.fg[j] = style.fg;
|
|
90
|
+
if (style.bg !== undefined)
|
|
91
|
+
this.bg[j] = style.bg;
|
|
92
|
+
if (style.attrs !== undefined)
|
|
93
|
+
this.attrs[j] = style.attrs;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
// No room for the second half: draw a space rather than corrupt the row.
|
|
98
|
+
this.chars[i] = 32;
|
|
99
|
+
return 1;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return Math.max(1, w);
|
|
103
|
+
}
|
|
104
|
+
/** Write text left to right. Returns the number of columns written. */
|
|
105
|
+
write(x, y, text, style, maxWidth = Infinity) {
|
|
106
|
+
if (y < 0 || y >= this.height)
|
|
107
|
+
return 0;
|
|
108
|
+
let cx = x;
|
|
109
|
+
let used = 0;
|
|
110
|
+
for (const g of graphemes(text)) {
|
|
111
|
+
if (used + g.width > maxWidth)
|
|
112
|
+
break;
|
|
113
|
+
if (cx >= this.width)
|
|
114
|
+
break;
|
|
115
|
+
if (cx + g.width > this.width)
|
|
116
|
+
break;
|
|
117
|
+
if (cx >= 0) {
|
|
118
|
+
this.setCell(cx, y, g.value, style);
|
|
119
|
+
}
|
|
120
|
+
cx += g.width;
|
|
121
|
+
used += g.width;
|
|
122
|
+
}
|
|
123
|
+
return used;
|
|
124
|
+
}
|
|
125
|
+
fillRect(x, y, w, h, ch = 32, style) {
|
|
126
|
+
const x0 = Math.max(0, x);
|
|
127
|
+
const y0 = Math.max(0, y);
|
|
128
|
+
const x1 = Math.min(this.width, x + w);
|
|
129
|
+
const y1 = Math.min(this.height, y + h);
|
|
130
|
+
for (let cy = y0; cy < y1; cy++) {
|
|
131
|
+
for (let cx = x0; cx < x1; cx++)
|
|
132
|
+
this.setCell(cx, cy, ch, style);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/** Restyle a region without touching its characters. */
|
|
136
|
+
styleRect(x, y, w, h, style) {
|
|
137
|
+
const x0 = Math.max(0, x);
|
|
138
|
+
const y0 = Math.max(0, y);
|
|
139
|
+
const x1 = Math.min(this.width, x + w);
|
|
140
|
+
const y1 = Math.min(this.height, y + h);
|
|
141
|
+
for (let cy = y0; cy < y1; cy++) {
|
|
142
|
+
for (let cx = x0; cx < x1; cx++) {
|
|
143
|
+
const i = this.index(cx, cy);
|
|
144
|
+
if (style.fg !== undefined)
|
|
145
|
+
this.fg[i] = style.fg;
|
|
146
|
+
if (style.bg !== undefined)
|
|
147
|
+
this.bg[i] = style.bg;
|
|
148
|
+
if (style.attrs !== undefined)
|
|
149
|
+
this.attrs[i] = style.attrs;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/** Copy another buffer's contents into this one (same dimensions assumed). */
|
|
154
|
+
copyFrom(other) {
|
|
155
|
+
const n = Math.min(this.width * this.height, other.width * other.height);
|
|
156
|
+
this.chars.set(other.chars.subarray(0, n));
|
|
157
|
+
this.fg.set(other.fg.subarray(0, n));
|
|
158
|
+
this.bg.set(other.bg.subarray(0, n));
|
|
159
|
+
this.attrs.set(other.attrs.subarray(0, n));
|
|
160
|
+
}
|
|
161
|
+
/** Plain text of one row, for tests and headless rendering. */
|
|
162
|
+
rowText(y) {
|
|
163
|
+
if (y < 0 || y >= this.height)
|
|
164
|
+
return "";
|
|
165
|
+
let out = "";
|
|
166
|
+
for (let x = 0; x < this.width; x++) {
|
|
167
|
+
const v = this.chars[this.index(x, y)];
|
|
168
|
+
if (v === CONTINUATION)
|
|
169
|
+
continue;
|
|
170
|
+
out += v === 0 ? " " : cellText(v);
|
|
171
|
+
}
|
|
172
|
+
return out;
|
|
173
|
+
}
|
|
174
|
+
/** Whole buffer as plain text. */
|
|
175
|
+
toText(trimEnd = true) {
|
|
176
|
+
const rows = [];
|
|
177
|
+
for (let y = 0; y < this.height; y++) {
|
|
178
|
+
const r = this.rowText(y);
|
|
179
|
+
rows.push(trimEnd ? r.replace(/\s+$/, "") : r);
|
|
180
|
+
}
|
|
181
|
+
return rows.join("\n");
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=buffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer.js","sourceRoot":"","sources":["../src/buffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAc,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE5E,yEAAyE;AACzE,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC,IAAI,CAAC;IACZ,GAAG,EAAE,CAAC,IAAI,CAAC;IACX,MAAM,EAAE,CAAC,IAAI,CAAC;IACd,SAAS,EAAE,CAAC,IAAI,CAAC;IACjB,KAAK,EAAE,CAAC,IAAI,CAAC;IACb,OAAO,EAAE,CAAC,IAAI,CAAC;IACf,MAAM,EAAE,CAAC,IAAI,CAAC;CACN,CAAC;AAUX;;;GAGG;AACH,MAAM,OAAO,WAAW;IACtB,KAAK,CAAS;IACd,MAAM,CAAS;IACf,KAAK,CAAc;IACnB,EAAE,CAAc;IAChB,EAAE,CAAc;IAChB,KAAK,CAAc;IAEnB,YAAY,KAAa,EAAE,MAAc;QACvC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;QACpC,IAAI,CAAC,MAAM,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AAC;YACpC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACvC,IAAI,CAAC,KAAK,YAAY;gBAAE,SAAS;YACjC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACrC,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,kCAAkC;IAClC,MAAM,CAAC,OAAO,GAAG,IAAI;QACnB,MAAM,IAAI,GAAa,EAAE,CAAC;QAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACrC,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC1B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACjD,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;CACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the terminal can actually do. Detection is deliberately conservative:
|
|
3
|
+
* we degrade colors and glyphs rather than print mojibake on someone's console.
|
|
4
|
+
*/
|
|
5
|
+
export type ColorDepth = "truecolor" | "ansi256" | "ansi16" | "none";
|
|
6
|
+
export interface Capabilities {
|
|
7
|
+
/** stdout is a real TTY, not a pipe or a file. */
|
|
8
|
+
tty: boolean;
|
|
9
|
+
colors: ColorDepth;
|
|
10
|
+
trueColor: boolean;
|
|
11
|
+
unicode: boolean;
|
|
12
|
+
braille: boolean;
|
|
13
|
+
mouse: boolean;
|
|
14
|
+
/** DEC 2026 atomic frame updates. */
|
|
15
|
+
synchronizedOutput: boolean;
|
|
16
|
+
bracketedPaste: boolean;
|
|
17
|
+
focusEvents: boolean;
|
|
18
|
+
tmux: boolean;
|
|
19
|
+
screen: boolean;
|
|
20
|
+
ssh: boolean;
|
|
21
|
+
windows: boolean;
|
|
22
|
+
/** Best guess at the emulator: kitty, wezterm, ghostty, iterm, alacritty, vscode, windows-terminal, xterm, unknown. */
|
|
23
|
+
program: string;
|
|
24
|
+
}
|
|
25
|
+
export interface CapabilityOverrides {
|
|
26
|
+
colors?: ColorDepth;
|
|
27
|
+
unicode?: boolean;
|
|
28
|
+
braille?: boolean;
|
|
29
|
+
mouse?: boolean;
|
|
30
|
+
synchronizedOutput?: boolean;
|
|
31
|
+
tty?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export declare function detectCapabilities(overrides?: CapabilityOverrides, env?: NodeJS.ProcessEnv, stream?: {
|
|
34
|
+
isTTY?: boolean;
|
|
35
|
+
}): Capabilities;
|
|
36
|
+
//# sourceMappingURL=capabilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../src/capabilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAC;AAErE,MAAM,WAAW,YAAY;IAC3B,kDAAkD;IAClD,GAAG,EAAE,OAAO,CAAC;IACb,MAAM,EAAE,UAAU,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,qCAAqC;IACrC,kBAAkB,EAAE,OAAO,CAAC;IAC5B,cAAc,EAAE,OAAO,CAAC;IACxB,WAAW,EAAE,OAAO,CAAC;IACrB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,GAAG,EAAE,OAAO,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,uHAAuH;IACvH,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AA4CD,wBAAgB,kBAAkB,CAChC,SAAS,GAAE,mBAAwB,EACnC,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,MAAM,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAmB,GAC3C,YAAY,CA6Bd"}
|