stitchkit-tui 0.2.14 → 0.4.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 (109) hide show
  1. package/README.md +133 -4
  2. package/dist/App.d.ts +2 -2
  3. package/dist/App.d.ts.map +1 -1
  4. package/dist/app-2zw4ra7n.js +638 -0
  5. package/dist/build/index.d.ts +42 -0
  6. package/dist/build/index.d.ts.map +1 -0
  7. package/dist/build/index.js +174 -0
  8. package/dist/cli.js +11 -2195
  9. package/dist/config.d.ts +16 -16
  10. package/dist/config.d.ts.map +1 -1
  11. package/dist/core/chart.d.ts +82 -0
  12. package/dist/core/chart.d.ts.map +1 -0
  13. package/dist/core/collection.d.ts.map +1 -1
  14. package/dist/core/command-palette.d.ts.map +1 -1
  15. package/dist/core/focus.d.ts +33 -0
  16. package/dist/core/focus.d.ts.map +1 -0
  17. package/dist/core/form.d.ts +88 -0
  18. package/dist/core/form.d.ts.map +1 -0
  19. package/dist/core/index.d.ts +17 -0
  20. package/dist/core/index.d.ts.map +1 -1
  21. package/dist/core/index.js +228 -358
  22. package/dist/core/json.d.ts +24 -0
  23. package/dist/core/json.d.ts.map +1 -0
  24. package/dist/core/key-hints.d.ts +28 -0
  25. package/dist/core/key-hints.d.ts.map +1 -0
  26. package/dist/core/keys.d.ts +32 -0
  27. package/dist/core/keys.d.ts.map +1 -0
  28. package/dist/core/labels.d.ts +48 -0
  29. package/dist/core/labels.d.ts.map +1 -0
  30. package/dist/core/list.d.ts +112 -0
  31. package/dist/core/list.d.ts.map +1 -0
  32. package/dist/core/meter.d.ts +61 -0
  33. package/dist/core/meter.d.ts.map +1 -0
  34. package/dist/core/navigation.d.ts +33 -0
  35. package/dist/core/navigation.d.ts.map +1 -0
  36. package/dist/core/notices.d.ts +39 -0
  37. package/dist/core/notices.d.ts.map +1 -0
  38. package/dist/core/progress.d.ts +53 -0
  39. package/dist/core/progress.d.ts.map +1 -0
  40. package/dist/core/search.d.ts +36 -0
  41. package/dist/core/search.d.ts.map +1 -0
  42. package/dist/core/table.d.ts +143 -0
  43. package/dist/core/table.d.ts.map +1 -0
  44. package/dist/core/tabs.d.ts +37 -0
  45. package/dist/core/tabs.d.ts.map +1 -0
  46. package/dist/core/text.d.ts +36 -0
  47. package/dist/core/text.d.ts.map +1 -0
  48. package/dist/core/theme.d.ts +38 -0
  49. package/dist/core/theme.d.ts.map +1 -0
  50. package/dist/gallery/app.d.ts +12 -0
  51. package/dist/gallery/app.d.ts.map +1 -0
  52. package/dist/gallery/catalogue.d.ts +11 -0
  53. package/dist/gallery/catalogue.d.ts.map +1 -0
  54. package/dist/gallery/main.d.ts +3 -0
  55. package/dist/gallery/main.d.ts.map +1 -0
  56. package/dist/gallery/main.js +16 -0
  57. package/dist/gallery/monitor-page.d.ts +8 -0
  58. package/dist/gallery/monitor-page.d.ts.map +1 -0
  59. package/dist/gallery/widgets-page.d.ts +7 -0
  60. package/dist/gallery/widgets-page.d.ts.map +1 -0
  61. package/dist/index-1qacnvfd.js +336 -0
  62. package/dist/index-51qwgt9f.js +172 -0
  63. package/dist/index-ahfc59de.js +495 -0
  64. package/dist/index-djrp2fey.js +1229 -0
  65. package/dist/index-ecpc5qkb.js +245 -0
  66. package/dist/index-m0dhvt6x.js +160 -0
  67. package/dist/index-p6nn7fsx.js +1599 -0
  68. package/dist/index-qhj2ne64.js +106 -0
  69. package/dist/index-wcbe2tnk.js +1237 -0
  70. package/dist/index.js +80 -2219
  71. package/dist/run-zchyzhwy.js +18 -0
  72. package/dist/run.d.ts.map +1 -1
  73. package/dist/status-line.d.ts +2 -2
  74. package/dist/status-line.d.ts.map +1 -1
  75. package/dist/testing/index.d.ts +50 -0
  76. package/dist/testing/index.d.ts.map +1 -0
  77. package/dist/testing/index.js +110 -0
  78. package/dist/transcript.d.ts +2 -1
  79. package/dist/transcript.d.ts.map +1 -1
  80. package/dist/widgets/app.d.ts +77 -0
  81. package/dist/widgets/app.d.ts.map +1 -0
  82. package/dist/widgets/chart.d.ts +32 -0
  83. package/dist/widgets/chart.d.ts.map +1 -0
  84. package/dist/widgets/context.d.ts +29 -0
  85. package/dist/widgets/context.d.ts.map +1 -0
  86. package/dist/widgets/feedback.d.ts +65 -0
  87. package/dist/widgets/feedback.d.ts.map +1 -0
  88. package/dist/widgets/form.d.ts +23 -0
  89. package/dist/widgets/form.d.ts.map +1 -0
  90. package/dist/widgets/index.d.ts +14 -0
  91. package/dist/widgets/index.d.ts.map +1 -0
  92. package/dist/widgets/index.js +89 -0
  93. package/dist/widgets/keyboard.d.ts +28 -0
  94. package/dist/widgets/keyboard.d.ts.map +1 -0
  95. package/dist/widgets/layout.d.ts +51 -0
  96. package/dist/widgets/layout.d.ts.map +1 -0
  97. package/dist/widgets/list.d.ts +32 -0
  98. package/dist/widgets/list.d.ts.map +1 -0
  99. package/dist/widgets/meter.d.ts +26 -0
  100. package/dist/widgets/meter.d.ts.map +1 -0
  101. package/dist/widgets/table.d.ts +25 -0
  102. package/dist/widgets/table.d.ts.map +1 -0
  103. package/dist/widgets/tabs.d.ts +13 -0
  104. package/dist/widgets/tabs.d.ts.map +1 -0
  105. package/dist/widgets/text-view.d.ts +24 -0
  106. package/dist/widgets/text-view.d.ts.map +1 -0
  107. package/dist/widgets/theme.d.ts +23 -0
  108. package/dist/widgets/theme.d.ts.map +1 -0
  109. package/package.json +29 -8
