create-termui-app 0.1.3 → 0.1.5
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 +54 -10
- package/dist/index.js +358 -75
- package/dist/index.js.map +1 -1
- package/package.json +11 -8
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -17,23 +17,28 @@ The CLI walks you through a few choices, then generates a working project.
|
|
|
17
17
|
|
|
18
18
|
| Template | What you get |
|
|
19
19
|
|----------|-------------|
|
|
20
|
-
| Empty | One file, no dependencies beyond core. Start
|
|
21
|
-
| Dashboard | Real-time gauges, tables,
|
|
22
|
-
| Interactive Tool | Forms, selects, prompts. Good for CLI wizards |
|
|
20
|
+
| Empty | One file, no dependencies beyond core. Start fresh |
|
|
21
|
+
| Dashboard | Real-time gauges, tables, a status bar, and Grid layout |
|
|
22
|
+
| Interactive Tool | Forms, selects, and prompts. Good for CLI wizards |
|
|
23
23
|
| CLI Wrapper | Wraps an existing shell command in a TermUI interface |
|
|
24
24
|
|
|
25
|
+
All templates include:
|
|
26
|
+
- `AutoThemeProvider` at the app root for automatic theme detection
|
|
27
|
+
- `ErrorBoundary` wrapping for crash recovery
|
|
28
|
+
- `useKeymap` for all key handling instead of raw `useInput`
|
|
29
|
+
|
|
25
30
|
## Themes
|
|
26
31
|
|
|
27
|
-
Choose one of
|
|
32
|
+
Choose one of six built-in themes during setup: Default, Cyberpunk, Nord, Dracula, Catppuccin, or Solarized. Change it later in `termui.config.ts` or switch at runtime with `useTheme()`.
|
|
28
33
|
|
|
29
34
|
## Optional features
|
|
30
35
|
|
|
31
36
|
The CLI asks which extras to include:
|
|
32
37
|
|
|
33
|
-
- **Screen Router**
|
|
34
|
-
- **Data Providers**
|
|
35
|
-
- **Hot Reload**
|
|
36
|
-
- **Testing**
|
|
38
|
+
- **Screen Router** - File-based navigation between screens
|
|
39
|
+
- **Data Providers** - CPU, memory, disk monitoring via `@termuijs/data` hooks
|
|
40
|
+
- **Hot Reload** - Auto-restart on save via `@termuijs/dev-server`
|
|
41
|
+
- **Testing** - Vitest config with `@termuijs/testing` ready to go
|
|
37
42
|
|
|
38
43
|
## Generated project
|
|
39
44
|
|
|
@@ -48,8 +53,47 @@ my-app/
|
|
|
48
53
|
index.tsx
|
|
49
54
|
```
|
|
50
55
|
|
|
51
|
-
Everything is TypeScript
|
|
52
|
-
|
|
56
|
+
Everything is TypeScript. The dev server is preconfigured in the `dev` script.
|
|
57
|
+
|
|
58
|
+
## Modern patterns in generated code
|
|
59
|
+
|
|
60
|
+
All templates use current TermUI patterns:
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
// Generated entry file example (dashboard template)
|
|
64
|
+
import { AutoThemeProvider, ErrorBoundary } from '@termuijs/jsx'
|
|
65
|
+
import { useKeymap } from '@termuijs/jsx'
|
|
66
|
+
import { useCpu, useMemory } from '@termuijs/data'
|
|
67
|
+
import { useNotifications } from '@termuijs/ui'
|
|
68
|
+
|
|
69
|
+
function App() {
|
|
70
|
+
const { notify } = useNotifications()
|
|
71
|
+
|
|
72
|
+
useKeymap({
|
|
73
|
+
'ctrl+c': () => process.exit(0),
|
|
74
|
+
'r': () => notify('Refreshed', { type: 'success' }),
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
const cpu = useCpu(1000)
|
|
78
|
+
const mem = useMemory(1000)
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<Box flexDirection="column" gap={1}>
|
|
82
|
+
<Text bold>System Monitor</Text>
|
|
83
|
+
<gauge label="CPU" value={cpu.usage / 100} />
|
|
84
|
+
<gauge label="MEM" value={mem.used / mem.total} />
|
|
85
|
+
</Box>
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
render(
|
|
90
|
+
<AutoThemeProvider fallback="dracula">
|
|
91
|
+
<ErrorBoundary fallback={(e) => <Text color="red">{e.message}</Text>}>
|
|
92
|
+
<App />
|
|
93
|
+
</ErrorBoundary>
|
|
94
|
+
</AutoThemeProvider>
|
|
95
|
+
)
|
|
96
|
+
```
|
|
53
97
|
|
|
54
98
|
## Documentation
|
|
55
99
|
|
package/dist/index.js
CHANGED
|
@@ -54,9 +54,9 @@ function generateProject(config) {
|
|
|
54
54
|
private: true,
|
|
55
55
|
type: "module",
|
|
56
56
|
scripts: {
|
|
57
|
-
dev: "
|
|
57
|
+
dev: "bun --watch src/index.tsx",
|
|
58
58
|
build: "tsup src/index.tsx --format esm",
|
|
59
|
-
start: "
|
|
59
|
+
start: "bun dist/index.js"
|
|
60
60
|
},
|
|
61
61
|
dependencies: {
|
|
62
62
|
"@termuijs/core": "latest",
|
|
@@ -70,9 +70,12 @@ function generateProject(config) {
|
|
|
70
70
|
...config.features.router ? { "@termuijs/router": "latest" } : {}
|
|
71
71
|
},
|
|
72
72
|
devDependencies: {
|
|
73
|
-
|
|
73
|
+
"@types/bun": "latest",
|
|
74
74
|
tsup: "^8.0.0",
|
|
75
75
|
typescript: "^5.3.0"
|
|
76
|
+
},
|
|
77
|
+
engines: {
|
|
78
|
+
bun: ">=1.3.0"
|
|
76
79
|
}
|
|
77
80
|
}, null, 2) + "\n"
|
|
78
81
|
});
|
|
@@ -126,94 +129,374 @@ export default defineConfig({
|
|
|
126
129
|
function generateEmptyTemplate(config) {
|
|
127
130
|
return [{
|
|
128
131
|
path: "src/index.tsx",
|
|
129
|
-
content:
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
|
|
132
|
+
content: `/** @jsxImportSource @termuijs/jsx */
|
|
133
|
+
import { render, useState, useKeymap, ErrorBoundary } from '@termuijs/jsx';
|
|
134
|
+
import { AutoThemeProvider } from '@termuijs/tss';
|
|
135
|
+
|
|
136
|
+
function App() {
|
|
137
|
+
const [count, setCount] = useState(0);
|
|
138
|
+
|
|
139
|
+
useKeymap([
|
|
140
|
+
{ key: 'q', action: () => process.exit(0), description: 'Quit' },
|
|
141
|
+
{ key: 'c', ctrl: true, action: () => process.exit(0), description: 'Quit' },
|
|
142
|
+
{ key: '+', action: () => setCount(c => c + 1), description: 'Increment' },
|
|
143
|
+
{ key: '-', action: () => setCount(c => Math.max(0, c - 1)), description: 'Decrement' },
|
|
144
|
+
]);
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<AutoThemeProvider>
|
|
148
|
+
<ErrorBoundary fallback={(err) => <text color="red">{err.message}</text>}>
|
|
149
|
+
<box border="single" padding={1}>
|
|
150
|
+
<text bold>Welcome to ${config.name}!</text>
|
|
151
|
+
<text>Edit src/index.tsx to get started.</text>
|
|
152
|
+
<text>Count: {count} (+/- to change, q to quit)</text>
|
|
153
|
+
</box>
|
|
154
|
+
</ErrorBoundary>
|
|
155
|
+
</AutoThemeProvider>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
render(<App />, { title: '${config.name}' });
|
|
137
160
|
`
|
|
138
161
|
}];
|
|
139
162
|
}
|
|
140
163
|
function generateDashboardTemplate(config) {
|
|
141
164
|
return [{
|
|
142
165
|
path: "src/index.tsx",
|
|
143
|
-
content:
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
166
|
+
content: `/** @jsxImportSource @termuijs/jsx */
|
|
167
|
+
import { render, useState, useEffect, useKeymap, ErrorBoundary } from '@termuijs/jsx';
|
|
168
|
+
import { AutoThemeProvider, useTheme } from '@termuijs/tss';
|
|
169
|
+
${config.features.dataProviders ? "import { useCpu, useMemory, useDisk } from '@termuijs/data';" : ""}
|
|
170
|
+
|
|
171
|
+
// \u2500\u2500 Sample static data (replace with live hooks when dataProviders = true) \u2500\u2500
|
|
172
|
+
${config.features.dataProviders ? "" : `const SAMPLE_PROCS = [
|
|
173
|
+
{ Name: 'node', PID: 1234, 'CPU%': '5.0', 'MEM%': '2.1' },
|
|
174
|
+
{ Name: 'chrome', PID: 5678, 'CPU%': '12.3', 'MEM%': '8.4' },
|
|
175
|
+
{ Name: 'bash', PID: 9012, 'CPU%': '0.1', 'MEM%': '0.3' },
|
|
176
|
+
];`}
|
|
177
|
+
|
|
178
|
+
function GaugeRow({ label, value }: { label: string; value: number }) {
|
|
179
|
+
const theme = useTheme();
|
|
180
|
+
const filled = Math.round(value * 20);
|
|
181
|
+
const empty = 20 - filled;
|
|
182
|
+
const bar = '[' + '#'.repeat(filled) + '-'.repeat(empty) + ']';
|
|
183
|
+
return (
|
|
184
|
+
<row gap={2}>
|
|
185
|
+
<text color={theme.colors.primary}>{label.padEnd(4)}</text>
|
|
186
|
+
<text>{bar}</text>
|
|
187
|
+
<text>{(value * 100).toFixed(1).padStart(5)}%</text>
|
|
188
|
+
</row>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function Dashboard() {
|
|
193
|
+
const [tick, setTick] = useState(0);
|
|
194
|
+
${config.features.dataProviders ? ` const cpu = useCpu();
|
|
195
|
+
const mem = useMemory();
|
|
196
|
+
const disk = useDisk();
|
|
197
|
+
const cpuVal = (cpu.percent ?? 0) / 100;
|
|
198
|
+
const memVal = (mem.percent ?? 0) / 100;
|
|
199
|
+
const diskVal = (disk.percent ?? 0) / 100;` : ` const [cpuVal, setCpuVal] = useState(0.45);
|
|
200
|
+
const [memVal, setMemVal] = useState(0.62);
|
|
201
|
+
const [diskVal, setDiskVal] = useState(0.38);
|
|
202
|
+
|
|
203
|
+
// Simulate live updates
|
|
204
|
+
useEffect(() => {
|
|
205
|
+
const id = setInterval(() => {
|
|
206
|
+
setCpuVal(v => Math.min(1, Math.max(0, v + (Math.random() - 0.5) * 0.05)));
|
|
207
|
+
setMemVal(v => Math.min(1, Math.max(0, v + (Math.random() - 0.5) * 0.02)));
|
|
208
|
+
setDiskVal(v => Math.min(1, Math.max(0, v + (Math.random() - 0.5) * 0.01)));
|
|
209
|
+
setTick(t => t + 1);
|
|
210
|
+
}, 1000);
|
|
211
|
+
return () => clearInterval(id);
|
|
212
|
+
}, []);`}
|
|
213
|
+
|
|
214
|
+
useKeymap([
|
|
215
|
+
{ key: 'q', action: () => process.exit(0), description: 'Quit' },
|
|
216
|
+
{ key: 'c', ctrl: true, action: () => process.exit(0), description: 'Quit' },
|
|
217
|
+
{ key: 'r', action: () => setTick(t => t + 1), description: 'Refresh' },
|
|
218
|
+
]);
|
|
219
|
+
|
|
220
|
+
const theme = useTheme();
|
|
221
|
+
|
|
222
|
+
return (
|
|
223
|
+
<box flexDirection="column" padding={1}>
|
|
224
|
+
<text bold color={theme.colors.primary}>${config.name} Dashboard</text>
|
|
225
|
+
<divider />
|
|
226
|
+
|
|
227
|
+
<grid columns={12} gap={1}>
|
|
228
|
+
{/* Gauges \u2014 top row */}
|
|
229
|
+
<box width="100%" flexDirection="column" border="single" padding={1} flexGrow={4}>
|
|
230
|
+
<text bold>System Resources</text>
|
|
231
|
+
<GaugeRow label="CPU" value={cpuVal} />
|
|
232
|
+
<GaugeRow label="MEM" value={memVal} />
|
|
233
|
+
<GaugeRow label="DISK" value={diskVal} />
|
|
234
|
+
</box>
|
|
235
|
+
|
|
236
|
+
{/* Info panel */}
|
|
237
|
+
<box width="100%" flexDirection="column" border="single" padding={1} flexGrow={8}>
|
|
238
|
+
<text bold>Process Summary</text>
|
|
239
|
+
<text color={theme.colors.muted}>Press r to refresh, q to quit</text>
|
|
240
|
+
<text>Tick: {tick}</text>
|
|
241
|
+
${config.features.dataProviders ? ` <skeleton variant="shimmer" />` : ` <text>node PID:1234 CPU: {(cpuVal * 100).toFixed(1)}%</text>
|
|
242
|
+
<text>chrome PID:5678 MEM: {(memVal * 100).toFixed(1)}%</text>`}
|
|
243
|
+
</box>
|
|
244
|
+
</grid>
|
|
245
|
+
</box>
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function App() {
|
|
250
|
+
return (
|
|
251
|
+
<AutoThemeProvider>
|
|
252
|
+
<ErrorBoundary fallback={(err) => (
|
|
253
|
+
<box border="single" borderColor="red" padding={1}>
|
|
254
|
+
<text color="red" bold>Dashboard Error</text>
|
|
255
|
+
<text>{err.message}</text>
|
|
256
|
+
</box>
|
|
257
|
+
)}>
|
|
258
|
+
<Dashboard />
|
|
259
|
+
</ErrorBoundary>
|
|
260
|
+
</AutoThemeProvider>
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
render(<App />, { title: '${config.name}' });
|
|
174
265
|
`
|
|
175
266
|
}];
|
|
176
267
|
}
|
|
177
268
|
function generateInteractiveTemplate(config) {
|
|
178
269
|
return [{
|
|
179
270
|
path: "src/index.tsx",
|
|
180
|
-
content:
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
271
|
+
content: `/** @jsxImportSource @termuijs/jsx */
|
|
272
|
+
import { render, useState, useKeymap, useRef, ErrorBoundary } from '@termuijs/jsx';
|
|
273
|
+
import { AutoThemeProvider, useTheme } from '@termuijs/tss';
|
|
274
|
+
import { caps } from '@termuijs/core';
|
|
275
|
+
|
|
276
|
+
// ASCII-safe symbols
|
|
277
|
+
const CHECK = caps.unicode ? '\u2713' : 'v';
|
|
278
|
+
const BULLET = caps.unicode ? '\u203A' : '>';
|
|
279
|
+
const SEP = caps.unicode ? '\u2500'.repeat(40) : '-'.repeat(40);
|
|
280
|
+
|
|
281
|
+
const INITIAL_ITEMS = ['Option A', 'Option B', 'Option C'];
|
|
282
|
+
|
|
283
|
+
function InteractiveTool() {
|
|
284
|
+
const [items, setItems] = useState<string[]>(INITIAL_ITEMS);
|
|
285
|
+
const [selected, setSelected] = useState(0);
|
|
286
|
+
const [input, setInput] = useState('');
|
|
287
|
+
const [done, setDone] = useState<string[]>([]);
|
|
288
|
+
const theme = useTheme();
|
|
289
|
+
|
|
290
|
+
useKeymap([
|
|
291
|
+
{ key: 'q', action: () => process.exit(0), description: 'Quit' },
|
|
292
|
+
{ key: 'c', ctrl: true, action: () => process.exit(0), description: 'Quit' },
|
|
293
|
+
{ key: 'ArrowUp', action: () => setSelected(s => Math.max(0, s - 1)), description: 'Move up' },
|
|
294
|
+
{ key: 'ArrowDown', action: () => setSelected(s => Math.min(items.length - 1, s + 1)), description: 'Move down' },
|
|
295
|
+
{ key: 'k', action: () => setSelected(s => Math.max(0, s - 1)), description: 'Move up (vim)' },
|
|
296
|
+
{ key: 'j', action: () => setSelected(s => Math.min(items.length - 1, s + 1)), description: 'Move down (vim)' },
|
|
297
|
+
{ key: 'Enter', action: () => {
|
|
298
|
+
const item = items[selected];
|
|
299
|
+
if (item) setDone(d => d.includes(item) ? d.filter(x => x !== item) : [...d, item]);
|
|
300
|
+
}, description: 'Toggle selected' },
|
|
301
|
+
{ key: 'Backspace', action: () => setInput(v => v.slice(0, -1)), description: 'Delete char' },
|
|
302
|
+
{ key: 'n', action: () => {
|
|
303
|
+
if (input.trim()) {
|
|
304
|
+
setItems(prev => [...prev, input.trim()]);
|
|
305
|
+
setInput('');
|
|
306
|
+
}
|
|
307
|
+
}, description: 'Add new item' },
|
|
308
|
+
]);
|
|
309
|
+
|
|
310
|
+
return (
|
|
311
|
+
<box flexDirection="column" padding={1}>
|
|
312
|
+
<text bold color={theme.colors.primary}>${config.name}</text>
|
|
313
|
+
<text color={theme.colors.muted}>j/k or arrows: navigate | Enter: toggle | n: add | q: quit</text>
|
|
314
|
+
<text>{SEP}</text>
|
|
315
|
+
|
|
316
|
+
<box flexDirection="column">
|
|
317
|
+
{items.map((item, i) => (
|
|
318
|
+
<row key={item} gap={1}>
|
|
319
|
+
<text color={i === selected ? theme.colors.primary : undefined}>
|
|
320
|
+
{i === selected ? BULLET : ' '}
|
|
321
|
+
</text>
|
|
322
|
+
<text color={done.includes(item) ? theme.colors.success : undefined}>
|
|
323
|
+
{done.includes(item) ? CHECK + ' ' : ' '}{item}
|
|
324
|
+
</text>
|
|
325
|
+
</row>
|
|
326
|
+
))}
|
|
327
|
+
</box>
|
|
328
|
+
|
|
329
|
+
<text>{SEP}</text>
|
|
330
|
+
<row gap={1}>
|
|
331
|
+
<text color={theme.colors.muted}>New item:</text>
|
|
332
|
+
<text>{input}_</text>
|
|
333
|
+
</row>
|
|
334
|
+
<text color={theme.colors.muted} dim>Type letters then press n to add</text>
|
|
335
|
+
</box>
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function App() {
|
|
340
|
+
return (
|
|
341
|
+
<AutoThemeProvider>
|
|
342
|
+
<ErrorBoundary fallback={(err) => (
|
|
343
|
+
<box border="single" borderColor="red" padding={1}>
|
|
344
|
+
<text color="red" bold>Error</text>
|
|
345
|
+
<text>{err.message}</text>
|
|
346
|
+
</box>
|
|
347
|
+
)}>
|
|
348
|
+
<InteractiveTool />
|
|
349
|
+
</ErrorBoundary>
|
|
350
|
+
</AutoThemeProvider>
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
render(<App />, { title: '${config.name}' });
|
|
194
355
|
`
|
|
195
356
|
}];
|
|
196
357
|
}
|
|
197
358
|
function generateCliWrapperTemplate(config) {
|
|
198
359
|
return [{
|
|
199
360
|
path: "src/index.tsx",
|
|
200
|
-
content:
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
361
|
+
content: `/** @jsxImportSource @termuijs/jsx */
|
|
362
|
+
import { render, useState, useEffect, useKeymap, ErrorBoundary } from '@termuijs/jsx';
|
|
363
|
+
import { AutoThemeProvider, useTheme } from '@termuijs/tss';
|
|
364
|
+
import { caps } from '@termuijs/core';
|
|
365
|
+
import { spawn } from 'node:child_process';
|
|
366
|
+
|
|
367
|
+
// ASCII-safe symbols for terminals without full unicode support
|
|
368
|
+
const ICON_RUN = caps.unicode ? '>' : '>';
|
|
369
|
+
const ICON_DONE = caps.unicode ? '*' : '*';
|
|
370
|
+
const ICON_ERR = caps.unicode ? '!' : '!';
|
|
371
|
+
const SEP = '-'.repeat(60);
|
|
372
|
+
|
|
373
|
+
type LogLevel = 'info' | 'debug' | 'error' | 'warn';
|
|
374
|
+
interface LogLine {
|
|
375
|
+
level: LogLevel;
|
|
376
|
+
text: string;
|
|
377
|
+
ts: number;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function levelColor(level: LogLevel): string {
|
|
381
|
+
switch (level) {
|
|
382
|
+
case 'info': return 'green';
|
|
383
|
+
case 'debug': return 'cyan';
|
|
384
|
+
case 'warn': return 'yellow';
|
|
385
|
+
case 'error': return 'red';
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function CliWrapper() {
|
|
390
|
+
const [logs, setLogs] = useState<LogLine[]>([
|
|
391
|
+
{ level: 'info', text: 'Application started', ts: Date.now() },
|
|
392
|
+
{ level: 'debug', text: 'Press r to re-run, q to quit', ts: Date.now() },
|
|
393
|
+
]);
|
|
394
|
+
const [running, setRunning] = useState(false);
|
|
395
|
+
const [exitCode, setExitCode] = useState<number | null>(null);
|
|
396
|
+
const procRef = useRef<any>(null);
|
|
397
|
+
const theme = useTheme();
|
|
398
|
+
|
|
399
|
+
const addLog = (level: LogLevel, text: string) =>
|
|
400
|
+
setLogs(prev => [...prev.slice(-200), { level, text, ts: Date.now() }]);
|
|
401
|
+
|
|
402
|
+
// Example: run 'echo hello' \u2014 replace with your real command
|
|
403
|
+
const runCommand = () => {
|
|
404
|
+
if (running) return;
|
|
405
|
+
setRunning(true);
|
|
406
|
+
setExitCode(null);
|
|
407
|
+
addLog('info', \`\${ICON_RUN} Running command...\`);
|
|
408
|
+
|
|
409
|
+
const proc = spawn('echo', ['Hello from CLI wrapper!']);
|
|
410
|
+
procRef.current = proc;
|
|
411
|
+
proc.stdout.on('data', (d: Buffer) => {
|
|
412
|
+
for (const line of d.toString().split('\\n').filter(Boolean)) {
|
|
413
|
+
addLog('info', line);
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
proc.stderr.on('data', (d: Buffer) => {
|
|
417
|
+
for (const line of d.toString().split('\\n').filter(Boolean)) {
|
|
418
|
+
addLog('error', line);
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
proc.on('close', (code: number | null) => {
|
|
422
|
+
setRunning(false);
|
|
423
|
+
setExitCode(code);
|
|
424
|
+
addLog(code === 0 ? 'info' : 'error',
|
|
425
|
+
\`\${code === 0 ? ICON_DONE : ICON_ERR} Process exited with code \${code ?? 'null'}\`);
|
|
426
|
+
procRef.current = null;
|
|
427
|
+
});
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
// Auto-run on mount, kill process on unmount
|
|
431
|
+
useEffect(() => {
|
|
432
|
+
runCommand();
|
|
433
|
+
return () => {
|
|
434
|
+
if (procRef.current) {
|
|
435
|
+
procRef.current.kill();
|
|
436
|
+
procRef.current = null;
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
}, []);
|
|
440
|
+
|
|
441
|
+
useKeymap([
|
|
442
|
+
{ key: 'q', action: () => process.exit(0), description: 'Quit' },
|
|
443
|
+
{ key: 'c', ctrl: true, action: () => process.exit(0), description: 'Quit' },
|
|
444
|
+
{ key: 'r', action: runCommand, description: 'Re-run command' },
|
|
445
|
+
{ key: 'l', action: () => setLogs([]), description: 'Clear logs' },
|
|
446
|
+
]);
|
|
447
|
+
|
|
448
|
+
return (
|
|
449
|
+
<box flexDirection="column" padding={1}>
|
|
450
|
+
<row gap={2}>
|
|
451
|
+
<text bold color={theme.colors.primary}>${config.name}</text>
|
|
452
|
+
<text color={running ? theme.colors.warning : theme.colors.muted}>
|
|
453
|
+
{running ? 'Running...' : exitCode === null ? 'Ready' : \`Exit: \${exitCode}\`}
|
|
454
|
+
</text>
|
|
455
|
+
<spacer />
|
|
456
|
+
<text color={theme.colors.muted}>r: re-run | l: clear | q: quit</text>
|
|
457
|
+
</row>
|
|
458
|
+
<text>{SEP}</text>
|
|
459
|
+
|
|
460
|
+
<box flexDirection="column" flexGrow={1}>
|
|
461
|
+
{logs.map((line, i) => (
|
|
462
|
+
<row key={i} gap={1}>
|
|
463
|
+
<text color={theme.colors.muted} dim>
|
|
464
|
+
{new Date(line.ts).toLocaleTimeString()}
|
|
465
|
+
</text>
|
|
466
|
+
<text color={levelColor(line.level)} bold>
|
|
467
|
+
{line.level.toUpperCase().padEnd(5)}
|
|
468
|
+
</text>
|
|
469
|
+
<text>{line.text}</text>
|
|
470
|
+
</row>
|
|
471
|
+
))}
|
|
472
|
+
</box>
|
|
473
|
+
|
|
474
|
+
{!caps.color && (
|
|
475
|
+
<text color="yellow" dim>
|
|
476
|
+
Note: running in a terminal without color support (TERM={process.env.TERM ?? 'unset'})
|
|
477
|
+
</text>
|
|
478
|
+
)}
|
|
479
|
+
</box>
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function App() {
|
|
484
|
+
return (
|
|
485
|
+
<AutoThemeProvider>
|
|
486
|
+
<ErrorBoundary fallback={(err) => (
|
|
487
|
+
<box border="single" borderColor="red" padding={1}>
|
|
488
|
+
<text color="red" bold>CLI Wrapper Error</text>
|
|
489
|
+
<text>{err.message}</text>
|
|
490
|
+
<text color="yellow">Check that the command exists and is executable.</text>
|
|
491
|
+
</box>
|
|
492
|
+
)}>
|
|
493
|
+
<CliWrapper />
|
|
494
|
+
</ErrorBoundary>
|
|
495
|
+
</AutoThemeProvider>
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
render(<App />, { title: '${config.name}' });
|
|
217
500
|
`
|
|
218
501
|
}];
|
|
219
502
|
}
|
|
@@ -273,8 +556,8 @@ async function main() {
|
|
|
273
556
|
console.log();
|
|
274
557
|
console.log(` Next steps:`);
|
|
275
558
|
console.log(` cd ${projectName}`);
|
|
276
|
-
console.log(`
|
|
277
|
-
console.log(`
|
|
559
|
+
console.log(` bun install`);
|
|
560
|
+
console.log(` bun run dev`);
|
|
278
561
|
console.log();
|
|
279
562
|
}
|
|
280
563
|
main().catch((err) => {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/prompts.ts","../src/templates.ts"],"sourcesContent":["// ─────────────────────────────────────────────────────\n// create-termui-app — Interactive CLI scaffolding tool\n// ─────────────────────────────────────────────────────\n\nimport { resolve, join } from 'node:path';\nimport { mkdirSync, writeFileSync, existsSync } from 'node:fs';\nimport { getBuiltinThemeNames } from '@termuijs/tss';\nimport { textPrompt, selectPrompt, multiSelectPrompt } from './prompts.js';\nimport { generateProject, type ProjectConfig } from './templates.js';\n\nconst TEMPLATES = ['Empty (start from scratch)', 'Dashboard (real-time data)', 'Interactive Tool (forms, prompts)', 'CLI Wrapper (wrap existing CLI)'];\nconst TEMPLATE_KEYS = ['empty', 'dashboard', 'interactive-tool', 'cli-wrapper'] as const;\nconst FEATURES = ['Screen Router', 'Data Providers', 'Hot Reload'];\n\nasync function main() {\n console.log();\n console.log(' ┌──────────────────────────────────┐');\n console.log(' │ create-termui-app │');\n console.log(' │ The React/Next.js for CLI apps │');\n console.log(' └──────────────────────────────────┘');\n console.log();\n\n // ── Get project name from args or prompt ──\n let projectName = process.argv[2];\n if (!projectName) {\n projectName = await textPrompt('Project name', 'my-termui-app');\n }\n\n // ── Template selection ──\n const templateIdx = await selectPrompt('What kind of app?', TEMPLATES);\n const template = TEMPLATE_KEYS[templateIdx];\n\n // ── Theme selection ──\n const themes = getBuiltinThemeNames();\n const themeIdx = await selectPrompt('Choose a theme', themes.map(t => t.charAt(0).toUpperCase() + t.slice(1)));\n const theme = themes[themeIdx];\n\n // ── Feature selection ──\n const featureDefaults = [false, template === 'dashboard', true]; // Router off, Data on for dashboard, HotReload on\n const featureFlags = await multiSelectPrompt('Features to include', FEATURES, featureDefaults);\n\n const config: ProjectConfig = {\n name: projectName,\n template,\n theme,\n features: {\n router: featureFlags[0],\n dataProviders: featureFlags[1],\n hotReload: featureFlags[2],\n },\n };\n\n // ── Generate project ──\n const projectDir = resolve(process.cwd(), projectName);\n if (existsSync(projectDir)) {\n console.log(`\\n ⚠ Directory \"${projectName}\" already exists. Files may be overwritten.\\n`);\n }\n\n console.log(`\\n Creating ${projectName}...`);\n\n const files = generateProject(config);\n\n for (const file of files) {\n const fullPath = join(projectDir, file.path);\n const dir = fullPath.substring(0, fullPath.lastIndexOf('/'));\n mkdirSync(dir, { recursive: true });\n writeFileSync(fullPath, file.content, 'utf-8');\n console.log(` ✓ ${file.path}`);\n }\n\n console.log();\n console.log(' ┌──────────────────────────────────┐');\n console.log(' │ ✅ Project created successfully! │');\n console.log(' └──────────────────────────────────┘');\n console.log();\n console.log(` Next steps:`);\n console.log(` cd ${projectName}`);\n console.log(` npm install`);\n console.log(` npm run dev`);\n console.log();\n}\n\nmain().catch(err => {\n console.error('Error:', err.message);\n process.exit(1);\n});\n","// ─────────────────────────────────────────────────────\n// Minimal interactive prompts (no external deps)\n// ─────────────────────────────────────────────────────\n\nimport { createInterface } from 'node:readline';\n\nconst rl = () => createInterface({ input: process.stdin, output: process.stdout });\n\nexport async function textPrompt(question: string, defaultValue?: string): Promise<string> {\n return new Promise(resolve => {\n const r = rl();\n const suffix = defaultValue ? ` (${defaultValue})` : '';\n r.question(` ${question}${suffix}: `, answer => {\n r.close();\n resolve(answer.trim() || defaultValue || '');\n });\n });\n}\n\nexport async function selectPrompt(question: string, options: string[]): Promise<number> {\n console.log(`\\n ${question}`);\n for (let i = 0; i < options.length; i++) {\n console.log(` ${i + 1}) ${options[i]}`);\n }\n const answer = await textPrompt('Enter number', '1');\n const idx = parseInt(answer) - 1;\n return Math.max(0, Math.min(idx, options.length - 1));\n}\n\nexport async function confirmPrompt(question: string, defaultValue = true): Promise<boolean> {\n const suffix = defaultValue ? '(Y/n)' : '(y/N)';\n const answer = await textPrompt(`${question} ${suffix}`);\n if (!answer) return defaultValue;\n return answer.toLowerCase().startsWith('y');\n}\n\nexport async function multiSelectPrompt(question: string, options: string[], defaults: boolean[] = []): Promise<boolean[]> {\n console.log(`\\n ${question} (comma-separated numbers, or 'all')`);\n for (let i = 0; i < options.length; i++) {\n const def = defaults[i] ? '✓' : ' ';\n console.log(` ${i + 1}) [${def}] ${options[i]}`);\n }\n const answer = await textPrompt('Enter numbers', defaults.some(d => d) ? 'keep defaults' : 'all');\n if (answer === 'all') return options.map(() => true);\n if (answer === 'keep defaults' || answer === '') return defaults.length ? defaults : options.map(() => true);\n const selected = answer.split(',').map(s => parseInt(s.trim()) - 1);\n return options.map((_, i) => selected.includes(i));\n}\n","// ─────────────────────────────────────────────────────\n// Project Templates — generates files for new apps\n// ─────────────────────────────────────────────────────\n\nimport { getBuiltinTheme } from '@termuijs/tss';\n\nexport interface ProjectConfig {\n name: string;\n template: 'empty' | 'dashboard' | 'interactive-tool' | 'cli-wrapper';\n theme: string;\n features: {\n router: boolean;\n dataProviders: boolean;\n hotReload: boolean;\n };\n}\n\nexport interface GeneratedFile {\n path: string;\n content: string;\n}\n\nexport function generateProject(config: ProjectConfig): GeneratedFile[] {\n const files: GeneratedFile[] = [];\n\n // ── package.json ──\n files.push({\n path: 'package.json',\n content: JSON.stringify({\n name: config.name,\n version: '0.1.0',\n private: true,\n type: 'module',\n scripts: {\n dev: 'tsx --watch src/index.tsx',\n build: 'tsup src/index.tsx --format esm',\n start: 'node dist/index.js',\n },\n dependencies: {\n '@termuijs/core': 'latest',\n '@termuijs/widgets': 'latest',\n '@termuijs/ui': 'latest',\n '@termuijs/jsx': 'latest',\n '@termuijs/tss': 'latest',\n '@termuijs/quick': 'latest',\n '@termuijs/motion': 'latest',\n ...(config.features.dataProviders ? { '@termuijs/data': 'latest' } : {}),\n ...(config.features.router ? { '@termuijs/router': 'latest' } : {}),\n },\n devDependencies: {\n tsx: '^4.0.0',\n tsup: '^8.0.0',\n typescript: '^5.3.0',\n },\n }, null, 2) + '\\n',\n });\n\n // ── tsconfig.json ──\n files.push({\n path: 'tsconfig.json',\n content: JSON.stringify({\n compilerOptions: {\n target: 'ES2022',\n module: 'ESNext',\n moduleResolution: 'bundler',\n jsx: 'react-jsx',\n jsxImportSource: '@termuijs/jsx',\n strict: true,\n esModuleInterop: true,\n outDir: 'dist',\n rootDir: 'src',\n },\n include: ['src'],\n }, null, 2) + '\\n',\n });\n\n // ── termui.config.ts ──\n files.push({\n path: 'termui.config.ts',\n content: `import { defineConfig } from '@termuijs/core';\n\nexport default defineConfig({\n theme: '${config.theme}',\n ${config.features.hotReload ? \"hotReload: true,\" : ''}\n ${config.features.router ? \"router: { dir: './screens' },\" : ''}\n});\n`,\n });\n\n // ── Theme file ──\n const themeSrc = getBuiltinTheme(config.theme);\n if (themeSrc) {\n files.push({ path: `themes/${config.theme}.tss`, content: themeSrc.trim() + '\\n' });\n }\n\n // ── Template-specific files ──\n switch (config.template) {\n case 'dashboard':\n files.push(...generateDashboardTemplate(config));\n break;\n case 'interactive-tool':\n files.push(...generateInteractiveTemplate(config));\n break;\n case 'cli-wrapper':\n files.push(...generateCliWrapperTemplate(config));\n break;\n default:\n files.push(...generateEmptyTemplate(config));\n }\n\n return files;\n}\n\nfunction generateEmptyTemplate(config: ProjectConfig): GeneratedFile[] {\n return [{\n path: 'src/index.tsx',\n content: `import { app, text } from '@termuijs/quick';\n\napp('${config.name}')\n .rows(\n text('Hello from TermUI! Edit src/index.tsx to get started.'),\n )\n .keys({ q: 'quit' })\n .run();\n`,\n }];\n}\n\nfunction generateDashboardTemplate(config: ProjectConfig): GeneratedFile[] {\n return [{\n path: 'src/index.tsx',\n content: `import { app, gauge, table, sparkline } from '@termuijs/quick';\n${config.features.dataProviders ? \"import { cpu, memory, disk, processes } from '@termuijs/data';\" : ''}\n\n// Sample data for demo\nlet cpuVal = 0.45;\nlet memVal = 0.62;\nlet dskVal = 0.38;\n\napp('⚡ ${config.name}')\n .rows(\n // Row 1: Gauges\n gauge('CPU', () => ${config.features.dataProviders ? 'cpu.percent / 100' : 'cpuVal'}),\n gauge('MEM', () => ${config.features.dataProviders ? 'memory.percent / 100' : 'memVal'}),\n gauge('DSK', () => ${config.features.dataProviders ? 'disk.percent / 100' : 'dskVal'}),\n // Row 2: Table\n table('Processes',\n () => ${config.features.dataProviders\n ? `processes.top(10).map(p => ({\n Name: p.name.slice(0, 18),\n PID: p.pid,\n 'CPU%': p.cpu.toFixed(1),\n 'MEM%': p.mem.toFixed(1),\n }))`\n : `[\n { Name: 'node', PID: 1234, 'CPU%': '5.0', 'MEM%': '2.1' },\n { Name: 'chrome', PID: 5678, 'CPU%': '12.3', 'MEM%': '8.4' },\n ]`},\n ['Name', 'PID', 'CPU%', 'MEM%'],\n ),\n )\n .keys({ q: 'quit', r: 'refresh' })\n .refresh('1s')\n .run();\n`,\n }];\n}\n\nfunction generateInteractiveTemplate(config: ProjectConfig): GeneratedFile[] {\n return [{\n path: 'src/index.tsx',\n content: `import { app, text, list, input } from '@termuijs/quick';\n\nconst items = ['Option 1', 'Option 2', 'Option 3'];\n\napp('🔧 ${config.name}')\n .rows(\n text('Select an option or type a command:'),\n list(() => items),\n input('Type here...', {\n onSubmit: (value) => items.push(value),\n }),\n )\n .keys({ q: 'quit' })\n .run();\n`,\n }];\n}\n\nfunction generateCliWrapperTemplate(config: ProjectConfig): GeneratedFile[] {\n return [{\n path: 'src/index.tsx',\n content: `import { app, text, logView } from '@termuijs/quick';\n\n// CLI wrapper — displays log output\nconst logs: string[] = [\n 'INFO Application started',\n 'INFO Waiting for input...',\n 'DEBUG Press q to quit',\n];\n\napp('📟 ${config.name}')\n .rows(\n text('Command output:'),\n logView(() => logs),\n )\n .keys({ q: 'quit' })\n .refresh('1s')\n .run();\n`,\n }];\n}\n\n"],"mappings":";;;AAIA,SAAS,SAAS,YAAY;AAC9B,SAAS,WAAW,eAAe,kBAAkB;AACrD,SAAS,4BAA4B;;;ACFrC,SAAS,uBAAuB;AAEhC,IAAM,KAAK,MAAM,gBAAgB,EAAE,OAAO,QAAQ,OAAO,QAAQ,QAAQ,OAAO,CAAC;AAEjF,eAAsB,WAAW,UAAkB,cAAwC;AACvF,SAAO,IAAI,QAAQ,CAAAA,aAAW;AAC1B,UAAM,IAAI,GAAG;AACb,UAAM,SAAS,eAAe,KAAK,YAAY,MAAM;AACrD,MAAE,SAAS,KAAK,QAAQ,GAAG,MAAM,MAAM,YAAU;AAC7C,QAAE,MAAM;AACR,MAAAA,SAAQ,OAAO,KAAK,KAAK,gBAAgB,EAAE;AAAA,IAC/C,CAAC;AAAA,EACL,CAAC;AACL;AAEA,eAAsB,aAAa,UAAkB,SAAoC;AACrF,UAAQ,IAAI;AAAA,IAAO,QAAQ,EAAE;AAC7B,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACrC,YAAQ,IAAI,OAAO,IAAI,CAAC,KAAK,QAAQ,CAAC,CAAC,EAAE;AAAA,EAC7C;AACA,QAAM,SAAS,MAAM,WAAW,gBAAgB,GAAG;AACnD,QAAM,MAAM,SAAS,MAAM,IAAI;AAC/B,SAAO,KAAK,IAAI,GAAG,KAAK,IAAI,KAAK,QAAQ,SAAS,CAAC,CAAC;AACxD;AASA,eAAsB,kBAAkB,UAAkB,SAAmB,WAAsB,CAAC,GAAuB;AACvH,UAAQ,IAAI;AAAA,IAAO,QAAQ,sCAAsC;AACjE,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACrC,UAAM,MAAM,SAAS,CAAC,I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wC;AACpD,UAAQ,IAAI,wDAAyC;AACrD,UAAQ,IAAI,4NAAwC;AACpD,UAAQ,IAAI;AACZ,UAAQ,IAAI,eAAe;AAC3B,UAAQ,IAAI,UAAU,WAAW,EAAE;AACnC,UAAQ,IAAI,iBAAiB;AAC7B,UAAQ,IAAI,iBAAiB;AAC7B,UAAQ,IAAI;AAChB;AAEA,KAAK,EAAE,MAAM,SAAO;AAChB,UAAQ,MAAM,UAAU,IAAI,OAAO;AACnC,UAAQ,KAAK,CAAC;AAClB,CAAC;","names":["resolve"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/prompts.ts","../src/templates.ts"],"sourcesContent":["// ─────────────────────────────────────────────────────\n// create-termui-app — Interactive CLI scaffolding tool\n// ─────────────────────────────────────────────────────\n\nimport { resolve, join } from 'node:path';\nimport { mkdirSync, writeFileSync, existsSync } from 'node:fs';\nimport { getBuiltinThemeNames } from '@termuijs/tss';\nimport { textPrompt, selectPrompt, multiSelectPrompt } from './prompts.js';\nimport { generateProject, type ProjectConfig } from './templates.js';\n\nconst TEMPLATES = ['Empty (start from scratch)', 'Dashboard (real-time data)', 'Interactive Tool (forms, prompts)', 'CLI Wrapper (wrap existing CLI)'];\nconst TEMPLATE_KEYS = ['empty', 'dashboard', 'interactive-tool', 'cli-wrapper'] as const;\nconst FEATURES = ['Screen Router', 'Data Providers', 'Hot Reload'];\n\nasync function main() {\n console.log();\n console.log(' ┌──────────────────────────────────┐');\n console.log(' │ create-termui-app │');\n console.log(' │ The React/Next.js for CLI apps │');\n console.log(' └──────────────────────────────────┘');\n console.log();\n\n // ── Get project name from args or prompt ──\n let projectName = process.argv[2];\n if (!projectName) {\n projectName = await textPrompt('Project name', 'my-termui-app');\n }\n\n // ── Template selection ──\n const templateIdx = await selectPrompt('What kind of app?', TEMPLATES);\n const template = TEMPLATE_KEYS[templateIdx];\n\n // ── Theme selection ──\n const themes = getBuiltinThemeNames();\n const themeIdx = await selectPrompt('Choose a theme', themes.map(t => t.charAt(0).toUpperCase() + t.slice(1)));\n const theme = themes[themeIdx];\n\n // ── Feature selection ──\n const featureDefaults = [false, template === 'dashboard', true]; // Router off, Data on for dashboard, HotReload on\n const featureFlags = await multiSelectPrompt('Features to include', FEATURES, featureDefaults);\n\n const config: ProjectConfig = {\n name: projectName,\n template,\n theme,\n features: {\n router: featureFlags[0],\n dataProviders: featureFlags[1],\n hotReload: featureFlags[2],\n },\n };\n\n // ── Generate project ──\n const projectDir = resolve(process.cwd(), projectName);\n if (existsSync(projectDir)) {\n console.log(`\\n ⚠ Directory \"${projectName}\" already exists. Files may be overwritten.\\n`);\n }\n\n console.log(`\\n Creating ${projectName}...`);\n\n const files = generateProject(config);\n\n for (const file of files) {\n const fullPath = join(projectDir, file.path);\n const dir = fullPath.substring(0, fullPath.lastIndexOf('/'));\n mkdirSync(dir, { recursive: true });\n writeFileSync(fullPath, file.content, 'utf-8');\n console.log(` ✓ ${file.path}`);\n }\n\n console.log();\n console.log(' ┌──────────────────────────────────┐');\n console.log(' │ ✅ Project created successfully! │');\n console.log(' └──────────────────────────────────┘');\n console.log();\n console.log(` Next steps:`);\n console.log(` cd ${projectName}`);\n console.log(` bun install`);\n console.log(` bun run dev`);\n console.log();\n}\n\nmain().catch(err => {\n console.error('Error:', err.message);\n process.exit(1);\n});\n","// ─────────────────────────────────────────────────────\n// Minimal interactive prompts (no external deps)\n// ─────────────────────────────────────────────────────\n\nimport { createInterface } from 'node:readline';\n\nconst rl = () => createInterface({ input: process.stdin, output: process.stdout });\n\nexport async function textPrompt(question: string, defaultValue?: string): Promise<string> {\n return new Promise(resolve => {\n const r = rl();\n const suffix = defaultValue ? ` (${defaultValue})` : '';\n r.question(` ${question}${suffix}: `, answer => {\n r.close();\n resolve(answer.trim() || defaultValue || '');\n });\n });\n}\n\nexport async function selectPrompt(question: string, options: string[]): Promise<number> {\n console.log(`\\n ${question}`);\n for (let i = 0; i < options.length; i++) {\n console.log(` ${i + 1}) ${options[i]}`);\n }\n const answer = await textPrompt('Enter number', '1');\n const idx = parseInt(answer) - 1;\n return Math.max(0, Math.min(idx, options.length - 1));\n}\n\nexport async function confirmPrompt(question: string, defaultValue = true): Promise<boolean> {\n const suffix = defaultValue ? '(Y/n)' : '(y/N)';\n const answer = await textPrompt(`${question} ${suffix}`);\n if (!answer) return defaultValue;\n return answer.toLowerCase().startsWith('y');\n}\n\nexport async function multiSelectPrompt(question: string, options: string[], defaults: boolean[] = []): Promise<boolean[]> {\n console.log(`\\n ${question} (comma-separated numbers, or 'all')`);\n for (let i = 0; i < options.length; i++) {\n const def = defaults[i] ? '✓' : ' ';\n console.log(` ${i + 1}) [${def}] ${options[i]}`);\n }\n const answer = await textPrompt('Enter numbers', defaults.some(d => d) ? 'keep defaults' : 'all');\n if (answer === 'all') return options.map(() => true);\n if (answer === 'keep defaults' || answer === '') return defaults.length ? defaults : options.map(() => true);\n const selected = answer.split(',').map(s => parseInt(s.trim()) - 1);\n return options.map((_, i) => selected.includes(i));\n}\n","// ─────────────────────────────────────────────────────\n// Project Templates — generates files for new apps\n// ─────────────────────────────────────────────────────\n\nimport { getBuiltinTheme } from '@termuijs/tss';\n\nexport interface ProjectConfig {\n name: string;\n template: 'empty' | 'dashboard' | 'interactive-tool' | 'cli-wrapper';\n theme: string;\n features: {\n router: boolean;\n dataProviders: boolean;\n hotReload: boolean;\n };\n}\n\nexport interface GeneratedFile {\n path: string;\n content: string;\n}\n\nexport function generateProject(config: ProjectConfig): GeneratedFile[] {\n const files: GeneratedFile[] = [];\n\n // ── package.json ──\n files.push({\n path: 'package.json',\n content: JSON.stringify({\n name: config.name,\n version: '0.1.0',\n private: true,\n type: 'module',\n scripts: {\n dev: 'bun --watch src/index.tsx',\n build: 'tsup src/index.tsx --format esm',\n start: 'bun dist/index.js',\n },\n dependencies: {\n '@termuijs/core': 'latest',\n '@termuijs/widgets': 'latest',\n '@termuijs/ui': 'latest',\n '@termuijs/jsx': 'latest',\n '@termuijs/tss': 'latest',\n '@termuijs/quick': 'latest',\n '@termuijs/motion': 'latest',\n ...(config.features.dataProviders ? { '@termuijs/data': 'latest' } : {}),\n ...(config.features.router ? { '@termuijs/router': 'latest' } : {}),\n },\n devDependencies: {\n '@types/bun': 'latest',\n tsup: '^8.0.0',\n typescript: '^5.3.0',\n },\n engines: {\n bun: '>=1.3.0',\n },\n }, null, 2) + '\\n',\n });\n\n // ── tsconfig.json ──\n files.push({\n path: 'tsconfig.json',\n content: JSON.stringify({\n compilerOptions: {\n target: 'ES2022',\n module: 'ESNext',\n moduleResolution: 'bundler',\n jsx: 'react-jsx',\n jsxImportSource: '@termuijs/jsx',\n strict: true,\n esModuleInterop: true,\n outDir: 'dist',\n rootDir: 'src',\n },\n include: ['src'],\n }, null, 2) + '\\n',\n });\n\n // ── termui.config.ts ──\n files.push({\n path: 'termui.config.ts',\n content: `import { defineConfig } from '@termuijs/core';\n\nexport default defineConfig({\n theme: '${config.theme}',\n ${config.features.hotReload ? \"hotReload: true,\" : ''}\n ${config.features.router ? \"router: { dir: './screens' },\" : ''}\n});\n`,\n });\n\n // ── Theme file ──\n const themeSrc = getBuiltinTheme(config.theme);\n if (themeSrc) {\n files.push({ path: `themes/${config.theme}.tss`, content: themeSrc.trim() + '\\n' });\n }\n\n // ── Template-specific files ──\n switch (config.template) {\n case 'dashboard':\n files.push(...generateDashboardTemplate(config));\n break;\n case 'interactive-tool':\n files.push(...generateInteractiveTemplate(config));\n break;\n case 'cli-wrapper':\n files.push(...generateCliWrapperTemplate(config));\n break;\n default:\n files.push(...generateEmptyTemplate(config));\n }\n\n return files;\n}\n\nfunction generateEmptyTemplate(config: ProjectConfig): GeneratedFile[] {\n return [{\n path: 'src/index.tsx',\n content: `/** @jsxImportSource @termuijs/jsx */\nimport { render, useState, useKeymap, ErrorBoundary } from '@termuijs/jsx';\nimport { AutoThemeProvider } from '@termuijs/tss';\n\nfunction App() {\n const [count, setCount] = useState(0);\n\n useKeymap([\n { key: 'q', action: () => process.exit(0), description: 'Quit' },\n { key: 'c', ctrl: true, action: () => process.exit(0), description: 'Quit' },\n { key: '+', action: () => setCount(c => c + 1), description: 'Increment' },\n { key: '-', action: () => setCount(c => Math.max(0, c - 1)), description: 'Decrement' },\n ]);\n\n return (\n <AutoThemeProvider>\n <ErrorBoundary fallback={(err) => <text color=\"red\">{err.message}</text>}>\n <box border=\"single\" padding={1}>\n <text bold>Welcome to ${config.name}!</text>\n <text>Edit src/index.tsx to get started.</text>\n <text>Count: {count} (+/- to change, q to quit)</text>\n </box>\n </ErrorBoundary>\n </AutoThemeProvider>\n );\n}\n\nrender(<App />, { title: '${config.name}' });\n`,\n }];\n}\n\nfunction generateDashboardTemplate(config: ProjectConfig): GeneratedFile[] {\n return [{\n path: 'src/index.tsx',\n content: `/** @jsxImportSource @termuijs/jsx */\nimport { render, useState, useEffect, useKeymap, ErrorBoundary } from '@termuijs/jsx';\nimport { AutoThemeProvider, useTheme } from '@termuijs/tss';\n${config.features.dataProviders ? \"import { useCpu, useMemory, useDisk } from '@termuijs/data';\" : ''}\n\n// ── Sample static data (replace with live hooks when dataProviders = true) ──\n${config.features.dataProviders ? '' : `const SAMPLE_PROCS = [\n { Name: 'node', PID: 1234, 'CPU%': '5.0', 'MEM%': '2.1' },\n { Name: 'chrome', PID: 5678, 'CPU%': '12.3', 'MEM%': '8.4' },\n { Name: 'bash', PID: 9012, 'CPU%': '0.1', 'MEM%': '0.3' },\n];`}\n\nfunction GaugeRow({ label, value }: { label: string; value: number }) {\n const theme = useTheme();\n const filled = Math.round(value * 20);\n const empty = 20 - filled;\n const bar = '[' + '#'.repeat(filled) + '-'.repeat(empty) + ']';\n return (\n <row gap={2}>\n <text color={theme.colors.primary}>{label.padEnd(4)}</text>\n <text>{bar}</text>\n <text>{(value * 100).toFixed(1).padStart(5)}%</text>\n </row>\n );\n}\n\nfunction Dashboard() {\n const [tick, setTick] = useState(0);\n${config.features.dataProviders\n ? ` const cpu = useCpu();\n const mem = useMemory();\n const disk = useDisk();\n const cpuVal = (cpu.percent ?? 0) / 100;\n const memVal = (mem.percent ?? 0) / 100;\n const diskVal = (disk.percent ?? 0) / 100;`\n : ` const [cpuVal, setCpuVal] = useState(0.45);\n const [memVal, setMemVal] = useState(0.62);\n const [diskVal, setDiskVal] = useState(0.38);\n\n // Simulate live updates\n useEffect(() => {\n const id = setInterval(() => {\n setCpuVal(v => Math.min(1, Math.max(0, v + (Math.random() - 0.5) * 0.05)));\n setMemVal(v => Math.min(1, Math.max(0, v + (Math.random() - 0.5) * 0.02)));\n setDiskVal(v => Math.min(1, Math.max(0, v + (Math.random() - 0.5) * 0.01)));\n setTick(t => t + 1);\n }, 1000);\n return () => clearInterval(id);\n }, []);`}\n\n useKeymap([\n { key: 'q', action: () => process.exit(0), description: 'Quit' },\n { key: 'c', ctrl: true, action: () => process.exit(0), description: 'Quit' },\n { key: 'r', action: () => setTick(t => t + 1), description: 'Refresh' },\n ]);\n\n const theme = useTheme();\n\n return (\n <box flexDirection=\"column\" padding={1}>\n <text bold color={theme.colors.primary}>${config.name} Dashboard</text>\n <divider />\n\n <grid columns={12} gap={1}>\n {/* Gauges — top row */}\n <box width=\"100%\" flexDirection=\"column\" border=\"single\" padding={1} flexGrow={4}>\n <text bold>System Resources</text>\n <GaugeRow label=\"CPU\" value={cpuVal} />\n <GaugeRow label=\"MEM\" value={memVal} />\n <GaugeRow label=\"DISK\" value={diskVal} />\n </box>\n\n {/* Info panel */}\n <box width=\"100%\" flexDirection=\"column\" border=\"single\" padding={1} flexGrow={8}>\n <text bold>Process Summary</text>\n <text color={theme.colors.muted}>Press r to refresh, q to quit</text>\n <text>Tick: {tick}</text>\n${config.features.dataProviders\n ? ` <skeleton variant=\"shimmer\" />`\n : ` <text>node PID:1234 CPU: {(cpuVal * 100).toFixed(1)}%</text>\n <text>chrome PID:5678 MEM: {(memVal * 100).toFixed(1)}%</text>`}\n </box>\n </grid>\n </box>\n );\n}\n\nfunction App() {\n return (\n <AutoThemeProvider>\n <ErrorBoundary fallback={(err) => (\n <box border=\"single\" borderColor=\"red\" padding={1}>\n <text color=\"red\" bold>Dashboard Error</text>\n <text>{err.message}</text>\n </box>\n )}>\n <Dashboard />\n </ErrorBoundary>\n </AutoThemeProvider>\n );\n}\n\nrender(<App />, { title: '${config.name}' });\n`,\n }];\n}\n\nfunction generateInteractiveTemplate(config: ProjectConfig): GeneratedFile[] {\n return [{\n path: 'src/index.tsx',\n content: `/** @jsxImportSource @termuijs/jsx */\nimport { render, useState, useKeymap, useRef, ErrorBoundary } from '@termuijs/jsx';\nimport { AutoThemeProvider, useTheme } from '@termuijs/tss';\nimport { caps } from '@termuijs/core';\n\n// ASCII-safe symbols\nconst CHECK = caps.unicode ? '✓' : 'v';\nconst BULLET = caps.unicode ? '›' : '>';\nconst SEP = caps.unicode ? '─'.repeat(40) : '-'.repeat(40);\n\nconst INITIAL_ITEMS = ['Option A', 'Option B', 'Option C'];\n\nfunction InteractiveTool() {\n const [items, setItems] = useState<string[]>(INITIAL_ITEMS);\n const [selected, setSelected] = useState(0);\n const [input, setInput] = useState('');\n const [done, setDone] = useState<string[]>([]);\n const theme = useTheme();\n\n useKeymap([\n { key: 'q', action: () => process.exit(0), description: 'Quit' },\n { key: 'c', ctrl: true, action: () => process.exit(0), description: 'Quit' },\n { key: 'ArrowUp', action: () => setSelected(s => Math.max(0, s - 1)), description: 'Move up' },\n { key: 'ArrowDown', action: () => setSelected(s => Math.min(items.length - 1, s + 1)), description: 'Move down' },\n { key: 'k', action: () => setSelected(s => Math.max(0, s - 1)), description: 'Move up (vim)' },\n { key: 'j', action: () => setSelected(s => Math.min(items.length - 1, s + 1)), description: 'Move down (vim)' },\n { key: 'Enter', action: () => {\n const item = items[selected];\n if (item) setDone(d => d.includes(item) ? d.filter(x => x !== item) : [...d, item]);\n }, description: 'Toggle selected' },\n { key: 'Backspace', action: () => setInput(v => v.slice(0, -1)), description: 'Delete char' },\n { key: 'n', action: () => {\n if (input.trim()) {\n setItems(prev => [...prev, input.trim()]);\n setInput('');\n }\n }, description: 'Add new item' },\n ]);\n\n return (\n <box flexDirection=\"column\" padding={1}>\n <text bold color={theme.colors.primary}>${config.name}</text>\n <text color={theme.colors.muted}>j/k or arrows: navigate | Enter: toggle | n: add | q: quit</text>\n <text>{SEP}</text>\n\n <box flexDirection=\"column\">\n {items.map((item, i) => (\n <row key={item} gap={1}>\n <text color={i === selected ? theme.colors.primary : undefined}>\n {i === selected ? BULLET : ' '}\n </text>\n <text color={done.includes(item) ? theme.colors.success : undefined}>\n {done.includes(item) ? CHECK + ' ' : ' '}{item}\n </text>\n </row>\n ))}\n </box>\n\n <text>{SEP}</text>\n <row gap={1}>\n <text color={theme.colors.muted}>New item:</text>\n <text>{input}_</text>\n </row>\n <text color={theme.colors.muted} dim>Type letters then press n to add</text>\n </box>\n );\n}\n\nfunction App() {\n return (\n <AutoThemeProvider>\n <ErrorBoundary fallback={(err) => (\n <box border=\"single\" borderColor=\"red\" padding={1}>\n <text color=\"red\" bold>Error</text>\n <text>{err.message}</text>\n </box>\n )}>\n <InteractiveTool />\n </ErrorBoundary>\n </AutoThemeProvider>\n );\n}\n\nrender(<App />, { title: '${config.name}' });\n`,\n }];\n}\n\nfunction generateCliWrapperTemplate(config: ProjectConfig): GeneratedFile[] {\n return [{\n path: 'src/index.tsx',\n content: `/** @jsxImportSource @termuijs/jsx */\nimport { render, useState, useEffect, useKeymap, ErrorBoundary } from '@termuijs/jsx';\nimport { AutoThemeProvider, useTheme } from '@termuijs/tss';\nimport { caps } from '@termuijs/core';\nimport { spawn } from 'node:child_process';\n\n// ASCII-safe symbols for terminals without full unicode support\nconst ICON_RUN = caps.unicode ? '>' : '>';\nconst ICON_DONE = caps.unicode ? '*' : '*';\nconst ICON_ERR = caps.unicode ? '!' : '!';\nconst SEP = '-'.repeat(60);\n\ntype LogLevel = 'info' | 'debug' | 'error' | 'warn';\ninterface LogLine {\n level: LogLevel;\n text: string;\n ts: number;\n}\n\nfunction levelColor(level: LogLevel): string {\n switch (level) {\n case 'info': return 'green';\n case 'debug': return 'cyan';\n case 'warn': return 'yellow';\n case 'error': return 'red';\n }\n}\n\nfunction CliWrapper() {\n const [logs, setLogs] = useState<LogLine[]>([\n { level: 'info', text: 'Application started', ts: Date.now() },\n { level: 'debug', text: 'Press r to re-run, q to quit', ts: Date.now() },\n ]);\n const [running, setRunning] = useState(false);\n const [exitCode, setExitCode] = useState<number | null>(null);\n const procRef = useRef<any>(null);\n const theme = useTheme();\n\n const addLog = (level: LogLevel, text: string) =>\n setLogs(prev => [...prev.slice(-200), { level, text, ts: Date.now() }]);\n\n // Example: run 'echo hello' — replace with your real command\n const runCommand = () => {\n if (running) return;\n setRunning(true);\n setExitCode(null);\n addLog('info', \\`\\${ICON_RUN} Running command...\\`);\n\n const proc = spawn('echo', ['Hello from CLI wrapper!']);\n procRef.current = proc;\n proc.stdout.on('data', (d: Buffer) => {\n for (const line of d.toString().split('\\\\n').filter(Boolean)) {\n addLog('info', line);\n }\n });\n proc.stderr.on('data', (d: Buffer) => {\n for (const line of d.toString().split('\\\\n').filter(Boolean)) {\n addLog('error', line);\n }\n });\n proc.on('close', (code: number | null) => {\n setRunning(false);\n setExitCode(code);\n addLog(code === 0 ? 'info' : 'error',\n \\`\\${code === 0 ? ICON_DONE : ICON_ERR} Process exited with code \\${code ?? 'null'}\\`);\n procRef.current = null;\n });\n };\n\n // Auto-run on mount, kill process on unmount\n useEffect(() => {\n runCommand();\n return () => {\n if (procRef.current) {\n procRef.current.kill();\n procRef.current = null;\n }\n };\n }, []);\n\n useKeymap([\n { key: 'q', action: () => process.exit(0), description: 'Quit' },\n { key: 'c', ctrl: true, action: () => process.exit(0), description: 'Quit' },\n { key: 'r', action: runCommand, description: 'Re-run command' },\n { key: 'l', action: () => setLogs([]), description: 'Clear logs' },\n ]);\n\n return (\n <box flexDirection=\"column\" padding={1}>\n <row gap={2}>\n <text bold color={theme.colors.primary}>${config.name}</text>\n <text color={running ? theme.colors.warning : theme.colors.muted}>\n {running ? 'Running...' : exitCode === null ? 'Ready' : \\`Exit: \\${exitCode}\\`}\n </text>\n <spacer />\n <text color={theme.colors.muted}>r: re-run | l: clear | q: quit</text>\n </row>\n <text>{SEP}</text>\n\n <box flexDirection=\"column\" flexGrow={1}>\n {logs.map((line, i) => (\n <row key={i} gap={1}>\n <text color={theme.colors.muted} dim>\n {new Date(line.ts).toLocaleTimeString()}\n </text>\n <text color={levelColor(line.level)} bold>\n {line.level.toUpperCase().padEnd(5)}\n </text>\n <text>{line.text}</text>\n </row>\n ))}\n </box>\n\n {!caps.color && (\n <text color=\"yellow\" dim>\n Note: running in a terminal without color support (TERM={process.env.TERM ?? 'unset'})\n </text>\n )}\n </box>\n );\n}\n\nfunction App() {\n return (\n <AutoThemeProvider>\n <ErrorBoundary fallback={(err) => (\n <box border=\"single\" borderColor=\"red\" padding={1}>\n <text color=\"red\" bold>CLI Wrapper Error</text>\n <text>{err.message}</text>\n <text color=\"yellow\">Check that the command exists and is executable.</text>\n </box>\n )}>\n <CliWrapper />\n </ErrorBoundary>\n </AutoThemeProvider>\n );\n}\n\nrender(<App />, { title: '${config.name}' });\n`,\n }];\n}\n\n"],"mappings":";;;AAIA,SAAS,SAAS,YAAY;AAC9B,SAAS,WAAW,eAAe,kBAAkB;AACrD,SAAS,4BAA4B;;;ACFrC,SAAS,uBAAuB;AAEhC,IAAM,KAAK,MAAM,gBAAgB,EAAE,OAAO,QAAQ,OAAO,QAAQ,QAAQ,OAAO,CAAC;AAEjF,eAAsB,WAAW,UAAkB,cAAwC;AACvF,SAAO,IAAI,QAAQ,CAAAA,aAAW;AAC1B,UAAM,IAAI,GAAG;AACb,UAAM,SAAS,eAAe,KAAK,YAAY,MAAM;AACrD,MAAE,SAAS,KAAK,QAAQ,GAAG,MAAM,MAAM,YAAU;AAC7C,QAAE,MAAM;AACR,MAAAA,SAAQ,OAAO,KAAK,KAAK,gBAAgB,EAAE;AAAA,IAC/C,CAAC;AAAA,EACL,CAAC;AACL;AAEA,eAAsB,aAAa,UAAkB,SAAoC;AACrF,UAAQ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,UAAQ,IAAI,iBAAiB;AAC7B,UAAQ,IAAI;AAChB;AAEA,KAAK,EAAE,MAAM,SAAO;AAChB,UAAQ,MAAM,UAAU,IAAI,OAAO;AACnC,UAAQ,KAAK,CAAC;AAClB,CAAC;","names":["resolve"]}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/Karanjot786/TermUI"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.1.
|
|
8
|
+
"version": "0.1.5",
|
|
9
9
|
"description": "Scaffold a new TermUI project with templates, themes, and dev server",
|
|
10
10
|
"type": "module",
|
|
11
11
|
"bin": {
|
|
@@ -15,8 +15,12 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup",
|
|
20
|
+
"dev": "tsup --watch"
|
|
21
|
+
},
|
|
18
22
|
"dependencies": {
|
|
19
|
-
"@termuijs/tss": "0.1.
|
|
23
|
+
"@termuijs/tss": "0.1.4"
|
|
20
24
|
},
|
|
21
25
|
"devDependencies": {
|
|
22
26
|
"tsup": "^8.0.0",
|
|
@@ -30,9 +34,8 @@
|
|
|
30
34
|
"create-app",
|
|
31
35
|
"generator"
|
|
32
36
|
],
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
37
|
+
"engines": {
|
|
38
|
+
"bun": ">=1.3.0"
|
|
39
|
+
},
|
|
40
|
+
"license": "MIT"
|
|
41
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Karanjot Singh
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|