agentlas 1.0.42 → 1.0.44

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 (70) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/engine/agentlas-workforce.cjs +1 -1
  3. package/engine/hephaestus/runtime.cjs +1 -1
  4. package/engine/storm/storm.cjs +1 -1
  5. package/engine/storm/swarm.cjs +1 -1
  6. package/engine/ui/palette.cjs +1 -0
  7. package/engine/ui/repl.cjs +34 -4
  8. package/engine/ui/shell.cjs +22 -3
  9. package/engine/vendor/mermaid/LICENSE +205 -0
  10. package/engine/vendor/mermaid/ansi.js +23 -0
  11. package/engine/vendor/mermaid/canvas.js +366 -0
  12. package/engine/vendor/mermaid/graph.js +91 -0
  13. package/engine/vendor/mermaid/index.js +100 -0
  14. package/engine/vendor/mermaid/labels.js +324 -0
  15. package/engine/vendor/mermaid/layout-seq.js +194 -0
  16. package/engine/vendor/mermaid/layout.js +881 -0
  17. package/engine/vendor/mermaid/package.json +1 -0
  18. package/engine/vendor/mermaid/parse.js +1108 -0
  19. package/engine/vendor/mermaid/source-box.js +78 -0
  20. package/engine/vendor/mermaid/types.js +1 -0
  21. package/engine/vendor/mermaid/width-data.js +994 -0
  22. package/engine/vendor/mermaid/width.js +76 -0
  23. package/engine/vendor/tui/LICENSE +20 -0
  24. package/engine/vendor/tui/autocomplete.js +632 -0
  25. package/engine/vendor/tui/components/alt-screen-flash.js +37 -0
  26. package/engine/vendor/tui/components/box.js +104 -0
  27. package/engine/vendor/tui/components/cancellable-loader.js +35 -0
  28. package/engine/vendor/tui/components/editor.js +1961 -0
  29. package/engine/vendor/tui/components/h-stack.js +43 -0
  30. package/engine/vendor/tui/components/image.js +90 -0
  31. package/engine/vendor/tui/components/input.js +378 -0
  32. package/engine/vendor/tui/components/loader.js +69 -0
  33. package/engine/vendor/tui/components/markdown.js +806 -0
  34. package/engine/vendor/tui/components/scroll-view.js +173 -0
  35. package/engine/vendor/tui/components/select-list.js +159 -0
  36. package/engine/vendor/tui/components/settings-list.js +182 -0
  37. package/engine/vendor/tui/components/spacer.js +23 -0
  38. package/engine/vendor/tui/components/stack.js +111 -0
  39. package/engine/vendor/tui/components/text.js +89 -0
  40. package/engine/vendor/tui/components/truncated-text.js +51 -0
  41. package/engine/vendor/tui/components/v-stack.js +26 -0
  42. package/engine/vendor/tui/deps/east-asian-width/LICENSE +9 -0
  43. package/engine/vendor/tui/deps/east-asian-width/index.js +30 -0
  44. package/engine/vendor/tui/deps/east-asian-width/lookup-data.js +21 -0
  45. package/engine/vendor/tui/deps/east-asian-width/lookup.js +138 -0
  46. package/engine/vendor/tui/deps/east-asian-width/utilities.js +24 -0
  47. package/engine/vendor/tui/deps/marked/LICENSE +44 -0
  48. package/engine/vendor/tui/deps/marked/index.js +77 -0
  49. package/engine/vendor/tui/editor-component.js +2 -0
  50. package/engine/vendor/tui/fuzzy.js +110 -0
  51. package/engine/vendor/tui/index.js +42 -0
  52. package/engine/vendor/tui/keybindings.js +209 -0
  53. package/engine/vendor/tui/keys.js +1174 -0
  54. package/engine/vendor/tui/kill-ring.js +44 -0
  55. package/engine/vendor/tui/latex.js +1264 -0
  56. package/engine/vendor/tui/layout-node.js +6 -0
  57. package/engine/vendor/tui/layout.js +314 -0
  58. package/engine/vendor/tui/native-modifiers.js +60 -0
  59. package/engine/vendor/tui/package.json +1 -0
  60. package/engine/vendor/tui/stdin-buffer.js +361 -0
  61. package/engine/vendor/tui/terminal-colors.js +59 -0
  62. package/engine/vendor/tui/terminal-image.js +518 -0
  63. package/engine/vendor/tui/terminal.js +436 -0
  64. package/engine/vendor/tui/tui-alt-screen.js +902 -0
  65. package/engine/vendor/tui/tui-main-screen.js +533 -0
  66. package/engine/vendor/tui/tui.js +937 -0
  67. package/engine/vendor/tui/undo-stack.js +25 -0
  68. package/engine/vendor/tui/utils.js +1191 -0
  69. package/engine/vendor/tui/word-navigation.js +96 -0
  70. package/package.json +2 -6
