@prometheus-ai/tui 0.5.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.
Files changed (65) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +704 -0
  3. package/dist/types/autocomplete.d.ts +76 -0
  4. package/dist/types/bracketed-paste.d.ts +26 -0
  5. package/dist/types/components/box.d.ts +17 -0
  6. package/dist/types/components/cancellable-loader.d.ts +21 -0
  7. package/dist/types/components/editor.d.ts +105 -0
  8. package/dist/types/components/image.d.ts +84 -0
  9. package/dist/types/components/input.d.ts +18 -0
  10. package/dist/types/components/loader.d.ts +13 -0
  11. package/dist/types/components/markdown.d.ts +61 -0
  12. package/dist/types/components/scroll-view.d.ts +40 -0
  13. package/dist/types/components/select-list.d.ts +48 -0
  14. package/dist/types/components/settings-list.d.ts +41 -0
  15. package/dist/types/components/spacer.d.ts +11 -0
  16. package/dist/types/components/tab-bar.d.ts +56 -0
  17. package/dist/types/components/text.d.ts +13 -0
  18. package/dist/types/components/truncated-text.d.ts +10 -0
  19. package/dist/types/deccara.d.ts +49 -0
  20. package/dist/types/editor-component.d.ts +36 -0
  21. package/dist/types/fuzzy.d.ts +15 -0
  22. package/dist/types/index.d.ts +28 -0
  23. package/dist/types/keybindings.d.ts +189 -0
  24. package/dist/types/keys.d.ts +208 -0
  25. package/dist/types/kill-ring.d.ts +27 -0
  26. package/dist/types/kitty-graphics.d.ts +94 -0
  27. package/dist/types/stdin-buffer.d.ts +43 -0
  28. package/dist/types/symbols.d.ts +25 -0
  29. package/dist/types/terminal-capabilities.d.ts +196 -0
  30. package/dist/types/terminal.d.ts +103 -0
  31. package/dist/types/ttyid.d.ts +9 -0
  32. package/dist/types/tui.d.ts +275 -0
  33. package/dist/types/utils.d.ts +89 -0
  34. package/package.json +73 -0
  35. package/src/autocomplete.ts +871 -0
  36. package/src/bracketed-paste.ts +47 -0
  37. package/src/components/box.ts +156 -0
  38. package/src/components/cancellable-loader.ts +40 -0
  39. package/src/components/editor.ts +2695 -0
  40. package/src/components/image.ts +318 -0
  41. package/src/components/input.ts +459 -0
  42. package/src/components/loader.ts +86 -0
  43. package/src/components/markdown.ts +1189 -0
  44. package/src/components/scroll-view.ts +166 -0
  45. package/src/components/select-list.ts +331 -0
  46. package/src/components/settings-list.ts +212 -0
  47. package/src/components/spacer.ts +28 -0
  48. package/src/components/tab-bar.ts +175 -0
  49. package/src/components/text.ts +110 -0
  50. package/src/components/truncated-text.ts +61 -0
  51. package/src/deccara.ts +314 -0
  52. package/src/editor-component.ts +71 -0
  53. package/src/fuzzy.ts +143 -0
  54. package/src/index.ts +44 -0
  55. package/src/keybindings.ts +279 -0
  56. package/src/keys.ts +537 -0
  57. package/src/kill-ring.ts +46 -0
  58. package/src/kitty-graphics.ts +270 -0
  59. package/src/stdin-buffer.ts +423 -0
  60. package/src/symbols.ts +26 -0
  61. package/src/terminal-capabilities.ts +1009 -0
  62. package/src/terminal.ts +1114 -0
  63. package/src/ttyid.ts +70 -0
  64. package/src/tui.ts +2988 -0
  65. package/src/utils.ts +452 -0
