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