@@ -0,0 +1,43 @@
1
+ import { compositeTuiLine } from "../tui.js";
2
+ import { visibleWidth } from "../utils.js";
3
+ import { allocateStackSizes, Stack, visibleStackEntries } from "./stack.js";
4
+ export class HStack extends Stack {
5
+ layoutType = "hstack";
6
+ constructor(children = [], options = {}) {
7
+ super(children, options);
8
+ }
9
+ render(width) {
10
+ const safeWidth = Math.max(1, width);
11
+ const viewport = { width: safeWidth, height: Number.MAX_SAFE_INTEGER };
12
+ const entries = visibleStackEntries(this.entries, viewport);
13
+ if (entries.length === 0)
14
+ return [];
15
+ const intrinsicWidths = entries.map((entry) => {
16
+ const lines = entry.component.render(safeWidth);
17
+ return lines.reduce((max, line) => Math.max(max, visibleWidth(line)), 0);
18
+ });
19
+ const widths = allocateStackSizes(entries, intrinsicWidths, safeWidth, this.gap);
20
+ const rendered = entries.map((entry, index) => widths[index] === 0 ? [] : entry.component.render(widths[index]));
21
+ const height = rendered.reduce((max, lines) => Math.max(max, lines.length), 0);
22
+ const result = Array.from({ length: height }, () => "");
23
+ let x = 0;
24
+ for (let index = 0; index < rendered.length; index++) {
25
+ const lines = rendered[index];
26
+ const childWidth = widths[index];
27
+ let offset = 0;
28
+ if (this.align === "center")
29
+ offset = Math.floor((height - lines.length) / 2);
30
+ else if (this.align === "end")
31
+ offset = height - lines.length;
32
+ for (let row = 0; row < lines.length; row++) {
33
+ const target = row + offset;
34
+ if (target < 0 || target >= result.length)
35
+ continue;
36
+ result[target] = compositeTuiLine(result[target], lines[row], x, childWidth, safeWidth);
37
+ }
38
+ x += childWidth + this.gap;
39
+ }
40
+ return result;
41
+ }
42
+ }
43
+ //# sourceMappingURL=h-stack.js.map
@@ -0,0 +1,90 @@
1
+ import { allocateImageId, getCapabilities, getCellDimensions, getImageDimensions, imageFallback, renderImage, } from "../terminal-image.js";
2
+ import { truncateToWidth } from "../utils.js";
3
+ export class Image {
4
+ base64Data;
5
+ mimeType;
6
+ dimensions;
7
+ theme;
8
+ options;
9
+ imageId;
10
+ cachedLines;
11
+ cachedWidth;
12
+ constructor(base64Data, mimeType, theme, options = {}, dimensions) {
13
+ this.base64Data = base64Data;
14
+ this.mimeType = mimeType;
15
+ this.theme = theme;
16
+ this.options = options;
17
+ this.dimensions = dimensions || getImageDimensions(base64Data, mimeType) || { widthPx: 800, heightPx: 600 };
18
+ this.imageId = options.imageId;
19
+ }
20
+ /** Get the Kitty image ID used by this image (if any). */
21
+ getImageId() {
22
+ return this.imageId;
23
+ }
24
+ invalidate() {
25
+ this.cachedLines = undefined;
26
+ this.cachedWidth = undefined;
27
+ }
28
+ render(width) {
29
+ if (this.cachedLines && this.cachedWidth === width) {
30
+ return this.cachedLines;
31
+ }
32
+ const maxWidth = Math.max(1, Math.min(width - 2, this.options.maxWidthCells ?? 60));
33
+ const cellDimensions = getCellDimensions();
34
+ const defaultMaxHeight = Math.max(1, Math.ceil((maxWidth * cellDimensions.widthPx) / cellDimensions.heightPx));
35
+ const maxHeight = this.options.maxHeightCells ?? defaultMaxHeight;
36
+ const caps = getCapabilities();
37
+ let lines;
38
+ if (caps.images) {
39
+ if (caps.images === "kitty" && this.imageId === undefined) {
40
+ this.imageId = allocateImageId();
41
+ }
42
+ const result = renderImage(this.base64Data, this.dimensions, {
43
+ maxWidthCells: maxWidth,
44
+ maxHeightCells: maxHeight,
45
+ imageId: this.imageId,
46
+ moveCursor: false,
47
+ });
48
+ if (result) {
49
+ // Store the image ID for later cleanup
50
+ if (result.imageId) {
51
+ this.imageId = result.imageId;
52
+ }
53
+ if (caps.images === "kitty") {
54
+ // For Kitty: C=1 prevents cursor movement.
55
+ // Don't need the cursor movement.
56
+ lines = [result.sequence];
57
+ // Return `rows` lines so TUI accounts for image height.
58
+ for (let i = 0; i < result.rows - 1; i++) {
59
+ lines.push("");
60
+ }
61
+ }
62
+ else {
63
+ // Return `rows` lines so TUI accounts for image height.
64
+ // First (rows-1) lines are empty and cleared before the image is drawn.
65
+ // Last line: move cursor back up, draw the image, then move back down
66
+ // so TUI cursor accounting stays inside the scroll area.
67
+ lines = [];
68
+ for (let i = 0; i < result.rows - 1; i++) {
69
+ lines.push("");
70
+ }
71
+ const rowOffset = result.rows - 1;
72
+ const moveUp = rowOffset > 0 ? `\x1b[${rowOffset}A` : "";
73
+ lines.push(moveUp + result.sequence);
74
+ }
75
+ }
76
+ else {
77
+ const fallback = imageFallback(this.mimeType, this.dimensions, this.options.filename);
78
+ lines = [truncateToWidth(this.theme.fallbackColor(fallback), width)];
79
+ }
80
+ }
81
+ else {
82
+ const fallback = imageFallback(this.mimeType, this.dimensions, this.options.filename);
83
+ lines = [truncateToWidth(this.theme.fallbackColor(fallback), width)];
84
+ }
85
+ this.cachedLines = lines;
86
+ this.cachedWidth = width;
87
+ return lines;
88
+ }
89
+ }
90
+ //# sourceMappingURL=image.js.map
@@ -0,0 +1,378 @@
1
+ import { getKeybindings } from "../keybindings.js";
2
+ import { decodeKittyPrintable } from "../keys.js";
3
+ import { KillRing } from "../kill-ring.js";
4
+ import { CURSOR_MARKER } from "../tui.js";
5
+ import { UndoStack } from "../undo-stack.js";
6
+ import { getGraphemeSegmenter, isWhitespaceChar, sliceByColumn, visibleWidth } from "../utils.js";
7
+ import { findWordBackward, findWordForward } from "../word-navigation.js";
8
+ const segmenter = getGraphemeSegmenter();
9
+ /**
10
+ * Input component - single-line text input with horizontal scrolling
11
+ */
12
+ export class Input {
13
+ value = "";
14
+ cursor = 0; // Cursor position in the value
15
+ onSubmit;
16
+ onEscape;
17
+ /** Focusable interface - set by TUI when focus changes */
18
+ focused = false;
19
+ // Bracketed paste mode buffering
20
+ pasteBuffer = "";
21
+ isInPaste = false;
22
+ // Kill ring for Emacs-style kill/yank operations
23
+ killRing = new KillRing();
24
+ lastAction = null;
25
+ // Undo support
26
+ undoStack = new UndoStack();
27
+ getValue() {
28
+ return this.value;
29
+ }
30
+ setValue(value) {
31
+ this.value = value;
32
+ this.cursor = Math.min(this.cursor, value.length);
33
+ }
34
+ handleInput(data) {
35
+ // Handle bracketed paste mode
36
+ // Start of paste: \x1b[200~
37
+ // End of paste: \x1b[201~
38
+ // Check if we're starting a bracketed paste
39
+ if (data.includes("\x1b[200~")) {
40
+ this.isInPaste = true;
41
+ this.pasteBuffer = "";
42
+ data = data.replace("\x1b[200~", "");
43
+ }
44
+ // If we're in a paste, buffer the data
45
+ if (this.isInPaste) {
46
+ // Check if this chunk contains the end marker
47
+ this.pasteBuffer += data;
48
+ const endIndex = this.pasteBuffer.indexOf("\x1b[201~");
49
+ if (endIndex !== -1) {
50
+ // Extract the pasted content
51
+ const pasteContent = this.pasteBuffer.substring(0, endIndex);
52
+ // Process the complete paste
53
+ this.handlePaste(pasteContent);
54
+ // Reset paste state
55
+ this.isInPaste = false;
56
+ // Handle any remaining input after the paste marker
57
+ const remaining = this.pasteBuffer.substring(endIndex + 6); // 6 = length of \x1b[201~
58
+ this.pasteBuffer = "";
59
+ if (remaining) {
60
+ this.handleInput(remaining);
61
+ }
62
+ }
63
+ return;
64
+ }
65
+ const kb = getKeybindings();
66
+ // Escape/Cancel
67
+ if (kb.matches(data, "tui.select.cancel")) {
68
+ if (this.onEscape)
69
+ this.onEscape();
70
+ return;
71
+ }
72
+ // Undo
73
+ if (kb.matches(data, "tui.editor.undo")) {
74
+ this.undo();
75
+ return;
76
+ }
77
+ // Submit
78
+ if (kb.matches(data, "tui.input.submit") || data === "\n") {
79
+ if (this.onSubmit)
80
+ this.onSubmit(this.value);
81
+ return;
82
+ }
83
+ // Deletion
84
+ if (kb.matches(data, "tui.editor.deleteCharBackward")) {
85
+ this.handleBackspace();
86
+ return;
87
+ }
88
+ if (kb.matches(data, "tui.editor.deleteCharForward")) {
89
+ this.handleForwardDelete();
90
+ return;
91
+ }
92
+ if (kb.matches(data, "tui.editor.deleteWordBackward")) {
93
+ this.deleteWordBackwards();
94
+ return;
95
+ }
96
+ if (kb.matches(data, "tui.editor.deleteWordForward")) {
97
+ this.deleteWordForward();
98
+ return;
99
+ }
100
+ if (kb.matches(data, "tui.editor.deleteToLineStart")) {
101
+ this.deleteToLineStart();
102
+ return;
103
+ }
104
+ if (kb.matches(data, "tui.editor.deleteToLineEnd")) {
105
+ this.deleteToLineEnd();
106
+ return;
107
+ }
108
+ // Kill ring actions
109
+ if (kb.matches(data, "tui.editor.yank")) {
110
+ this.yank();
111
+ return;
112
+ }
113
+ if (kb.matches(data, "tui.editor.yankPop")) {
114
+ this.yankPop();
115
+ return;
116
+ }
117
+ // Cursor movement
118
+ if (kb.matches(data, "tui.editor.cursorLeft")) {
119
+ this.lastAction = null;
120
+ if (this.cursor > 0) {
121
+ const beforeCursor = this.value.slice(0, this.cursor);
122
+ const graphemes = [...segmenter.segment(beforeCursor)];
123
+ const lastGrapheme = graphemes[graphemes.length - 1];
124
+ this.cursor -= lastGrapheme ? lastGrapheme.segment.length : 1;
125
+ }
126
+ return;
127
+ }
128
+ if (kb.matches(data, "tui.editor.cursorRight")) {
129
+ this.lastAction = null;
130
+ if (this.cursor < this.value.length) {
131
+ const afterCursor = this.value.slice(this.cursor);
132
+ const graphemes = [...segmenter.segment(afterCursor)];
133
+ const firstGrapheme = graphemes[0];
134
+ this.cursor += firstGrapheme ? firstGrapheme.segment.length : 1;
135
+ }
136
+ return;
137
+ }
138
+ if (kb.matches(data, "tui.editor.cursorLineStart")) {
139
+ this.lastAction = null;
140
+ this.cursor = 0;
141
+ return;
142
+ }
143
+ if (kb.matches(data, "tui.editor.cursorLineEnd")) {
144
+ this.lastAction = null;
145
+ this.cursor = this.value.length;
146
+ return;
147
+ }
148
+ if (kb.matches(data, "tui.editor.cursorWordLeft")) {
149
+ this.moveWordBackwards();
150
+ return;
151
+ }
152
+ if (kb.matches(data, "tui.editor.cursorWordRight")) {
153
+ this.moveWordForwards();
154
+ return;
155
+ }
156
+ // Kitty CSI-u printable character (e.g. \x1b[97u for 'a').
157
+ // Terminals with Kitty protocol flag 1 (disambiguate) send CSI-u for all keys,
158
+ // including plain printable characters. Decode before the control-char check
159
+ // since CSI-u sequences contain \x1b which would be rejected.
160
+ const kittyPrintable = decodeKittyPrintable(data);
161
+ if (kittyPrintable !== undefined) {
162
+ this.insertCharacter(kittyPrintable);
163
+ return;
164
+ }
165
+ // Regular character input - accept printable characters including Unicode,
166
+ // but reject control characters (C0: 0x00-0x1F, DEL: 0x7F, C1: 0x80-0x9F)
167
+ const hasControlChars = [...data].some((ch) => {
168
+ const code = ch.charCodeAt(0);
169
+ return code < 32 || code === 0x7f || (code >= 0x80 && code <= 0x9f);
170
+ });
171
+ if (!hasControlChars) {
172
+ this.insertCharacter(data);
173
+ }
174
+ }
175
+ insertCharacter(char) {
176
+ // Undo coalescing: consecutive word chars coalesce into one undo unit
177
+ if (isWhitespaceChar(char) || this.lastAction !== "type-word") {
178
+ this.pushUndo();
179
+ }
180
+ this.lastAction = "type-word";
181
+ this.value = this.value.slice(0, this.cursor) + char + this.value.slice(this.cursor);
182
+ this.cursor += char.length;
183
+ }
184
+ handleBackspace() {
185
+ this.lastAction = null;
186
+ if (this.cursor > 0) {
187
+ this.pushUndo();
188
+ const beforeCursor = this.value.slice(0, this.cursor);
189
+ const graphemes = [...segmenter.segment(beforeCursor)];
190
+ const lastGrapheme = graphemes[graphemes.length - 1];
191
+ const graphemeLength = lastGrapheme ? lastGrapheme.segment.length : 1;
192
+ this.value = this.value.slice(0, this.cursor - graphemeLength) + this.value.slice(this.cursor);
193
+ this.cursor -= graphemeLength;
194
+ }
195
+ }
196
+ handleForwardDelete() {
197
+ this.lastAction = null;
198
+ if (this.cursor < this.value.length) {
199
+ this.pushUndo();
200
+ const afterCursor = this.value.slice(this.cursor);
201
+ const graphemes = [...segmenter.segment(afterCursor)];
202
+ const firstGrapheme = graphemes[0];
203
+ const graphemeLength = firstGrapheme ? firstGrapheme.segment.length : 1;
204
+ this.value = this.value.slice(0, this.cursor) + this.value.slice(this.cursor + graphemeLength);
205
+ }
206
+ }
207
+ deleteToLineStart() {
208
+ if (this.cursor === 0)
209
+ return;
210
+ this.pushUndo();
211
+ const deletedText = this.value.slice(0, this.cursor);
212
+ this.killRing.push(deletedText, { prepend: true, accumulate: this.lastAction === "kill" });
213
+ this.lastAction = "kill";
214
+ this.value = this.value.slice(this.cursor);
215
+ this.cursor = 0;
216
+ }
217
+ deleteToLineEnd() {
218
+ if (this.cursor >= this.value.length)
219
+ return;
220
+ this.pushUndo();
221
+ const deletedText = this.value.slice(this.cursor);
222
+ this.killRing.push(deletedText, { prepend: false, accumulate: this.lastAction === "kill" });
223
+ this.lastAction = "kill";
224
+ this.value = this.value.slice(0, this.cursor);
225
+ }
226
+ deleteWordBackwards() {
227
+ if (this.cursor === 0)
228
+ return;
229
+ // Save lastAction before cursor movement (moveWordBackwards resets it)
230
+ const wasKill = this.lastAction === "kill";
231
+ this.pushUndo();
232
+ const oldCursor = this.cursor;
233
+ this.moveWordBackwards();
234
+ const deleteFrom = this.cursor;
235
+ this.cursor = oldCursor;
236
+ const deletedText = this.value.slice(deleteFrom, this.cursor);
237
+ this.killRing.push(deletedText, { prepend: true, accumulate: wasKill });
238
+ this.lastAction = "kill";
239
+ this.value = this.value.slice(0, deleteFrom) + this.value.slice(this.cursor);
240
+ this.cursor = deleteFrom;
241
+ }
242
+ deleteWordForward() {
243
+ if (this.cursor >= this.value.length)
244
+ return;
245
+ // Save lastAction before cursor movement (moveWordForwards resets it)
246
+ const wasKill = this.lastAction === "kill";
247
+ this.pushUndo();
248
+ const oldCursor = this.cursor;
249
+ this.moveWordForwards();
250
+ const deleteTo = this.cursor;
251
+ this.cursor = oldCursor;
252
+ const deletedText = this.value.slice(this.cursor, deleteTo);
253
+ this.killRing.push(deletedText, { prepend: false, accumulate: wasKill });
254
+ this.lastAction = "kill";
255
+ this.value = this.value.slice(0, this.cursor) + this.value.slice(deleteTo);
256
+ }
257
+ yank() {
258
+ const text = this.killRing.peek();
259
+ if (!text)
260
+ return;
261
+ this.pushUndo();
262
+ this.value = this.value.slice(0, this.cursor) + text + this.value.slice(this.cursor);
263
+ this.cursor += text.length;
264
+ this.lastAction = "yank";
265
+ }
266
+ yankPop() {
267
+ if (this.lastAction !== "yank" || this.killRing.length <= 1)
268
+ return;
269
+ this.pushUndo();
270
+ // Delete the previously yanked text (still at end of ring before rotation)
271
+ const prevText = this.killRing.peek() || "";
272
+ this.value = this.value.slice(0, this.cursor - prevText.length) + this.value.slice(this.cursor);
273
+ this.cursor -= prevText.length;
274
+ // Rotate and insert new entry
275
+ this.killRing.rotate();
276
+ const text = this.killRing.peek() || "";
277
+ this.value = this.value.slice(0, this.cursor) + text + this.value.slice(this.cursor);
278
+ this.cursor += text.length;
279
+ this.lastAction = "yank";
280
+ }
281
+ pushUndo() {
282
+ this.undoStack.push({ value: this.value, cursor: this.cursor });
283
+ }
284
+ undo() {
285
+ const snapshot = this.undoStack.pop();
286
+ if (!snapshot)
287
+ return;
288
+ this.value = snapshot.value;
289
+ this.cursor = snapshot.cursor;
290
+ this.lastAction = null;
291
+ }
292
+ moveWordBackwards() {
293
+ if (this.cursor === 0)
294
+ return;
295
+ this.lastAction = null;
296
+ this.cursor = findWordBackward(this.value, this.cursor);
297
+ }
298
+ moveWordForwards() {
299
+ if (this.cursor >= this.value.length)
300
+ return;
301
+ this.lastAction = null;
302
+ this.cursor = findWordForward(this.value, this.cursor);
303
+ }
304
+ handlePaste(pastedText) {
305
+ this.lastAction = null;
306
+ this.pushUndo();
307
+ // Clean the pasted text - remove newlines and carriage returns
308
+ const cleanText = pastedText.replace(/\r\n/g, "").replace(/\r/g, "").replace(/\n/g, "").replace(/\t/g, " ");
309
+ // Insert at cursor position
310
+ this.value = this.value.slice(0, this.cursor) + cleanText + this.value.slice(this.cursor);
311
+ this.cursor += cleanText.length;
312
+ }
313
+ invalidate() {
314
+ // No cached state to invalidate currently
315
+ }
316
+ render(width) {
317
+ // Calculate visible window
318
+ const prompt = "> ";
319
+ const availableWidth = width - prompt.length;
320
+ if (availableWidth <= 0) {
321
+ return [prompt];
322
+ }
323
+ let visibleText = "";
324
+ let cursorDisplay = this.cursor;
325
+ const totalWidth = visibleWidth(this.value);
326
+ if (totalWidth < availableWidth) {
327
+ // Everything fits (leave room for cursor at end)
328
+ visibleText = this.value;
329
+ }
330
+ else {
331
+ // Need horizontal scrolling
332
+ // Reserve one column for cursor if it's at the end
333
+ const scrollWidth = this.cursor === this.value.length ? availableWidth - 1 : availableWidth;
334
+ const cursorCol = visibleWidth(this.value.slice(0, this.cursor));
335
+ if (scrollWidth > 0) {
336
+ const halfWidth = Math.floor(scrollWidth / 2);
337
+ let startCol = 0;
338
+ if (cursorCol < halfWidth) {
339
+ // Cursor near start
340
+ startCol = 0;
341
+ }
342
+ else if (cursorCol > totalWidth - halfWidth) {
343
+ // Cursor near end
344
+ startCol = Math.max(0, totalWidth - scrollWidth);
345
+ }
346
+ else {
347
+ // Cursor in middle
348
+ startCol = Math.max(0, cursorCol - halfWidth);
349
+ }
350
+ visibleText = sliceByColumn(this.value, startCol, scrollWidth, true);
351
+ const beforeCursor = sliceByColumn(this.value, startCol, Math.max(0, cursorCol - startCol), true);
352
+ cursorDisplay = beforeCursor.length;
353
+ }
354
+ else {
355
+ visibleText = "";
356
+ cursorDisplay = 0;
357
+ }
358
+ }
359
+ // Build line with fake cursor
360
+ // Insert cursor character at cursor position
361
+ const graphemes = [...segmenter.segment(visibleText.slice(cursorDisplay))];
362
+ const cursorGrapheme = graphemes[0];
363
+ const beforeCursor = visibleText.slice(0, cursorDisplay);
364
+ const atCursor = cursorGrapheme?.segment ?? " "; // Character at cursor, or space if at end
365
+ const afterCursor = visibleText.slice(cursorDisplay + atCursor.length);
366
+ // Hardware cursor marker (zero-width, emitted before fake cursor for IME positioning)
367
+ const marker = this.focused ? CURSOR_MARKER : "";
368
+ // Use inverse video to show cursor
369
+ const cursorChar = `\x1b[7m${atCursor}\x1b[27m`; // ESC[7m = reverse video, ESC[27m = normal
370
+ const textWithCursor = beforeCursor + marker + cursorChar + afterCursor;
371
+ // Calculate visual width
372
+ const visualLength = visibleWidth(textWithCursor);
373
+ const padding = " ".repeat(Math.max(0, availableWidth - visualLength));
374
+ const line = prompt + textWithCursor + padding;
375
+ return [line];
376
+ }
377
+ }
378
+ //# sourceMappingURL=input.js.map
@@ -0,0 +1,69 @@
1
+ import { Text } from "./text.js";
2
+ const DEFAULT_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
3
+ const DEFAULT_INTERVAL_MS = 80;
4
+ /**
5
+ * Loader component that updates with an optional spinning animation.
6
+ */
7
+ export class Loader extends Text {
8
+ frames = [...DEFAULT_FRAMES];
9
+ intervalMs = DEFAULT_INTERVAL_MS;
10
+ currentFrame = 0;
11
+ intervalId = null;
12
+ ui = null;
13
+ renderIndicatorVerbatim = false;
14
+ spinnerColorFn;
15
+ messageColorFn;
16
+ message = "Loading...";
17
+ constructor(ui, spinnerColorFn, messageColorFn, message = "Loading...", indicator) {
18
+ super("", 1, 0);
19
+ this.ui = ui;
20
+ this.spinnerColorFn = spinnerColorFn;
21
+ this.messageColorFn = messageColorFn;
22
+ this.message = message;
23
+ this.setIndicator(indicator);
24
+ }
25
+ render(width) {
26
+ return ["", ...super.render(width)];
27
+ }
28
+ start() {
29
+ this.updateDisplay();
30
+ this.restartAnimation();
31
+ }
32
+ stop() {
33
+ if (this.intervalId) {
34
+ clearInterval(this.intervalId);
35
+ this.intervalId = null;
36
+ }
37
+ }
38
+ setMessage(message) {
39
+ this.message = message;
40
+ this.updateDisplay();
41
+ }
42
+ setIndicator(indicator) {
43
+ this.renderIndicatorVerbatim = indicator !== undefined;
44
+ this.frames = indicator?.frames !== undefined ? [...indicator.frames] : [...DEFAULT_FRAMES];
45
+ this.intervalMs = indicator?.intervalMs && indicator.intervalMs > 0 ? indicator.intervalMs : DEFAULT_INTERVAL_MS;
46
+ this.currentFrame = 0;
47
+ this.start();
48
+ }
49
+ restartAnimation() {
50
+ this.stop();
51
+ if (this.frames.length <= 1) {
52
+ return;
53
+ }
54
+ this.intervalId = setInterval(() => {
55
+ this.currentFrame = (this.currentFrame + 1) % this.frames.length;
56
+ this.updateDisplay();
57
+ }, this.intervalMs);
58
+ }
59
+ updateDisplay() {
60
+ const frame = this.frames[this.currentFrame] ?? "";
61
+ const renderedFrame = this.renderIndicatorVerbatim ? frame : this.spinnerColorFn(frame);
62
+ const indicator = frame.length > 0 ? `${renderedFrame} ` : "";
63
+ this.setText(`${indicator}${this.messageColorFn(this.message)}`);
64
+ if (this.ui) {
65
+ this.ui.requestRender();
66
+ }
67
+ }
68
+ }
69
+ //# sourceMappingURL=loader.js.map