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