silvery 0.4.0 → 0.4.2
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/package.json +2 -7
- package/bin/silvery.ts +0 -258
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "silvery",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "React terminal UI renderer for complex interactive apps — layout-aware rendering, flexbox, scrolling, and incremental updates",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ansi",
|
|
@@ -30,16 +30,11 @@
|
|
|
30
30
|
"type": "git",
|
|
31
31
|
"url": "https://github.com/beorn/silvery.git"
|
|
32
32
|
},
|
|
33
|
-
"bin": {
|
|
34
|
-
"silvery": "./bin/silvery.ts"
|
|
35
|
-
},
|
|
36
33
|
"workspaces": [
|
|
37
34
|
"packages/*"
|
|
38
35
|
],
|
|
39
36
|
"files": [
|
|
40
|
-
"src"
|
|
41
|
-
"dist",
|
|
42
|
-
"bin"
|
|
37
|
+
"src"
|
|
43
38
|
],
|
|
44
39
|
"type": "module",
|
|
45
40
|
"main": "src/index.ts",
|
package/bin/silvery.ts
DELETED
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
/**
|
|
3
|
-
* silvery CLI
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* silvery example — list all available examples
|
|
7
|
-
* silvery example <name> — run an example by name (fuzzy match)
|
|
8
|
-
* silvery example --list — list all available examples
|
|
9
|
-
* silvery --help — show usage help
|
|
10
|
-
*
|
|
11
|
-
* Designed for: bunx silvery example <name>
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
// =============================================================================
|
|
15
|
-
// ANSI helpers (no deps — must work before anything is imported)
|
|
16
|
-
// =============================================================================
|
|
17
|
-
|
|
18
|
-
const RESET = "\x1b[0m"
|
|
19
|
-
const BOLD = "\x1b[1m"
|
|
20
|
-
const DIM = "\x1b[2m"
|
|
21
|
-
const RED = "\x1b[31m"
|
|
22
|
-
const GREEN = "\x1b[32m"
|
|
23
|
-
const YELLOW = "\x1b[33m"
|
|
24
|
-
const BLUE = "\x1b[34m"
|
|
25
|
-
const MAGENTA = "\x1b[35m"
|
|
26
|
-
const CYAN = "\x1b[36m"
|
|
27
|
-
const WHITE = "\x1b[37m"
|
|
28
|
-
|
|
29
|
-
// =============================================================================
|
|
30
|
-
// Types
|
|
31
|
-
// =============================================================================
|
|
32
|
-
|
|
33
|
-
interface Example {
|
|
34
|
-
name: string
|
|
35
|
-
file: string
|
|
36
|
-
description: string
|
|
37
|
-
category: string
|
|
38
|
-
features?: string[]
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// =============================================================================
|
|
42
|
-
// Auto-Discovery (mirrors examples/cli.ts)
|
|
43
|
-
// =============================================================================
|
|
44
|
-
|
|
45
|
-
const CATEGORY_DIRS = ["layout", "interactive", "runtime", "inline", "kitty"] as const
|
|
46
|
-
|
|
47
|
-
const CATEGORY_DISPLAY: Record<string, string> = {
|
|
48
|
-
kitty: "Kitty Protocol",
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const CATEGORY_ORDER: Record<string, number> = {
|
|
52
|
-
Layout: 0,
|
|
53
|
-
Interactive: 1,
|
|
54
|
-
Runtime: 2,
|
|
55
|
-
Inline: 3,
|
|
56
|
-
"Kitty Protocol": 4,
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const CATEGORY_COLOR: Record<string, string> = {
|
|
60
|
-
Layout: MAGENTA,
|
|
61
|
-
Interactive: CYAN,
|
|
62
|
-
Runtime: GREEN,
|
|
63
|
-
Inline: YELLOW,
|
|
64
|
-
"Kitty Protocol": BLUE,
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async function discoverExamples(): Promise<Example[]> {
|
|
68
|
-
const { resolve } = await import("node:path")
|
|
69
|
-
const examplesDir = resolve(new URL(".", import.meta.url).pathname, "../examples")
|
|
70
|
-
const results: Example[] = []
|
|
71
|
-
|
|
72
|
-
for (const dir of CATEGORY_DIRS) {
|
|
73
|
-
const category = CATEGORY_DISPLAY[dir] ?? dir.charAt(0).toUpperCase() + dir.slice(1)
|
|
74
|
-
const glob = new Bun.Glob("*.tsx")
|
|
75
|
-
const dirPath = resolve(examplesDir, dir)
|
|
76
|
-
|
|
77
|
-
for (const file of glob.scanSync({ cwd: dirPath })) {
|
|
78
|
-
if (file.startsWith("_")) continue
|
|
79
|
-
|
|
80
|
-
try {
|
|
81
|
-
const mod = await import(resolve(dirPath, file))
|
|
82
|
-
if (!mod.meta?.name) continue
|
|
83
|
-
|
|
84
|
-
results.push({
|
|
85
|
-
name: mod.meta.name,
|
|
86
|
-
description: mod.meta.description ?? "",
|
|
87
|
-
file: resolve(dirPath, file),
|
|
88
|
-
category,
|
|
89
|
-
features: mod.meta.features,
|
|
90
|
-
})
|
|
91
|
-
} catch {
|
|
92
|
-
// Skip files that fail to import
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
results.sort((a, b) => {
|
|
98
|
-
const catDiff = (CATEGORY_ORDER[a.category] ?? 99) - (CATEGORY_ORDER[b.category] ?? 99)
|
|
99
|
-
if (catDiff !== 0) return catDiff
|
|
100
|
-
return a.name.localeCompare(b.name)
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
return results
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// =============================================================================
|
|
107
|
-
// Formatting
|
|
108
|
-
// =============================================================================
|
|
109
|
-
|
|
110
|
-
function printHelp(): void {
|
|
111
|
-
console.log(`
|
|
112
|
-
${BOLD}${YELLOW}silvery${RESET} — React framework for modern terminal UIs
|
|
113
|
-
|
|
114
|
-
${BOLD}Usage:${RESET}
|
|
115
|
-
silvery example List all available examples
|
|
116
|
-
silvery example ${DIM}<name>${RESET} Run an example by name (fuzzy match)
|
|
117
|
-
silvery example --list List all available examples
|
|
118
|
-
silvery --help Show this help
|
|
119
|
-
silvery --version Show version
|
|
120
|
-
|
|
121
|
-
${BOLD}Examples:${RESET}
|
|
122
|
-
bunx silvery example todo Run the Todo App example
|
|
123
|
-
bunx silvery example kanban Run the Kanban Board example
|
|
124
|
-
bunx silvery example dashboard Run the Dashboard example
|
|
125
|
-
|
|
126
|
-
${DIM}Documentation: https://silvery.dev${RESET}
|
|
127
|
-
`)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function printExampleList(examples: Example[]): void {
|
|
131
|
-
console.log(`\n${BOLD}${YELLOW} silvery${RESET}${DIM} examples${RESET}\n`)
|
|
132
|
-
|
|
133
|
-
let currentCategory = ""
|
|
134
|
-
|
|
135
|
-
for (const ex of examples) {
|
|
136
|
-
if (ex.category !== currentCategory) {
|
|
137
|
-
currentCategory = ex.category
|
|
138
|
-
const color = CATEGORY_COLOR[currentCategory] ?? WHITE
|
|
139
|
-
console.log(` ${color}${BOLD}${currentCategory}${RESET}`)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const nameStr = `${BOLD}${WHITE}${ex.name}${RESET}`
|
|
143
|
-
const descStr = `${DIM}${ex.description}${RESET}`
|
|
144
|
-
console.log(` ${nameStr} ${descStr}`)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
console.log(`\n ${DIM}Run an example: bunx silvery example <name>${RESET}\n`)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function findExample(examples: Example[], query: string): Example | undefined {
|
|
151
|
-
const q = query.toLowerCase()
|
|
152
|
-
|
|
153
|
-
const exact = examples.find((ex) => ex.name.toLowerCase() === q)
|
|
154
|
-
if (exact) return exact
|
|
155
|
-
|
|
156
|
-
const prefix = examples.find((ex) => ex.name.toLowerCase().startsWith(q))
|
|
157
|
-
if (prefix) return prefix
|
|
158
|
-
|
|
159
|
-
const substring = examples.find((ex) => ex.name.toLowerCase().includes(q))
|
|
160
|
-
if (substring) return substring
|
|
161
|
-
|
|
162
|
-
return undefined
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function printNoMatch(query: string, examples: Example[]): void {
|
|
166
|
-
console.error(`\n${RED}${BOLD}Error:${RESET} No example matching "${query}"\n`)
|
|
167
|
-
console.error(`${DIM}Available examples:${RESET}`)
|
|
168
|
-
|
|
169
|
-
for (const ex of examples) {
|
|
170
|
-
console.error(` ${WHITE}${ex.name}${RESET}`)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
console.error(`\n${DIM}Run ${BOLD}bunx silvery example${RESET}${DIM} for full list with descriptions.${RESET}\n`)
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// =============================================================================
|
|
177
|
-
// Subcommands
|
|
178
|
-
// =============================================================================
|
|
179
|
-
|
|
180
|
-
async function exampleCommand(args: string[]): Promise<void> {
|
|
181
|
-
if (args.includes("--help") || args.includes("-h")) {
|
|
182
|
-
printHelp()
|
|
183
|
-
return
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const examples = await discoverExamples()
|
|
187
|
-
|
|
188
|
-
if (args.length === 0 || args[0] === "--list" || args[0] === "-l") {
|
|
189
|
-
printExampleList(examples)
|
|
190
|
-
return
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const query = args.filter((a) => !a.startsWith("--")).join(" ")
|
|
194
|
-
if (!query) {
|
|
195
|
-
printExampleList(examples)
|
|
196
|
-
return
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const match = findExample(examples, query)
|
|
200
|
-
if (!match) {
|
|
201
|
-
printNoMatch(query, examples)
|
|
202
|
-
process.exit(1)
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
console.log(`${DIM}Running ${BOLD}${match.name}${RESET}${DIM}...${RESET}\n`)
|
|
206
|
-
|
|
207
|
-
const proc = Bun.spawn(["bun", "run", match.file], {
|
|
208
|
-
stdio: ["inherit", "inherit", "inherit"],
|
|
209
|
-
})
|
|
210
|
-
const exitCode = await proc.exited
|
|
211
|
-
process.exit(exitCode)
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// =============================================================================
|
|
215
|
-
// Main
|
|
216
|
-
// =============================================================================
|
|
217
|
-
|
|
218
|
-
async function main(): Promise<void> {
|
|
219
|
-
const args = process.argv.slice(2)
|
|
220
|
-
|
|
221
|
-
// Top-level flags
|
|
222
|
-
if (args.includes("--help") || args.includes("-h") || args.length === 0) {
|
|
223
|
-
printHelp()
|
|
224
|
-
return
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (args.includes("--version") || args.includes("-v")) {
|
|
228
|
-
try {
|
|
229
|
-
const { resolve } = await import("node:path")
|
|
230
|
-
const pkgPath = resolve(new URL(".", import.meta.url).pathname, "../package.json")
|
|
231
|
-
const pkg = await Bun.file(pkgPath).json()
|
|
232
|
-
console.log(`silvery ${pkg.version}`)
|
|
233
|
-
} catch {
|
|
234
|
-
console.log("silvery (version unknown)")
|
|
235
|
-
}
|
|
236
|
-
return
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const subcommand = args[0]
|
|
240
|
-
const subArgs = args.slice(1)
|
|
241
|
-
|
|
242
|
-
switch (subcommand) {
|
|
243
|
-
case "example":
|
|
244
|
-
case "examples":
|
|
245
|
-
case "demo":
|
|
246
|
-
await exampleCommand(subArgs)
|
|
247
|
-
break
|
|
248
|
-
default:
|
|
249
|
-
// If user types "silvery todo", treat it as "silvery example todo"
|
|
250
|
-
await exampleCommand(args)
|
|
251
|
-
break
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
main().catch((err) => {
|
|
256
|
-
console.error(err)
|
|
257
|
-
process.exit(1)
|
|
258
|
-
})
|