@@ -0,0 +1,1237 @@
1
+ // @bun
2
+ import {
3
+ sanitizeTerminalText2,
4
+ terminalTextWidth2,
5
+ truncateTerminalText2,
6
+ fitTerminalText2,
7
+ wrapTerminalText2,
8
+ terminalTextEdit2
9
+ } from "./index-ahfc59de.js";
10
+ import {
11
+ terminalHighlightRuns2,
12
+ sampleTerminalTimeSeries2,
13
+ terminalSparkline2,
14
+ terminalBrailleChart2,
15
+ terminalTimeAxis2,
16
+ terminalJsonLines2,
17
+ layoutTerminalDetails2,
18
+ defineTerminalKeymap2,
19
+ matchTerminalKey2,
20
+ fitTerminalKeyHints2,
21
+ terminalTableKeymap2,
22
+ terminalTableKey2,
23
+ terminalTabsKeymap2,
24
+ terminalTabsKey2,
25
+ selectedTerminalListItem2,
26
+ visibleTerminalListLines2,
27
+ terminalMeter2,
28
+ layoutTerminalMeterGrid2,
29
+ terminalSpinners2,
30
+ terminalSpinnerFrame2,
31
+ formatTerminalDuration2,
32
+ terminalProgress2,
33
+ terminalIndeterminateBlock2,
34
+ formatTerminalTableCell2,
35
+ visibleTerminalTableRows2,
36
+ layoutTerminalTableColumns2,
37
+ terminalTableTreePrefix2
38
+ } from "./index-djrp2fey.js";
39
+ import {
40
+ useTerminalLabels2,
41
+ useTerminalFocused2,
42
+ TerminalKeyPriority2,
43
+ useTerminalKeyboard2,
44
+ terminalToneAttributes2,
45
+ useTerminalPalette2
46
+ } from "./index-m0dhvt6x.js";
47
+
48
+ // src/widgets/chart.tsx
49
+ import { jsx, jsxs } from "@opentui/react/jsx-runtime";
50
+ function TerminalChart2({
51
+ series,
52
+ now,
53
+ width,
54
+ height,
55
+ min,
56
+ max,
57
+ fill = false,
58
+ axis = true
59
+ }) {
60
+ const palette = useTerminalPalette2();
61
+ const rows = terminalBrailleChart2({
62
+ series: series.map(({ data, tone }) => ({
63
+ values: sampleTerminalTimeSeries2(data, { now, count: width * 2 }),
64
+ tone
65
+ })),
66
+ width,
67
+ height,
68
+ fill,
69
+ ...min !== undefined && { min },
70
+ ...max !== undefined && { max }
71
+ });
72
+ const windowMs = Math.max(1, ...series.map(({ data }) => data.windowMs));
73
+ return /* @__PURE__ */ jsxs("box", {
74
+ style: { flexDirection: "column", width, height: height + (axis ? 1 : 0) },
75
+ children: [
76
+ rows.map((segments, line) => /* @__PURE__ */ jsx("text", {
77
+ wrapMode: "none",
78
+ children: segments.map((segment, index) => /* @__PURE__ */ jsx("span", {
79
+ ...segment.tone && { fg: palette[segment.tone] },
80
+ children: segment.text
81
+ }, index))
82
+ }, line)),
83
+ axis ? /* @__PURE__ */ jsx("text", {
84
+ fg: palette.muted,
85
+ wrapMode: "none",
86
+ children: terminalTimeAxis2(windowMs, width)
87
+ }) : null
88
+ ]
89
+ });
90
+ }
91
+ function TerminalSparkline2({
92
+ data,
93
+ now,
94
+ width,
95
+ tone = "accent",
96
+ min,
97
+ max
98
+ }) {
99
+ const palette = useTerminalPalette2();
100
+ const values = sampleTerminalTimeSeries2(data, { now, count: width });
101
+ return /* @__PURE__ */ jsx("text", {
102
+ fg: palette[tone],
103
+ wrapMode: "none",
104
+ children: terminalSparkline2(values, {
105
+ ...min !== undefined && { min },
106
+ ...max !== undefined && { max }
107
+ })
108
+ });
109
+ }
110
+
111
+ // src/widgets/feedback.tsx
112
+ import { useEffect, useState } from "react";
113
+ import { jsx as jsx2, jsxs as jsxs2, Fragment } from "@opentui/react/jsx-runtime";
114
+ function useTerminalClock2(intervalMs, clock = Date.now) {
115
+ const [now, setNow] = useState(clock);
116
+ useEffect(() => {
117
+ const timer = setInterval(() => setNow(clock()), intervalMs);
118
+ return () => clearInterval(timer);
119
+ }, [intervalMs, clock]);
120
+ return now;
121
+ }
122
+ function TerminalSpinner2({
123
+ label,
124
+ startedAt,
125
+ kind = "dots",
126
+ tone = "accent",
127
+ clock
128
+ }) {
129
+ const palette = useTerminalPalette2();
130
+ const now = useTerminalClock2(terminalSpinners2[kind].intervalMs, clock);
131
+ const elapsed = now - startedAt;
132
+ return /* @__PURE__ */ jsxs2("text", {
133
+ wrapMode: "none",
134
+ children: [
135
+ /* @__PURE__ */ jsx2("span", {
136
+ fg: palette[tone],
137
+ children: `${terminalSpinnerFrame2(kind, elapsed)} `
138
+ }),
139
+ /* @__PURE__ */ jsx2("span", {
140
+ fg: palette.primary,
141
+ children: sanitizeTerminalText2(label)
142
+ }),
143
+ /* @__PURE__ */ jsx2("span", {
144
+ fg: palette.muted,
145
+ children: ` \xB7 ${formatTerminalDuration2(elapsed)}`
146
+ })
147
+ ]
148
+ });
149
+ }
150
+ function TerminalProgressBar2({
151
+ done,
152
+ total,
153
+ startedAt,
154
+ now,
155
+ width,
156
+ label,
157
+ unit = ""
158
+ }) {
159
+ const palette = useTerminalPalette2();
160
+ const progress = terminalProgress2({ done, total, startedAt, now });
161
+ const tail = progress.ratio === null ? ` ${formatTerminalDuration2(progress.elapsedMs)}` : ` ${Math.round(progress.ratio * 100)}%${progress.etaMs === null ? "" : ` \xB7 ${formatTerminalDuration2(progress.etaMs)}`}${progress.rate === null || unit === "" ? "" : ` \xB7 ${progress.rate.toFixed(1)} ${unit}/s`}`;
162
+ const head = label ? `${sanitizeTerminalText2(label)} ` : "";
163
+ const barWidth = Math.max(1, width - terminalTextWidth2(head) - terminalTextWidth2(tail));
164
+ if (progress.ratio === null) {
165
+ const [start, length] = terminalIndeterminateBlock2(barWidth, progress.elapsedMs);
166
+ return /* @__PURE__ */ jsxs2("text", {
167
+ wrapMode: "none",
168
+ children: [
169
+ /* @__PURE__ */ jsx2("span", {
170
+ fg: palette.primary,
171
+ children: head
172
+ }),
173
+ /* @__PURE__ */ jsx2("span", {
174
+ fg: palette.panelRaised,
175
+ children: "\u2501".repeat(start)
176
+ }),
177
+ /* @__PURE__ */ jsx2("span", {
178
+ fg: palette.accent,
179
+ children: "\u2501".repeat(length)
180
+ }),
181
+ /* @__PURE__ */ jsx2("span", {
182
+ fg: palette.panelRaised,
183
+ children: "\u2501".repeat(Math.max(0, barWidth - start - length))
184
+ }),
185
+ /* @__PURE__ */ jsx2("span", {
186
+ fg: palette.muted,
187
+ children: tail
188
+ })
189
+ ]
190
+ });
191
+ }
192
+ const bar = terminalMeter2({
193
+ value: progress.ratio,
194
+ max: 1,
195
+ width: barWidth,
196
+ thresholds: [
197
+ { ratio: 0, tone: "accent" },
198
+ { ratio: 1, tone: "success" }
199
+ ]
200
+ });
201
+ return /* @__PURE__ */ jsxs2("text", {
202
+ wrapMode: "none",
203
+ children: [
204
+ /* @__PURE__ */ jsx2("span", {
205
+ fg: palette.primary,
206
+ children: head
207
+ }),
208
+ /* @__PURE__ */ jsx2("span", {
209
+ fg: palette[bar.tone],
210
+ children: bar.filled
211
+ }),
212
+ /* @__PURE__ */ jsx2("span", {
213
+ fg: palette.panelRaised,
214
+ children: "\u2501".repeat(Math.max(0, barWidth - Array.from(bar.filled).length))
215
+ }),
216
+ /* @__PURE__ */ jsx2("span", {
217
+ fg: palette.muted,
218
+ children: tail
219
+ })
220
+ ]
221
+ });
222
+ }
223
+ function TerminalAsyncView2({
224
+ state,
225
+ width,
226
+ children,
227
+ clock
228
+ }) {
229
+ const palette = useTerminalPalette2();
230
+ const labels = useTerminalLabels2();
231
+ if (state.status === "loading") {
232
+ return /* @__PURE__ */ jsx2(TerminalSpinner2, {
233
+ label: state.label ?? labels.loading,
234
+ startedAt: state.startedAt,
235
+ ...clock && { clock }
236
+ });
237
+ }
238
+ if (state.status === "error") {
239
+ return /* @__PURE__ */ jsxs2("box", {
240
+ style: { flexDirection: "column" },
241
+ children: [
242
+ /* @__PURE__ */ jsx2("text", {
243
+ fg: palette.danger,
244
+ wrapMode: "none",
245
+ children: `\u2715 ${labels.error}`
246
+ }),
247
+ wrapTerminalText2(sanitizeTerminalText2(state.message), Math.max(1, width)).slice(0, 6).map((line, index) => /* @__PURE__ */ jsx2("text", {
248
+ fg: palette.primary,
249
+ wrapMode: "none",
250
+ children: line
251
+ }, index))
252
+ ]
253
+ });
254
+ }
255
+ if (state.status === "empty") {
256
+ return /* @__PURE__ */ jsx2("text", {
257
+ fg: palette.muted,
258
+ children: state.message ?? labels.empty
259
+ });
260
+ }
261
+ return /* @__PURE__ */ jsx2(Fragment, {
262
+ children: children(state.data)
263
+ });
264
+ }
265
+ function TerminalDetails2({
266
+ pairs,
267
+ width
268
+ }) {
269
+ const palette = useTerminalPalette2();
270
+ return /* @__PURE__ */ jsx2("box", {
271
+ style: { flexDirection: "column" },
272
+ children: layoutTerminalDetails2(pairs, width).map((pair, index) => /* @__PURE__ */ jsxs2("text", {
273
+ wrapMode: "none",
274
+ children: [
275
+ /* @__PURE__ */ jsx2("span", {
276
+ fg: palette.muted,
277
+ children: pair.key
278
+ }),
279
+ /* @__PURE__ */ jsx2("span", {
280
+ fg: palette[pair.tone],
281
+ children: pair.value
282
+ })
283
+ ]
284
+ }, index))
285
+ });
286
+ }
287
+ function TerminalDialog2({
288
+ title,
289
+ message,
290
+ tone = "warning",
291
+ confirmLabel,
292
+ cancelLabel,
293
+ onConfirm,
294
+ onCancel,
295
+ width = 56,
296
+ focusId,
297
+ focused
298
+ }) {
299
+ const palette = useTerminalPalette2();
300
+ const labels = useTerminalLabels2();
301
+ const active = useTerminalFocused2(focusId, focused);
302
+ const [choice, setChoice] = useState("cancel");
303
+ useTerminalKeyboard2((key) => {
304
+ if (key.name === "y")
305
+ onConfirm();
306
+ else if (key.name === "n" || key.name === "escape")
307
+ onCancel();
308
+ else if (key.name === "left" || key.name === "right" || key.name === "tab")
309
+ setChoice((current) => current === "confirm" ? "cancel" : "confirm");
310
+ else if (key.name === "return" || key.name === "enter")
311
+ (choice === "confirm" ? onConfirm : onCancel)();
312
+ return !(key.ctrl && key.name === "c");
313
+ }, { active, priority: TerminalKeyPriority2.layer });
314
+ const inner = Math.max(10, width - 4);
315
+ const button = (text, selected) => selected ? `[ ${text} ]` : ` ${text} `;
316
+ return /* @__PURE__ */ jsxs2("box", {
317
+ border: true,
318
+ borderStyle: "rounded",
319
+ borderColor: palette[tone],
320
+ title: ` ${truncateTerminalText2(sanitizeTerminalText2(title), inner - 2)} `,
321
+ titleColor: palette[tone],
322
+ backgroundColor: palette.panel,
323
+ style: { flexDirection: "column", width, paddingLeft: 1, paddingRight: 1 },
324
+ children: [
325
+ wrapTerminalText2(sanitizeTerminalText2(message), inner).slice(0, 8).map((line, index) => /* @__PURE__ */ jsx2("text", {
326
+ fg: palette.primary,
327
+ wrapMode: "none",
328
+ children: line
329
+ }, index)),
330
+ /* @__PURE__ */ jsxs2("text", {
331
+ wrapMode: "none",
332
+ children: [
333
+ /* @__PURE__ */ jsx2("span", {
334
+ fg: choice === "confirm" ? palette[tone] : palette.muted,
335
+ children: button(`${confirmLabel ?? labels.yes} (y)`, choice === "confirm")
336
+ }),
337
+ /* @__PURE__ */ jsx2("span", {
338
+ fg: choice === "cancel" ? palette.primary : palette.muted,
339
+ children: button(`${cancelLabel ?? labels.no} (n)`, choice === "cancel")
340
+ })
341
+ ]
342
+ })
343
+ ]
344
+ });
345
+ }
346
+ function TerminalHelp2({
347
+ groups,
348
+ width
349
+ }) {
350
+ const palette = useTerminalPalette2();
351
+ return /* @__PURE__ */ jsx2("box", {
352
+ style: { flexDirection: "column", width },
353
+ children: groups.map((group) => /* @__PURE__ */ jsxs2("box", {
354
+ style: { flexDirection: "column", marginBottom: 1 },
355
+ children: [
356
+ /* @__PURE__ */ jsx2("text", {
357
+ fg: palette.accent,
358
+ children: sanitizeTerminalText2(group.title)
359
+ }),
360
+ group.bindings.map((binding) => /* @__PURE__ */ jsxs2("text", {
361
+ wrapMode: "none",
362
+ children: [
363
+ /* @__PURE__ */ jsx2("span", {
364
+ fg: palette.primary,
365
+ children: ` ${binding.keys.join(" ").padEnd(16)}`
366
+ }),
367
+ /* @__PURE__ */ jsx2("span", {
368
+ fg: palette.muted,
369
+ children: truncateTerminalText2(sanitizeTerminalText2(binding.label), Math.max(1, width - 18))
370
+ })
371
+ ]
372
+ }, binding.id))
373
+ ]
374
+ }, group.title))
375
+ });
376
+ }
377
+
378
+ // src/widgets/form.tsx
379
+ import { useEffect as useEffect2, useRef } from "react";
380
+ import { jsx as jsx3, jsxs as jsxs3 } from "@opentui/react/jsx-runtime";
381
+ function terminalFormKeymap2(labels, cancel = true) {
382
+ return defineTerminalKeymap2([
383
+ {
384
+ id: "next",
385
+ keys: ["tab", "down"],
386
+ shift: false,
387
+ display: "Tab",
388
+ label: labels.next,
389
+ priority: 1
390
+ },
391
+ {
392
+ id: "previous",
393
+ keys: ["tab", "up"],
394
+ shift: true,
395
+ display: "\u21E7Tab",
396
+ label: labels.next,
397
+ hidden: true
398
+ },
399
+ {
400
+ id: "previous-arrow",
401
+ keys: ["up"],
402
+ shift: false,
403
+ display: "\u2191",
404
+ label: labels.next,
405
+ hidden: true
406
+ },
407
+ {
408
+ id: "change",
409
+ keys: ["left", "right", "space"],
410
+ display: "\u2190\u2192",
411
+ label: labels.change,
412
+ priority: 2
413
+ },
414
+ {
415
+ id: "submit",
416
+ keys: ["return", "enter"],
417
+ display: "Enter",
418
+ label: labels.submit,
419
+ priority: 0
420
+ },
421
+ ...cancel ? [{ id: "cancel", keys: ["escape"], display: "Esc", label: labels.back, priority: 0 }] : []
422
+ ]);
423
+ }
424
+ function TerminalForm2({
425
+ state,
426
+ onAction,
427
+ onSubmit,
428
+ onCancel,
429
+ width,
430
+ focusId,
431
+ focused,
432
+ keymap
433
+ }) {
434
+ const palette = useTerminalPalette2();
435
+ const labels = useTerminalLabels2();
436
+ const active = useTerminalFocused2(focusId, focused);
437
+ const bindings = keymap ?? terminalFormKeymap2(labels, onCancel !== undefined);
438
+ const current = state.fields[state.focus];
439
+ const cycles = current?.kind === "boolean" || current?.kind === "choice";
440
+ const delivered = useRef(state.accepted?.serial ?? 0);
441
+ useEffect2(() => {
442
+ const accepted = state.accepted;
443
+ if (!accepted || accepted.serial === delivered.current)
444
+ return;
445
+ delivered.current = accepted.serial;
446
+ onSubmit(accepted.values);
447
+ }, [state.accepted, onSubmit]);
448
+ useTerminalKeyboard2((key) => {
449
+ const id = matchTerminalKey2(bindings, key)?.id;
450
+ if (state.fields.length === 0) {
451
+ if (id === "submit")
452
+ onAction({ type: "submit" });
453
+ else if (id === "cancel" && onCancel)
454
+ onCancel();
455
+ else
456
+ return false;
457
+ return true;
458
+ }
459
+ if (id === "change" && cycles)
460
+ onAction({ type: "cycle", delta: key.name === "left" ? -1 : 1 });
461
+ else if (id === "next")
462
+ onAction({ type: "move", delta: 1 });
463
+ else if (id === "previous" || id === "previous-arrow")
464
+ onAction({ type: "move", delta: -1 });
465
+ else if (id === "cancel" && onCancel)
466
+ onCancel();
467
+ else if (id === "submit")
468
+ onAction({ type: "submit" });
469
+ else if (!cycles) {
470
+ const edit = terminalTextEdit2(key);
471
+ if (edit === null || edit.kind === "commit" || edit.kind === "clear")
472
+ return false;
473
+ onAction({ type: "edit", edit });
474
+ } else
475
+ return false;
476
+ return true;
477
+ }, { active, priority: TerminalKeyPriority2.input });
478
+ const labelWidth = Math.min(Math.max(4, ...state.fields.map(({ label, required }) => Array.from(label).length + (required ? 2 : 0) + 1)), Math.floor(width / 3));
479
+ if (state.fields.length === 0) {
480
+ return /* @__PURE__ */ jsx3("box", {
481
+ style: { flexDirection: "column", width },
482
+ children: /* @__PURE__ */ jsx3("text", {
483
+ fg: palette.muted,
484
+ wrapMode: "none",
485
+ children: truncateTerminalText2(labels.noFields, width)
486
+ })
487
+ });
488
+ }
489
+ return /* @__PURE__ */ jsx3("box", {
490
+ style: { flexDirection: "column", width },
491
+ children: state.fields.map((field, index) => {
492
+ const isFocused = index === state.focus && active;
493
+ const draft = state.drafts[field.name] ?? "";
494
+ const error = state.errors[field.name];
495
+ const shown = field.kind === "secret" ? "\u2022".repeat(Array.from(draft).length) : field.kind === "boolean" || field.kind === "choice" ? `\u2039 ${sanitizeTerminalText2(draft) || "\u2014"} \u203A` : sanitizeTerminalText2(draft);
496
+ const placeholder = draft === "" && field.kind !== "boolean" && field.kind !== "choice" ? field.placeholder ?? (field.required ? labels.required : "") : "";
497
+ const valueWidth = Math.max(1, width - labelWidth - 2);
498
+ const value = truncateTerminalText2(shown + (isFocused && field.kind !== "boolean" && field.kind !== "choice" ? "\u258F" : ""), valueWidth);
499
+ const description = isFocused && field.description ? wrapTerminalText2(sanitizeTerminalText2(field.description), Math.max(1, width - labelWidth - 2)).slice(0, 2) : [];
500
+ return /* @__PURE__ */ jsxs3("box", {
501
+ style: { flexDirection: "column" },
502
+ children: [
503
+ /* @__PURE__ */ jsxs3("text", {
504
+ wrapMode: "none",
505
+ ...isFocused && { bg: palette.panelRaised },
506
+ children: [
507
+ /* @__PURE__ */ jsx3("span", {
508
+ fg: isFocused ? palette.accent : palette.muted,
509
+ children: isFocused ? "\u203A " : " "
510
+ }),
511
+ /* @__PURE__ */ jsx3("span", {
512
+ fg: error ? palette.danger : isFocused ? palette.primary : palette.muted,
513
+ children: fitTerminalText2(`${sanitizeTerminalText2(field.label)}${field.required ? " *" : ""}`, labelWidth)
514
+ }),
515
+ /* @__PURE__ */ jsx3("span", {
516
+ fg: palette.primary,
517
+ children: value
518
+ }),
519
+ /* @__PURE__ */ jsx3("span", {
520
+ fg: palette.muted,
521
+ children: fitTerminalText2(placeholder, Math.max(0, valueWidth - Array.from(value).length))
522
+ })
523
+ ]
524
+ }),
525
+ description.map((line, offset) => /* @__PURE__ */ jsx3("text", {
526
+ fg: palette.muted,
527
+ wrapMode: "none",
528
+ children: " ".repeat(labelWidth + 2) + line
529
+ }, offset)),
530
+ error ? /* @__PURE__ */ jsx3("text", {
531
+ fg: palette.danger,
532
+ wrapMode: "none",
533
+ children: " ".repeat(labelWidth + 2) + truncateTerminalText2(error, Math.max(1, width - labelWidth - 2))
534
+ }) : null
535
+ ]
536
+ }, field.name);
537
+ })
538
+ });
539
+ }
540
+
541
+ // src/widgets/layout.tsx
542
+ import { jsx as jsx4, jsxs as jsxs4 } from "@opentui/react/jsx-runtime";
543
+ function TerminalPanel2({
544
+ title,
545
+ badge,
546
+ focused = false,
547
+ width,
548
+ height,
549
+ grow,
550
+ children
551
+ }) {
552
+ const palette = useTerminalPalette2();
553
+ const heading = title === undefined ? undefined : ` ${title}${badge === undefined ? "" : ` \xB7 ${badge}`} `;
554
+ return /* @__PURE__ */ jsx4("box", {
555
+ border: true,
556
+ borderStyle: "rounded",
557
+ borderColor: focused ? palette.borderActive : palette.border,
558
+ ...heading !== undefined && {
559
+ title: heading,
560
+ titleColor: focused ? palette.accent : palette.muted
561
+ },
562
+ style: {
563
+ flexDirection: "column",
564
+ paddingLeft: 1,
565
+ paddingRight: 1,
566
+ ...width !== undefined && { width },
567
+ ...height !== undefined && { height },
568
+ ...grow && { flexGrow: 1 }
569
+ },
570
+ children
571
+ });
572
+ }
573
+ function TerminalStatusBar2({
574
+ segments,
575
+ width,
576
+ separator = " \xB7 "
577
+ }) {
578
+ const palette = useTerminalPalette2();
579
+ let left = width;
580
+ const parts = [];
581
+ segments.forEach((segment, index) => {
582
+ if (left <= 0)
583
+ return;
584
+ const prefix = index === 0 ? "" : separator;
585
+ const text = truncateTerminalText2(prefix + sanitizeTerminalText2(segment.text), left);
586
+ left -= terminalTextWidth2(text);
587
+ parts.push({ text, tone: segment.tone ?? "muted" });
588
+ });
589
+ return /* @__PURE__ */ jsx4("text", {
590
+ wrapMode: "none",
591
+ children: parts.map((part, index) => /* @__PURE__ */ jsx4("span", {
592
+ fg: palette[part.tone],
593
+ children: part.text
594
+ }, index))
595
+ });
596
+ }
597
+ function TerminalKeyHints2({
598
+ bindings,
599
+ width
600
+ }) {
601
+ const palette = useTerminalPalette2();
602
+ return /* @__PURE__ */ jsx4("text", {
603
+ fg: palette.muted,
604
+ wrapMode: "none",
605
+ children: fitTerminalText2(fitTerminalKeyHints2(bindings, width), width)
606
+ });
607
+ }
608
+ function TerminalNotices2({
609
+ state,
610
+ width
611
+ }) {
612
+ const palette = useTerminalPalette2();
613
+ return /* @__PURE__ */ jsx4("box", {
614
+ style: { flexDirection: "column" },
615
+ children: state.notices.map((notice) => /* @__PURE__ */ jsx4("text", {
616
+ fg: palette[notice.tone],
617
+ bg: palette.panelRaised,
618
+ wrapMode: "none",
619
+ children: fitTerminalText2(` ${sanitizeTerminalText2(notice.text)} `, Math.min(width, 60))
620
+ }, notice.id))
621
+ });
622
+ }
623
+ function TerminalAppShell2({
624
+ breadcrumbs,
625
+ status = [],
626
+ bindings = [],
627
+ notices,
628
+ width,
629
+ height,
630
+ children
631
+ }) {
632
+ const palette = useTerminalPalette2();
633
+ const crumbs = breadcrumbs.map((crumb) => sanitizeTerminalText2(crumb));
634
+ const last = crumbs.length - 1;
635
+ return /* @__PURE__ */ jsxs4("box", {
636
+ style: { flexDirection: "column", width, height },
637
+ children: [
638
+ /* @__PURE__ */ jsx4("text", {
639
+ wrapMode: "none",
640
+ children: crumbs.map((crumb, index) => /* @__PURE__ */ jsx4("span", {
641
+ fg: index === last ? palette.accent : palette.muted,
642
+ children: `${index === 0 ? "" : " \u203A "}${crumb}`
643
+ }, index))
644
+ }),
645
+ status.map((segments, index) => /* @__PURE__ */ jsx4(TerminalStatusBar2, {
646
+ segments,
647
+ width
648
+ }, index)),
649
+ /* @__PURE__ */ jsx4("text", {
650
+ fg: palette.border,
651
+ wrapMode: "none",
652
+ children: "\u2500".repeat(Math.max(0, width))
653
+ }),
654
+ /* @__PURE__ */ jsx4("box", {
655
+ style: { flexDirection: "column", flexGrow: 1, flexShrink: 1, overflow: "hidden" },
656
+ children
657
+ }),
658
+ bindings.length > 0 ? /* @__PURE__ */ jsx4(TerminalKeyHints2, {
659
+ bindings,
660
+ width
661
+ }) : null,
662
+ notices && notices.notices.length > 0 ? /* @__PURE__ */ jsx4("box", {
663
+ style: { position: "absolute", top: 1, right: 1, zIndex: 10 },
664
+ children: /* @__PURE__ */ jsx4(TerminalNotices2, {
665
+ state: notices,
666
+ width
667
+ })
668
+ }) : null
669
+ ]
670
+ });
671
+ }
672
+
673
+ // src/widgets/list.tsx
674
+ import { useEffect as useEffect3, useRef as useRef2 } from "react";
675
+ import { jsx as jsx5, jsxs as jsxs5 } from "@opentui/react/jsx-runtime";
676
+ function terminalListKeymap2(labels, options = {}) {
677
+ return defineTerminalKeymap2([
678
+ { id: "up", keys: ["up"], display: "\u2191\u2193", label: labels.move, priority: 0 },
679
+ { id: "down", keys: ["down"], display: "\u2193", label: labels.move, hidden: true },
680
+ {
681
+ id: "activate",
682
+ keys: ["return", "enter"],
683
+ display: "Enter",
684
+ label: labels.open,
685
+ priority: 0
686
+ },
687
+ ...options.back ? [{ id: "back", keys: ["escape"], display: "Esc", label: labels.back, priority: 1 }] : [],
688
+ ...options.searchable ? [
689
+ {
690
+ id: "search",
691
+ keys: ["/"],
692
+ display: labels.typing,
693
+ label: labels.search,
694
+ priority: 2
695
+ }
696
+ ] : [],
697
+ ...options.multiple ? [{ id: "pick", keys: ["space"], display: "Space", label: labels.pick, priority: 1 }] : [],
698
+ { id: "page-up", keys: ["pageup"], display: "PgUp/PgDn", label: labels.page, priority: 3 },
699
+ { id: "page-down", keys: ["pagedown"], display: "PgDn", label: labels.page, hidden: true },
700
+ { id: "section-up", keys: ["["], display: "[ ]", label: labels.move, hidden: true },
701
+ { id: "section-down", keys: ["]"], display: "]", label: labels.move, hidden: true }
702
+ ]);
703
+ }
704
+ function TerminalList2({
705
+ state,
706
+ onAction,
707
+ onActivate,
708
+ onBack,
709
+ width,
710
+ height,
711
+ searchable = false,
712
+ descriptionLines = 2,
713
+ focusId,
714
+ focused,
715
+ keymap
716
+ }) {
717
+ const palette = useTerminalPalette2();
718
+ const labels = useTerminalLabels2();
719
+ const active = useTerminalFocused2(focusId, focused);
720
+ const bindings = keymap ?? terminalListKeymap2(labels, {
721
+ searchable,
722
+ multiple: state.multiple,
723
+ back: onBack !== undefined
724
+ });
725
+ const searchRows = searchable ? 2 : 0;
726
+ const listRows = Math.max(1, height - searchRows - descriptionLines - 2);
727
+ const delivered = useRef2(state.activation?.serial ?? 0);
728
+ useEffect3(() => {
729
+ const activation = state.activation;
730
+ if (!activation || activation.serial === delivered.current)
731
+ return;
732
+ delivered.current = activation.serial;
733
+ const item = state.items.find(({ key }) => key === activation.key);
734
+ if (item)
735
+ onActivate?.(item);
736
+ }, [state.activation, state.items, onActivate]);
737
+ useTerminalKeyboard2((key) => {
738
+ const id = matchTerminalKey2(bindings, key)?.id;
739
+ if (id === "up" || id === "down")
740
+ onAction({ type: "move", delta: id === "up" ? -1 : 1 });
741
+ else if (id === "page-up" || id === "page-down")
742
+ onAction({ type: "move", delta: (id === "page-up" ? -1 : 1) * listRows });
743
+ else if (id === "section-up" || id === "section-down")
744
+ onAction({ type: "section", delta: id === "section-up" ? -1 : 1 });
745
+ else if (id === "pick")
746
+ onAction({ type: "toggle" });
747
+ else if (id === "activate")
748
+ onAction({ type: "activate" });
749
+ else if (id === "back" && searchable && state.query !== "")
750
+ onAction({ type: "query", query: "" });
751
+ else if (id === "back" && onBack)
752
+ onBack();
753
+ else if (searchable) {
754
+ const edit = terminalTextEdit2(key);
755
+ if (edit === null || edit.kind === "commit" || edit.kind === "clear")
756
+ return false;
757
+ onAction({ type: "query-edit", edit });
758
+ } else
759
+ return false;
760
+ return true;
761
+ }, { active });
762
+ const { lines, above, below } = visibleTerminalListLines2(state, listRows);
763
+ const selected = selectedTerminalListItem2(state);
764
+ const description = wrapTerminalText2(sanitizeTerminalText2(selected?.description ?? ""), Math.max(1, width)).slice(0, descriptionLines);
765
+ const hasItems = state.lines.some((line) => line.kind === "item");
766
+ return /* @__PURE__ */ jsxs5("box", {
767
+ style: { flexDirection: "column", width, height },
768
+ children: [
769
+ searchable ? /* @__PURE__ */ jsxs5("text", {
770
+ wrapMode: "none",
771
+ children: [
772
+ /* @__PURE__ */ jsx5("span", {
773
+ fg: palette.accent,
774
+ children: "\u2315 "
775
+ }),
776
+ /* @__PURE__ */ jsx5("span", {
777
+ fg: state.query ? palette.primary : palette.muted,
778
+ children: fitTerminalText2(state.query || labels.search, Math.max(0, width - 2))
779
+ })
780
+ ]
781
+ }) : null,
782
+ searchable ? /* @__PURE__ */ jsx5("text", {
783
+ fg: palette.border,
784
+ children: "\u2500".repeat(width)
785
+ }) : null,
786
+ /* @__PURE__ */ jsx5("text", {
787
+ fg: palette.muted,
788
+ wrapMode: "none",
789
+ children: above > 0 ? labels.moreAbove(above) : " "
790
+ }),
791
+ /* @__PURE__ */ jsx5("box", {
792
+ style: { flexDirection: "column", height: listRows },
793
+ children: !hasItems ? /* @__PURE__ */ jsx5("text", {
794
+ fg: palette.muted,
795
+ children: labels.nothingFound
796
+ }) : lines.map((line, slot) => {
797
+ if (line.kind === "section") {
798
+ return /* @__PURE__ */ jsxs5("text", {
799
+ wrapMode: "none",
800
+ children: [
801
+ /* @__PURE__ */ jsx5("span", {
802
+ fg: palette.accent,
803
+ children: truncateTerminalText2(sanitizeTerminalText2(line.title), width - 6)
804
+ }),
805
+ /* @__PURE__ */ jsx5("span", {
806
+ fg: palette.muted,
807
+ children: ` ${line.count}`
808
+ })
809
+ ]
810
+ }, slot);
811
+ }
812
+ const item = line.item;
813
+ const isSelected = line.key === state.collection.selectedKey;
814
+ const mark = state.multiple ? state.picked.has(item.key) ? "\u25C9 " : "\u25CB " : "";
815
+ const badge = item.badge === undefined ? "" : ` ${sanitizeTerminalText2(String(item.badge))}`;
816
+ const meta = item.meta ? ` ${sanitizeTerminalText2(item.meta)}` : "";
817
+ const room = Math.max(1, width - 2 - terminalTextWidth2(mark) - terminalTextWidth2(badge));
818
+ const title = truncateTerminalText2(sanitizeTerminalText2(item.title), room);
819
+ const metaText = truncateTerminalText2(meta, Math.max(0, room - terminalTextWidth2(title)));
820
+ const pad = Math.max(0, room - terminalTextWidth2(title) - terminalTextWidth2(metaText));
821
+ const tone = item.disabled ? palette.muted : palette[item.tone ?? "primary"];
822
+ return /* @__PURE__ */ jsxs5("text", {
823
+ wrapMode: "none",
824
+ ...isSelected && active && { bg: palette.panelRaised },
825
+ children: [
826
+ /* @__PURE__ */ jsx5("span", {
827
+ fg: isSelected ? palette.accent : palette.muted,
828
+ children: isSelected ? "\u203A " : " "
829
+ }),
830
+ /* @__PURE__ */ jsx5("span", {
831
+ fg: palette.accent,
832
+ children: mark
833
+ }),
834
+ terminalHighlightRuns2(title, line.titleRanges).map((run, index) => /* @__PURE__ */ jsx5("span", {
835
+ fg: run.highlighted ? palette.accent : tone,
836
+ children: run.text
837
+ }, index)),
838
+ /* @__PURE__ */ jsx5("span", {
839
+ fg: palette.muted,
840
+ children: metaText + " ".repeat(pad)
841
+ }),
842
+ /* @__PURE__ */ jsx5("span", {
843
+ fg: palette.muted,
844
+ children: badge
845
+ })
846
+ ]
847
+ }, slot);
848
+ })
849
+ }),
850
+ /* @__PURE__ */ jsx5("text", {
851
+ fg: palette.muted,
852
+ wrapMode: "none",
853
+ children: below > 0 ? labels.moreBelow(below) : " "
854
+ }),
855
+ /* @__PURE__ */ jsx5("box", {
856
+ style: { flexDirection: "column", height: descriptionLines },
857
+ children: description.map((line, index) => /* @__PURE__ */ jsx5("text", {
858
+ fg: palette.muted,
859
+ wrapMode: "none",
860
+ children: line
861
+ }, index))
862
+ })
863
+ ]
864
+ });
865
+ }
866
+
867
+ // src/widgets/meter.tsx
868
+ import { jsx as jsx6, jsxs as jsxs6 } from "@opentui/react/jsx-runtime";
869
+ function TerminalMeter2({
870
+ label,
871
+ value,
872
+ max,
873
+ width,
874
+ labelWidth = Math.max(1, label.length),
875
+ text,
876
+ textWidth = 6,
877
+ thresholds
878
+ }) {
879
+ const palette = useTerminalPalette2();
880
+ const barWidth = Math.max(0, width - labelWidth - textWidth - 3);
881
+ const bar = terminalMeter2({
882
+ value,
883
+ max,
884
+ width: barWidth,
885
+ ...thresholds && { thresholds: [...thresholds] }
886
+ });
887
+ const reading = text ?? (bar.ratio === null || value === null ? "\u2014" : `${(value / max * 100).toFixed(1)}%`);
888
+ return /* @__PURE__ */ jsxs6("text", {
889
+ wrapMode: "none",
890
+ children: [
891
+ /* @__PURE__ */ jsx6("span", {
892
+ fg: palette.muted,
893
+ children: fitTerminalText2(label, labelWidth, "left")
894
+ }),
895
+ /* @__PURE__ */ jsx6("span", {
896
+ fg: palette.border,
897
+ children: " ["
898
+ }),
899
+ /* @__PURE__ */ jsx6("span", {
900
+ fg: palette[bar.tone],
901
+ children: bar.filled
902
+ }),
903
+ /* @__PURE__ */ jsx6("span", {
904
+ children: bar.empty
905
+ }),
906
+ /* @__PURE__ */ jsx6("span", {
907
+ fg: palette.border,
908
+ children: "]"
909
+ }),
910
+ /* @__PURE__ */ jsx6("span", {
911
+ fg: bar.ratio === null ? palette.muted : palette.primary,
912
+ children: fitTerminalText2(reading, textWidth, "right")
913
+ })
914
+ ]
915
+ });
916
+ }
917
+ function TerminalMeterGrid2({
918
+ meters,
919
+ width,
920
+ minMeterWidth = 20,
921
+ gap = 1
922
+ }) {
923
+ const grid = layoutTerminalMeterGrid2({ count: meters.length, width, minMeterWidth, gap });
924
+ const labelWidth = Math.max(1, ...meters.map(({ label }) => label.length));
925
+ return /* @__PURE__ */ jsx6("box", {
926
+ style: { flexDirection: "column", width, height: grid.rows },
927
+ children: grid.cells.map((row) => /* @__PURE__ */ jsx6("box", {
928
+ style: { flexDirection: "row", height: 1, gap },
929
+ children: row.map((index) => {
930
+ const meter = meters[index];
931
+ if (!meter)
932
+ return null;
933
+ return /* @__PURE__ */ jsx6("box", {
934
+ style: { width: grid.meterWidth, height: 1 },
935
+ children: /* @__PURE__ */ jsx6(TerminalMeter2, {
936
+ ...meter,
937
+ width: grid.meterWidth,
938
+ labelWidth
939
+ })
940
+ }, index);
941
+ })
942
+ }, row.join(",")))
943
+ });
944
+ }
945
+
946
+ // src/widgets/table.tsx
947
+ import { useEffect as useEffect4, useMemo, useRef as useRef3, useState as useState2 } from "react";
948
+ import { jsx as jsx7, jsxs as jsxs7 } from "@opentui/react/jsx-runtime";
949
+ function TerminalTable2({
950
+ state,
951
+ onAction,
952
+ onActivate,
953
+ width,
954
+ height,
955
+ focusId,
956
+ focused,
957
+ keymap
958
+ }) {
959
+ const palette = useTerminalPalette2();
960
+ const labels = useTerminalLabels2();
961
+ const active = useTerminalFocused2(focusId, focused);
962
+ const bindings = useMemo(() => keymap ?? terminalTableKeymap2(labels), [keymap, labels]);
963
+ const [filtering, setFilteringState] = useState2(false);
964
+ const filteringNow = useRef3(false);
965
+ const setFiltering = (open) => {
966
+ filteringNow.current = open;
967
+ setFilteringState(open);
968
+ };
969
+ const capacity = Math.max(1, height - 2);
970
+ useEffect4(() => {
971
+ if (state.collection.capacity !== capacity)
972
+ onAction({ type: "resize", capacity });
973
+ }, [capacity, onAction, state.collection.capacity]);
974
+ useEffect4(() => {
975
+ if (active)
976
+ return;
977
+ filteringNow.current = false;
978
+ setFilteringState(false);
979
+ }, [active]);
980
+ const delivered = useRef3(state.activation?.serial ?? 0);
981
+ useEffect4(() => {
982
+ const activation = state.activation;
983
+ if (!activation || activation.serial === delivered.current)
984
+ return;
985
+ delivered.current = activation.serial;
986
+ const row = state.rows.find(({ key }) => key === activation.key);
987
+ if (row)
988
+ onActivate?.(row);
989
+ }, [state.activation, state.rows, onActivate]);
990
+ useTerminalKeyboard2((key) => {
991
+ if (!filteringNow.current)
992
+ return false;
993
+ const edit = terminalTextEdit2(key);
994
+ if (edit === null)
995
+ return false;
996
+ if (edit.kind !== "commit")
997
+ onAction({ type: "filter-edit", edit });
998
+ if (edit.kind === "commit" || edit.kind === "clear")
999
+ setFiltering(false);
1000
+ return true;
1001
+ }, { active, priority: TerminalKeyPriority2.input });
1002
+ useTerminalKeyboard2((key) => {
1003
+ if (filteringNow.current)
1004
+ return false;
1005
+ const result = terminalTableKey2(state, key, bindings);
1006
+ if (result === null)
1007
+ return false;
1008
+ if (result.kind === "filter-start")
1009
+ setFiltering(true);
1010
+ else if (result.kind === "activate")
1011
+ onAction({ type: "activate" });
1012
+ else
1013
+ onAction(result.action);
1014
+ return true;
1015
+ }, { active });
1016
+ const widths = layoutTerminalTableColumns2(state.columns, width);
1017
+ const columns = state.columns.map((column, index) => ({ column, width: widths[index]?.width ?? 0 })).filter(({ width }) => width > 0);
1018
+ const rows = visibleTerminalTableRows2(state).slice(0, capacity);
1019
+ const blank = Math.max(0, capacity - rows.length);
1020
+ const count = labels.rows(state.view.length, state.rows.length);
1021
+ const footer = filtering ? `/${sanitizeTerminalText2(state.filter)}\u258F` : state.filter ? `${labels.filter}: ${sanitizeTerminalText2(state.filter)} \xB7 ${count}` : count;
1022
+ return /* @__PURE__ */ jsxs7("box", {
1023
+ style: { flexDirection: "column", width, height },
1024
+ children: [
1025
+ /* @__PURE__ */ jsx7("text", {
1026
+ fg: palette.muted,
1027
+ wrapMode: "none",
1028
+ children: columns.map(({ column, width }, index) => {
1029
+ const mark = state.sort?.columnId === column.id ? state.sort.direction === "asc" ? "\u25B2" : "\u25BC" : "";
1030
+ const align = column.align ?? (column.kind === "number" ? "right" : "left");
1031
+ return /* @__PURE__ */ jsx7("span", {
1032
+ fg: mark ? palette.accent : palette.muted,
1033
+ children: `${index === 0 ? "" : " "}${fitTerminalText2(column.title + mark, width, align)}`
1034
+ }, column.id);
1035
+ })
1036
+ }),
1037
+ rows.map((view, slot) => {
1038
+ const selected = view.row.key === state.collection.selectedKey;
1039
+ const rowTone = view.matched ? view.row.tone : undefined;
1040
+ const tone = rowTone ? palette[rowTone] : selected && active || view.matched ? palette.primary : palette.muted;
1041
+ return /* @__PURE__ */ jsx7("text", {
1042
+ fg: tone,
1043
+ ...selected && { bg: palette.panelRaised },
1044
+ wrapMode: "none",
1045
+ children: columns.map(({ column, width }, index) => {
1046
+ const align = column.align ?? (column.kind === "number" ? "right" : "left");
1047
+ const prefix = index === 0 ? terminalTableTreePrefix2(view) : "";
1048
+ const text = formatTerminalTableCell2(column, view.row.cells[column.id] ?? null);
1049
+ const cell = index === 0 ? fitTerminalText2(prefix + text, width, align) : ` ${fitTerminalText2(text, width, align)}`;
1050
+ const value = view.row.cells[column.id] ?? null;
1051
+ const missing = value === null;
1052
+ const cellTone = missing || !view.matched ? undefined : column.tone?.(value, view.row);
1053
+ const fg = cellTone ? palette[cellTone] : missing && !selected ? palette.muted : undefined;
1054
+ return /* @__PURE__ */ jsx7("span", {
1055
+ ...fg && { fg },
1056
+ attributes: terminalToneAttributes2(cellTone ?? rowTone),
1057
+ children: cell
1058
+ }, column.id);
1059
+ })
1060
+ }, slot);
1061
+ }),
1062
+ blank > 0 && /* @__PURE__ */ jsx7("box", {
1063
+ style: { height: blank }
1064
+ }),
1065
+ /* @__PURE__ */ jsx7("text", {
1066
+ fg: filtering ? palette.accent : palette.muted,
1067
+ wrapMode: "none",
1068
+ children: fitTerminalText2(footer, width, "left")
1069
+ })
1070
+ ]
1071
+ });
1072
+ }
1073
+
1074
+ // src/widgets/tabs.tsx
1075
+ import { useMemo as useMemo2 } from "react";
1076
+ import { jsx as jsx8 } from "@opentui/react/jsx-runtime";
1077
+ function TerminalTabs2({
1078
+ state,
1079
+ onAction,
1080
+ focusId,
1081
+ focused,
1082
+ keymap
1083
+ }) {
1084
+ const palette = useTerminalPalette2();
1085
+ const labels = useTerminalLabels2();
1086
+ const active = useTerminalFocused2(focusId, focused);
1087
+ const bindings = useMemo2(() => keymap ?? terminalTabsKeymap2(labels), [keymap, labels]);
1088
+ useTerminalKeyboard2((key) => {
1089
+ const action = terminalTabsKey2(key, bindings);
1090
+ if (action === null)
1091
+ return false;
1092
+ onAction(action);
1093
+ return true;
1094
+ }, { active });
1095
+ return /* @__PURE__ */ jsx8("text", {
1096
+ wrapMode: "none",
1097
+ children: state.tabs.map((tab, index) => {
1098
+ const selected = tab.id === state.selectedId;
1099
+ return /* @__PURE__ */ jsx8("span", {
1100
+ fg: selected ? palette.primary : palette.muted,
1101
+ ...selected && { bg: palette.panelRaised },
1102
+ children: `${index === 0 ? "" : " "} ${index < 9 ? `${index + 1} ` : ""}${sanitizeTerminalText2(tab.label)}${tab.badge === null ? "" : ` ${tab.badge}`} `
1103
+ }, tab.id);
1104
+ })
1105
+ });
1106
+ }
1107
+
1108
+ // src/widgets/text-view.tsx
1109
+ import { useMemo as useMemo3, useState as useState3 } from "react";
1110
+ import { jsx as jsx9, jsxs as jsxs8 } from "@opentui/react/jsx-runtime";
1111
+ function terminalTextViewKeymap2(labels, back = true) {
1112
+ return defineTerminalKeymap2([
1113
+ {
1114
+ id: "up",
1115
+ keys: ["up", "k"],
1116
+ shift: false,
1117
+ display: "\u2191\u2193",
1118
+ label: labels.move,
1119
+ priority: 1
1120
+ },
1121
+ {
1122
+ id: "down",
1123
+ keys: ["down", "j"],
1124
+ shift: false,
1125
+ display: "\u2193",
1126
+ label: labels.move,
1127
+ hidden: true
1128
+ },
1129
+ {
1130
+ id: "page-up",
1131
+ keys: ["pageup", "b"],
1132
+ shift: false,
1133
+ display: "PgUp/PgDn",
1134
+ label: labels.page,
1135
+ priority: 0
1136
+ },
1137
+ {
1138
+ id: "page-down",
1139
+ keys: ["pagedown", "space"],
1140
+ display: "Space",
1141
+ label: labels.page,
1142
+ hidden: true
1143
+ },
1144
+ {
1145
+ id: "home",
1146
+ keys: ["home", "g"],
1147
+ shift: false,
1148
+ display: "Home",
1149
+ label: labels.top,
1150
+ hidden: true
1151
+ },
1152
+ { id: "end", keys: ["end", "G"], display: "End", label: labels.bottom, hidden: true },
1153
+ ...back ? [
1154
+ {
1155
+ id: "back",
1156
+ keys: ["escape", "q"],
1157
+ display: "Esc",
1158
+ label: labels.back,
1159
+ priority: 0
1160
+ }
1161
+ ] : []
1162
+ ]);
1163
+ }
1164
+ function TerminalTextView2({
1165
+ content,
1166
+ width,
1167
+ height,
1168
+ onBack,
1169
+ focusId,
1170
+ focused
1171
+ }) {
1172
+ const palette = useTerminalPalette2();
1173
+ const labels = useTerminalLabels2();
1174
+ const active = useTerminalFocused2(focusId, focused);
1175
+ const bindings = terminalTextViewKeymap2(labels, onBack !== undefined);
1176
+ const lines = useMemo3(() => typeof content === "string" ? wrapTerminalText2(sanitizeTerminalText2(content), Math.max(1, width)).map((text) => [
1177
+ { text, tone: "primary" }
1178
+ ]) : [...content], [content, width]);
1179
+ const rows = Math.max(1, height - 1);
1180
+ const last = Math.max(0, lines.length - rows);
1181
+ const [start, setStart] = useState3(0);
1182
+ const top = Math.min(start, last);
1183
+ useTerminalKeyboard2((key) => {
1184
+ const id = matchTerminalKey2(bindings, key)?.id;
1185
+ const step = (move) => setStart((from) => Math.min(Math.max(0, move(Math.min(from, last))), last));
1186
+ if (id === "up")
1187
+ step((from) => from - 1);
1188
+ else if (id === "down")
1189
+ step((from) => from + 1);
1190
+ else if (id === "page-up")
1191
+ step((from) => from - rows);
1192
+ else if (id === "page-down")
1193
+ step((from) => from + rows);
1194
+ else if (id === "home")
1195
+ step(() => 0);
1196
+ else if (id === "end")
1197
+ step(() => last);
1198
+ else if (id === "back" && onBack)
1199
+ onBack();
1200
+ else
1201
+ return false;
1202
+ return true;
1203
+ }, { active });
1204
+ const percent = last === 0 ? 100 : Math.round(top / last * 100);
1205
+ return /* @__PURE__ */ jsxs8("box", {
1206
+ style: { flexDirection: "column", width, height },
1207
+ children: [
1208
+ /* @__PURE__ */ jsx9("box", {
1209
+ style: { flexDirection: "column", height: rows },
1210
+ children: lines.slice(top, top + rows).map((line, slot) => /* @__PURE__ */ jsx9("text", {
1211
+ wrapMode: "none",
1212
+ children: line.map((run, index) => /* @__PURE__ */ jsx9("span", {
1213
+ fg: palette[run.tone],
1214
+ children: run.text
1215
+ }, index))
1216
+ }, slot))
1217
+ }),
1218
+ /* @__PURE__ */ jsx9("text", {
1219
+ fg: palette.muted,
1220
+ wrapMode: "none",
1221
+ children: `${top + 1}\u2013${Math.min(lines.length, top + rows)} / ${lines.length} \xB7 ${labels.scroll(percent)}`
1222
+ })
1223
+ ]
1224
+ });
1225
+ }
1226
+ function TerminalJsonView2({
1227
+ value,
1228
+ ...props
1229
+ }) {
1230
+ const lines = useMemo3(() => terminalJsonLines2(value), [value]);
1231
+ return /* @__PURE__ */ jsx9(TerminalTextView2, {
1232
+ ...props,
1233
+ content: lines
1234
+ });
1235
+ }
1236
+
1237
+ export { TerminalChart2, TerminalSparkline2, useTerminalClock2, TerminalSpinner2, TerminalProgressBar2, TerminalAsyncView2, TerminalDetails2, TerminalDialog2, TerminalHelp2, terminalFormKeymap2, TerminalForm2, TerminalPanel2, TerminalStatusBar2, TerminalKeyHints2, TerminalNotices2, TerminalAppShell2, terminalListKeymap2, TerminalList2, TerminalMeter2, TerminalMeterGrid2, TerminalTable2, TerminalTabs2, terminalTextViewKeymap2, TerminalTextView2, TerminalJsonView2 };