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,618 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
TerminalToneSchema2,
|
|
4
|
+
createTerminalTimeSeries2,
|
|
5
|
+
appendTerminalSample2,
|
|
6
|
+
createTerminalForm2,
|
|
7
|
+
reduceTerminalForm2,
|
|
8
|
+
terminalFormFieldsFromJsonSchema2,
|
|
9
|
+
defineTerminalKeymap2,
|
|
10
|
+
matchTerminalKey2,
|
|
11
|
+
terminalLabelsEn2,
|
|
12
|
+
terminalLabelsRu2,
|
|
13
|
+
createTerminalList2,
|
|
14
|
+
reduceTerminalList2,
|
|
15
|
+
layoutTerminalMeterGrid2,
|
|
16
|
+
TerminalSpinnerKindSchema2,
|
|
17
|
+
createTerminalTable2,
|
|
18
|
+
reduceTerminalTable2
|
|
19
|
+
} from "./index-z4c2ehg4.js";
|
|
20
|
+
import {
|
|
21
|
+
createTerminalNotices2,
|
|
22
|
+
reduceTerminalNotices2,
|
|
23
|
+
nextTerminalNoticeExpiry2,
|
|
24
|
+
createTerminalTabs2,
|
|
25
|
+
reduceTerminalTabs2
|
|
26
|
+
} from "./index-251fexwh.js";
|
|
27
|
+
import {
|
|
28
|
+
useTerminalPalette2,
|
|
29
|
+
useTerminalThemeMode2,
|
|
30
|
+
TerminalThemeProvider2,
|
|
31
|
+
TerminalChart2,
|
|
32
|
+
TerminalSparkline2,
|
|
33
|
+
TerminalLabelsProvider2,
|
|
34
|
+
useTerminalLabels2,
|
|
35
|
+
TerminalKeyPriority2,
|
|
36
|
+
useTerminalKeyboard2,
|
|
37
|
+
TerminalSpinner2,
|
|
38
|
+
TerminalProgressBar2,
|
|
39
|
+
TerminalDetails2,
|
|
40
|
+
TerminalDialog2,
|
|
41
|
+
terminalFormKeymap2,
|
|
42
|
+
TerminalForm2,
|
|
43
|
+
TerminalPanel2,
|
|
44
|
+
TerminalAppShell2,
|
|
45
|
+
terminalListKeymap2,
|
|
46
|
+
TerminalList2,
|
|
47
|
+
TerminalMeter2,
|
|
48
|
+
TerminalMeterGrid2,
|
|
49
|
+
TerminalTable2,
|
|
50
|
+
TerminalTabs2,
|
|
51
|
+
terminalTextViewKeymap2,
|
|
52
|
+
TerminalJsonView2
|
|
53
|
+
} from "./index-54sqbm3r.js";
|
|
54
|
+
|
|
55
|
+
// src/gallery/app.tsx
|
|
56
|
+
import { useRenderer, useTerminalDimensions } from "@opentui/react";
|
|
57
|
+
import { useCallback as useCallback3, useEffect as useEffect4, useReducer as useReducer2, useState as useState4 } from "react";
|
|
58
|
+
|
|
59
|
+
// src/gallery/catalogue.tsx
|
|
60
|
+
import { useCallback, useEffect, useReducer, useRef, useState } from "react";
|
|
61
|
+
import { jsx } from "@opentui/react/jsx-runtime";
|
|
62
|
+
var SECTIONS = [
|
|
63
|
+
{ id: "docs", title: "Documents" },
|
|
64
|
+
{ id: "repo", title: "Repositories" },
|
|
65
|
+
{ id: "hosts", title: "Hosts" }
|
|
66
|
+
];
|
|
67
|
+
var METHODS = [
|
|
68
|
+
...["read", "search", "projects", "tasks", "watch"].map((name) => ({
|
|
69
|
+
name: `docs_${name}`,
|
|
70
|
+
section: "docs",
|
|
71
|
+
description: `Documents: ${name} across every project, with provenance and scope.`,
|
|
72
|
+
destructive: false,
|
|
73
|
+
schema: {
|
|
74
|
+
type: "object",
|
|
75
|
+
properties: {
|
|
76
|
+
project: { type: "string", description: "Project id, owner/repo" },
|
|
77
|
+
query: { type: "string" },
|
|
78
|
+
limit: { type: "integer", default: 20 }
|
|
79
|
+
},
|
|
80
|
+
required: ["project"]
|
|
81
|
+
}
|
|
82
|
+
})),
|
|
83
|
+
...["query_issues", "portfolio", "transfer", "release_status"].map((name) => ({
|
|
84
|
+
name: `repo_${name}`,
|
|
85
|
+
section: "repo",
|
|
86
|
+
description: `Repositories: ${name.replace("_", " ")} across every repository.`,
|
|
87
|
+
destructive: name === "transfer",
|
|
88
|
+
schema: {
|
|
89
|
+
type: "object",
|
|
90
|
+
properties: {
|
|
91
|
+
project: { type: "string" },
|
|
92
|
+
status: { type: "string", enum: ["inbox", "planned", "in-progress", "done"] },
|
|
93
|
+
dryRun: { type: "boolean", default: true },
|
|
94
|
+
filter: { type: "object" }
|
|
95
|
+
},
|
|
96
|
+
required: ["project", "status"]
|
|
97
|
+
}
|
|
98
|
+
})),
|
|
99
|
+
...["state", "quota", "restart", "logs"].map((name) => ({
|
|
100
|
+
name: `hosts_${name}`,
|
|
101
|
+
section: "hosts",
|
|
102
|
+
description: `Hosts: ${name} for one machine or all of them.`,
|
|
103
|
+
destructive: name === "restart",
|
|
104
|
+
schema: {
|
|
105
|
+
type: "object",
|
|
106
|
+
properties: {
|
|
107
|
+
machine: { type: "string", enum: ["alpha", "beta", "gamma"] },
|
|
108
|
+
token: { type: "string", format: "password" }
|
|
109
|
+
},
|
|
110
|
+
required: ["machine"]
|
|
111
|
+
}
|
|
112
|
+
}))
|
|
113
|
+
];
|
|
114
|
+
function methodItems() {
|
|
115
|
+
return METHODS.map((method) => ({
|
|
116
|
+
key: method.name,
|
|
117
|
+
title: method.name,
|
|
118
|
+
meta: method.section,
|
|
119
|
+
section: method.section,
|
|
120
|
+
description: method.description,
|
|
121
|
+
...method.destructive && { tone: "warning", badge: "!" }
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
function masked(method, values) {
|
|
125
|
+
const secrets = new Set(terminalFormFieldsFromJsonSchema2(method.schema).filter(({ kind }) => kind === "secret").map(({ name }) => name));
|
|
126
|
+
return Object.fromEntries(Object.entries(values).map(([name, value]) => [name, secrets.has(name) ? "\u2022\u2022\u2022\u2022" : value]));
|
|
127
|
+
}
|
|
128
|
+
function CatalogueDemo({
|
|
129
|
+
width,
|
|
130
|
+
height,
|
|
131
|
+
active,
|
|
132
|
+
clock,
|
|
133
|
+
onScreen,
|
|
134
|
+
onNotice
|
|
135
|
+
}) {
|
|
136
|
+
const labels = useTerminalLabels2();
|
|
137
|
+
const [list, listDispatch] = useReducer(reduceTerminalList2, undefined, () => createTerminalList2({ items: methodItems(), sections: SECTIONS }));
|
|
138
|
+
const [form, setForm] = useState(null);
|
|
139
|
+
const [screen, setScreen] = useState({ kind: "list" });
|
|
140
|
+
const onList = useCallback((action) => listDispatch(action), []);
|
|
141
|
+
const onForm = useCallback((action) => setForm((current) => current ? reduceTerminalForm2(current, action, labels.form) : current), [labels.form]);
|
|
142
|
+
const pending = useRef(null);
|
|
143
|
+
useEffect(() => () => {
|
|
144
|
+
if (pending.current)
|
|
145
|
+
clearTimeout(pending.current);
|
|
146
|
+
}, []);
|
|
147
|
+
const run = useCallback((method, values) => {
|
|
148
|
+
const startedAt = clock();
|
|
149
|
+
setScreen({
|
|
150
|
+
kind: "result",
|
|
151
|
+
method,
|
|
152
|
+
result: { status: "loading", startedAt, label: method.name }
|
|
153
|
+
});
|
|
154
|
+
pending.current = setTimeout(() => {
|
|
155
|
+
pending.current = null;
|
|
156
|
+
const failed = values.project === "fail";
|
|
157
|
+
setScreen({
|
|
158
|
+
kind: "result",
|
|
159
|
+
method,
|
|
160
|
+
result: failed ? {
|
|
161
|
+
status: "error",
|
|
162
|
+
message: `${method.name}: project "fail" does not exist`,
|
|
163
|
+
retryable: true
|
|
164
|
+
} : {
|
|
165
|
+
status: "ready",
|
|
166
|
+
data: {
|
|
167
|
+
ok: true,
|
|
168
|
+
method: method.name,
|
|
169
|
+
input: masked(method, values),
|
|
170
|
+
items: [
|
|
171
|
+
{ id: 1, title: "First" },
|
|
172
|
+
{ id: 2, title: "Second", tags: ["a", "b"] }
|
|
173
|
+
],
|
|
174
|
+
tookMs: 1180
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
onNotice(failed ? `${method.name} failed` : `${method.name} done`, failed ? "danger" : "success");
|
|
179
|
+
}, 1200);
|
|
180
|
+
}, [clock, onNotice]);
|
|
181
|
+
useEffect(() => {
|
|
182
|
+
if (!active)
|
|
183
|
+
return;
|
|
184
|
+
const crumbs = ["Catalogue"];
|
|
185
|
+
if (screen.kind === "list")
|
|
186
|
+
onScreen(crumbs, terminalListKeymap2(labels, { searchable: true }));
|
|
187
|
+
else if (screen.kind === "form")
|
|
188
|
+
onScreen([...crumbs, screen.method.name], terminalFormKeymap2(labels));
|
|
189
|
+
else if (screen.kind === "confirm")
|
|
190
|
+
onScreen([...crumbs, screen.method.name], defineTerminalKeymap2([
|
|
191
|
+
{ id: "y", keys: ["y"], display: "y", label: labels.yes },
|
|
192
|
+
{ id: "n", keys: ["n", "escape"], display: "n/Esc", label: labels.no }
|
|
193
|
+
]));
|
|
194
|
+
else
|
|
195
|
+
onScreen([...crumbs, screen.method.name, "result"], terminalTextViewKeymap2(labels));
|
|
196
|
+
}, [active, screen, labels, onScreen]);
|
|
197
|
+
if (screen.kind === "list") {
|
|
198
|
+
return /* @__PURE__ */ jsx(TerminalList2, {
|
|
199
|
+
state: list,
|
|
200
|
+
onAction: onList,
|
|
201
|
+
searchable: true,
|
|
202
|
+
width,
|
|
203
|
+
height,
|
|
204
|
+
focused: active,
|
|
205
|
+
onActivate: (item) => {
|
|
206
|
+
const method = METHODS.find(({ name }) => name === item.key);
|
|
207
|
+
if (!method)
|
|
208
|
+
return;
|
|
209
|
+
setForm(createTerminalForm2(terminalFormFieldsFromJsonSchema2(method.schema)));
|
|
210
|
+
setScreen({ kind: "form", method });
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
if (screen.kind === "form" && form) {
|
|
215
|
+
return /* @__PURE__ */ jsx(TerminalForm2, {
|
|
216
|
+
state: form,
|
|
217
|
+
onAction: onForm,
|
|
218
|
+
width,
|
|
219
|
+
focused: active,
|
|
220
|
+
onCancel: () => setScreen({ kind: "list" }),
|
|
221
|
+
onSubmit: (values) => screen.method.destructive ? setScreen({ kind: "confirm", method: screen.method, values }) : run(screen.method, values)
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
if (screen.kind === "confirm") {
|
|
225
|
+
return /* @__PURE__ */ jsx("box", {
|
|
226
|
+
style: { alignItems: "center", justifyContent: "center", height },
|
|
227
|
+
children: /* @__PURE__ */ jsx(TerminalDialog2, {
|
|
228
|
+
title: screen.method.name,
|
|
229
|
+
message: `This method changes state. Run ${screen.method.name} with ${JSON.stringify(masked(screen.method, screen.values))}?`,
|
|
230
|
+
focused: active,
|
|
231
|
+
onConfirm: () => run(screen.method, screen.values),
|
|
232
|
+
onCancel: () => setScreen({ kind: "form", method: screen.method })
|
|
233
|
+
})
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
if (screen.kind === "result") {
|
|
237
|
+
const back = () => setScreen({ kind: "list" });
|
|
238
|
+
const { result } = screen;
|
|
239
|
+
if (result.status === "loading")
|
|
240
|
+
return /* @__PURE__ */ jsx(TerminalSpinner2, {
|
|
241
|
+
label: result.label ?? labels.loading,
|
|
242
|
+
startedAt: result.startedAt,
|
|
243
|
+
clock
|
|
244
|
+
});
|
|
245
|
+
return /* @__PURE__ */ jsx(TerminalJsonView2, {
|
|
246
|
+
value: result.status === "ready" ? result.data : { ok: false, error: result.status === "error" ? result.message : null },
|
|
247
|
+
width,
|
|
248
|
+
height,
|
|
249
|
+
focused: active,
|
|
250
|
+
onBack: back
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// src/gallery/monitor-page.tsx
|
|
257
|
+
import { useCallback as useCallback2, useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
|
|
258
|
+
import { jsx as jsx2, jsxs } from "@opentui/react/jsx-runtime";
|
|
259
|
+
var columns = [
|
|
260
|
+
{ id: "name", title: "NAME", kind: "text", width: { flex: 1 } },
|
|
261
|
+
{ id: "pid", title: "PID", kind: "number", width: 7, filterable: true },
|
|
262
|
+
{ id: "cpu", title: "CPU%", kind: "number", width: 6, format: (v) => Number(v).toFixed(1) },
|
|
263
|
+
{
|
|
264
|
+
id: "mem",
|
|
265
|
+
title: "MEM",
|
|
266
|
+
kind: "number",
|
|
267
|
+
width: 7,
|
|
268
|
+
format: (v) => `${Math.round(Number(v))}M`
|
|
269
|
+
}
|
|
270
|
+
];
|
|
271
|
+
function noise(seed) {
|
|
272
|
+
const x = Math.sin(seed * 12.9898) * 43758.5453;
|
|
273
|
+
return x - Math.floor(x);
|
|
274
|
+
}
|
|
275
|
+
function rows(tick) {
|
|
276
|
+
return Array.from({ length: 30 }, (_, app) => [
|
|
277
|
+
{
|
|
278
|
+
key: `app-${app}`,
|
|
279
|
+
parentKey: null,
|
|
280
|
+
cells: {
|
|
281
|
+
name: `service-${app}`,
|
|
282
|
+
pid: 1000 + app,
|
|
283
|
+
cpu: Math.round(noise(app * 31 + tick) * 400) / 10,
|
|
284
|
+
mem: app % 9 === 0 ? null : 40 + noise(app) * 600
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
...Array.from({ length: 4 }, (_, worker) => ({
|
|
288
|
+
key: `app-${app}/w${worker}`,
|
|
289
|
+
parentKey: `app-${app}`,
|
|
290
|
+
cells: {
|
|
291
|
+
name: `worker-${worker}`,
|
|
292
|
+
pid: 20000 + app * 10 + worker,
|
|
293
|
+
cpu: Math.round(noise(app * 7 + worker + tick) * 1000) / 10,
|
|
294
|
+
mem: 10 + noise(worker + app) * 100
|
|
295
|
+
}
|
|
296
|
+
}))
|
|
297
|
+
]).flat();
|
|
298
|
+
}
|
|
299
|
+
function MonitorDemo({
|
|
300
|
+
width,
|
|
301
|
+
height,
|
|
302
|
+
active,
|
|
303
|
+
clock
|
|
304
|
+
}) {
|
|
305
|
+
const tick = useRef2(0);
|
|
306
|
+
const [table, setTable] = useState2(() => createTerminalTable2({
|
|
307
|
+
columns,
|
|
308
|
+
rows: rows(0),
|
|
309
|
+
capacity: 10,
|
|
310
|
+
sort: { columnId: "cpu", direction: "desc" },
|
|
311
|
+
expanded: ["app-1"]
|
|
312
|
+
}));
|
|
313
|
+
const [cpu, setCpu] = useState2(() => createTerminalTimeSeries2({ windowMs: 60000 }));
|
|
314
|
+
const [cores, setCores] = useState2(() => Array.from({ length: 8 }, () => null));
|
|
315
|
+
const onAction = useCallback2((action) => setTable((current) => reduceTerminalTable2(current, action)), []);
|
|
316
|
+
useEffect2(() => {
|
|
317
|
+
const timer = setInterval(() => {
|
|
318
|
+
tick.current += 1;
|
|
319
|
+
const next = tick.current;
|
|
320
|
+
const values = Array.from({ length: 8 }, (_, core) => Math.round(noise(core * 5 + next) * 1000) / 10);
|
|
321
|
+
setCores(values);
|
|
322
|
+
setCpu((series) => appendTerminalSample2(series, {
|
|
323
|
+
at: clock(),
|
|
324
|
+
value: values.reduce((a, b) => a + b, 0) / 8
|
|
325
|
+
}));
|
|
326
|
+
setTable((state) => reduceTerminalTable2(state, { type: "rows", rows: rows(next) }));
|
|
327
|
+
}, 1000);
|
|
328
|
+
return () => clearInterval(timer);
|
|
329
|
+
}, [clock]);
|
|
330
|
+
const chartWidth = Math.max(10, width);
|
|
331
|
+
const meterRows = layoutTerminalMeterGrid2({
|
|
332
|
+
count: cores.length,
|
|
333
|
+
width,
|
|
334
|
+
minMeterWidth: 24
|
|
335
|
+
}).rows;
|
|
336
|
+
return /* @__PURE__ */ jsxs("box", {
|
|
337
|
+
style: { flexDirection: "column", width, height },
|
|
338
|
+
children: [
|
|
339
|
+
/* @__PURE__ */ jsx2(TerminalMeterGrid2, {
|
|
340
|
+
width,
|
|
341
|
+
minMeterWidth: 24,
|
|
342
|
+
meters: cores.map((value, core) => ({ label: `cpu${core}`, value, max: 100 }))
|
|
343
|
+
}),
|
|
344
|
+
/* @__PURE__ */ jsx2(TerminalChart2, {
|
|
345
|
+
series: [{ data: cpu, tone: "accent" }],
|
|
346
|
+
now: clock(),
|
|
347
|
+
width: chartWidth,
|
|
348
|
+
height: 3,
|
|
349
|
+
min: 0,
|
|
350
|
+
max: 100,
|
|
351
|
+
fill: true
|
|
352
|
+
}),
|
|
353
|
+
/* @__PURE__ */ jsx2(TerminalTable2, {
|
|
354
|
+
state: table,
|
|
355
|
+
onAction,
|
|
356
|
+
width,
|
|
357
|
+
height: Math.max(3, height - meterRows - 4),
|
|
358
|
+
focused: active
|
|
359
|
+
})
|
|
360
|
+
]
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// src/gallery/widgets-page.tsx
|
|
365
|
+
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
366
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "@opentui/react/jsx-runtime";
|
|
367
|
+
function WidgetsDemo({
|
|
368
|
+
width,
|
|
369
|
+
clock,
|
|
370
|
+
startedAt
|
|
371
|
+
}) {
|
|
372
|
+
const palette = useTerminalPalette2();
|
|
373
|
+
const [now, setNow] = useState3(clock);
|
|
374
|
+
const [series, setSeries] = useState3(() => createTerminalTimeSeries2({ windowMs: 30000 }));
|
|
375
|
+
useEffect3(() => {
|
|
376
|
+
const timer = setInterval(() => {
|
|
377
|
+
const at = clock();
|
|
378
|
+
setNow(at);
|
|
379
|
+
setSeries((current) => appendTerminalSample2(current, { at, value: 50 + 40 * Math.sin(at / 2500) }));
|
|
380
|
+
}, 250);
|
|
381
|
+
return () => clearInterval(timer);
|
|
382
|
+
}, [clock]);
|
|
383
|
+
const half = Math.max(20, Math.floor((width - 2) / 2));
|
|
384
|
+
const elapsed = now - startedAt;
|
|
385
|
+
const load = (offset) => 50 + 50 * Math.sin(elapsed / 1700 + offset);
|
|
386
|
+
return /* @__PURE__ */ jsxs2("box", {
|
|
387
|
+
style: { flexDirection: "row", gap: 2 },
|
|
388
|
+
children: [
|
|
389
|
+
/* @__PURE__ */ jsxs2("box", {
|
|
390
|
+
style: { flexDirection: "column", width: half },
|
|
391
|
+
children: [
|
|
392
|
+
/* @__PURE__ */ jsxs2(TerminalPanel2, {
|
|
393
|
+
title: "Progress",
|
|
394
|
+
width: half,
|
|
395
|
+
children: [
|
|
396
|
+
/* @__PURE__ */ jsx3(TerminalProgressBar2, {
|
|
397
|
+
label: "upload",
|
|
398
|
+
done: elapsed / 40 % 1000,
|
|
399
|
+
total: 1000,
|
|
400
|
+
startedAt,
|
|
401
|
+
now,
|
|
402
|
+
width: half - 4,
|
|
403
|
+
unit: "kB"
|
|
404
|
+
}),
|
|
405
|
+
/* @__PURE__ */ jsx3(TerminalProgressBar2, {
|
|
406
|
+
label: "sync",
|
|
407
|
+
done: null,
|
|
408
|
+
total: null,
|
|
409
|
+
startedAt,
|
|
410
|
+
now,
|
|
411
|
+
width: half - 4
|
|
412
|
+
}),
|
|
413
|
+
TerminalSpinnerKindSchema2.options.map((kind) => /* @__PURE__ */ jsx3(TerminalSpinner2, {
|
|
414
|
+
kind,
|
|
415
|
+
label: `spinner ${kind}`,
|
|
416
|
+
startedAt,
|
|
417
|
+
clock
|
|
418
|
+
}, kind))
|
|
419
|
+
]
|
|
420
|
+
}),
|
|
421
|
+
/* @__PURE__ */ jsx3(TerminalPanel2, {
|
|
422
|
+
title: "Meters",
|
|
423
|
+
width: half,
|
|
424
|
+
children: ["cpu", "mem", "swap", "disk"].map((label, index) => /* @__PURE__ */ jsx3(TerminalMeter2, {
|
|
425
|
+
label,
|
|
426
|
+
value: label === "swap" ? null : load(index),
|
|
427
|
+
max: 100,
|
|
428
|
+
width: half - 4,
|
|
429
|
+
labelWidth: 4
|
|
430
|
+
}, label))
|
|
431
|
+
})
|
|
432
|
+
]
|
|
433
|
+
}),
|
|
434
|
+
/* @__PURE__ */ jsxs2("box", {
|
|
435
|
+
style: { flexDirection: "column", width: half },
|
|
436
|
+
children: [
|
|
437
|
+
/* @__PURE__ */ jsxs2(TerminalPanel2, {
|
|
438
|
+
title: "Chart",
|
|
439
|
+
badge: "30s",
|
|
440
|
+
width: half,
|
|
441
|
+
children: [
|
|
442
|
+
/* @__PURE__ */ jsx3(TerminalChart2, {
|
|
443
|
+
series: [{ data: series, tone: "accent" }],
|
|
444
|
+
now,
|
|
445
|
+
width: half - 4,
|
|
446
|
+
height: 4,
|
|
447
|
+
min: 0,
|
|
448
|
+
max: 100,
|
|
449
|
+
fill: true
|
|
450
|
+
}),
|
|
451
|
+
/* @__PURE__ */ jsx3(TerminalSparkline2, {
|
|
452
|
+
data: series,
|
|
453
|
+
now,
|
|
454
|
+
width: half - 4,
|
|
455
|
+
tone: "success",
|
|
456
|
+
min: 0,
|
|
457
|
+
max: 100
|
|
458
|
+
})
|
|
459
|
+
]
|
|
460
|
+
}),
|
|
461
|
+
/* @__PURE__ */ jsx3(TerminalPanel2, {
|
|
462
|
+
title: "Details",
|
|
463
|
+
width: half,
|
|
464
|
+
children: /* @__PURE__ */ jsx3(TerminalDetails2, {
|
|
465
|
+
width: half - 4,
|
|
466
|
+
pairs: [
|
|
467
|
+
{ key: "status", value: "running", tone: "success" },
|
|
468
|
+
{ key: "uptime", value: `${Math.floor(elapsed / 1000)}s` },
|
|
469
|
+
{
|
|
470
|
+
key: "endpoint",
|
|
471
|
+
value: "https://example.invalid/a/very/long/path/that/is/cut"
|
|
472
|
+
},
|
|
473
|
+
{ key: "error", value: "none", tone: "muted" }
|
|
474
|
+
]
|
|
475
|
+
})
|
|
476
|
+
}),
|
|
477
|
+
/* @__PURE__ */ jsx3(TerminalPanel2, {
|
|
478
|
+
title: "Palette",
|
|
479
|
+
width: half,
|
|
480
|
+
children: [TerminalToneSchema2.options.slice(0, 3), TerminalToneSchema2.options.slice(3)].map((tones) => /* @__PURE__ */ jsx3("text", {
|
|
481
|
+
wrapMode: "none",
|
|
482
|
+
children: tones.map((tone) => /* @__PURE__ */ jsx3("span", {
|
|
483
|
+
fg: palette[tone],
|
|
484
|
+
children: `\u25A0 ${tone.padEnd(9)}`
|
|
485
|
+
}, tone))
|
|
486
|
+
}, tones.join()))
|
|
487
|
+
})
|
|
488
|
+
]
|
|
489
|
+
})
|
|
490
|
+
]
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// src/gallery/app.tsx
|
|
495
|
+
import { jsx as jsx4, jsxs as jsxs3 } from "@opentui/react/jsx-runtime";
|
|
496
|
+
var PAGES = [
|
|
497
|
+
{ id: "catalogue", label: "Catalogue" },
|
|
498
|
+
{ id: "monitor", label: "Monitor" },
|
|
499
|
+
{ id: "widgets", label: "Widgets" }
|
|
500
|
+
];
|
|
501
|
+
var globalKeymap = defineTerminalKeymap2([
|
|
502
|
+
{ id: "page-1", keys: ["f1"], display: "F1\u2013F3", label: "pages", priority: 2 },
|
|
503
|
+
{ id: "page-2", keys: ["f2"], display: "F2", label: "pages", hidden: true },
|
|
504
|
+
{ id: "page-3", keys: ["f3"], display: "F3", label: "pages", hidden: true },
|
|
505
|
+
{ id: "theme", keys: ["t"], ctrl: true, display: "^T", label: "theme", priority: 3 },
|
|
506
|
+
{ id: "language", keys: ["l"], ctrl: true, display: "^L", label: "language", priority: 3 },
|
|
507
|
+
{ id: "quit", keys: ["c"], ctrl: true, display: "^C", label: "quit", priority: 1 }
|
|
508
|
+
]);
|
|
509
|
+
function TerminalGallery({ clock = Date.now, onExit }) {
|
|
510
|
+
const [mode, setMode] = useState4("auto");
|
|
511
|
+
const resolved = useTerminalThemeMode2(mode);
|
|
512
|
+
const [language, setLanguage] = useState4("en");
|
|
513
|
+
return /* @__PURE__ */ jsx4(TerminalThemeProvider2, {
|
|
514
|
+
mode: resolved,
|
|
515
|
+
children: /* @__PURE__ */ jsx4(TerminalLabelsProvider2, {
|
|
516
|
+
labels: language === "ru" ? terminalLabelsRu2 : terminalLabelsEn2,
|
|
517
|
+
children: /* @__PURE__ */ jsx4(GalleryScreen, {
|
|
518
|
+
clock,
|
|
519
|
+
...onExit && { onExit },
|
|
520
|
+
status: `theme ${mode}${mode === "auto" ? ` (${resolved})` : ""} \xB7 ${language}`,
|
|
521
|
+
onTheme: () => setMode((current) => current === "auto" ? "dark" : current === "dark" ? "light" : "auto"),
|
|
522
|
+
onLanguage: () => setLanguage((current) => current === "en" ? "ru" : "en")
|
|
523
|
+
})
|
|
524
|
+
})
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
function GalleryScreen({
|
|
528
|
+
clock,
|
|
529
|
+
onExit,
|
|
530
|
+
status,
|
|
531
|
+
onTheme,
|
|
532
|
+
onLanguage
|
|
533
|
+
}) {
|
|
534
|
+
const { width, height } = useTerminalDimensions();
|
|
535
|
+
const renderer = useRenderer();
|
|
536
|
+
const [startedAt] = useState4(clock);
|
|
537
|
+
const [tabs, tabsDispatch] = useReducer2(reduceTerminalTabs2, undefined, () => createTerminalTabs2(PAGES));
|
|
538
|
+
const [notices, noticesDispatch] = useReducer2(reduceTerminalNotices2, undefined, () => createTerminalNotices2());
|
|
539
|
+
const [screen, setScreen] = useState4({
|
|
540
|
+
crumbs: [],
|
|
541
|
+
bindings: []
|
|
542
|
+
});
|
|
543
|
+
const onScreen = useCallback3((crumbs, bindings) => setScreen({ crumbs, bindings }), []);
|
|
544
|
+
const onNotice = useCallback3((text, tone) => noticesDispatch({
|
|
545
|
+
type: "push",
|
|
546
|
+
notice: { id: crypto.randomUUID(), text, tone, at: clock() }
|
|
547
|
+
}), [clock]);
|
|
548
|
+
useEffect4(() => {
|
|
549
|
+
const expiry = nextTerminalNoticeExpiry2(notices);
|
|
550
|
+
if (expiry === null)
|
|
551
|
+
return;
|
|
552
|
+
const timer = setTimeout(() => noticesDispatch({ type: "expire", now: clock() }), Math.max(0, expiry - clock()));
|
|
553
|
+
return () => clearTimeout(timer);
|
|
554
|
+
}, [notices, clock]);
|
|
555
|
+
useTerminalKeyboard2((key) => {
|
|
556
|
+
const id = matchTerminalKey2(globalKeymap, key)?.id;
|
|
557
|
+
if (id === undefined)
|
|
558
|
+
return false;
|
|
559
|
+
if (id === "quit") {
|
|
560
|
+
if (onExit)
|
|
561
|
+
onExit();
|
|
562
|
+
else
|
|
563
|
+
renderer.destroy();
|
|
564
|
+
} else if (id === "theme")
|
|
565
|
+
onTheme();
|
|
566
|
+
else if (id === "language")
|
|
567
|
+
onLanguage();
|
|
568
|
+
else
|
|
569
|
+
tabsDispatch({ type: "select-index", index: Number(id.slice(-1)) - 1 });
|
|
570
|
+
return true;
|
|
571
|
+
}, { priority: TerminalKeyPriority2.global });
|
|
572
|
+
const page = tabs.selectedId;
|
|
573
|
+
const body = Math.max(6, height - 6);
|
|
574
|
+
const bindings = page === "catalogue" ? [...screen.bindings, ...globalKeymap] : globalKeymap;
|
|
575
|
+
return /* @__PURE__ */ jsxs3(TerminalAppShell2, {
|
|
576
|
+
breadcrumbs: [
|
|
577
|
+
"stitchkit-tui",
|
|
578
|
+
...page === "catalogue" ? screen.crumbs : [PAGES.find(({ id }) => id === page)?.label ?? page]
|
|
579
|
+
],
|
|
580
|
+
status: [
|
|
581
|
+
[
|
|
582
|
+
{ text: status, tone: "muted" },
|
|
583
|
+
{ text: `${width}\xD7${height}`, tone: "muted" }
|
|
584
|
+
]
|
|
585
|
+
],
|
|
586
|
+
bindings,
|
|
587
|
+
notices,
|
|
588
|
+
width,
|
|
589
|
+
height,
|
|
590
|
+
children: [
|
|
591
|
+
/* @__PURE__ */ jsx4(TerminalTabs2, {
|
|
592
|
+
state: tabs,
|
|
593
|
+
onAction: tabsDispatch,
|
|
594
|
+
focused: false
|
|
595
|
+
}),
|
|
596
|
+
page === "catalogue" ? /* @__PURE__ */ jsx4(CatalogueDemo, {
|
|
597
|
+
width,
|
|
598
|
+
height: body,
|
|
599
|
+
active: true,
|
|
600
|
+
clock,
|
|
601
|
+
onScreen,
|
|
602
|
+
onNotice
|
|
603
|
+
}) : page === "monitor" ? /* @__PURE__ */ jsx4(MonitorDemo, {
|
|
604
|
+
width,
|
|
605
|
+
height: body,
|
|
606
|
+
active: true,
|
|
607
|
+
clock
|
|
608
|
+
}) : /* @__PURE__ */ jsx4(WidgetsDemo, {
|
|
609
|
+
width,
|
|
610
|
+
clock,
|
|
611
|
+
startedAt
|
|
612
|
+
})
|
|
613
|
+
]
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
export {
|
|
617
|
+
TerminalGallery
|
|
618
|
+
};
|