stitchkit-tui 0.3.0 → 0.4.1
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 +61 -16
- package/dist/{app-mqzzrp1t.js → app-2zw4ra7n.js} +36 -16
- package/dist/build/index.d.ts +42 -0
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +174 -0
- package/dist/cli.js +2 -2
- package/dist/config.d.ts +8 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/controller.d.ts.map +1 -1
- package/dist/core/index.js +27 -25
- package/dist/core/labels.d.ts +4 -0
- package/dist/core/labels.d.ts.map +1 -1
- package/dist/core/table.d.ts +18 -1
- package/dist/core/table.d.ts.map +1 -1
- package/dist/gallery/main.js +1 -1
- package/dist/gallery/monitor-page.d.ts.map +1 -1
- package/dist/{index-kz62sdr9.js → index-1qacnvfd.js} +1 -1
- package/dist/index-51qwgt9f.js +172 -0
- package/dist/index-ahfc59de.js +495 -0
- package/dist/{index-ecpc5qkb.js → index-as4srnct.js} +1 -0
- package/dist/{index-z4c2ehg4.js → index-djrp2fey.js} +107 -583
- package/dist/index-m0dhvt6x.js +160 -0
- package/dist/{index-251fexwh.js → index-qhj2ne64.js} +1 -1
- package/dist/{index-fxx9ktw7.js → index-t6mwjbgr.js} +68 -58
- package/dist/{index-54sqbm3r.js → index-wcbe2tnk.js} +168 -285
- package/dist/index.js +8 -5
- package/dist/{run-e1kdpzna.js → run-ea636vch.js} +8 -5
- package/dist/run.d.ts.map +1 -1
- package/dist/session.d.ts.map +1 -1
- package/dist/testing/index.d.ts +50 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +110 -0
- package/dist/widgets/app.d.ts +77 -0
- package/dist/widgets/app.d.ts.map +1 -0
- package/dist/widgets/form.d.ts.map +1 -1
- package/dist/widgets/index.d.ts +1 -0
- package/dist/widgets/index.d.ts.map +1 -1
- package/dist/widgets/index.js +20 -7
- package/dist/widgets/table.d.ts.map +1 -1
- package/dist/widgets/theme.d.ts +7 -1
- package/dist/widgets/theme.d.ts.map +1 -1
- package/package.json +12 -4
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
import {
|
|
3
|
+
TerminalToneSchema2,
|
|
4
|
+
sanitizeTerminalText2,
|
|
5
|
+
terminalTextWidth2,
|
|
6
|
+
truncateTerminalText2,
|
|
7
|
+
fitTerminalText2,
|
|
8
|
+
applyTerminalTextEdit2,
|
|
9
|
+
terminalLabelsEn2
|
|
10
|
+
} from "./index-ahfc59de.js";
|
|
11
|
+
|
|
2
12
|
// src/core/search.ts
|
|
3
13
|
function fold(text) {
|
|
4
14
|
return Array.from(text, (char) => char.toLocaleLowerCase());
|
|
@@ -92,76 +102,14 @@ function terminalHighlightRuns2(text, ranges) {
|
|
|
92
102
|
}
|
|
93
103
|
|
|
94
104
|
// src/core/chart.ts
|
|
95
|
-
import { z as z2 } from "zod";
|
|
96
|
-
|
|
97
|
-
// src/core/theme.ts
|
|
98
105
|
import { z } from "zod";
|
|
99
|
-
var
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
"accent",
|
|
103
|
-
"success",
|
|
104
|
-
"warning",
|
|
105
|
-
"danger"
|
|
106
|
-
]);
|
|
107
|
-
var TerminalThemeModeSchema2 = z.enum(["dark", "light"]);
|
|
108
|
-
var ColorSchema = z.string().min(1);
|
|
109
|
-
var TerminalPaletteSchema2 = z.object({
|
|
110
|
-
canvas: ColorSchema,
|
|
111
|
-
panel: ColorSchema,
|
|
112
|
-
panelRaised: ColorSchema,
|
|
113
|
-
border: ColorSchema,
|
|
114
|
-
borderActive: ColorSchema,
|
|
115
|
-
primary: ColorSchema,
|
|
116
|
-
muted: ColorSchema,
|
|
117
|
-
accent: ColorSchema,
|
|
118
|
-
success: ColorSchema,
|
|
119
|
-
warning: ColorSchema,
|
|
120
|
-
danger: ColorSchema
|
|
121
|
-
}).strict();
|
|
122
|
-
var terminalPalettes2 = Object.freeze({
|
|
123
|
-
dark: Object.freeze({
|
|
124
|
-
canvas: "#111111",
|
|
125
|
-
panel: "#1e2129",
|
|
126
|
-
panelRaised: "#303441",
|
|
127
|
-
border: "#454a57",
|
|
128
|
-
borderActive: "#d9dde7",
|
|
129
|
-
primary: "#e6ebf5",
|
|
130
|
-
muted: "#828aa0",
|
|
131
|
-
accent: "#e58a66",
|
|
132
|
-
success: "#64df98",
|
|
133
|
-
warning: "#ffd04f",
|
|
134
|
-
danger: "#ff6b78"
|
|
135
|
-
}),
|
|
136
|
-
light: Object.freeze({
|
|
137
|
-
canvas: "#fafafa",
|
|
138
|
-
panel: "#eef0f4",
|
|
139
|
-
panelRaised: "#dfe3ea",
|
|
140
|
-
border: "#b4bac6",
|
|
141
|
-
borderActive: "#2b303b",
|
|
142
|
-
primary: "#1d2129",
|
|
143
|
-
muted: "#646b7a",
|
|
144
|
-
accent: "#b5502b",
|
|
145
|
-
success: "#1a7f45",
|
|
146
|
-
warning: "#946200",
|
|
147
|
-
danger: "#c4283a"
|
|
148
|
-
})
|
|
149
|
-
});
|
|
150
|
-
function resolveTerminalPalette2(mode, overrides = {}) {
|
|
151
|
-
return TerminalPaletteSchema2.parse({
|
|
152
|
-
...terminalPalettes2[TerminalThemeModeSchema2.parse(mode)],
|
|
153
|
-
...overrides
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// src/core/chart.ts
|
|
158
|
-
var SampleSchema = z2.object({
|
|
159
|
-
at: z2.number(),
|
|
160
|
-
value: z2.number().nullable()
|
|
106
|
+
var SampleSchema = z.object({
|
|
107
|
+
at: z.number(),
|
|
108
|
+
value: z.number().nullable()
|
|
161
109
|
}).strict();
|
|
162
|
-
var TimeSeriesOptionsSchema =
|
|
163
|
-
windowMs:
|
|
164
|
-
maxSamples:
|
|
110
|
+
var TimeSeriesOptionsSchema = z.object({
|
|
111
|
+
windowMs: z.int().positive(),
|
|
112
|
+
maxSamples: z.int().min(2).default(4096)
|
|
165
113
|
}).strict();
|
|
166
114
|
function createTerminalTimeSeries2(options) {
|
|
167
115
|
return { ...TimeSeriesOptionsSchema.parse(options), samples: [] };
|
|
@@ -180,7 +128,7 @@ function appendTerminalSample2(series, sample) {
|
|
|
180
128
|
return { ...series, samples: [...series.samples.slice(first), next] };
|
|
181
129
|
}
|
|
182
130
|
function sampleTerminalTimeSeries2(series, input) {
|
|
183
|
-
const count =
|
|
131
|
+
const count = z.int().nonnegative().parse(input.count);
|
|
184
132
|
const values = [];
|
|
185
133
|
let cursor = -1;
|
|
186
134
|
for (let index = 0;index < count; index += 1) {
|
|
@@ -214,16 +162,16 @@ var DOT_BITS = [
|
|
|
214
162
|
[4, 32],
|
|
215
163
|
[64, 128]
|
|
216
164
|
];
|
|
217
|
-
var ChartInputSchema =
|
|
218
|
-
series:
|
|
219
|
-
values:
|
|
165
|
+
var ChartInputSchema = z.object({
|
|
166
|
+
series: z.array(z.object({
|
|
167
|
+
values: z.array(z.number().nullable()),
|
|
220
168
|
tone: TerminalToneSchema2
|
|
221
169
|
}).strict()),
|
|
222
|
-
width:
|
|
223
|
-
height:
|
|
224
|
-
min:
|
|
225
|
-
max:
|
|
226
|
-
fill:
|
|
170
|
+
width: z.int().positive(),
|
|
171
|
+
height: z.int().positive(),
|
|
172
|
+
min: z.number().optional(),
|
|
173
|
+
max: z.number().optional(),
|
|
174
|
+
fill: z.boolean().default(false)
|
|
227
175
|
}).strict();
|
|
228
176
|
function terminalBrailleChart2(input) {
|
|
229
177
|
const { series, width, height, fill, ...fixed } = ChartInputSchema.parse(input);
|
|
@@ -283,8 +231,8 @@ function durationLabel(ms) {
|
|
|
283
231
|
return `${seconds}s`;
|
|
284
232
|
}
|
|
285
233
|
function terminalTimeAxis2(windowMs, width) {
|
|
286
|
-
const cells =
|
|
287
|
-
const left = `-${durationLabel(
|
|
234
|
+
const cells = z.int().nonnegative().parse(width);
|
|
235
|
+
const left = `-${durationLabel(z.int().positive().parse(windowMs))}`;
|
|
288
236
|
const right = "now";
|
|
289
237
|
if (cells < left.length + right.length + 1)
|
|
290
238
|
return right.padStart(cells).slice(0, cells);
|
|
@@ -297,12 +245,12 @@ function terminalTimeAxis2(windowMs, width) {
|
|
|
297
245
|
}
|
|
298
246
|
|
|
299
247
|
// src/core/collection.ts
|
|
300
|
-
import { z as
|
|
301
|
-
var TerminalCollectionStateSchema2 =
|
|
302
|
-
keys:
|
|
303
|
-
selectedKey:
|
|
304
|
-
start:
|
|
305
|
-
capacity:
|
|
248
|
+
import { z as z2 } from "zod";
|
|
249
|
+
var TerminalCollectionStateSchema2 = z2.object({
|
|
250
|
+
keys: z2.array(z2.string().min(1)),
|
|
251
|
+
selectedKey: z2.string().min(1).nullable(),
|
|
252
|
+
start: z2.int().nonnegative(),
|
|
253
|
+
capacity: z2.int().positive()
|
|
306
254
|
}).strict();
|
|
307
255
|
function maximumStart(total, capacity) {
|
|
308
256
|
return Math.max(0, total - capacity);
|
|
@@ -316,7 +264,7 @@ function reveal(start, capacity, index, total) {
|
|
|
316
264
|
return bounded;
|
|
317
265
|
}
|
|
318
266
|
function uniqueKeys(keys) {
|
|
319
|
-
const result =
|
|
267
|
+
const result = z2.array(z2.string().min(1)).parse(keys);
|
|
320
268
|
if (new Set(result).size !== result.length) {
|
|
321
269
|
throw new Error("Terminal collection keys must be unique");
|
|
322
270
|
}
|
|
@@ -324,7 +272,7 @@ function uniqueKeys(keys) {
|
|
|
324
272
|
}
|
|
325
273
|
function createTerminalCollection2(keys, capacity, selectedKey) {
|
|
326
274
|
const parsedKeys = uniqueKeys(keys);
|
|
327
|
-
const parsedCapacity =
|
|
275
|
+
const parsedCapacity = z2.int().positive().parse(capacity);
|
|
328
276
|
const selected = selectedKey !== undefined && parsedKeys.includes(selectedKey) ? selectedKey : parsedKeys[0] ?? null;
|
|
329
277
|
const index = selected === null ? -1 : parsedKeys.indexOf(selected);
|
|
330
278
|
return TerminalCollectionStateSchema2.parse({
|
|
@@ -353,7 +301,7 @@ function reduceTerminalCollection2(state, action) {
|
|
|
353
301
|
};
|
|
354
302
|
}
|
|
355
303
|
if (action.type === "resize") {
|
|
356
|
-
const capacity =
|
|
304
|
+
const capacity = z2.int().positive().parse(action.capacity);
|
|
357
305
|
const index = current.selectedKey === null ? -1 : current.keys.indexOf(current.selectedKey);
|
|
358
306
|
return {
|
|
359
307
|
...current,
|
|
@@ -364,7 +312,7 @@ function reduceTerminalCollection2(state, action) {
|
|
|
364
312
|
if (action.type === "scroll") {
|
|
365
313
|
return {
|
|
366
314
|
...current,
|
|
367
|
-
start: Math.min(Math.max(0, current.start +
|
|
315
|
+
start: Math.min(Math.max(0, current.start + z2.int().parse(action.lines)), maximumStart(current.keys.length, current.capacity))
|
|
368
316
|
};
|
|
369
317
|
}
|
|
370
318
|
if (current.keys.length === 0)
|
|
@@ -390,357 +338,6 @@ function visibleTerminalCollectionRange2(state) {
|
|
|
390
338
|
};
|
|
391
339
|
}
|
|
392
340
|
|
|
393
|
-
// src/core/form.ts
|
|
394
|
-
import { z as z4 } from "zod";
|
|
395
|
-
|
|
396
|
-
// src/core/text.ts
|
|
397
|
-
var STRING_SEQUENCE = /(?:\u001b[\]PX^_]|[\u0090\u0098\u009d\u009e\u009f])[\s\S]*?(?:\u0007|\u001b\\|\u009c|$)/g;
|
|
398
|
-
var CSI = /(?:\u001b\[|\u009b)[0-?]*[ -/]*[@-~]?/g;
|
|
399
|
-
var ESCAPE = /\u001b[ -/]*[0-~]?/g;
|
|
400
|
-
var CONTROL = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g;
|
|
401
|
-
function sanitizeTerminalText2(text, tabWidth = 2) {
|
|
402
|
-
return text.replace(STRING_SEQUENCE, "").replace(CSI, "").replace(ESCAPE, "").replace(/\r\n?/g, `
|
|
403
|
-
`).replace(/\t/g, " ".repeat(tabWidth)).replace(CONTROL, "");
|
|
404
|
-
}
|
|
405
|
-
var WIDE = [
|
|
406
|
-
[4352, 4447],
|
|
407
|
-
[11904, 12350],
|
|
408
|
-
[12353, 13311],
|
|
409
|
-
[13312, 19903],
|
|
410
|
-
[19968, 40959],
|
|
411
|
-
[40960, 42191],
|
|
412
|
-
[44032, 55203],
|
|
413
|
-
[63744, 64255],
|
|
414
|
-
[65072, 65103],
|
|
415
|
-
[65280, 65376],
|
|
416
|
-
[65504, 65510],
|
|
417
|
-
[127744, 128591],
|
|
418
|
-
[129280, 129535],
|
|
419
|
-
[131072, 262141]
|
|
420
|
-
];
|
|
421
|
-
var segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
422
|
-
function terminalGraphemes2(text) {
|
|
423
|
-
return Array.from(segmenter.segment(text), ({ segment }) => segment);
|
|
424
|
-
}
|
|
425
|
-
function terminalGraphemeWidth2(grapheme) {
|
|
426
|
-
if (/^[\p{M}\p{Cf}]+$/u.test(grapheme))
|
|
427
|
-
return 0;
|
|
428
|
-
if (/\p{Emoji_Presentation}/u.test(grapheme) || grapheme.includes("\uFE0F") && /\p{Extended_Pictographic}/u.test(grapheme))
|
|
429
|
-
return 2;
|
|
430
|
-
const code = grapheme.codePointAt(0) ?? 0;
|
|
431
|
-
for (const [start, end] of WIDE)
|
|
432
|
-
if (code >= start && code <= end)
|
|
433
|
-
return 2;
|
|
434
|
-
return 1;
|
|
435
|
-
}
|
|
436
|
-
function terminalTextWidth2(text) {
|
|
437
|
-
let width = 0;
|
|
438
|
-
for (const grapheme of terminalGraphemes2(text))
|
|
439
|
-
width += terminalGraphemeWidth2(grapheme);
|
|
440
|
-
return width;
|
|
441
|
-
}
|
|
442
|
-
function truncateTerminalText2(text, width) {
|
|
443
|
-
if (width <= 0)
|
|
444
|
-
return "";
|
|
445
|
-
if (terminalTextWidth2(text) <= width)
|
|
446
|
-
return text;
|
|
447
|
-
let used = 0;
|
|
448
|
-
let result = "";
|
|
449
|
-
for (const grapheme of terminalGraphemes2(text)) {
|
|
450
|
-
const cells = terminalGraphemeWidth2(grapheme);
|
|
451
|
-
if (used + cells > width - 1)
|
|
452
|
-
break;
|
|
453
|
-
result += grapheme;
|
|
454
|
-
used += cells;
|
|
455
|
-
}
|
|
456
|
-
return `${result}\u2026`;
|
|
457
|
-
}
|
|
458
|
-
function fitTerminalText2(text, width, align = "left") {
|
|
459
|
-
const cut = truncateTerminalText2(text, width);
|
|
460
|
-
const pad = Math.max(0, width - terminalTextWidth2(cut));
|
|
461
|
-
if (align === "right")
|
|
462
|
-
return " ".repeat(pad) + cut;
|
|
463
|
-
if (align === "center") {
|
|
464
|
-
const before = Math.floor(pad / 2);
|
|
465
|
-
return " ".repeat(before) + cut + " ".repeat(pad - before);
|
|
466
|
-
}
|
|
467
|
-
return cut + " ".repeat(pad);
|
|
468
|
-
}
|
|
469
|
-
function wrapTerminalText2(text, width) {
|
|
470
|
-
if (width <= 0)
|
|
471
|
-
return [];
|
|
472
|
-
const lines = [];
|
|
473
|
-
for (const paragraph of text.split(`
|
|
474
|
-
`)) {
|
|
475
|
-
const indent = /^ */.exec(paragraph)?.[0] ?? "";
|
|
476
|
-
const words = paragraph.slice(indent.length).split(/ +/).filter(Boolean);
|
|
477
|
-
if (words.length === 0) {
|
|
478
|
-
lines.push("");
|
|
479
|
-
continue;
|
|
480
|
-
}
|
|
481
|
-
const first = indent.length < width ? indent : "";
|
|
482
|
-
const hang = indent.length < width / 2 ? indent : "";
|
|
483
|
-
let line = first;
|
|
484
|
-
let start = first.length;
|
|
485
|
-
let used = start;
|
|
486
|
-
const flush = () => {
|
|
487
|
-
lines.push(line.trimEnd());
|
|
488
|
-
line = hang;
|
|
489
|
-
start = hang.length;
|
|
490
|
-
used = start;
|
|
491
|
-
};
|
|
492
|
-
for (const word of words) {
|
|
493
|
-
const cells = terminalTextWidth2(word);
|
|
494
|
-
const separator = used > start ? 1 : 0;
|
|
495
|
-
if (used + separator + cells <= width) {
|
|
496
|
-
line += (separator ? " " : "") + word;
|
|
497
|
-
used += separator + cells;
|
|
498
|
-
continue;
|
|
499
|
-
}
|
|
500
|
-
if (used > start)
|
|
501
|
-
flush();
|
|
502
|
-
if (cells <= width - used) {
|
|
503
|
-
line += word;
|
|
504
|
-
used += cells;
|
|
505
|
-
continue;
|
|
506
|
-
}
|
|
507
|
-
for (const grapheme of terminalGraphemes2(word)) {
|
|
508
|
-
const graphemeCells = terminalGraphemeWidth2(grapheme);
|
|
509
|
-
if (used + graphemeCells > width && used > start)
|
|
510
|
-
flush();
|
|
511
|
-
line += grapheme;
|
|
512
|
-
used += graphemeCells;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
lines.push(line.trimEnd());
|
|
516
|
-
}
|
|
517
|
-
return lines;
|
|
518
|
-
}
|
|
519
|
-
function terminalTextEdit2(key) {
|
|
520
|
-
if (key.name === "escape")
|
|
521
|
-
return { kind: "clear" };
|
|
522
|
-
if (key.name === "return" || key.name === "enter")
|
|
523
|
-
return { kind: "commit" };
|
|
524
|
-
if (key.name === "backspace")
|
|
525
|
-
return { kind: "erase" };
|
|
526
|
-
const text = key.sequence ?? "";
|
|
527
|
-
const control = Array.from(text).some((char) => {
|
|
528
|
-
const code = char.codePointAt(0) ?? 0;
|
|
529
|
-
return code < 32 || code === 127;
|
|
530
|
-
});
|
|
531
|
-
if (key.ctrl || key.meta || text.length === 0 || control)
|
|
532
|
-
return null;
|
|
533
|
-
return { kind: "insert", text };
|
|
534
|
-
}
|
|
535
|
-
function applyTerminalTextEdit2(text, edit) {
|
|
536
|
-
if (edit.kind === "insert")
|
|
537
|
-
return text + edit.text;
|
|
538
|
-
if (edit.kind === "erase")
|
|
539
|
-
return terminalGraphemes2(text).slice(0, -1).join("");
|
|
540
|
-
if (edit.kind === "clear")
|
|
541
|
-
return "";
|
|
542
|
-
return text;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
// src/core/form.ts
|
|
546
|
-
var TerminalFormFieldSchema2 = z4.object({
|
|
547
|
-
name: z4.string().min(1),
|
|
548
|
-
label: z4.string().min(1),
|
|
549
|
-
kind: z4.enum(["text", "secret", "number", "integer", "boolean", "choice", "json"]),
|
|
550
|
-
required: z4.boolean().default(false),
|
|
551
|
-
choices: z4.array(z4.union([z4.string(), z4.number(), z4.boolean()])).optional(),
|
|
552
|
-
defaultValue: z4.unknown().optional(),
|
|
553
|
-
description: z4.string().optional(),
|
|
554
|
-
placeholder: z4.string().optional()
|
|
555
|
-
}).strict().refine((field) => field.kind !== "choice" || (field.choices?.length ?? 0) > 0, {
|
|
556
|
-
message: "A choice field needs at least one choice"
|
|
557
|
-
});
|
|
558
|
-
var terminalFormMessages2 = {
|
|
559
|
-
required: "Required",
|
|
560
|
-
number: "Expected a number",
|
|
561
|
-
integer: "Expected a whole number",
|
|
562
|
-
choice: (choices) => `Choose one of: ${choices.join(", ")}`,
|
|
563
|
-
json: (reason) => `Invalid JSON: ${reason}`
|
|
564
|
-
};
|
|
565
|
-
function draftOf(field) {
|
|
566
|
-
const value = field.defaultValue;
|
|
567
|
-
if (value === undefined || value === null)
|
|
568
|
-
return "";
|
|
569
|
-
if (field.kind === "json")
|
|
570
|
-
return JSON.stringify(value);
|
|
571
|
-
return String(value);
|
|
572
|
-
}
|
|
573
|
-
function readField(field, draft, messages) {
|
|
574
|
-
const text = field.kind === "text" || field.kind === "secret" ? draft : draft.trim();
|
|
575
|
-
if (text === "")
|
|
576
|
-
return field.required ? { error: messages.required } : {};
|
|
577
|
-
switch (field.kind) {
|
|
578
|
-
case "text":
|
|
579
|
-
case "secret":
|
|
580
|
-
return { value: text };
|
|
581
|
-
case "number":
|
|
582
|
-
case "integer": {
|
|
583
|
-
if (!/^[+-]?\d+(\.\d+)?([eE][+-]?\d+)?$/.test(text))
|
|
584
|
-
return { error: messages.number };
|
|
585
|
-
const value = Number(text);
|
|
586
|
-
if (!Number.isFinite(value))
|
|
587
|
-
return { error: messages.number };
|
|
588
|
-
if (field.kind === "integer" && !Number.isInteger(value))
|
|
589
|
-
return { error: messages.integer };
|
|
590
|
-
return { value };
|
|
591
|
-
}
|
|
592
|
-
case "boolean":
|
|
593
|
-
return text === "true" || text === "false" ? { value: text === "true" } : { error: messages.choice(["true", "false"]) };
|
|
594
|
-
case "choice": {
|
|
595
|
-
const choice = field.choices?.find((candidate) => String(candidate) === text);
|
|
596
|
-
return choice === undefined ? { error: messages.choice((field.choices ?? []).map(String)) } : { value: choice };
|
|
597
|
-
}
|
|
598
|
-
case "json":
|
|
599
|
-
try {
|
|
600
|
-
return { value: JSON.parse(text) };
|
|
601
|
-
} catch (error) {
|
|
602
|
-
return {
|
|
603
|
-
error: messages.json(error instanceof Error ? error.message : String(error))
|
|
604
|
-
};
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
function createTerminalForm2(fields) {
|
|
609
|
-
const parsed = z4.array(TerminalFormFieldSchema2).parse(fields);
|
|
610
|
-
const names = new Set;
|
|
611
|
-
for (const field of parsed) {
|
|
612
|
-
if (names.has(field.name))
|
|
613
|
-
throw new Error(`Terminal form field ${field.name} is declared twice`);
|
|
614
|
-
names.add(field.name);
|
|
615
|
-
}
|
|
616
|
-
return {
|
|
617
|
-
fields: parsed,
|
|
618
|
-
drafts: Object.fromEntries(parsed.map((field) => [field.name, draftOf(field)])),
|
|
619
|
-
errors: {},
|
|
620
|
-
focus: 0,
|
|
621
|
-
submitted: false,
|
|
622
|
-
accepted: null
|
|
623
|
-
};
|
|
624
|
-
}
|
|
625
|
-
function fieldNamed(state, name) {
|
|
626
|
-
const field = name === undefined ? state.fields[state.focus] : state.fields.find((f) => f.name === name);
|
|
627
|
-
if (!field)
|
|
628
|
-
throw new Error(`Unknown terminal form field: ${name ?? `#${state.focus}`}`);
|
|
629
|
-
return field;
|
|
630
|
-
}
|
|
631
|
-
function readTerminalForm2(state, messages = terminalFormMessages2) {
|
|
632
|
-
const values = {};
|
|
633
|
-
const errors = {};
|
|
634
|
-
for (const field of state.fields) {
|
|
635
|
-
const read = readField(field, state.drafts[field.name] ?? "", messages);
|
|
636
|
-
if (read.error !== undefined)
|
|
637
|
-
errors[field.name] = read.error;
|
|
638
|
-
else if ("value" in read)
|
|
639
|
-
values[field.name] = read.value;
|
|
640
|
-
}
|
|
641
|
-
return Object.keys(errors).length > 0 ? { ok: false, errors } : { ok: true, values };
|
|
642
|
-
}
|
|
643
|
-
function reduceTerminalForm2(state, action, messages = terminalFormMessages2) {
|
|
644
|
-
const validate = (next, name) => {
|
|
645
|
-
const field = fieldNamed(next, name);
|
|
646
|
-
const read = readField(field, next.drafts[name] ?? "", messages);
|
|
647
|
-
const errors = { ...next.errors };
|
|
648
|
-
if (read.error !== undefined)
|
|
649
|
-
errors[name] = read.error;
|
|
650
|
-
else
|
|
651
|
-
delete errors[name];
|
|
652
|
-
return { ...next, errors };
|
|
653
|
-
};
|
|
654
|
-
switch (action.type) {
|
|
655
|
-
case "focus":
|
|
656
|
-
case "move": {
|
|
657
|
-
if (state.fields.length === 0)
|
|
658
|
-
return state;
|
|
659
|
-
const target = action.type === "focus" ? state.fields.findIndex(({ name }) => name === action.name) : Math.min(Math.max(0, state.focus + action.delta), state.fields.length - 1);
|
|
660
|
-
if (target < 0)
|
|
661
|
-
throw new Error(`Unknown terminal form field: ${action.type === "focus" ? action.name : ""}`);
|
|
662
|
-
const left = state.fields[state.focus];
|
|
663
|
-
const checked = left && target !== state.focus ? validate(state, left.name) : state;
|
|
664
|
-
return { ...checked, focus: target };
|
|
665
|
-
}
|
|
666
|
-
case "set":
|
|
667
|
-
case "edit": {
|
|
668
|
-
const field = fieldNamed(state, action.name);
|
|
669
|
-
const text = action.type === "set" ? action.text : applyTerminalTextEdit2(state.drafts[field.name] ?? "", action.edit);
|
|
670
|
-
const next = { ...state, drafts: { ...state.drafts, [field.name]: text } };
|
|
671
|
-
return state.errors[field.name] !== undefined || state.submitted ? validate(next, field.name) : next;
|
|
672
|
-
}
|
|
673
|
-
case "cycle": {
|
|
674
|
-
const field = fieldNamed(state, action.name);
|
|
675
|
-
const options = field.kind === "boolean" ? ["true", "false"] : field.kind === "choice" ? (field.choices ?? []).map(String) : null;
|
|
676
|
-
if (options === null)
|
|
677
|
-
return state;
|
|
678
|
-
const all = field.required ? options : ["", ...options];
|
|
679
|
-
const index = all.indexOf(state.drafts[field.name] ?? "");
|
|
680
|
-
const next = all[((index + action.delta) % all.length + all.length) % all.length] ?? "";
|
|
681
|
-
return validate({ ...state, drafts: { ...state.drafts, [field.name]: next } }, field.name);
|
|
682
|
-
}
|
|
683
|
-
case "clear": {
|
|
684
|
-
const field = fieldNamed(state, action.name);
|
|
685
|
-
const next = { ...state, drafts: { ...state.drafts, [field.name]: "" } };
|
|
686
|
-
return state.errors[field.name] !== undefined || state.submitted ? validate(next, field.name) : next;
|
|
687
|
-
}
|
|
688
|
-
case "submit": {
|
|
689
|
-
const result = readTerminalForm2(state, messages);
|
|
690
|
-
if (result.ok) {
|
|
691
|
-
const serial = (state.accepted?.serial ?? 0) + 1;
|
|
692
|
-
return {
|
|
693
|
-
...state,
|
|
694
|
-
errors: {},
|
|
695
|
-
submitted: true,
|
|
696
|
-
accepted: { serial, values: result.values }
|
|
697
|
-
};
|
|
698
|
-
}
|
|
699
|
-
const first = state.fields.findIndex(({ name }) => result.errors[name] !== undefined);
|
|
700
|
-
return {
|
|
701
|
-
...state,
|
|
702
|
-
errors: result.errors,
|
|
703
|
-
submitted: true,
|
|
704
|
-
focus: first < 0 ? state.focus : first
|
|
705
|
-
};
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
var JsonSchemaPropertySchema = z4.object({
|
|
710
|
-
type: z4.union([z4.string(), z4.array(z4.string())]).optional(),
|
|
711
|
-
enum: z4.array(z4.unknown()).optional(),
|
|
712
|
-
title: z4.string().optional(),
|
|
713
|
-
description: z4.string().optional(),
|
|
714
|
-
default: z4.unknown().optional(),
|
|
715
|
-
format: z4.string().optional(),
|
|
716
|
-
writeOnly: z4.boolean().optional()
|
|
717
|
-
}).loose();
|
|
718
|
-
var JsonSchemaObjectSchema = z4.object({
|
|
719
|
-
properties: z4.record(z4.string(), z4.unknown()).default({}),
|
|
720
|
-
required: z4.array(z4.string()).default([])
|
|
721
|
-
}).loose();
|
|
722
|
-
function terminalFormFieldsFromJsonSchema2(schema) {
|
|
723
|
-
const object = JsonSchemaObjectSchema.parse(schema);
|
|
724
|
-
return Object.entries(object.properties).map(([name, raw]) => {
|
|
725
|
-
const property = JsonSchemaPropertySchema.parse(typeof raw === "boolean" ? {} : raw ?? {});
|
|
726
|
-
const types = (Array.isArray(property.type) ? property.type : [property.type]).filter((type) => type !== undefined && type !== "null");
|
|
727
|
-
const type = types.length === 1 ? types[0] : undefined;
|
|
728
|
-
const listed = property.enum?.filter((value) => value !== null);
|
|
729
|
-
const scalars = listed?.filter((value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean");
|
|
730
|
-
const choices = scalars !== undefined && scalars.length > 0 && scalars.length === listed?.length ? scalars : undefined;
|
|
731
|
-
const kind = choices ? "choice" : type === "string" ? property.format === "password" || property.writeOnly ? "secret" : "text" : type === "number" ? "number" : type === "integer" ? "integer" : type === "boolean" ? "boolean" : "json";
|
|
732
|
-
return {
|
|
733
|
-
name,
|
|
734
|
-
label: property.title ?? name,
|
|
735
|
-
kind,
|
|
736
|
-
required: object.required.includes(name),
|
|
737
|
-
...choices && { choices },
|
|
738
|
-
...property.default !== undefined && { defaultValue: property.default },
|
|
739
|
-
...property.description !== undefined && { description: property.description }
|
|
740
|
-
};
|
|
741
|
-
});
|
|
742
|
-
}
|
|
743
|
-
|
|
744
341
|
// src/core/json.ts
|
|
745
342
|
function terminalJsonLines2(value, indent = 2) {
|
|
746
343
|
const lines = [];
|
|
@@ -806,20 +403,20 @@ function layoutTerminalDetails2(pairs, width, gap = 2) {
|
|
|
806
403
|
}
|
|
807
404
|
|
|
808
405
|
// src/core/key-hints.ts
|
|
809
|
-
import { z as
|
|
810
|
-
var TerminalKeyBindingSchema2 =
|
|
811
|
-
id:
|
|
812
|
-
keys:
|
|
813
|
-
display:
|
|
814
|
-
label:
|
|
815
|
-
short:
|
|
816
|
-
priority:
|
|
817
|
-
ctrl:
|
|
818
|
-
shift:
|
|
819
|
-
hidden:
|
|
406
|
+
import { z as z3 } from "zod";
|
|
407
|
+
var TerminalKeyBindingSchema2 = z3.object({
|
|
408
|
+
id: z3.string().min(1),
|
|
409
|
+
keys: z3.array(z3.string().min(1)).min(1),
|
|
410
|
+
display: z3.string().min(1),
|
|
411
|
+
label: z3.string().min(1),
|
|
412
|
+
short: z3.string().min(1).optional(),
|
|
413
|
+
priority: z3.int().nonnegative().default(1),
|
|
414
|
+
ctrl: z3.boolean().default(false),
|
|
415
|
+
shift: z3.boolean().optional(),
|
|
416
|
+
hidden: z3.boolean().default(false)
|
|
820
417
|
}).strict();
|
|
821
418
|
function defineTerminalKeymap2(bindings) {
|
|
822
|
-
const parsed =
|
|
419
|
+
const parsed = z3.array(TerminalKeyBindingSchema2).parse(bindings);
|
|
823
420
|
const ids = new Set;
|
|
824
421
|
const chords = new Map;
|
|
825
422
|
for (const binding of parsed) {
|
|
@@ -872,84 +469,6 @@ function fitTerminalKeyHints2(bindings, width, separator = " \xB7 ") {
|
|
|
872
469
|
}
|
|
873
470
|
}
|
|
874
471
|
|
|
875
|
-
// src/core/labels.ts
|
|
876
|
-
var terminalLabelsEn2 = Object.freeze({
|
|
877
|
-
form: terminalFormMessages2,
|
|
878
|
-
rows: (shown, total) => shown === total ? `${total} ${total === 1 ? "row" : "rows"}` : `${shown} of ${total} rows`,
|
|
879
|
-
filter: "filter",
|
|
880
|
-
nothingFound: "Nothing found",
|
|
881
|
-
moreAbove: (count) => `\u2191 ${count} more`,
|
|
882
|
-
moreBelow: (count) => `\u2193 ${count} more`,
|
|
883
|
-
loading: "Loading",
|
|
884
|
-
empty: "Nothing here yet",
|
|
885
|
-
error: "Failed",
|
|
886
|
-
retry: "retry",
|
|
887
|
-
yes: "Yes",
|
|
888
|
-
no: "No",
|
|
889
|
-
back: "back",
|
|
890
|
-
open: "open",
|
|
891
|
-
move: "move",
|
|
892
|
-
page: "page",
|
|
893
|
-
search: "search",
|
|
894
|
-
typing: "type",
|
|
895
|
-
submit: "submit",
|
|
896
|
-
next: "next field",
|
|
897
|
-
change: "change",
|
|
898
|
-
sort: "sort",
|
|
899
|
-
invert: "invert",
|
|
900
|
-
expand: "expand",
|
|
901
|
-
collapse: "collapse",
|
|
902
|
-
tabs: "views",
|
|
903
|
-
pick: "pick",
|
|
904
|
-
help: "help",
|
|
905
|
-
quit: "quit",
|
|
906
|
-
top: "top",
|
|
907
|
-
bottom: "bottom",
|
|
908
|
-
required: "required",
|
|
909
|
-
scroll: (percent) => `${percent}%`
|
|
910
|
-
});
|
|
911
|
-
var terminalLabelsRu2 = Object.freeze({
|
|
912
|
-
form: {
|
|
913
|
-
required: "\u041E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E\u0435 \u043F\u043E\u043B\u0435",
|
|
914
|
-
number: "\u041D\u0443\u0436\u043D\u043E \u0447\u0438\u0441\u043B\u043E",
|
|
915
|
-
integer: "\u041D\u0443\u0436\u043D\u043E \u0446\u0435\u043B\u043E\u0435 \u0447\u0438\u0441\u043B\u043E",
|
|
916
|
-
choice: (choices) => `\u0412\u044B\u0431\u0435\u0440\u0438\u0442\u0435 \u043E\u0434\u043D\u043E \u0438\u0437: ${choices.join(", ")}`,
|
|
917
|
-
json: (reason) => `\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 JSON: ${reason}`
|
|
918
|
-
},
|
|
919
|
-
rows: (shown, total) => shown === total ? `\u0441\u0442\u0440\u043E\u043A: ${total}` : `${shown} \u0438\u0437 ${total}`,
|
|
920
|
-
filter: "\u0444\u0438\u043B\u044C\u0442\u0440",
|
|
921
|
-
nothingFound: "\u041D\u0438\u0447\u0435\u0433\u043E \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u043E",
|
|
922
|
-
moreAbove: (count) => `\u2191 \u0435\u0449\u0451 ${count}`,
|
|
923
|
-
moreBelow: (count) => `\u2193 \u0435\u0449\u0451 ${count}`,
|
|
924
|
-
loading: "\u0417\u0430\u0433\u0440\u0443\u0437\u043A\u0430",
|
|
925
|
-
empty: "\u041F\u043E\u043A\u0430 \u043F\u0443\u0441\u0442\u043E",
|
|
926
|
-
error: "\u041E\u0448\u0438\u0431\u043A\u0430",
|
|
927
|
-
retry: "\u043F\u043E\u0432\u0442\u043E\u0440\u0438\u0442\u044C",
|
|
928
|
-
yes: "\u0414\u0430",
|
|
929
|
-
no: "\u041D\u0435\u0442",
|
|
930
|
-
back: "\u043D\u0430\u0437\u0430\u0434",
|
|
931
|
-
open: "\u043E\u0442\u043A\u0440\u044B\u0442\u044C",
|
|
932
|
-
move: "\u0432\u044B\u0431\u043E\u0440",
|
|
933
|
-
page: "\u0441\u0442\u0440\u0430\u043D\u0438\u0446\u0430",
|
|
934
|
-
search: "\u043F\u043E\u0438\u0441\u043A",
|
|
935
|
-
typing: "\u043F\u0435\u0447\u0430\u0442\u0430\u0439\u0442\u0435",
|
|
936
|
-
submit: "\u0432\u044B\u043F\u043E\u043B\u043D\u0438\u0442\u044C",
|
|
937
|
-
next: "\u0441\u043B\u0435\u0434\u0443\u044E\u0449\u0435\u0435 \u043F\u043E\u043B\u0435",
|
|
938
|
-
change: "\u0438\u0437\u043C\u0435\u043D\u0438\u0442\u044C",
|
|
939
|
-
sort: "\u0441\u043E\u0440\u0442\u0438\u0440\u043E\u0432\u043A\u0430",
|
|
940
|
-
invert: "\u043E\u0431\u0440\u0430\u0442\u043D\u044B\u0439 \u043F\u043E\u0440\u044F\u0434\u043E\u043A",
|
|
941
|
-
expand: "\u0440\u0430\u0441\u043A\u0440\u044B\u0442\u044C",
|
|
942
|
-
collapse: "\u0441\u0432\u0435\u0440\u043D\u0443\u0442\u044C",
|
|
943
|
-
tabs: "\u0432\u043A\u043B\u0430\u0434\u043A\u0438",
|
|
944
|
-
pick: "\u043E\u0442\u043C\u0435\u0442\u0438\u0442\u044C",
|
|
945
|
-
help: "\u0441\u043F\u0440\u0430\u0432\u043A\u0430",
|
|
946
|
-
quit: "\u0432\u044B\u0445\u043E\u0434",
|
|
947
|
-
top: "\u0432 \u043D\u0430\u0447\u0430\u043B\u043E",
|
|
948
|
-
bottom: "\u0432 \u043A\u043E\u043D\u0435\u0446",
|
|
949
|
-
required: "\u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E",
|
|
950
|
-
scroll: (percent) => `${percent}%`
|
|
951
|
-
});
|
|
952
|
-
|
|
953
472
|
// src/core/keys.ts
|
|
954
473
|
function terminalTableKeymap2(labels = terminalLabelsEn2) {
|
|
955
474
|
return defineTerminalKeymap2([
|
|
@@ -1089,20 +608,20 @@ function terminalTabsKey2(key, keymap = defaultTabsKeymap) {
|
|
|
1089
608
|
}
|
|
1090
609
|
|
|
1091
610
|
// src/core/list.ts
|
|
1092
|
-
import { z as
|
|
1093
|
-
var TerminalListItemSchema2 =
|
|
1094
|
-
key:
|
|
1095
|
-
title:
|
|
1096
|
-
meta:
|
|
1097
|
-
description:
|
|
1098
|
-
section:
|
|
1099
|
-
badge:
|
|
611
|
+
import { z as z4 } from "zod";
|
|
612
|
+
var TerminalListItemSchema2 = z4.object({
|
|
613
|
+
key: z4.string().min(1),
|
|
614
|
+
title: z4.string().min(1),
|
|
615
|
+
meta: z4.string().optional(),
|
|
616
|
+
description: z4.string().optional(),
|
|
617
|
+
section: z4.string().min(1).optional(),
|
|
618
|
+
badge: z4.union([z4.string(), z4.int()]).optional(),
|
|
1100
619
|
tone: TerminalToneSchema2.optional(),
|
|
1101
|
-
disabled:
|
|
1102
|
-
keywords:
|
|
620
|
+
disabled: z4.boolean().default(false),
|
|
621
|
+
keywords: z4.array(z4.string()).default([])
|
|
1103
622
|
}).strict();
|
|
1104
623
|
function parseItems(items) {
|
|
1105
|
-
const parsed =
|
|
624
|
+
const parsed = z4.array(TerminalListItemSchema2).parse(items);
|
|
1106
625
|
const keys = new Set;
|
|
1107
626
|
for (const item of parsed) {
|
|
1108
627
|
if (keys.has(item.key))
|
|
@@ -1205,7 +724,7 @@ function reduceTerminalList2(state, action) {
|
|
|
1205
724
|
}
|
|
1206
725
|
case "query":
|
|
1207
726
|
case "query-edit": {
|
|
1208
|
-
const query = action.type === "query" ?
|
|
727
|
+
const query = action.type === "query" ? z4.string().parse(action.query) : applyTerminalTextEdit2(state.query, action.edit);
|
|
1209
728
|
return query === state.query ? state : withLines({ ...base, query }, state.collection, true);
|
|
1210
729
|
}
|
|
1211
730
|
case "activate": {
|
|
@@ -1292,11 +811,11 @@ function visibleTerminalListLines2(state, height) {
|
|
|
1292
811
|
}
|
|
1293
812
|
|
|
1294
813
|
// src/core/meter.ts
|
|
1295
|
-
import { z as
|
|
814
|
+
import { z as z5 } from "zod";
|
|
1296
815
|
var EIGHTHS = ["", "\u258F", "\u258E", "\u258D", "\u258C", "\u258B", "\u258A", "\u2589"];
|
|
1297
816
|
var FULL = "\u2588";
|
|
1298
|
-
var TerminalMeterThresholdSchema2 =
|
|
1299
|
-
ratio:
|
|
817
|
+
var TerminalMeterThresholdSchema2 = z5.object({
|
|
818
|
+
ratio: z5.number().min(0).max(1),
|
|
1300
819
|
tone: TerminalToneSchema2
|
|
1301
820
|
}).strict();
|
|
1302
821
|
var defaultTerminalMeterThresholds2 = Object.freeze([
|
|
@@ -1304,11 +823,11 @@ var defaultTerminalMeterThresholds2 = Object.freeze([
|
|
|
1304
823
|
{ ratio: 0.6, tone: "warning" },
|
|
1305
824
|
{ ratio: 0.85, tone: "danger" }
|
|
1306
825
|
]);
|
|
1307
|
-
var MeterInputSchema =
|
|
1308
|
-
value:
|
|
1309
|
-
max:
|
|
1310
|
-
width:
|
|
1311
|
-
thresholds:
|
|
826
|
+
var MeterInputSchema = z5.object({
|
|
827
|
+
value: z5.number().nullable(),
|
|
828
|
+
max: z5.number().positive(),
|
|
829
|
+
width: z5.int().nonnegative(),
|
|
830
|
+
thresholds: z5.array(TerminalMeterThresholdSchema2).min(1).optional()
|
|
1312
831
|
}).strict();
|
|
1313
832
|
function toneFor(ratio, thresholds) {
|
|
1314
833
|
const sorted = [...thresholds].sort((a, b) => a.ratio - b.ratio);
|
|
@@ -1337,11 +856,11 @@ function terminalMeter2(input) {
|
|
|
1337
856
|
tone: toneFor(ratio, thresholds ?? defaultTerminalMeterThresholds2)
|
|
1338
857
|
};
|
|
1339
858
|
}
|
|
1340
|
-
var GridInputSchema =
|
|
1341
|
-
count:
|
|
1342
|
-
width:
|
|
1343
|
-
minMeterWidth:
|
|
1344
|
-
gap:
|
|
859
|
+
var GridInputSchema = z5.object({
|
|
860
|
+
count: z5.int().nonnegative(),
|
|
861
|
+
width: z5.int().positive(),
|
|
862
|
+
minMeterWidth: z5.int().positive(),
|
|
863
|
+
gap: z5.int().nonnegative().default(1)
|
|
1345
864
|
}).strict();
|
|
1346
865
|
function layoutTerminalMeterGrid2(input) {
|
|
1347
866
|
const { count, width, minMeterWidth, gap } = GridInputSchema.parse(input);
|
|
@@ -1356,8 +875,8 @@ function layoutTerminalMeterGrid2(input) {
|
|
|
1356
875
|
}
|
|
1357
876
|
|
|
1358
877
|
// src/core/progress.ts
|
|
1359
|
-
import { z as
|
|
1360
|
-
var TerminalSpinnerKindSchema2 =
|
|
878
|
+
import { z as z6 } from "zod";
|
|
879
|
+
var TerminalSpinnerKindSchema2 = z6.enum(["dots", "line", "pulse", "arc"]);
|
|
1361
880
|
var terminalSpinners2 = Object.freeze({
|
|
1362
881
|
dots: { intervalMs: 80, frames: ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"] },
|
|
1363
882
|
line: { intervalMs: 120, frames: ["-", "\\", "|", "/"] },
|
|
@@ -1381,11 +900,11 @@ function formatTerminalDuration2(ms) {
|
|
|
1381
900
|
return `${minutes}m ${String(seconds % 60).padStart(2, "0")}s`;
|
|
1382
901
|
return `${Math.floor(minutes / 60)}h ${String(minutes % 60).padStart(2, "0")}m`;
|
|
1383
902
|
}
|
|
1384
|
-
var ProgressInputSchema =
|
|
1385
|
-
done:
|
|
1386
|
-
total:
|
|
1387
|
-
startedAt:
|
|
1388
|
-
now:
|
|
903
|
+
var ProgressInputSchema = z6.object({
|
|
904
|
+
done: z6.number().nonnegative().nullable(),
|
|
905
|
+
total: z6.number().positive().nullable(),
|
|
906
|
+
startedAt: z6.number(),
|
|
907
|
+
now: z6.number()
|
|
1389
908
|
}).strict();
|
|
1390
909
|
function terminalProgress2(input) {
|
|
1391
910
|
const { done, total, startedAt, now } = ProgressInputSchema.parse(input);
|
|
@@ -1404,30 +923,35 @@ function terminalIndeterminateBlock2(width, elapsedMs, periodMs = 1600) {
|
|
|
1404
923
|
}
|
|
1405
924
|
|
|
1406
925
|
// src/core/table.ts
|
|
1407
|
-
import { z as
|
|
1408
|
-
var TerminalTableColumnSchema2 =
|
|
1409
|
-
id:
|
|
1410
|
-
title:
|
|
1411
|
-
kind:
|
|
1412
|
-
width:
|
|
1413
|
-
align:
|
|
1414
|
-
sortable:
|
|
1415
|
-
filterable:
|
|
926
|
+
import { z as z7 } from "zod";
|
|
927
|
+
var TerminalTableColumnSchema2 = z7.object({
|
|
928
|
+
id: z7.string().min(1),
|
|
929
|
+
title: z7.string(),
|
|
930
|
+
kind: z7.enum(["number", "text"]),
|
|
931
|
+
width: z7.union([z7.int().positive(), z7.object({ flex: z7.int().positive() }).strict()]),
|
|
932
|
+
align: z7.enum(["left", "right"]).optional(),
|
|
933
|
+
sortable: z7.boolean().default(true),
|
|
934
|
+
filterable: z7.boolean().optional()
|
|
1416
935
|
}).strict();
|
|
1417
|
-
var TerminalTableRowSchema2 =
|
|
1418
|
-
key:
|
|
1419
|
-
parentKey:
|
|
1420
|
-
cells:
|
|
936
|
+
var TerminalTableRowSchema2 = z7.object({
|
|
937
|
+
key: z7.string().min(1),
|
|
938
|
+
parentKey: z7.string().min(1).nullable().default(null),
|
|
939
|
+
cells: z7.record(z7.string(), z7.union([z7.string(), z7.number(), z7.null()])),
|
|
940
|
+
tone: TerminalToneSchema2.optional()
|
|
1421
941
|
}).strict();
|
|
1422
|
-
var TerminalTableSortSchema2 =
|
|
942
|
+
var TerminalTableSortSchema2 = z7.object({ columnId: z7.string().min(1), direction: z7.enum(["asc", "desc"]) }).strict();
|
|
1423
943
|
var collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
|
1424
944
|
function parseColumns(columns) {
|
|
1425
945
|
if (columns.length === 0)
|
|
1426
946
|
throw new Error("A terminal table needs at least one column");
|
|
1427
947
|
const parsed = columns.map((column) => {
|
|
1428
|
-
const { format, ...shape } = column;
|
|
948
|
+
const { format, tone, ...shape } = column;
|
|
1429
949
|
const value = TerminalTableColumnSchema2.parse(shape);
|
|
1430
|
-
return
|
|
950
|
+
return {
|
|
951
|
+
...value,
|
|
952
|
+
...format !== undefined && { format },
|
|
953
|
+
...tone !== undefined && { tone }
|
|
954
|
+
};
|
|
1431
955
|
});
|
|
1432
956
|
if (new Set(parsed.map(({ id }) => id)).size !== parsed.length) {
|
|
1433
957
|
throw new Error("Terminal table column ids must be unique");
|
|
@@ -1435,7 +959,7 @@ function parseColumns(columns) {
|
|
|
1435
959
|
return parsed;
|
|
1436
960
|
}
|
|
1437
961
|
function parseRows(columns, rows) {
|
|
1438
|
-
const parsed =
|
|
962
|
+
const parsed = z7.array(TerminalTableRowSchema2).parse(rows);
|
|
1439
963
|
const byKey = new Map;
|
|
1440
964
|
for (const row of parsed) {
|
|
1441
965
|
if (byKey.has(row.key))
|
|
@@ -1602,7 +1126,7 @@ function reduceTerminalTable2(state, action) {
|
|
|
1602
1126
|
if (sortable.length === 0)
|
|
1603
1127
|
return state;
|
|
1604
1128
|
const index = sortable.findIndex(({ id }) => id === base.sort?.columnId);
|
|
1605
|
-
const step =
|
|
1129
|
+
const step = z7.int().parse(action.delta);
|
|
1606
1130
|
const next = sortable[(((index < 0 ? step > 0 ? -1 : 0 : index) + step) % sortable.length + sortable.length) % sortable.length];
|
|
1607
1131
|
if (!next)
|
|
1608
1132
|
return state;
|
|
@@ -1649,7 +1173,7 @@ function reduceTerminalTable2(state, action) {
|
|
|
1649
1173
|
return withView({ ...base, expanded }, collection, open ? undefined : target.row.key);
|
|
1650
1174
|
}
|
|
1651
1175
|
case "filter":
|
|
1652
|
-
return withView({ ...base, filter:
|
|
1176
|
+
return withView({ ...base, filter: z7.string().parse(action.query) }, collection);
|
|
1653
1177
|
case "activate": {
|
|
1654
1178
|
const key = state.collection.selectedKey;
|
|
1655
1179
|
if (key === null)
|
|
@@ -1672,7 +1196,7 @@ function selectedTerminalTableRow2(state) {
|
|
|
1672
1196
|
return selectedRow(state)?.row ?? null;
|
|
1673
1197
|
}
|
|
1674
1198
|
function layoutTerminalTableColumns2(columns, width, gap = 1) {
|
|
1675
|
-
const total =
|
|
1199
|
+
const total = z7.int().nonnegative().parse(width);
|
|
1676
1200
|
let remaining = total;
|
|
1677
1201
|
const widths = columns.map((column, index) => {
|
|
1678
1202
|
if (typeof column.width !== "number")
|
|
@@ -1702,4 +1226,4 @@ function terminalTableTreePrefix2(row) {
|
|
|
1702
1226
|
return " ".repeat(row.depth) + mark;
|
|
1703
1227
|
}
|
|
1704
1228
|
|
|
1705
|
-
export { matchTerminalSearch2, searchTerminalItems2, terminalHighlightRuns2,
|
|
1229
|
+
export { matchTerminalSearch2, searchTerminalItems2, terminalHighlightRuns2, createTerminalTimeSeries2, appendTerminalSample2, sampleTerminalTimeSeries2, terminalChartScale2, terminalSparkline2, terminalBrailleChart2, terminalTimeAxis2, TerminalCollectionStateSchema2, createTerminalCollection2, reduceTerminalCollection2, visibleTerminalCollectionRange2, terminalJsonLines2, layoutTerminalDetails2, TerminalKeyBindingSchema2, defineTerminalKeymap2, matchTerminalKey2, fitTerminalKeyHints2, terminalTableKeymap2, terminalTableKey2, terminalTabsKeymap2, terminalTabsKey2, TerminalListItemSchema2, createTerminalList2, reduceTerminalList2, selectedTerminalListItem2, visibleTerminalListLines2, TerminalMeterThresholdSchema2, defaultTerminalMeterThresholds2, terminalMeter2, layoutTerminalMeterGrid2, TerminalSpinnerKindSchema2, terminalSpinners2, terminalSpinnerFrame2, formatTerminalDuration2, terminalProgress2, terminalIndeterminateBlock2, TerminalTableColumnSchema2, TerminalTableRowSchema2, TerminalTableSortSchema2, formatTerminalTableCell2, projectTerminalTable2, createTerminalTable2, reduceTerminalTable2, visibleTerminalTableRows2, selectedTerminalTableRow2, layoutTerminalTableColumns2, terminalTableTreePrefix2 };
|