@silvery/examples 0.17.3 → 0.17.4
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/dist/UPNG-Cy7ViL8f.mjs +5074 -0
- package/dist/__vite-browser-external-2447137e-BML7CYau.mjs +4 -0
- package/dist/_banner-DLPxCqVy.mjs +44 -0
- package/dist/ansi-CCE2pVS0.mjs +16397 -0
- package/dist/apng-HhhBjRGt.mjs +68 -0
- package/dist/apng-mwUQbTTF.mjs +3 -0
- package/dist/apps/aichat/index.mjs +1299 -0
- package/dist/apps/app-todo.mjs +139 -0
- package/dist/apps/async-data.mjs +204 -0
- package/dist/apps/cli-wizard.mjs +339 -0
- package/dist/apps/clipboard.mjs +198 -0
- package/dist/apps/components.mjs +864 -0
- package/dist/apps/data-explorer.mjs +483 -0
- package/dist/apps/dev-tools.mjs +397 -0
- package/dist/apps/explorer.mjs +698 -0
- package/dist/apps/gallery.mjs +766 -0
- package/dist/apps/inline-bench.mjs +115 -0
- package/dist/apps/kanban.mjs +280 -0
- package/dist/apps/layout-ref.mjs +187 -0
- package/dist/apps/outline.mjs +203 -0
- package/dist/apps/paste-demo.mjs +189 -0
- package/dist/apps/scroll.mjs +86 -0
- package/dist/apps/search-filter.mjs +287 -0
- package/dist/apps/selection.mjs +355 -0
- package/dist/apps/spatial-focus-demo.mjs +388 -0
- package/dist/apps/task-list.mjs +258 -0
- package/dist/apps/terminal-caps-demo.mjs +315 -0
- package/dist/apps/terminal.mjs +872 -0
- package/dist/apps/text-selection-demo.mjs +254 -0
- package/dist/apps/textarea.mjs +178 -0
- package/dist/apps/theme.mjs +661 -0
- package/dist/apps/transform.mjs +215 -0
- package/dist/apps/virtual-10k.mjs +422 -0
- package/dist/assets/resvgjs.darwin-arm64-BtufyGW1.node +0 -0
- package/dist/backends-Bahh9mKN.mjs +1179 -0
- package/dist/backends-CCtCDQ94.mjs +3 -0
- package/dist/{cli.mjs → bin/cli.mjs} +15 -19
- package/dist/chunk-BSw8zbkd.mjs +37 -0
- package/dist/components/counter.mjs +48 -0
- package/dist/components/hello.mjs +31 -0
- package/dist/components/progress-bar.mjs +59 -0
- package/dist/components/select-list.mjs +85 -0
- package/dist/components/spinner.mjs +57 -0
- package/dist/components/text-input.mjs +62 -0
- package/dist/components/virtual-list.mjs +51 -0
- package/dist/flexily-zero-adapter-UB-ra8fR.mjs +3374 -0
- package/dist/gif-BZaqPPVX.mjs +3 -0
- package/dist/gif-BtnXuxLF.mjs +71 -0
- package/dist/gifenc-CLRW41dk.mjs +728 -0
- package/dist/jsx-runtime-dMs_8fNu.mjs +241 -0
- package/dist/key-mapping-5oYQdAQE.mjs +3 -0
- package/dist/key-mapping-D4LR1go6.mjs +130 -0
- package/dist/layout/dashboard.mjs +1204 -0
- package/dist/layout/live-resize.mjs +303 -0
- package/dist/layout/overflow.mjs +70 -0
- package/dist/layout/text-layout.mjs +335 -0
- package/dist/node-NuJ94BWl.mjs +1083 -0
- package/dist/plugins-D1KtkT4a.mjs +3057 -0
- package/dist/resvg-js-C_8Wps1F.mjs +201 -0
- package/dist/src-BTEVGpd9.mjs +23538 -0
- package/dist/src-CUUOuRH6.mjs +5322 -0
- package/dist/src-CzfRafCQ.mjs +814 -0
- package/dist/usingCtx-CsEf0xO3.mjs +57 -0
- package/dist/yoga-adapter-BVtQ5OJR.mjs +237 -0
- package/package.json +18 -13
- package/_banner.tsx +0 -60
- package/apps/aichat/components.tsx +0 -469
- package/apps/aichat/index.tsx +0 -220
- package/apps/aichat/script.ts +0 -460
- package/apps/aichat/state.ts +0 -325
- package/apps/aichat/types.ts +0 -19
- package/apps/app-todo.tsx +0 -201
- package/apps/async-data.tsx +0 -196
- package/apps/cli-wizard.tsx +0 -332
- package/apps/clipboard.tsx +0 -183
- package/apps/components.tsx +0 -658
- package/apps/data-explorer.tsx +0 -490
- package/apps/dev-tools.tsx +0 -395
- package/apps/explorer.tsx +0 -731
- package/apps/gallery.tsx +0 -653
- package/apps/inline-bench.tsx +0 -138
- package/apps/kanban.tsx +0 -265
- package/apps/layout-ref.tsx +0 -173
- package/apps/outline.tsx +0 -160
- package/apps/panes/index.tsx +0 -203
- package/apps/paste-demo.tsx +0 -185
- package/apps/scroll.tsx +0 -80
- package/apps/search-filter.tsx +0 -240
- package/apps/selection.tsx +0 -346
- package/apps/spatial-focus-demo.tsx +0 -372
- package/apps/task-list.tsx +0 -271
- package/apps/terminal-caps-demo.tsx +0 -317
- package/apps/terminal.tsx +0 -784
- package/apps/text-selection-demo.tsx +0 -193
- package/apps/textarea.tsx +0 -155
- package/apps/theme.tsx +0 -515
- package/apps/transform.tsx +0 -229
- package/apps/virtual-10k.tsx +0 -405
- package/apps/vterm-demo/index.tsx +0 -216
- package/components/counter.tsx +0 -49
- package/components/hello.tsx +0 -38
- package/components/progress-bar.tsx +0 -52
- package/components/select-list.tsx +0 -54
- package/components/spinner.tsx +0 -44
- package/components/text-input.tsx +0 -61
- package/components/virtual-list.tsx +0 -56
- package/dist/cli.d.mts +0 -1
- package/dist/cli.mjs.map +0 -1
- package/layout/dashboard.tsx +0 -953
- package/layout/live-resize.tsx +0 -282
- package/layout/overflow.tsx +0 -51
- package/layout/text-layout.tsx +0 -283
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
import { t as _usingCtx } from "../usingCtx-CsEf0xO3.mjs";
|
|
2
|
+
import { t as require_jsx_runtime } from "../jsx-runtime-dMs_8fNu.mjs";
|
|
3
|
+
import { t as ExampleBanner } from "../_banner-DLPxCqVy.mjs";
|
|
4
|
+
import { useCallback, useDeferredValue, useMemo, useState } from "react";
|
|
5
|
+
import { Box, Divider, Kbd, Lead, ListView, Muted, Text, TextInput, createTerm, render, useApp, useBoxRect, useInput } from "silvery";
|
|
6
|
+
//#region apps/data-explorer.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Data Explorer — Process Table Example
|
|
9
|
+
*
|
|
10
|
+
* A process explorer with a searchable, scrollable table demonstrating:
|
|
11
|
+
* - Table-like display with responsive column widths via useBoxRect()
|
|
12
|
+
* - TextInput for live search/filter with useDeferredValue
|
|
13
|
+
* - ListView for smooth scrolling through 500+ rows
|
|
14
|
+
* - Keyboard navigation with j/k and vim-style jumps
|
|
15
|
+
* - Color-coded status indicators
|
|
16
|
+
*
|
|
17
|
+
* Usage: bun run examples/apps/data-explorer.tsx
|
|
18
|
+
*
|
|
19
|
+
* Controls:
|
|
20
|
+
* j/k or Up/Down - Navigate rows
|
|
21
|
+
* d/u - Half-page down/up
|
|
22
|
+
* g/G - Jump to first/last
|
|
23
|
+
* / - Toggle search mode
|
|
24
|
+
* Esc - Exit search / quit
|
|
25
|
+
* q - Quit (when not searching)
|
|
26
|
+
*/
|
|
27
|
+
var import_jsx_runtime = require_jsx_runtime();
|
|
28
|
+
const meta = {
|
|
29
|
+
name: "Data Explorer",
|
|
30
|
+
description: "Process explorer table with search, ListView, and responsive column widths",
|
|
31
|
+
features: [
|
|
32
|
+
"useBoxRect()",
|
|
33
|
+
"TextInput",
|
|
34
|
+
"useInput()",
|
|
35
|
+
"responsive layout",
|
|
36
|
+
"useDeferredValue"
|
|
37
|
+
]
|
|
38
|
+
};
|
|
39
|
+
const PROCESS_NAMES = [
|
|
40
|
+
"node",
|
|
41
|
+
"python3",
|
|
42
|
+
"nginx",
|
|
43
|
+
"redis-server",
|
|
44
|
+
"postgres",
|
|
45
|
+
"docker",
|
|
46
|
+
"sshd",
|
|
47
|
+
"systemd",
|
|
48
|
+
"cron",
|
|
49
|
+
"rsyslogd",
|
|
50
|
+
"webpack",
|
|
51
|
+
"vite",
|
|
52
|
+
"chrome",
|
|
53
|
+
"firefox",
|
|
54
|
+
"code",
|
|
55
|
+
"vim",
|
|
56
|
+
"tmux",
|
|
57
|
+
"bash",
|
|
58
|
+
"zsh",
|
|
59
|
+
"containerd",
|
|
60
|
+
"kubelet",
|
|
61
|
+
"etcd",
|
|
62
|
+
"coredns",
|
|
63
|
+
"flannel",
|
|
64
|
+
"prometheus",
|
|
65
|
+
"grafana",
|
|
66
|
+
"elasticsearch",
|
|
67
|
+
"kibana",
|
|
68
|
+
"logstash",
|
|
69
|
+
"rabbitmq",
|
|
70
|
+
"kafka",
|
|
71
|
+
"zookeeper",
|
|
72
|
+
"consul",
|
|
73
|
+
"vault",
|
|
74
|
+
"haproxy",
|
|
75
|
+
"traefik",
|
|
76
|
+
"envoy",
|
|
77
|
+
"istio-proxy",
|
|
78
|
+
"jaeger",
|
|
79
|
+
"mysql",
|
|
80
|
+
"mongo",
|
|
81
|
+
"cassandra",
|
|
82
|
+
"clickhouse",
|
|
83
|
+
"influxdb",
|
|
84
|
+
"jenkins",
|
|
85
|
+
"gitlab-runner",
|
|
86
|
+
"buildkitd",
|
|
87
|
+
"registry",
|
|
88
|
+
"cadvisor",
|
|
89
|
+
"node-exporter",
|
|
90
|
+
"alertmanager",
|
|
91
|
+
"telegraf",
|
|
92
|
+
"bun",
|
|
93
|
+
"deno",
|
|
94
|
+
"esbuild",
|
|
95
|
+
"swc",
|
|
96
|
+
"turbo",
|
|
97
|
+
"pnpm"
|
|
98
|
+
];
|
|
99
|
+
const USERS = [
|
|
100
|
+
"root",
|
|
101
|
+
"www-data",
|
|
102
|
+
"postgres",
|
|
103
|
+
"redis",
|
|
104
|
+
"node",
|
|
105
|
+
"admin",
|
|
106
|
+
"deploy",
|
|
107
|
+
"monitor"
|
|
108
|
+
];
|
|
109
|
+
const STATUSES = [
|
|
110
|
+
"running",
|
|
111
|
+
"sleeping",
|
|
112
|
+
"stopped",
|
|
113
|
+
"zombie"
|
|
114
|
+
];
|
|
115
|
+
function seededRandom(seed) {
|
|
116
|
+
let s = seed;
|
|
117
|
+
return () => {
|
|
118
|
+
s = s * 1664525 + 1013904223 & 2147483647;
|
|
119
|
+
return s / 2147483647;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function formatUptime(seconds) {
|
|
123
|
+
if (seconds < 60) return `${seconds}s`;
|
|
124
|
+
if (seconds < 3600) return `${Math.floor(seconds / 60)}m`;
|
|
125
|
+
if (seconds < 86400) return `${Math.floor(seconds / 3600)}h${Math.floor(seconds % 3600 / 60)}m`;
|
|
126
|
+
return `${Math.floor(seconds / 86400)}d${Math.floor(seconds % 86400 / 3600)}h`;
|
|
127
|
+
}
|
|
128
|
+
function generateProcesses(count) {
|
|
129
|
+
const rng = seededRandom(42);
|
|
130
|
+
const processes = [];
|
|
131
|
+
for (let i = 0; i < count; i++) {
|
|
132
|
+
const nameBase = PROCESS_NAMES[Math.floor(rng() * PROCESS_NAMES.length)];
|
|
133
|
+
const name = rng() > .6 ? `${nameBase}:${Math.floor(rng() * 20)}` : nameBase;
|
|
134
|
+
const status = rng() < .7 ? "running" : STATUSES[Math.floor(rng() * STATUSES.length)];
|
|
135
|
+
processes.push({
|
|
136
|
+
pid: 1e3 + i,
|
|
137
|
+
name,
|
|
138
|
+
cpu: status === "running" ? Math.round(rng() * 1e3) / 10 : 0,
|
|
139
|
+
mem: Math.round(rng() * 500) / 10,
|
|
140
|
+
status,
|
|
141
|
+
user: USERS[Math.floor(rng() * USERS.length)],
|
|
142
|
+
threads: 1 + Math.floor(rng() * 64),
|
|
143
|
+
uptime: formatUptime(Math.floor(rng() * 864e3))
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
return processes.sort((a, b) => b.cpu - a.cpu);
|
|
147
|
+
}
|
|
148
|
+
const ALL_PROCESSES = generateProcesses(600);
|
|
149
|
+
const STATUS_COLORS = {
|
|
150
|
+
running: "$success",
|
|
151
|
+
sleeping: "$muted",
|
|
152
|
+
stopped: "$warning",
|
|
153
|
+
zombie: "$error"
|
|
154
|
+
};
|
|
155
|
+
const STATUS_ICONS = {
|
|
156
|
+
running: "▶",
|
|
157
|
+
sleeping: "◌",
|
|
158
|
+
stopped: "■",
|
|
159
|
+
zombie: "☠"
|
|
160
|
+
};
|
|
161
|
+
/** Column layout helper -- computes column widths based on available space */
|
|
162
|
+
function useColumns(totalWidth) {
|
|
163
|
+
return useMemo(() => {
|
|
164
|
+
const pidW = 6;
|
|
165
|
+
const cpuW = 7;
|
|
166
|
+
const memW = 7;
|
|
167
|
+
const statusW = 10;
|
|
168
|
+
const threadsW = 5;
|
|
169
|
+
const uptimeW = 8;
|
|
170
|
+
const userW = 10;
|
|
171
|
+
const fixed = pidW + cpuW + memW + statusW + threadsW + uptimeW + userW + 8;
|
|
172
|
+
return {
|
|
173
|
+
pidW,
|
|
174
|
+
nameW: Math.max(10, totalWidth - fixed),
|
|
175
|
+
cpuW,
|
|
176
|
+
memW,
|
|
177
|
+
statusW,
|
|
178
|
+
userW,
|
|
179
|
+
threadsW,
|
|
180
|
+
uptimeW
|
|
181
|
+
};
|
|
182
|
+
}, [totalWidth]);
|
|
183
|
+
}
|
|
184
|
+
function TableHeader({ width }) {
|
|
185
|
+
const cols = useColumns(width);
|
|
186
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Box, {
|
|
187
|
+
paddingX: 1,
|
|
188
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, {
|
|
189
|
+
bold: true,
|
|
190
|
+
color: "$muted",
|
|
191
|
+
children: [
|
|
192
|
+
"PID".padEnd(cols.pidW),
|
|
193
|
+
"NAME".padEnd(cols.nameW),
|
|
194
|
+
"CPU%".padStart(cols.cpuW),
|
|
195
|
+
"MEM%".padStart(cols.memW),
|
|
196
|
+
" ",
|
|
197
|
+
"STATUS".padEnd(cols.statusW),
|
|
198
|
+
"USER".padEnd(cols.userW),
|
|
199
|
+
"THR".padStart(cols.threadsW),
|
|
200
|
+
" ",
|
|
201
|
+
"UPTIME".padStart(cols.uptimeW)
|
|
202
|
+
]
|
|
203
|
+
})
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
function ProcessRow({ proc, isSelected, width }) {
|
|
207
|
+
const cols = useColumns(width);
|
|
208
|
+
const cpuColor = proc.cpu > 80 ? "$error" : proc.cpu > 40 ? "$warning" : "$success";
|
|
209
|
+
const memColor = proc.mem > 40 ? "$warning" : "$muted";
|
|
210
|
+
const displayName = proc.name.length > cols.nameW - 1 ? proc.name.slice(0, cols.nameW - 2) + "…" : proc.name;
|
|
211
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Box, {
|
|
212
|
+
paddingX: 1,
|
|
213
|
+
backgroundColor: isSelected ? "$primary" : void 0,
|
|
214
|
+
children: [
|
|
215
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, {
|
|
216
|
+
color: isSelected ? "$primary-fg" : "$muted",
|
|
217
|
+
children: String(proc.pid).padEnd(cols.pidW)
|
|
218
|
+
}),
|
|
219
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, {
|
|
220
|
+
bold: isSelected,
|
|
221
|
+
color: isSelected ? "$primary-fg" : void 0,
|
|
222
|
+
children: displayName.padEnd(cols.nameW)
|
|
223
|
+
}),
|
|
224
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, {
|
|
225
|
+
color: isSelected ? "$primary-fg" : cpuColor,
|
|
226
|
+
children: [proc.cpu.toFixed(1).padStart(cols.cpuW - 1), "%"]
|
|
227
|
+
}),
|
|
228
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, {
|
|
229
|
+
color: isSelected ? "$primary-fg" : memColor,
|
|
230
|
+
children: [proc.mem.toFixed(1).padStart(cols.memW - 1), "%"]
|
|
231
|
+
}),
|
|
232
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { children: " " }),
|
|
233
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, {
|
|
234
|
+
color: isSelected ? "$primary-fg" : STATUS_COLORS[proc.status],
|
|
235
|
+
children: [
|
|
236
|
+
STATUS_ICONS[proc.status],
|
|
237
|
+
" ",
|
|
238
|
+
proc.status.padEnd(cols.statusW - 2)
|
|
239
|
+
]
|
|
240
|
+
}),
|
|
241
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, {
|
|
242
|
+
color: isSelected ? "$primary-fg" : "$muted",
|
|
243
|
+
children: proc.user.padEnd(cols.userW)
|
|
244
|
+
}),
|
|
245
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, {
|
|
246
|
+
color: isSelected ? "$primary-fg" : "$muted",
|
|
247
|
+
children: String(proc.threads).padStart(cols.threadsW)
|
|
248
|
+
}),
|
|
249
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { children: " " }),
|
|
250
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, {
|
|
251
|
+
color: isSelected ? "$primary-fg" : "$muted",
|
|
252
|
+
children: proc.uptime.padStart(cols.uptimeW)
|
|
253
|
+
})
|
|
254
|
+
]
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function SummaryBar({ processes, query }) {
|
|
258
|
+
const stats = useMemo(() => {
|
|
259
|
+
let running = 0;
|
|
260
|
+
let totalCpu = 0;
|
|
261
|
+
let totalMem = 0;
|
|
262
|
+
for (const p of processes) {
|
|
263
|
+
if (p.status === "running") running++;
|
|
264
|
+
totalCpu += p.cpu;
|
|
265
|
+
totalMem += p.mem;
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
running,
|
|
269
|
+
totalCpu: totalCpu.toFixed(1),
|
|
270
|
+
totalMem: totalMem.toFixed(1)
|
|
271
|
+
};
|
|
272
|
+
}, [processes]);
|
|
273
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Box, {
|
|
274
|
+
paddingX: 1,
|
|
275
|
+
gap: 2,
|
|
276
|
+
children: [
|
|
277
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, {
|
|
278
|
+
bold: true,
|
|
279
|
+
children: processes.length
|
|
280
|
+
}),
|
|
281
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Muted, { children: "processes" }),
|
|
282
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, {
|
|
283
|
+
color: "$success",
|
|
284
|
+
bold: true,
|
|
285
|
+
children: stats.running
|
|
286
|
+
}),
|
|
287
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Muted, { children: "running" }),
|
|
288
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Muted, { children: "|" }),
|
|
289
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, {
|
|
290
|
+
color: "$primary",
|
|
291
|
+
children: [
|
|
292
|
+
"CPU: ",
|
|
293
|
+
stats.totalCpu,
|
|
294
|
+
"%"
|
|
295
|
+
]
|
|
296
|
+
}),
|
|
297
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, {
|
|
298
|
+
color: "$warning",
|
|
299
|
+
children: [
|
|
300
|
+
"MEM: ",
|
|
301
|
+
stats.totalMem,
|
|
302
|
+
"%"
|
|
303
|
+
]
|
|
304
|
+
}),
|
|
305
|
+
query && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Muted, { children: "|" }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, {
|
|
306
|
+
dim: true,
|
|
307
|
+
children: [
|
|
308
|
+
"filter: \"",
|
|
309
|
+
query,
|
|
310
|
+
"\""
|
|
311
|
+
]
|
|
312
|
+
})] })
|
|
313
|
+
]
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
/** Inner component that reads the flex container's height */
|
|
317
|
+
function ProcessListArea({ processes, cursor, width }) {
|
|
318
|
+
const { height } = useBoxRect();
|
|
319
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ListView, {
|
|
320
|
+
items: processes,
|
|
321
|
+
height,
|
|
322
|
+
estimateHeight: 1,
|
|
323
|
+
scrollTo: cursor,
|
|
324
|
+
overscan: 5,
|
|
325
|
+
renderItem: (proc, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProcessRow, {
|
|
326
|
+
proc,
|
|
327
|
+
isSelected: index === cursor,
|
|
328
|
+
width
|
|
329
|
+
}, proc.pid)
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
function DataExplorer() {
|
|
333
|
+
const { exit } = useApp();
|
|
334
|
+
const { width } = useBoxRect();
|
|
335
|
+
const [cursor, setCursor] = useState(0);
|
|
336
|
+
const [searchMode, setSearchMode] = useState(false);
|
|
337
|
+
const [query, setQuery] = useState("");
|
|
338
|
+
const deferredQuery = useDeferredValue(query);
|
|
339
|
+
const filtered = useMemo(() => {
|
|
340
|
+
if (!deferredQuery) return ALL_PROCESSES;
|
|
341
|
+
const q = deferredQuery.toLowerCase();
|
|
342
|
+
return ALL_PROCESSES.filter((p) => p.name.toLowerCase().includes(q) || p.user.toLowerCase().includes(q) || p.status.includes(q) || String(p.pid).includes(q));
|
|
343
|
+
}, [deferredQuery]);
|
|
344
|
+
const listHeight = useMemo(() => Math.max(5, filtered.length), [filtered.length]);
|
|
345
|
+
const halfPage = Math.max(1, Math.floor(listHeight / 4));
|
|
346
|
+
const effectiveCursor = Math.min(cursor, Math.max(0, filtered.length - 1));
|
|
347
|
+
const handleSearchSubmit = useCallback(() => {
|
|
348
|
+
setSearchMode(false);
|
|
349
|
+
}, []);
|
|
350
|
+
useInput(useCallback((input, key) => {
|
|
351
|
+
if (searchMode) {
|
|
352
|
+
if (key.escape) {
|
|
353
|
+
setSearchMode(false);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
if (input === "q" || key.escape) {
|
|
359
|
+
exit();
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
if (input === "/") {
|
|
363
|
+
setSearchMode(true);
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
if (input === "j" || key.downArrow) setCursor((c) => Math.min(filtered.length - 1, c + 1));
|
|
367
|
+
if (input === "k" || key.upArrow) setCursor((c) => Math.max(0, c - 1));
|
|
368
|
+
if (input === "d" || key.pageDown) setCursor((c) => Math.min(filtered.length - 1, c + halfPage));
|
|
369
|
+
if (input === "u" || key.pageUp) setCursor((c) => Math.max(0, c - halfPage));
|
|
370
|
+
if (input === "g" || key.home) setCursor(0);
|
|
371
|
+
if (input === "G" || key.end) setCursor(filtered.length - 1);
|
|
372
|
+
if (key.backspace && query) {
|
|
373
|
+
setQuery("");
|
|
374
|
+
setCursor(0);
|
|
375
|
+
}
|
|
376
|
+
}, [
|
|
377
|
+
searchMode,
|
|
378
|
+
exit,
|
|
379
|
+
filtered.length,
|
|
380
|
+
halfPage,
|
|
381
|
+
query
|
|
382
|
+
]));
|
|
383
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Box, {
|
|
384
|
+
flexDirection: "column",
|
|
385
|
+
flexGrow: 1,
|
|
386
|
+
children: [
|
|
387
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SummaryBar, {
|
|
388
|
+
processes: filtered,
|
|
389
|
+
query: deferredQuery
|
|
390
|
+
}),
|
|
391
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Box, {
|
|
392
|
+
paddingX: 1,
|
|
393
|
+
children: searchMode ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Box, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, {
|
|
394
|
+
color: "$primary",
|
|
395
|
+
bold: true,
|
|
396
|
+
children: ["/", " "]
|
|
397
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TextInput, {
|
|
398
|
+
value: query,
|
|
399
|
+
onChange: (v) => {
|
|
400
|
+
setQuery(v);
|
|
401
|
+
setCursor(0);
|
|
402
|
+
},
|
|
403
|
+
onSubmit: handleSearchSubmit,
|
|
404
|
+
prompt: "",
|
|
405
|
+
isActive: searchMode
|
|
406
|
+
})] }) : query ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Muted, { children: [
|
|
407
|
+
"filter: ",
|
|
408
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, {
|
|
409
|
+
bold: true,
|
|
410
|
+
children: query
|
|
411
|
+
}),
|
|
412
|
+
" (backspace to clear, / to edit)"
|
|
413
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Muted, { children: [
|
|
414
|
+
"Press ",
|
|
415
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Kbd, { children: "/" }),
|
|
416
|
+
" to search"
|
|
417
|
+
] })
|
|
418
|
+
}),
|
|
419
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHeader, { width }),
|
|
420
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Box, {
|
|
421
|
+
paddingX: 1,
|
|
422
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Divider, {})
|
|
423
|
+
}),
|
|
424
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Box, {
|
|
425
|
+
flexGrow: 1,
|
|
426
|
+
flexDirection: "column",
|
|
427
|
+
children: filtered.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProcessListArea, {
|
|
428
|
+
processes: filtered,
|
|
429
|
+
cursor: effectiveCursor,
|
|
430
|
+
width
|
|
431
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Box, {
|
|
432
|
+
paddingX: 1,
|
|
433
|
+
justifyContent: "center",
|
|
434
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Lead, { children: [
|
|
435
|
+
"No processes match \"",
|
|
436
|
+
deferredQuery,
|
|
437
|
+
"\""
|
|
438
|
+
] })
|
|
439
|
+
})
|
|
440
|
+
}),
|
|
441
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Box, {
|
|
442
|
+
paddingX: 1,
|
|
443
|
+
justifyContent: "space-between",
|
|
444
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Muted, { children: [
|
|
445
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Kbd, { children: "j/k" }),
|
|
446
|
+
" navigate ",
|
|
447
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Kbd, { children: "d/u" }),
|
|
448
|
+
" half-page ",
|
|
449
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Kbd, { children: "g/G" }),
|
|
450
|
+
" start/end ",
|
|
451
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Kbd, { children: "/" }),
|
|
452
|
+
" search ",
|
|
453
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Kbd, { children: "Esc/q" }),
|
|
454
|
+
" ",
|
|
455
|
+
"quit"
|
|
456
|
+
] }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Muted, { children: [
|
|
457
|
+
effectiveCursor + 1,
|
|
458
|
+
"/",
|
|
459
|
+
filtered.length
|
|
460
|
+
] })]
|
|
461
|
+
})
|
|
462
|
+
]
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
async function main() {
|
|
466
|
+
try {
|
|
467
|
+
var _usingCtx$1 = _usingCtx();
|
|
468
|
+
const term = _usingCtx$1.u(createTerm());
|
|
469
|
+
const { waitUntilExit } = await render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ExampleBanner, {
|
|
470
|
+
meta,
|
|
471
|
+
controls: "j/k navigate d/u half-page g/G start/end / search Esc/q quit",
|
|
472
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DataExplorer, {})
|
|
473
|
+
}), term);
|
|
474
|
+
await waitUntilExit();
|
|
475
|
+
} catch (_) {
|
|
476
|
+
_usingCtx$1.e = _;
|
|
477
|
+
} finally {
|
|
478
|
+
_usingCtx$1.d();
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
if (import.meta.main) await main();
|
|
482
|
+
//#endregion
|
|
483
|
+
export { DataExplorer, main, meta };
|