@@ -0,0 +1,459 @@
1
+ import { BracketedPasteHandler } from "../bracketed-paste";
2
+ import { getKeybindings } from "../keybindings";
3
+ import { extractPrintableText } from "../keys";
4
+ import { KillRing } from "../kill-ring";
5
+ import { type Component, CURSOR_MARKER, type Focusable } from "../tui";
6
+ import {
7
+ getSegmenter,
8
+ getWordNavKind,
9
+ moveWordLeft,
10
+ moveWordRight,
11
+ padding,
12
+ replaceTabs,
13
+ sliceWithWidth,
14
+ visibleWidth,
15
+ } from "../utils";
16
+
17
+ const segmenter = getSegmenter();
18
+
19
+ interface InputState {
20
+ value: string;
21
+ cursor: number;
22
+ }
23
+
24
+ /**
25
+ * Input component - single-line text input with horizontal scrolling
26
+ */
27
+ export class Input implements Component, Focusable {
28
+ #value: string = "";
29
+ #cursor: number = 0; // Cursor position in the value
30
+ #useTerminalCursor = false;
31
+ onSubmit?: (value: string) => void;
32
+ onEscape?: () => void;
33
+
34
+ /** Focusable interface - set by TUI when focus changes */
35
+ focused: boolean = false;
36
+
37
+ // Bracketed paste mode buffering
38
+ #pasteHandler = new BracketedPasteHandler();
39
+
40
+ // Kill ring for Emacs-style kill/yank operations
41
+ #killRing = new KillRing();
42
+ #lastAction: "kill" | "yank" | "type-word" | null = null;
43
+
44
+ // Undo support
45
+ #undoStack: InputState[] = [];
46
+
47
+ getValue(): string {
48
+ return this.#value;
49
+ }
50
+
51
+ setValue(value: string): void {
52
+ this.#value = value;
53
+ this.#cursor = value.length;
54
+ }
55
+
56
+ setUseTerminalCursor(useTerminalCursor: boolean): void {
57
+ this.#useTerminalCursor = useTerminalCursor;
58
+ }
59
+
60
+ getUseTerminalCursor(): boolean {
61
+ return this.#useTerminalCursor;
62
+ }
63
+
64
+ handleInput(data: string): void {
65
+ // Handle bracketed paste mode
66
+ const paste = this.#pasteHandler.process(data);
67
+ if (paste.handled) {
68
+ if (paste.pasteContent !== undefined) {
69
+ this.#handlePaste(paste.pasteContent);
70
+ if (paste.remaining.length > 0) {
71
+ this.handleInput(paste.remaining);
72
+ }
73
+ }
74
+ return;
75
+ }
76
+
77
+ const kb = getKeybindings();
78
+
79
+ // Escape/Cancel
80
+ if (kb.matches(data, "tui.select.cancel")) {
81
+ if (this.onEscape) this.onEscape();
82
+ return;
83
+ }
84
+
85
+ // Undo
86
+ if (kb.matches(data, "tui.editor.undo")) {
87
+ this.#undo();
88
+ return;
89
+ }
90
+
91
+ // Submit
92
+ if (kb.matches(data, "tui.input.submit") || data === "\n") {
93
+ if (this.onSubmit) this.onSubmit(this.#value);
94
+ return;
95
+ }
96
+
97
+ // Deletion
98
+ if (kb.matches(data, "tui.editor.deleteCharBackward")) {
99
+ this.#handleBackspace();
100
+ return;
101
+ }
102
+
103
+ if (kb.matches(data, "tui.editor.deleteCharForward")) {
104
+ this.#handleForwardDelete();
105
+ return;
106
+ }
107
+
108
+ if (kb.matches(data, "tui.editor.deleteWordBackward")) {
109
+ this.#deleteWordBackwards();
110
+ return;
111
+ }
112
+
113
+ if (kb.matches(data, "tui.editor.deleteWordForward")) {
114
+ this.#deleteWordForward();
115
+ return;
116
+ }
117
+
118
+ if (kb.matches(data, "tui.editor.deleteToLineStart")) {
119
+ this.#deleteToLineStart();
120
+ return;
121
+ }
122
+
123
+ if (kb.matches(data, "tui.editor.deleteToLineEnd")) {
124
+ this.#deleteToLineEnd();
125
+ return;
126
+ }
127
+
128
+ // Kill ring actions
129
+ if (kb.matches(data, "tui.editor.yank")) {
130
+ this.#yank();
131
+ return;
132
+ }
133
+ if (kb.matches(data, "tui.editor.yankPop")) {
134
+ this.#yankPop();
135
+ return;
136
+ }
137
+
138
+ // Cursor movement
139
+ if (kb.matches(data, "tui.editor.cursorLeft")) {
140
+ this.#lastAction = null;
141
+ if (this.#cursor > 0) {
142
+ const beforeCursor = this.#value.slice(0, this.#cursor);
143
+ const graphemes = [...segmenter.segment(beforeCursor)];
144
+ const lastGrapheme = graphemes[graphemes.length - 1];
145
+ this.#cursor -= lastGrapheme ? lastGrapheme.segment.length : 1;
146
+ }
147
+ return;
148
+ }
149
+
150
+ if (kb.matches(data, "tui.editor.cursorRight")) {
151
+ this.#lastAction = null;
152
+ if (this.#cursor < this.#value.length) {
153
+ const afterCursor = this.#value.slice(this.#cursor);
154
+ const graphemes = [...segmenter.segment(afterCursor)];
155
+ const firstGrapheme = graphemes[0];
156
+ this.#cursor += firstGrapheme ? firstGrapheme.segment.length : 1;
157
+ }
158
+ return;
159
+ }
160
+
161
+ if (kb.matches(data, "tui.editor.cursorLineStart")) {
162
+ this.#lastAction = null;
163
+ this.#cursor = 0;
164
+ return;
165
+ }
166
+
167
+ if (kb.matches(data, "tui.editor.cursorLineEnd")) {
168
+ this.#lastAction = null;
169
+ this.#cursor = this.#value.length;
170
+ return;
171
+ }
172
+
173
+ if (kb.matches(data, "tui.editor.cursorWordLeft")) {
174
+ this.#moveWordBackwards();
175
+ return;
176
+ }
177
+
178
+ if (kb.matches(data, "tui.editor.cursorWordRight")) {
179
+ this.#moveWordForwards();
180
+ return;
181
+ }
182
+
183
+ // Regular character input, including Kitty CSI-u text-producing sequences.
184
+ const printableText = extractPrintableText(data);
185
+ if (printableText) {
186
+ this.#insertCharacter(printableText);
187
+ }
188
+ }
189
+
190
+ #insertCharacter(text: string): void {
191
+ const isWordChunk = [...segmenter.segment(text)].every(seg => getWordNavKind(seg.segment) !== "whitespace");
192
+ // Undo coalescing: consecutive word typing coalesces into one undo unit.
193
+ if (!isWordChunk || this.#lastAction !== "type-word") {
194
+ this.#pushUndo();
195
+ }
196
+ this.#lastAction = "type-word";
197
+
198
+ this.#value = this.#value.slice(0, this.#cursor) + text + this.#value.slice(this.#cursor);
199
+ this.#cursor += text.length;
200
+ }
201
+
202
+ #handleBackspace(): void {
203
+ this.#lastAction = null;
204
+ if (this.#cursor <= 0) {
205
+ return;
206
+ }
207
+
208
+ this.#pushUndo();
209
+
210
+ const beforeCursor = this.#value.slice(0, this.#cursor);
211
+ const graphemes = [...segmenter.segment(beforeCursor)];
212
+ const lastGrapheme = graphemes[graphemes.length - 1];
213
+ const graphemeLength = lastGrapheme ? lastGrapheme.segment.length : 1;
214
+
215
+ this.#value = this.#value.slice(0, this.#cursor - graphemeLength) + this.#value.slice(this.#cursor);
216
+ this.#cursor -= graphemeLength;
217
+ }
218
+
219
+ #handleForwardDelete(): void {
220
+ this.#lastAction = null;
221
+ if (this.#cursor >= this.#value.length) {
222
+ return;
223
+ }
224
+
225
+ this.#pushUndo();
226
+
227
+ const afterCursor = this.#value.slice(this.#cursor);
228
+ const graphemes = [...segmenter.segment(afterCursor)];
229
+ const firstGrapheme = graphemes[0];
230
+ const graphemeLength = firstGrapheme ? firstGrapheme.segment.length : 1;
231
+
232
+ this.#value = this.#value.slice(0, this.#cursor) + this.#value.slice(this.#cursor + graphemeLength);
233
+ }
234
+
235
+ #deleteToLineStart(): void {
236
+ if (this.#cursor === 0) {
237
+ return;
238
+ }
239
+
240
+ this.#pushUndo();
241
+ const deletedText = this.#value.slice(0, this.#cursor);
242
+ this.#killRing.push(deletedText, { prepend: true, accumulate: this.#lastAction === "kill" });
243
+ this.#lastAction = "kill";
244
+
245
+ this.#value = this.#value.slice(this.#cursor);
246
+ this.#cursor = 0;
247
+ }
248
+
249
+ #deleteToLineEnd(): void {
250
+ if (this.#cursor >= this.#value.length) {
251
+ return;
252
+ }
253
+
254
+ this.#pushUndo();
255
+ const deletedText = this.#value.slice(this.#cursor);
256
+ this.#killRing.push(deletedText, { prepend: false, accumulate: this.#lastAction === "kill" });
257
+ this.#lastAction = "kill";
258
+
259
+ this.#value = this.#value.slice(0, this.#cursor);
260
+ }
261
+
262
+ #deleteWordBackwards(): void {
263
+ if (this.#cursor === 0) {
264
+ return;
265
+ }
266
+
267
+ // Save state before cursor movement (moveWordBackwards resets lastAction).
268
+ const wasKill = this.#lastAction === "kill";
269
+ this.#pushUndo();
270
+
271
+ const oldCursor = this.#cursor;
272
+ this.#moveWordBackwards();
273
+ const deleteFrom = this.#cursor;
274
+ this.#cursor = oldCursor;
275
+
276
+ const deletedText = this.#value.slice(deleteFrom, this.#cursor);
277
+ this.#killRing.push(deletedText, { prepend: true, accumulate: wasKill });
278
+ this.#lastAction = "kill";
279
+
280
+ this.#value = this.#value.slice(0, deleteFrom) + this.#value.slice(this.#cursor);
281
+ this.#cursor = deleteFrom;
282
+ }
283
+
284
+ #deleteWordForward(): void {
285
+ if (this.#cursor >= this.#value.length) {
286
+ return;
287
+ }
288
+
289
+ // Save state before cursor movement (moveWordForwards resets lastAction).
290
+ const wasKill = this.#lastAction === "kill";
291
+ this.#pushUndo();
292
+
293
+ const oldCursor = this.#cursor;
294
+ this.#moveWordForwards();
295
+ const deleteTo = this.#cursor;
296
+ this.#cursor = oldCursor;
297
+
298
+ const deletedText = this.#value.slice(this.#cursor, deleteTo);
299
+ this.#killRing.push(deletedText, { prepend: false, accumulate: wasKill });
300
+ this.#lastAction = "kill";
301
+
302
+ this.#value = this.#value.slice(0, this.#cursor) + this.#value.slice(deleteTo);
303
+ }
304
+
305
+ #yank(): void {
306
+ const text = this.#killRing.peek();
307
+ if (!text) {
308
+ return;
309
+ }
310
+
311
+ this.#pushUndo();
312
+ this.#value = this.#value.slice(0, this.#cursor) + text + this.#value.slice(this.#cursor);
313
+ this.#cursor += text.length;
314
+ this.#lastAction = "yank";
315
+ }
316
+
317
+ #yankPop(): void {
318
+ if (this.#lastAction !== "yank" || this.#killRing.length <= 1) {
319
+ return;
320
+ }
321
+
322
+ this.#pushUndo();
323
+
324
+ const prevText = this.#killRing.peek() ?? "";
325
+ this.#value = this.#value.slice(0, this.#cursor - prevText.length) + this.#value.slice(this.#cursor);
326
+ this.#cursor -= prevText.length;
327
+
328
+ this.#killRing.rotate();
329
+ const text = this.#killRing.peek() ?? "";
330
+ this.#value = this.#value.slice(0, this.#cursor) + text + this.#value.slice(this.#cursor);
331
+ this.#cursor += text.length;
332
+ this.#lastAction = "yank";
333
+ }
334
+
335
+ #pushUndo(): void {
336
+ this.#undoStack.push({ value: this.#value, cursor: this.#cursor });
337
+ }
338
+
339
+ #undo(): void {
340
+ const snapshot = this.#undoStack.pop();
341
+ if (!snapshot) {
342
+ return;
343
+ }
344
+ this.#value = snapshot.value;
345
+ this.#cursor = snapshot.cursor;
346
+ this.#lastAction = null;
347
+ }
348
+
349
+ #moveWordBackwards(): void {
350
+ if (this.#cursor === 0) {
351
+ return;
352
+ }
353
+ this.#lastAction = null;
354
+ this.#cursor = moveWordLeft(this.#value, this.#cursor);
355
+ }
356
+
357
+ #moveWordForwards(): void {
358
+ if (this.#cursor >= this.#value.length) {
359
+ return;
360
+ }
361
+ this.#lastAction = null;
362
+ this.#cursor = moveWordRight(this.#value, this.#cursor);
363
+ }
364
+
365
+ #handlePaste(pastedText: string): void {
366
+ this.#lastAction = null;
367
+ this.#pushUndo();
368
+
369
+ // Clean the pasted text — remove newlines and carriage returns, normalize
370
+ // tabs, AND normalize Unicode to NFC.
371
+ //
372
+ // NFC normalization rationale: macOS Finder drag-drops file paths in NFD
373
+ // (Conjoining Jamo, U+1100..U+11FF). `Bun.stringWidth` counts each
374
+ // conjoining jamo as a separate cell — a Korean syllable like `화` is
375
+ // 1 char and 2 cells in NFC, but 2 chars and 3 cells in NFD (ᄒ=2 cells
376
+ // + ᅪ=1 cell). The terminal renders the NFD sequence as a single
377
+ // combined syllable (2 cells visible), so the width mismatch shows up
378
+ // as cursor drift past the visible filename — N×~1.5 cells for a path
379
+ // with N Korean syllables. NFC normalization at paste time stores the
380
+ // value in the same form everything else in the codebase assumes.
381
+ const cleanText = replaceTabs(pastedText.replace(/\r\n/g, "").replace(/\r/g, "").replace(/\n/g, "")).normalize(
382
+ "NFC",
383
+ );
384
+
385
+ // Insert at cursor position
386
+ this.#value = this.#value.slice(0, this.#cursor) + cleanText + this.#value.slice(this.#cursor);
387
+ this.#cursor += cleanText.length;
388
+ }
389
+
390
+ invalidate(): void {
391
+ // No cached state to invalidate currently
392
+ }
393
+
394
+ render(width: number): string[] {
395
+ // Calculate visible window
396
+ const prompt = "> ";
397
+ const availableWidth = width - prompt.length;
398
+
399
+ if (availableWidth <= 0) {
400
+ return [prompt];
401
+ }
402
+
403
+ const cursorIndex = this.#cursor;
404
+ // Ensure we always have a grapheme to invert at the cursor (space at end).
405
+ const displayValue = cursorIndex >= this.#value.length ? `${this.#value} ` : this.#value;
406
+
407
+ const totalCols = visibleWidth(displayValue);
408
+ const cursorCols = visibleWidth(displayValue.slice(0, cursorIndex));
409
+
410
+ // Width of the grapheme at the cursor, for ensuring it fits in the viewport.
411
+ const cursorIter = segmenter.segment(displayValue.slice(cursorIndex))[Symbol.iterator]();
412
+ const cursorG = cursorIter.next().value?.segment ?? " ";
413
+ const cursorGWidth = visibleWidth(cursorG);
414
+
415
+ const maxStart = Math.max(0, totalCols - availableWidth);
416
+ let startCol = 0;
417
+ if (totalCols > availableWidth) {
418
+ const half = Math.floor(availableWidth / 2);
419
+ startCol = Math.max(0, Math.min(maxStart, cursorCols - half));
420
+
421
+ // Ensure the cursor grapheme is inside the viewport (and fits fully if wide).
422
+ const maxCursorRel = Math.max(0, availableWidth - cursorGWidth);
423
+ const cursorRel = cursorCols - startCol;
424
+ if (cursorRel > maxCursorRel) {
425
+ startCol = Math.max(0, Math.min(maxStart, cursorCols - maxCursorRel));
426
+ }
427
+ }
428
+
429
+ const visibleText = sliceWithWidth(displayValue, startCol, availableWidth, true).text;
430
+ const prefixText = sliceWithWidth(displayValue, startCol, Math.max(0, cursorCols - startCol), true).text;
431
+ let cursorDisplay = prefixText.length;
432
+ cursorDisplay = Math.max(0, Math.min(cursorDisplay, visibleText.length));
433
+
434
+ // Build the visible line and insert the cursor marker at the buffer cursor.
435
+ const graphemes = [...segmenter.segment(visibleText.slice(cursorDisplay))];
436
+ const cursorGrapheme = graphemes[0];
437
+
438
+ const beforeCursor = visibleText.slice(0, cursorDisplay);
439
+ const atCursor = cursorGrapheme?.segment ?? "";
440
+ const afterCursor = visibleText.slice(cursorDisplay + atCursor.length);
441
+
442
+ // Hardware cursor marker (zero-width, emitted before the cursor cell for IME positioning)
443
+ const marker = this.focused ? CURSOR_MARKER : "";
444
+ const cursorChar = this.#useTerminalCursor ? atCursor : `\x1b[7m${atCursor || " "}\x1b[27m`;
445
+
446
+ // Clamp only the trailing text (measured in terminal cells), keeping the cursor marker intact.
447
+ const beforeWidth = visibleWidth(beforeCursor);
448
+ const cursorWidth = this.#useTerminalCursor ? visibleWidth(atCursor) : visibleWidth(atCursor || " ");
449
+ const remainingAfterWidth = Math.max(0, availableWidth - beforeWidth - cursorWidth);
450
+ const clampedAfterCursor = sliceWithWidth(afterCursor, 0, remainingAfterWidth, true).text;
451
+ const renderedNoMarker = beforeCursor + cursorChar + clampedAfterCursor;
452
+ const textWithCursor = beforeCursor + marker + cursorChar + clampedAfterCursor;
453
+
454
+ const visualLength = visibleWidth(renderedNoMarker);
455
+ const pad = padding(Math.max(0, availableWidth - visualLength));
456
+ const line = prompt + textWithCursor + pad;
457
+ return [line];
458
+ }
459
+ }
@@ -0,0 +1,86 @@
1
+ import type { TUI } from "../tui";
2
+ import { sliceByColumn, visibleWidth } from "../utils";
3
+ import { Text } from "./text";
4
+
5
+ /**
6
+ * Loader component that drives display refresh at ~60fps so callers whose
7
+ * message colorizer is time-dependent (e.g. shimmer/KITT) animate smoothly.
8
+ *
9
+ * Two cadences are interleaved on a single timer:
10
+ * - **Render tick** (every `RENDER_INTERVAL_MS`) → asks the TUI to redraw.
11
+ * The TUI already throttles at 16ms (`MIN_RENDER_INTERVAL_MS`), so this
12
+ * is the natural upper bound; static messageColorFns produce identical
13
+ * output and the differ drops the no-op redraw at ~zero cost.
14
+ * - **Spinner advance** (every `SPINNER_ADVANCE_MS`) → bumps the spinner
15
+ * frame index. Decoupled from the render cadence so the spinner keeps
16
+ * its classic ~12.5fps step pace regardless of shimmer state.
17
+ */
18
+ const RENDER_INTERVAL_MS = 16;
19
+ const SPINNER_ADVANCE_MS = 80;
20
+
21
+ export class Loader extends Text {
22
+ #frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
23
+ #currentFrame = 0;
24
+ #intervalId?: NodeJS.Timeout;
25
+ #ui: TUI | null = null;
26
+ #lastSpinnerTick = 0;
27
+
28
+ constructor(
29
+ ui: TUI,
30
+ private spinnerColorFn: (str: string) => string,
31
+ private messageColorFn: (str: string) => string,
32
+ private message: string = "Loading...",
33
+ spinnerFrames?: string[],
34
+ ) {
35
+ super("", 1, 0);
36
+ this.#ui = ui;
37
+ if (spinnerFrames && spinnerFrames.length > 0) {
38
+ this.#frames = spinnerFrames;
39
+ }
40
+ this.start();
41
+ }
42
+
43
+ render(width: number): string[] {
44
+ const lines = ["", ...super.render(width)];
45
+ for (let i = 0; i < lines.length; i++) {
46
+ const line = lines[i];
47
+ if (visibleWidth(line) > width) {
48
+ lines[i] = sliceByColumn(line, 0, width, true);
49
+ }
50
+ }
51
+ return lines;
52
+ }
53
+
54
+ start() {
55
+ this.#lastSpinnerTick = performance.now();
56
+ this.#updateDisplay();
57
+ this.#intervalId = setInterval(() => {
58
+ const now = performance.now();
59
+ if (now - this.#lastSpinnerTick >= SPINNER_ADVANCE_MS) {
60
+ this.#currentFrame = (this.#currentFrame + 1) % this.#frames.length;
61
+ this.#lastSpinnerTick = now;
62
+ }
63
+ this.#updateDisplay();
64
+ }, RENDER_INTERVAL_MS);
65
+ }
66
+
67
+ stop() {
68
+ if (this.#intervalId) {
69
+ clearInterval(this.#intervalId);
70
+ this.#intervalId = undefined;
71
+ }
72
+ }
73
+
74
+ setMessage(message: string) {
75
+ this.message = message;
76
+ this.#updateDisplay();
77
+ }
78
+
79
+ #updateDisplay() {
80
+ const frame = this.#frames[this.#currentFrame];
81
+ this.setText(`${this.spinnerColorFn(frame)} ${this.messageColorFn(this.message)}`);
82
+ if (this.#ui) {
83
+ this.#ui.requestRender();
84
+ }
85
+ }
86
+ }