@shell-shock/plugin-console 0.0.5 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/console-builtin.cjs +718 -6
- package/dist/components/console-builtin.d.cts +5 -1
- package/dist/components/console-builtin.d.cts.map +1 -1
- package/dist/components/console-builtin.d.mts +5 -1
- package/dist/components/console-builtin.d.mts.map +1 -1
- package/dist/components/console-builtin.mjs +718 -7
- package/dist/components/console-builtin.mjs.map +1 -1
- package/dist/components/index.cjs +1 -0
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.mts +2 -2
- package/dist/components/index.mjs +2 -2
- package/package.json +9 -9
|
@@ -3,6 +3,7 @@ import { For, Show, code } from "@alloy-js/core";
|
|
|
3
3
|
import { ElseClause, ElseIfClause, FunctionDeclaration, IfStatement, InterfaceDeclaration, InterfaceMember, TypeDeclaration, VarDeclaration } from "@alloy-js/typescript";
|
|
4
4
|
import { ReflectionKind } from "@powerlines/deepkit/vendor/type";
|
|
5
5
|
import { Spacing } from "@powerlines/plugin-alloy/core/components/spacing";
|
|
6
|
+
import { ClassDeclaration, ClassField, ClassMethod, ClassPropertyGet, ClassPropertySet } from "@powerlines/plugin-alloy/typescript";
|
|
6
7
|
import { BuiltinFile } from "@powerlines/plugin-alloy/typescript/components/builtin-file";
|
|
7
8
|
import { TSDoc, TSDocDefaultValue, TSDocExample, TSDocParam, TSDocRemarks, TSDocReturns } from "@powerlines/plugin-alloy/typescript/components/tsdoc";
|
|
8
9
|
import { IsNotDebug, IsNotVerbose } from "@shell-shock/core/components/helpers";
|
|
@@ -1208,6 +1209,144 @@ function ColorsDeclaration() {
|
|
|
1208
1209
|
}
|
|
1209
1210
|
})}
|
|
1210
1211
|
}
|
|
1212
|
+
},
|
|
1213
|
+
spinner: {
|
|
1214
|
+
icon: {
|
|
1215
|
+
active: ${createComponent(ColorFunction, {
|
|
1216
|
+
get ansi16() {
|
|
1217
|
+
return colors.ansi16.theme.text.spinner.icon.active;
|
|
1218
|
+
},
|
|
1219
|
+
get ansi256() {
|
|
1220
|
+
return colors.ansi256.theme.text.spinner.icon.active;
|
|
1221
|
+
},
|
|
1222
|
+
get ansi16m() {
|
|
1223
|
+
return colors.ansi16m.theme.text.spinner.icon.active;
|
|
1224
|
+
}
|
|
1225
|
+
})},
|
|
1226
|
+
warning: ${createComponent(ColorFunction, {
|
|
1227
|
+
get ansi16() {
|
|
1228
|
+
return colors.ansi16.theme.text.spinner.icon.warning;
|
|
1229
|
+
},
|
|
1230
|
+
get ansi256() {
|
|
1231
|
+
return colors.ansi256.theme.text.spinner.icon.warning;
|
|
1232
|
+
},
|
|
1233
|
+
get ansi16m() {
|
|
1234
|
+
return colors.ansi16m.theme.text.spinner.icon.warning;
|
|
1235
|
+
}
|
|
1236
|
+
})},
|
|
1237
|
+
error: ${createComponent(ColorFunction, {
|
|
1238
|
+
get ansi16() {
|
|
1239
|
+
return colors.ansi16.theme.text.spinner.icon.error;
|
|
1240
|
+
},
|
|
1241
|
+
get ansi256() {
|
|
1242
|
+
return colors.ansi256.theme.text.spinner.icon.error;
|
|
1243
|
+
},
|
|
1244
|
+
get ansi16m() {
|
|
1245
|
+
return colors.ansi16m.theme.text.spinner.icon.error;
|
|
1246
|
+
}
|
|
1247
|
+
})},
|
|
1248
|
+
success: ${createComponent(ColorFunction, {
|
|
1249
|
+
get ansi16() {
|
|
1250
|
+
return colors.ansi16.theme.text.spinner.icon.success;
|
|
1251
|
+
},
|
|
1252
|
+
get ansi256() {
|
|
1253
|
+
return colors.ansi256.theme.text.spinner.icon.success;
|
|
1254
|
+
},
|
|
1255
|
+
get ansi16m() {
|
|
1256
|
+
return colors.ansi16m.theme.text.spinner.icon.success;
|
|
1257
|
+
}
|
|
1258
|
+
})},
|
|
1259
|
+
info: ${createComponent(ColorFunction, {
|
|
1260
|
+
get ansi16() {
|
|
1261
|
+
return colors.ansi16.theme.text.spinner.icon.info;
|
|
1262
|
+
},
|
|
1263
|
+
get ansi256() {
|
|
1264
|
+
return colors.ansi256.theme.text.spinner.icon.info;
|
|
1265
|
+
},
|
|
1266
|
+
get ansi16m() {
|
|
1267
|
+
return colors.ansi16m.theme.text.spinner.icon.info;
|
|
1268
|
+
}
|
|
1269
|
+
})},
|
|
1270
|
+
help: ${createComponent(ColorFunction, {
|
|
1271
|
+
get ansi16() {
|
|
1272
|
+
return colors.ansi16.theme.text.spinner.icon.help;
|
|
1273
|
+
},
|
|
1274
|
+
get ansi256() {
|
|
1275
|
+
return colors.ansi256.theme.text.spinner.icon.help;
|
|
1276
|
+
},
|
|
1277
|
+
get ansi16m() {
|
|
1278
|
+
return colors.ansi16m.theme.text.spinner.icon.help;
|
|
1279
|
+
}
|
|
1280
|
+
})}
|
|
1281
|
+
},
|
|
1282
|
+
message: {
|
|
1283
|
+
active: ${createComponent(ColorFunction, {
|
|
1284
|
+
get ansi16() {
|
|
1285
|
+
return colors.ansi16.theme.text.spinner.message.active;
|
|
1286
|
+
},
|
|
1287
|
+
get ansi256() {
|
|
1288
|
+
return colors.ansi256.theme.text.spinner.message.active;
|
|
1289
|
+
},
|
|
1290
|
+
get ansi16m() {
|
|
1291
|
+
return colors.ansi16m.theme.text.spinner.message.active;
|
|
1292
|
+
}
|
|
1293
|
+
})},
|
|
1294
|
+
warning: ${createComponent(ColorFunction, {
|
|
1295
|
+
get ansi16() {
|
|
1296
|
+
return colors.ansi16.theme.text.spinner.message.warning;
|
|
1297
|
+
},
|
|
1298
|
+
get ansi256() {
|
|
1299
|
+
return colors.ansi256.theme.text.spinner.message.warning;
|
|
1300
|
+
},
|
|
1301
|
+
get ansi16m() {
|
|
1302
|
+
return colors.ansi16m.theme.text.spinner.message.warning;
|
|
1303
|
+
}
|
|
1304
|
+
})},
|
|
1305
|
+
error: ${createComponent(ColorFunction, {
|
|
1306
|
+
get ansi16() {
|
|
1307
|
+
return colors.ansi16.theme.text.spinner.message.error;
|
|
1308
|
+
},
|
|
1309
|
+
get ansi256() {
|
|
1310
|
+
return colors.ansi256.theme.text.spinner.message.error;
|
|
1311
|
+
},
|
|
1312
|
+
get ansi16m() {
|
|
1313
|
+
return colors.ansi16m.theme.text.spinner.message.error;
|
|
1314
|
+
}
|
|
1315
|
+
})},
|
|
1316
|
+
success: ${createComponent(ColorFunction, {
|
|
1317
|
+
get ansi16() {
|
|
1318
|
+
return colors.ansi16.theme.text.spinner.message.success;
|
|
1319
|
+
},
|
|
1320
|
+
get ansi256() {
|
|
1321
|
+
return colors.ansi256.theme.text.spinner.message.success;
|
|
1322
|
+
},
|
|
1323
|
+
get ansi16m() {
|
|
1324
|
+
return colors.ansi16m.theme.text.spinner.message.success;
|
|
1325
|
+
}
|
|
1326
|
+
})},
|
|
1327
|
+
info: ${createComponent(ColorFunction, {
|
|
1328
|
+
get ansi16() {
|
|
1329
|
+
return colors.ansi16.theme.text.spinner.message.info;
|
|
1330
|
+
},
|
|
1331
|
+
get ansi256() {
|
|
1332
|
+
return colors.ansi256.theme.text.spinner.message.info;
|
|
1333
|
+
},
|
|
1334
|
+
get ansi16m() {
|
|
1335
|
+
return colors.ansi16m.theme.text.spinner.message.info;
|
|
1336
|
+
}
|
|
1337
|
+
})},
|
|
1338
|
+
help: ${createComponent(ColorFunction, {
|
|
1339
|
+
get ansi16() {
|
|
1340
|
+
return colors.ansi16.theme.text.spinner.message.help;
|
|
1341
|
+
},
|
|
1342
|
+
get ansi256() {
|
|
1343
|
+
return colors.ansi256.theme.text.spinner.message.help;
|
|
1344
|
+
},
|
|
1345
|
+
get ansi16m() {
|
|
1346
|
+
return colors.ansi16m.theme.text.spinner.message.help;
|
|
1347
|
+
}
|
|
1348
|
+
})}
|
|
1349
|
+
}
|
|
1211
1350
|
}
|
|
1212
1351
|
},
|
|
1213
1352
|
border: {
|
|
@@ -2095,6 +2234,564 @@ function LinkFunctionDeclaration() {
|
|
|
2095
2234
|
}
|
|
2096
2235
|
})];
|
|
2097
2236
|
}
|
|
2237
|
+
/**
|
|
2238
|
+
* A component to generate the `spinner` function in the `shell-shock:console` builtin module.
|
|
2239
|
+
*/
|
|
2240
|
+
function SpinnerFunctionDeclaration() {
|
|
2241
|
+
const theme = useTheme();
|
|
2242
|
+
return [
|
|
2243
|
+
createComponent(TypeDeclaration, {
|
|
2244
|
+
name: "WriteStream",
|
|
2245
|
+
children: `NodeJS.WriteStream;`
|
|
2246
|
+
}),
|
|
2247
|
+
createComponent(Spacing, {}),
|
|
2248
|
+
createComponent(VarDeclaration, {
|
|
2249
|
+
"const": true,
|
|
2250
|
+
name: "activeHooksPerStream",
|
|
2251
|
+
initializer: "new Set();"
|
|
2252
|
+
}),
|
|
2253
|
+
createComponent(Spacing, {}),
|
|
2254
|
+
createComponent(InterfaceDeclaration, {
|
|
2255
|
+
"export": true,
|
|
2256
|
+
name: "SpinnerOptions",
|
|
2257
|
+
doc: "Options for configuring the spinner.",
|
|
2258
|
+
get children() {
|
|
2259
|
+
return [
|
|
2260
|
+
createComponent(InterfaceMember, {
|
|
2261
|
+
name: "message",
|
|
2262
|
+
optional: true,
|
|
2263
|
+
type: "string",
|
|
2264
|
+
doc: "The message text to display next to the spinner. Defaults to an empty string."
|
|
2265
|
+
}),
|
|
2266
|
+
createIntrinsic("hbr", {}),
|
|
2267
|
+
createComponent(InterfaceMember, {
|
|
2268
|
+
name: "stream",
|
|
2269
|
+
optional: true,
|
|
2270
|
+
type: "WriteStream",
|
|
2271
|
+
doc: "The output stream to write the spinner to. Defaults to process.stderr."
|
|
2272
|
+
}),
|
|
2273
|
+
createIntrinsic("hbr", {}),
|
|
2274
|
+
createComponent(InterfaceMember, {
|
|
2275
|
+
name: "spinner",
|
|
2276
|
+
optional: true,
|
|
2277
|
+
type: "ThemeSpinnerResolvedConfig | SpinnerPreset",
|
|
2278
|
+
doc: "The spinner animation to use. Should be an object with a 'frames' property (an array of strings representing each frame of the animation) and an 'interval' property (the time in milliseconds between each frame). If not specified, a default spinner animation will be used."
|
|
2279
|
+
})
|
|
2280
|
+
];
|
|
2281
|
+
}
|
|
2282
|
+
}),
|
|
2283
|
+
createComponent(Spacing, {}),
|
|
2284
|
+
createComponent(ClassDeclaration, {
|
|
2285
|
+
name: "Spinner",
|
|
2286
|
+
get children() {
|
|
2287
|
+
return [
|
|
2288
|
+
createComponent(ClassField, {
|
|
2289
|
+
name: "frames",
|
|
2290
|
+
isPrivateMember: true,
|
|
2291
|
+
type: "string[]"
|
|
2292
|
+
}),
|
|
2293
|
+
createIntrinsic("hbr", {}),
|
|
2294
|
+
createComponent(ClassField, {
|
|
2295
|
+
name: "interval",
|
|
2296
|
+
isPrivateMember: true,
|
|
2297
|
+
type: "number"
|
|
2298
|
+
}),
|
|
2299
|
+
createIntrinsic("hbr", {}),
|
|
2300
|
+
createComponent(ClassField, {
|
|
2301
|
+
name: "currentFrame",
|
|
2302
|
+
isPrivateMember: true,
|
|
2303
|
+
type: "number",
|
|
2304
|
+
children: code`-1`
|
|
2305
|
+
}),
|
|
2306
|
+
createIntrinsic("hbr", {}),
|
|
2307
|
+
createComponent(ClassField, {
|
|
2308
|
+
name: "timer",
|
|
2309
|
+
isPrivateMember: true,
|
|
2310
|
+
optional: true,
|
|
2311
|
+
type: "NodeJS.Timeout"
|
|
2312
|
+
}),
|
|
2313
|
+
createIntrinsic("hbr", {}),
|
|
2314
|
+
createComponent(ClassField, {
|
|
2315
|
+
name: "message",
|
|
2316
|
+
isPrivateMember: true,
|
|
2317
|
+
type: "string",
|
|
2318
|
+
children: code`""`
|
|
2319
|
+
}),
|
|
2320
|
+
createIntrinsic("hbr", {}),
|
|
2321
|
+
createComponent(ClassField, {
|
|
2322
|
+
name: "stream",
|
|
2323
|
+
isPrivateMember: true,
|
|
2324
|
+
type: "WriteStream",
|
|
2325
|
+
children: code`process.stderr`
|
|
2326
|
+
}),
|
|
2327
|
+
createIntrinsic("hbr", {}),
|
|
2328
|
+
createComponent(ClassField, {
|
|
2329
|
+
name: "lines",
|
|
2330
|
+
isPrivateMember: true,
|
|
2331
|
+
type: "number",
|
|
2332
|
+
children: code`0`
|
|
2333
|
+
}),
|
|
2334
|
+
createIntrinsic("hbr", {}),
|
|
2335
|
+
createComponent(ClassField, {
|
|
2336
|
+
name: "exitHandlerBound",
|
|
2337
|
+
isPrivateMember: true,
|
|
2338
|
+
type: "(signal: any) => void",
|
|
2339
|
+
children: code`() => {}`
|
|
2340
|
+
}),
|
|
2341
|
+
createIntrinsic("hbr", {}),
|
|
2342
|
+
createComponent(ClassField, {
|
|
2343
|
+
name: "lastSpinnerFrameTime",
|
|
2344
|
+
isPrivateMember: true,
|
|
2345
|
+
type: "number",
|
|
2346
|
+
children: code`0`
|
|
2347
|
+
}),
|
|
2348
|
+
createIntrinsic("hbr", {}),
|
|
2349
|
+
createComponent(ClassField, {
|
|
2350
|
+
name: "isSpinning",
|
|
2351
|
+
isPrivateMember: true,
|
|
2352
|
+
type: "boolean",
|
|
2353
|
+
children: code`false`
|
|
2354
|
+
}),
|
|
2355
|
+
createIntrinsic("hbr", {}),
|
|
2356
|
+
createComponent(ClassField, {
|
|
2357
|
+
name: "hookedStreams",
|
|
2358
|
+
isPrivateMember: true,
|
|
2359
|
+
type: "Map<WriteStream, { write?: WriteStream[\"write\"]; originalWrite: WriteStream[\"write\"]; hookedWrite: WriteStream[\"write\"] }>",
|
|
2360
|
+
children: code`new Map()`
|
|
2361
|
+
}),
|
|
2362
|
+
createIntrinsic("hbr", {}),
|
|
2363
|
+
createComponent(ClassField, {
|
|
2364
|
+
name: "isInternalWrite",
|
|
2365
|
+
isPrivateMember: true,
|
|
2366
|
+
type: "boolean",
|
|
2367
|
+
children: code`false`
|
|
2368
|
+
}),
|
|
2369
|
+
createIntrinsic("hbr", {}),
|
|
2370
|
+
createComponent(ClassField, {
|
|
2371
|
+
name: "isDeferringRender",
|
|
2372
|
+
isPrivateMember: true,
|
|
2373
|
+
type: "boolean",
|
|
2374
|
+
children: code`false`
|
|
2375
|
+
}),
|
|
2376
|
+
createComponent(Spacing, {}),
|
|
2377
|
+
memo(() => code`constructor(options: SpinnerOptions = {}) {
|
|
2378
|
+
const spinner = (typeof options.spinner === "string" ? resolveSpinner(options.spinner as SpinnerPreset) : options.spinner) ?? ${JSON.stringify(theme.spinner)};
|
|
2379
|
+
this.#frames = spinner.frames;
|
|
2380
|
+
this.#interval = spinner.interval;
|
|
2381
|
+
|
|
2382
|
+
if (options.message) {
|
|
2383
|
+
this.#message = options.message;
|
|
2384
|
+
}
|
|
2385
|
+
if (options.stream) {
|
|
2386
|
+
this.#stream = options.stream;
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2389
|
+
this.#exitHandlerBound = this.#exitHandler.bind(this);
|
|
2390
|
+
}
|
|
2391
|
+
|
|
2392
|
+
#internalWrite(action: () => unknown) {
|
|
2393
|
+
this.#isInternalWrite = true;
|
|
2394
|
+
try {
|
|
2395
|
+
return action();
|
|
2396
|
+
} finally {
|
|
2397
|
+
this.#isInternalWrite = false;
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2400
|
+
|
|
2401
|
+
#stringifyChunk(chunk: string | Uint8Array<ArrayBufferLike> | ArrayBufferLike) {
|
|
2402
|
+
if (chunk === undefined || chunk === null) {
|
|
2403
|
+
return "";
|
|
2404
|
+
}
|
|
2405
|
+
|
|
2406
|
+
if (typeof chunk === "string") {
|
|
2407
|
+
return chunk;
|
|
2408
|
+
}
|
|
2409
|
+
|
|
2410
|
+
if (Buffer.isBuffer(chunk) || ArrayBuffer.isView(chunk)) {
|
|
2411
|
+
return Buffer.from(chunk).toString("utf8");
|
|
2412
|
+
}
|
|
2413
|
+
|
|
2414
|
+
return String(chunk);
|
|
2415
|
+
}
|
|
2416
|
+
|
|
2417
|
+
#withSynchronizedOutput(action: () => unknown) {
|
|
2418
|
+
if (!isInteractive) {
|
|
2419
|
+
return action();
|
|
2420
|
+
}
|
|
2421
|
+
|
|
2422
|
+
try {
|
|
2423
|
+
this.#write("\\u001B[?2026h");
|
|
2424
|
+
return action();
|
|
2425
|
+
} finally {
|
|
2426
|
+
this.#write("\\u001B[?2026l");
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
|
|
2430
|
+
#hookStream(stream: WriteStream) {
|
|
2431
|
+
if (!stream || this.#hookedStreams.has(stream) || typeof stream.write !== "function") {
|
|
2432
|
+
return;
|
|
2433
|
+
}
|
|
2434
|
+
|
|
2435
|
+
if (activeHooksPerStream.has(stream)) {
|
|
2436
|
+
return;
|
|
2437
|
+
}
|
|
2438
|
+
|
|
2439
|
+
const originalWrite = stream.write;
|
|
2440
|
+
const hookedWrite = ((...writeArguments: Parameters<WriteStream["write"]>) => this.#hookedWrite(stream, originalWrite, writeArguments)) as WriteStream["write"];
|
|
2441
|
+
|
|
2442
|
+
this.#hookedStreams.set(stream, {originalWrite, hookedWrite});
|
|
2443
|
+
activeHooksPerStream.add(stream);
|
|
2444
|
+
stream.write = hookedWrite;
|
|
2445
|
+
}
|
|
2446
|
+
|
|
2447
|
+
#installHook() {
|
|
2448
|
+
if (!isInteractive || this.#hookedStreams.size > 0) {
|
|
2449
|
+
return;
|
|
2450
|
+
}
|
|
2451
|
+
|
|
2452
|
+
const streamsToHook = new Set([this.#stream]);
|
|
2453
|
+
if (this.#stream === process.stdout || this.#stream === process.stderr) {
|
|
2454
|
+
if (isInteractive(process.stdout)) {
|
|
2455
|
+
streamsToHook.add(process.stdout);
|
|
2456
|
+
}
|
|
2457
|
+
|
|
2458
|
+
if (isInteractive(process.stderr)) {
|
|
2459
|
+
streamsToHook.add(process.stderr);
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2463
|
+
for (const stream of streamsToHook) {
|
|
2464
|
+
this.#hookStream(stream);
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
|
|
2468
|
+
#uninstallHook() {
|
|
2469
|
+
for (const [stream, hookInfo] of this.#hookedStreams) {
|
|
2470
|
+
if (stream.write === hookInfo.hookedWrite) {
|
|
2471
|
+
stream.write = hookInfo.originalWrite;
|
|
2472
|
+
}
|
|
2473
|
+
|
|
2474
|
+
activeHooksPerStream.delete(stream);
|
|
2475
|
+
}
|
|
2476
|
+
|
|
2477
|
+
this.#hookedStreams.clear();
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
#hookedWrite(stream: WriteStream, originalWrite: typeof stream.write, writeArguments: Parameters<typeof stream.write>) {
|
|
2481
|
+
const [chunk, callback] = writeArguments;
|
|
2482
|
+
|
|
2483
|
+
if (this.#isInternalWrite || !this.isSpinning) {
|
|
2484
|
+
return originalWrite.call(stream, chunk);
|
|
2485
|
+
}
|
|
2486
|
+
|
|
2487
|
+
if (this.#lines > 0) {
|
|
2488
|
+
this.clear();
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
const chunkString = this.#stringifyChunk(chunk);
|
|
2492
|
+
const chunkTerminatesLine = chunkString.at(-1) === "\\n";
|
|
2493
|
+
const writeResult = originalWrite.call(stream, chunk);
|
|
2494
|
+
|
|
2495
|
+
if (chunkTerminatesLine) {
|
|
2496
|
+
this.#isDeferringRender = false;
|
|
2497
|
+
} else if (chunkString !== "") {
|
|
2498
|
+
this.#isDeferringRender = true;
|
|
2499
|
+
}
|
|
2500
|
+
|
|
2501
|
+
if (this.isSpinning && !this.#isDeferringRender) {
|
|
2502
|
+
this.#render();
|
|
2503
|
+
}
|
|
2504
|
+
|
|
2505
|
+
return writeResult;
|
|
2506
|
+
}
|
|
2507
|
+
|
|
2508
|
+
#stopWithIcon(icon: string, message: string) {
|
|
2509
|
+
return this.stop(\`\${icon} \${message ?? this.#message}\`);
|
|
2510
|
+
}
|
|
2511
|
+
|
|
2512
|
+
#render() {
|
|
2513
|
+
if (this.#isDeferringRender) {
|
|
2514
|
+
return;
|
|
2515
|
+
}
|
|
2516
|
+
|
|
2517
|
+
const useSynchronizedOutput = isInteractive;
|
|
2518
|
+
if (this.#currentFrame === -1 || Date.now() - this.#lastSpinnerFrameTime >= this.#interval) {
|
|
2519
|
+
this.#currentFrame = ++this.#currentFrame % this.#frames.length;
|
|
2520
|
+
this.#lastSpinnerFrameTime = Date.now();
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
let display = \`\${colors.text.spinner.icon.active(this.#frames[this.#currentFrame])} \${colors.text.spinner.message.active(this.#message)}\`;
|
|
2524
|
+
if (!isInteractive) {
|
|
2525
|
+
display += "\\n";
|
|
2526
|
+
}
|
|
2527
|
+
|
|
2528
|
+
if (useSynchronizedOutput) {
|
|
2529
|
+
this.#withSynchronizedOutput(() => {
|
|
2530
|
+
this.clear();
|
|
2531
|
+
this.#write(display);
|
|
2532
|
+
});
|
|
2533
|
+
} else {
|
|
2534
|
+
this.#write(display);
|
|
2535
|
+
}
|
|
2536
|
+
|
|
2537
|
+
if (isInteractive) {
|
|
2538
|
+
this.#lines = this.#lineCount(display);
|
|
2539
|
+
}
|
|
2540
|
+
}
|
|
2541
|
+
|
|
2542
|
+
#write(message: string) {
|
|
2543
|
+
this.#internalWrite(() => {
|
|
2544
|
+
this.#stream.write(message);
|
|
2545
|
+
});
|
|
2546
|
+
}
|
|
2547
|
+
|
|
2548
|
+
#lineCount(message: string) {
|
|
2549
|
+
const width = this.#stream.columns ?? 80;
|
|
2550
|
+
const lines = stripVTControlCharacters(message).split("\\n");
|
|
2551
|
+
|
|
2552
|
+
let lineCount = 0;
|
|
2553
|
+
for (const line of lines) {
|
|
2554
|
+
lineCount += Math.max(1, Math.ceil(line.length / width));
|
|
2555
|
+
}
|
|
2556
|
+
|
|
2557
|
+
return lineCount;
|
|
2558
|
+
}
|
|
2559
|
+
|
|
2560
|
+
#hideCursor() {
|
|
2561
|
+
if (isInteractive) {
|
|
2562
|
+
this.#write("\\u001B[?25l");
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
|
|
2566
|
+
#showCursor() {
|
|
2567
|
+
if (isInteractive) {
|
|
2568
|
+
this.#write("\\u001B[?25h");
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2571
|
+
|
|
2572
|
+
#subscribeToProcessEvents() {
|
|
2573
|
+
process.once("SIGINT", this.#exitHandlerBound);
|
|
2574
|
+
process.once("SIGTERM", this.#exitHandlerBound);
|
|
2575
|
+
}
|
|
2576
|
+
|
|
2577
|
+
#unsubscribeFromProcessEvents() {
|
|
2578
|
+
process.off("SIGINT", this.#exitHandlerBound);
|
|
2579
|
+
process.off("SIGTERM", this.#exitHandlerBound);
|
|
2580
|
+
}
|
|
2581
|
+
|
|
2582
|
+
#exitHandler(signal: any) {
|
|
2583
|
+
if (this.isSpinning) {
|
|
2584
|
+
this.stop();
|
|
2585
|
+
}
|
|
2586
|
+
|
|
2587
|
+
process.exit(signal === "SIGINT" ? 130 : (signal === "SIGTERM" ? 143 : 1));
|
|
2588
|
+
} `),
|
|
2589
|
+
createComponent(ClassPropertyGet, {
|
|
2590
|
+
"public": true,
|
|
2591
|
+
name: "isSpinning",
|
|
2592
|
+
type: "boolean",
|
|
2593
|
+
doc: "Whether the spinner is currently active and spinning.",
|
|
2594
|
+
children: code`return this.#isSpinning;`
|
|
2595
|
+
}),
|
|
2596
|
+
createComponent(Spacing, {}),
|
|
2597
|
+
createComponent(ClassPropertySet, {
|
|
2598
|
+
"public": true,
|
|
2599
|
+
name: "message",
|
|
2600
|
+
type: "string",
|
|
2601
|
+
doc: "Set the message displayed by the spinner.",
|
|
2602
|
+
children: code`this.#message = value;`
|
|
2603
|
+
}),
|
|
2604
|
+
createComponent(Spacing, {}),
|
|
2605
|
+
createComponent(ClassPropertyGet, {
|
|
2606
|
+
"public": true,
|
|
2607
|
+
name: "message",
|
|
2608
|
+
type: "string",
|
|
2609
|
+
doc: "Get the message displayed by the spinner.",
|
|
2610
|
+
children: code`return this.#message;`
|
|
2611
|
+
}),
|
|
2612
|
+
createComponent(Spacing, {}),
|
|
2613
|
+
createComponent(ClassMethod, {
|
|
2614
|
+
name: "start",
|
|
2615
|
+
doc: "Start the spinner animation.",
|
|
2616
|
+
parameters: [{
|
|
2617
|
+
name: "message",
|
|
2618
|
+
type: "string"
|
|
2619
|
+
}],
|
|
2620
|
+
get children() {
|
|
2621
|
+
return [
|
|
2622
|
+
createComponent(IfStatement, {
|
|
2623
|
+
condition: code`message !== undefined`,
|
|
2624
|
+
children: code`this.#message = message;`
|
|
2625
|
+
}),
|
|
2626
|
+
createComponent(IfStatement, {
|
|
2627
|
+
condition: code`this.isSpinning`,
|
|
2628
|
+
children: code`return this;`
|
|
2629
|
+
}),
|
|
2630
|
+
code`this.#isSpinning = true;
|
|
2631
|
+
this.#hideCursor();
|
|
2632
|
+
this.#installHook();
|
|
2633
|
+
this.#render();
|
|
2634
|
+
this.#subscribeToProcessEvents();
|
|
2635
|
+
|
|
2636
|
+
if (isInteractive) {
|
|
2637
|
+
this.#timer = setInterval(() => {
|
|
2638
|
+
this.#render();
|
|
2639
|
+
}, this.#interval);
|
|
2640
|
+
}
|
|
2641
|
+
|
|
2642
|
+
return this;
|
|
2643
|
+
`
|
|
2644
|
+
];
|
|
2645
|
+
}
|
|
2646
|
+
}),
|
|
2647
|
+
createComponent(Spacing, {}),
|
|
2648
|
+
createComponent(ClassMethod, {
|
|
2649
|
+
name: "stop",
|
|
2650
|
+
doc: "Stop the spinner animation.",
|
|
2651
|
+
parameters: [{
|
|
2652
|
+
name: "finalMessage",
|
|
2653
|
+
optional: true,
|
|
2654
|
+
type: "string"
|
|
2655
|
+
}],
|
|
2656
|
+
children: code`if (!this.isSpinning) {
|
|
2657
|
+
return this;
|
|
2658
|
+
}
|
|
2659
|
+
|
|
2660
|
+
const shouldWriteNewline = this.#isDeferringRender;
|
|
2661
|
+
this.#isSpinning = false;
|
|
2662
|
+
if (this.#timer) {
|
|
2663
|
+
clearInterval(this.#timer);
|
|
2664
|
+
this.#timer = undefined;
|
|
2665
|
+
}
|
|
2666
|
+
|
|
2667
|
+
this.#isDeferringRender = false;
|
|
2668
|
+
this.#uninstallHook();
|
|
2669
|
+
this.#showCursor();
|
|
2670
|
+
this.clear();
|
|
2671
|
+
this.#unsubscribeFromProcessEvents();
|
|
2672
|
+
|
|
2673
|
+
if (finalMessage) {
|
|
2674
|
+
const prefix = shouldWriteNewline ? "\\n" : "";
|
|
2675
|
+
this.#stream.write(\`\${prefix}\${finalMessage}\\n\`);
|
|
2676
|
+
}
|
|
2677
|
+
|
|
2678
|
+
return this;
|
|
2679
|
+
|
|
2680
|
+
`
|
|
2681
|
+
}),
|
|
2682
|
+
createComponent(Spacing, {}),
|
|
2683
|
+
createComponent(ClassMethod, {
|
|
2684
|
+
name: "clear",
|
|
2685
|
+
doc: "Clear the spinner animation.",
|
|
2686
|
+
children: code`if (!isInteractive) {
|
|
2687
|
+
return this;
|
|
2688
|
+
}
|
|
2689
|
+
|
|
2690
|
+
if (this.#lines === 0) {
|
|
2691
|
+
return this;
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2694
|
+
this.#internalWrite(() => {
|
|
2695
|
+
this.#stream.cursorTo(0);
|
|
2696
|
+
|
|
2697
|
+
for (let index = 0; index < this.#lines; index++) {
|
|
2698
|
+
if (index > 0) {
|
|
2699
|
+
this.#stream.moveCursor(0, -1);
|
|
2700
|
+
}
|
|
2701
|
+
|
|
2702
|
+
this.#stream.clearLine(1);
|
|
2703
|
+
}
|
|
2704
|
+
});
|
|
2705
|
+
|
|
2706
|
+
this.#lines = 0;
|
|
2707
|
+
return this; `
|
|
2708
|
+
}),
|
|
2709
|
+
createComponent(Spacing, {}),
|
|
2710
|
+
createComponent(ClassMethod, {
|
|
2711
|
+
name: "success",
|
|
2712
|
+
doc: "Mark the spinner as successful.",
|
|
2713
|
+
parameters: [{
|
|
2714
|
+
name: "message",
|
|
2715
|
+
type: "string"
|
|
2716
|
+
}],
|
|
2717
|
+
get children() {
|
|
2718
|
+
return code`return this.#stopWithIcon(colors.text.spinner.icon.success("${theme.icons.spinner.success}"), colors.text.spinner.message.success(message)); `;
|
|
2719
|
+
}
|
|
2720
|
+
}),
|
|
2721
|
+
createComponent(Spacing, {}),
|
|
2722
|
+
createComponent(ClassMethod, {
|
|
2723
|
+
name: "error",
|
|
2724
|
+
doc: "Mark the spinner as failed.",
|
|
2725
|
+
parameters: [{
|
|
2726
|
+
name: "message",
|
|
2727
|
+
type: "string"
|
|
2728
|
+
}],
|
|
2729
|
+
get children() {
|
|
2730
|
+
return code`return this.#stopWithIcon(colors.text.spinner.icon.error("${theme.icons.spinner.error}"), colors.text.spinner.message.error(message)); `;
|
|
2731
|
+
}
|
|
2732
|
+
}),
|
|
2733
|
+
createComponent(Spacing, {}),
|
|
2734
|
+
createComponent(ClassMethod, {
|
|
2735
|
+
name: "warning",
|
|
2736
|
+
doc: "Mark the spinner as warning.",
|
|
2737
|
+
parameters: [{
|
|
2738
|
+
name: "message",
|
|
2739
|
+
type: "string"
|
|
2740
|
+
}],
|
|
2741
|
+
get children() {
|
|
2742
|
+
return code`return this.#stopWithIcon(colors.text.spinner.icon.warning("${theme.icons.spinner.warning}"), colors.text.spinner.message.warning(message)); `;
|
|
2743
|
+
}
|
|
2744
|
+
}),
|
|
2745
|
+
createComponent(Spacing, {}),
|
|
2746
|
+
createComponent(ClassMethod, {
|
|
2747
|
+
name: "info",
|
|
2748
|
+
doc: "Mark the spinner as informational.",
|
|
2749
|
+
parameters: [{
|
|
2750
|
+
name: "message",
|
|
2751
|
+
type: "string"
|
|
2752
|
+
}],
|
|
2753
|
+
get children() {
|
|
2754
|
+
return code`return this.#stopWithIcon(colors.text.spinner.icon.info("${theme.icons.spinner.info}"), colors.text.spinner.message.info(message)); `;
|
|
2755
|
+
}
|
|
2756
|
+
}),
|
|
2757
|
+
createComponent(Spacing, {}),
|
|
2758
|
+
createComponent(ClassMethod, {
|
|
2759
|
+
name: "help",
|
|
2760
|
+
doc: "Mark the spinner as help.",
|
|
2761
|
+
parameters: [{
|
|
2762
|
+
name: "message",
|
|
2763
|
+
type: "string"
|
|
2764
|
+
}],
|
|
2765
|
+
get children() {
|
|
2766
|
+
return code`return this.#stopWithIcon(colors.text.spinner.icon.help("${theme.icons.spinner.help}"), colors.text.spinner.message.help(message)); `;
|
|
2767
|
+
}
|
|
2768
|
+
}),
|
|
2769
|
+
createComponent(Spacing, {})
|
|
2770
|
+
];
|
|
2771
|
+
}
|
|
2772
|
+
}),
|
|
2773
|
+
createComponent(Spacing, {}),
|
|
2774
|
+
createComponent(TSDoc, {
|
|
2775
|
+
heading: "Render a spinner in the console.",
|
|
2776
|
+
get children() {
|
|
2777
|
+
return [createComponent(TSDocParam, {
|
|
2778
|
+
name: "options",
|
|
2779
|
+
children: `Options for configuring the spinner, including the message to display, the output stream to write to, and the spinner animation to use.`
|
|
2780
|
+
}), createComponent(TSDocReturns, { children: `An instance of the Spinner class, which can be used to control the spinner animation (e.g., start, stop, mark as success/error, etc.).` })];
|
|
2781
|
+
}
|
|
2782
|
+
}),
|
|
2783
|
+
createComponent(FunctionDeclaration, {
|
|
2784
|
+
"export": true,
|
|
2785
|
+
name: "createSpinner",
|
|
2786
|
+
parameters: [{
|
|
2787
|
+
name: "options",
|
|
2788
|
+
type: "SpinnerOptions",
|
|
2789
|
+
optional: true
|
|
2790
|
+
}],
|
|
2791
|
+
children: code`return new Spinner(options);`
|
|
2792
|
+
})
|
|
2793
|
+
];
|
|
2794
|
+
}
|
|
2098
2795
|
function extractBorderOptionsObject(direction, theme) {
|
|
2099
2796
|
return `borderOptions.${direction} === "primary" ? colors.border.app.table.primary("${theme.borderStyles.app.table.primary[direction]}") : borderOptions.${direction} === "secondary" ? colors.border.app.table.secondary("${theme.borderStyles.app.table.secondary[direction]}") : borderOptions.${direction} === "tertiary" ? colors.border.app.table.tertiary("${theme.borderStyles.app.table.tertiary[direction]}") : !borderOptions.${direction} || borderOptions.${direction} === "none" ? "" : borderOptions.${direction}`;
|
|
2100
2797
|
}
|
|
@@ -2796,16 +3493,28 @@ function ConsoleBuiltin(props) {
|
|
|
2796
3493
|
id: "console",
|
|
2797
3494
|
description: "A collection of helper utilities to assist in generating content meant for display in the console.",
|
|
2798
3495
|
get imports() {
|
|
2799
|
-
return defu(imports, {
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
3496
|
+
return defu(imports, {
|
|
3497
|
+
"@shell-shock/plugin-theme/types/theme": [{
|
|
3498
|
+
name: "ThemeColorsResolvedConfig",
|
|
3499
|
+
type: true
|
|
3500
|
+
}, {
|
|
3501
|
+
name: "ThemeSpinnerResolvedConfig",
|
|
3502
|
+
type: true
|
|
3503
|
+
}],
|
|
3504
|
+
"@shell-shock/plugin-theme/helpers/spinners": [{
|
|
3505
|
+
name: "SpinnerPreset",
|
|
3506
|
+
type: true
|
|
3507
|
+
}, { name: "resolveSpinner" }],
|
|
3508
|
+
"node:buffer": ["WithImplicitCoercion"],
|
|
3509
|
+
"node:util": ["stripVTControlCharacters"]
|
|
3510
|
+
});
|
|
2803
3511
|
},
|
|
2804
3512
|
get builtinImports() {
|
|
2805
3513
|
return defu(builtinImports, {
|
|
2806
3514
|
utils: [
|
|
2807
3515
|
"hasFlag",
|
|
2808
3516
|
"isMinimal",
|
|
3517
|
+
"isInteractive",
|
|
2809
3518
|
"isColorSupported",
|
|
2810
3519
|
"colorSupportLevels",
|
|
2811
3520
|
"isHyperlinkSupported"
|
|
@@ -2833,6 +3542,8 @@ function ConsoleBuiltin(props) {
|
|
|
2833
3542
|
createComponent(Spacing, {}),
|
|
2834
3543
|
createComponent(DividerFunctionDeclaration, {}),
|
|
2835
3544
|
createComponent(Spacing, {}),
|
|
3545
|
+
createComponent(SpinnerFunctionDeclaration, {}),
|
|
3546
|
+
createComponent(Spacing, {}),
|
|
2836
3547
|
createComponent(MessageFunctionDeclaration, {
|
|
2837
3548
|
type: "help",
|
|
2838
3549
|
variant: "help",
|
|
@@ -2931,8 +3642,8 @@ function ConsoleBuiltin(props) {
|
|
|
2931
3642
|
get children() {
|
|
2932
3643
|
return [createComponent(IfStatement, {
|
|
2933
3644
|
condition: code`(err as Error)?.stack`,
|
|
2934
|
-
children: code`message += " \\n\\n" + (err as Error).stack;`
|
|
2935
|
-
}), createComponent(ElseClause, { children: code`message += " \\n\\n" + (new Error(" ")).stack.split("\\n").slice(2).map(line => line.trim()).join("\\n");` })];
|
|
3645
|
+
children: code`message += " \\n\\n" + ((err as Error).stack || "");`
|
|
3646
|
+
}), createComponent(ElseClause, { children: code`message += " \\n\\n" + ((new Error(" ")).stack || "").split("\\n").slice(2).map(line => line.trim()).join("\\n");` })];
|
|
2936
3647
|
}
|
|
2937
3648
|
})
|
|
2938
3649
|
];
|
|
@@ -2949,5 +3660,5 @@ function ConsoleBuiltin(props) {
|
|
|
2949
3660
|
}
|
|
2950
3661
|
|
|
2951
3662
|
//#endregion
|
|
2952
|
-
export { AnsiHelpersDeclarations, ColorsDeclaration, ConsoleBuiltin, DividerFunctionDeclaration, LinkFunctionDeclaration, MessageFunctionDeclaration, StripAnsiFunctionDeclaration, TableFunctionDeclaration, WrapAnsiFunction, WriteLineFunctionDeclaration };
|
|
3663
|
+
export { AnsiHelpersDeclarations, ColorsDeclaration, ConsoleBuiltin, DividerFunctionDeclaration, LinkFunctionDeclaration, MessageFunctionDeclaration, SpinnerFunctionDeclaration, StripAnsiFunctionDeclaration, TableFunctionDeclaration, WrapAnsiFunction, WriteLineFunctionDeclaration };
|
|
2953
3664
|
//# sourceMappingURL=console-builtin.mjs.map
|