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