@shell-shock/plugin-console 0.2.12 → 0.2.15

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.
@@ -1,4 +1,35 @@
1
- import{createComponent as e,createIntrinsic as t,memo as n,mergeProps as r}from"@alloy-js/core/jsx-runtime";import{For as i,Show as a,code as o}from"@alloy-js/core";import{ElseClause as s,ElseIfClause as c,FunctionDeclaration as l,IfStatement as u,InterfaceDeclaration as d,InterfaceMember as f,TypeDeclaration as p,VarDeclaration as m}from"@alloy-js/typescript";import{ReflectionKind as h}from"@powerlines/deepkit/vendor/type";import{Spacing as g}from"@powerlines/plugin-alloy/core/components/spacing";import{ClassDeclaration as ee,ClassField as _,ClassMethod as v,ClassPropertyGet as y,ClassPropertySet as te}from"@powerlines/plugin-alloy/typescript";import{BuiltinFile as b}from"@powerlines/plugin-alloy/typescript/components/builtin-file";import{TSDoc as x,TSDocDefaultValue as S,TSDocExample as C,TSDocParam as w,TSDocRemarks as T,TSDocReturns as E}from"@powerlines/plugin-alloy/typescript/components/tsdoc";import{IsNotDebug as ne,IsNotVerbose as D}from"@shell-shock/core/components/helpers";import{useColors as re,useTheme as O}from"@shell-shock/plugin-theme/contexts/theme";import{colorKeys as ie,modifierKeys as ae}from"@shell-shock/plugin-theme/helpers/ansi-utils";import{camelCase as k,titleCase as A}from"@stryke/string-format";import{getIndefiniteArticle as j}from"@stryke/string-format/vowels";import{isSetObject as M}from"@stryke/type-checks/is-set-object";import{defu as N}from"defu";function P(){return[e(m,{const:!0,export:!0,name:`beep`,doc:`The ASCII Bell character, which can be used to trigger a beep sound in the console.`,children:o` "\\u0007"; `}),e(g,{}),e(m,{const:!0,export:!0,name:`cursor`,doc:`An object containing ANSI escape codes for controlling the console cursor.`,children:o` {
1
+ import { createComponent, createIntrinsic, memo, mergeProps } from "@alloy-js/core/jsx-runtime";
2
+ import { For, Show, code } from "@alloy-js/core";
3
+ import { ElseClause, ElseIfClause, FunctionDeclaration, IfStatement, InterfaceDeclaration, InterfaceMember, TypeDeclaration, VarDeclaration } from "@alloy-js/typescript";
4
+ import { Spacing } from "@powerlines/plugin-alloy/core/components/spacing";
5
+ import { ClassDeclaration, ClassField, ClassMethod, ClassPropertyGet, ClassPropertySet } from "@powerlines/plugin-alloy/typescript";
6
+ import { BuiltinFile } from "@powerlines/plugin-alloy/typescript/components/builtin-file";
7
+ import { TSDoc, TSDocDefaultValue, TSDocExample, TSDocParam, TSDocRemarks, TSDocReturns } from "@powerlines/plugin-alloy/typescript/components/tsdoc";
8
+ import { IsNotDebug, IsNotVerbose } from "@shell-shock/core/components/helpers";
9
+ import { useColors, useTheme } from "@shell-shock/plugin-theme/contexts/theme";
10
+ import { colorKeys, modifierKeys } from "@shell-shock/plugin-theme/helpers/ansi-utils";
11
+ import { camelCase, titleCase } from "@stryke/string-format";
12
+ import { getIndefiniteArticle } from "@stryke/string-format/vowels";
13
+ import { isSetObject } from "@stryke/type-checks/is-set-object";
14
+ import { defu } from "defu";
15
+
16
+ //#region src/components/console-builtin.tsx
17
+ function AnsiHelpersDeclarations() {
18
+ return [
19
+ createComponent(VarDeclaration, {
20
+ "const": true,
21
+ "export": true,
22
+ name: "beep",
23
+ doc: "The ASCII Bell character, which can be used to trigger a beep sound in the console.",
24
+ children: code` "\\u0007"; `
25
+ }),
26
+ createComponent(Spacing, {}),
27
+ createComponent(VarDeclaration, {
28
+ "const": true,
29
+ "export": true,
30
+ name: "cursor",
31
+ doc: "An object containing ANSI escape codes for controlling the console cursor.",
32
+ children: code` {
2
33
  to(x: number, y?: number) {
3
34
  if (!y) {
4
35
  return \`\\x1B[\${x + 1}G\`;
@@ -34,7 +65,15 @@ import{createComponent as e,createIntrinsic as t,memo as n,mergeProps as r}from"
34
65
  show: "\\x1B[?25h",
35
66
  save: "\\x1B7",
36
67
  restore: "\\x1B8"
37
- } `}),e(g,{}),e(m,{const:!0,export:!0,name:`erase`,doc:`An object containing ANSI escape codes for erasing parts of the console.`,children:o` {
68
+ } `
69
+ }),
70
+ createComponent(Spacing, {}),
71
+ createComponent(VarDeclaration, {
72
+ "const": true,
73
+ "export": true,
74
+ name: "erase",
75
+ doc: "An object containing ANSI escape codes for erasing parts of the console.",
76
+ children: code` {
38
77
  screen: "\\x1B[2J",
39
78
  up: (count = 1) => "\\x1B[1J".repeat(count),
40
79
  down: (count = 1) => "\\x1B[J".repeat(count),
@@ -53,10 +92,34 @@ import{createComponent as e,createIntrinsic as t,memo as n,mergeProps as r}from"
53
92
 
54
93
  return lineClear;
55
94
  }
56
- } `}),e(g,{}),e(m,{const:!0,export:!0,name:`scroll`,doc:`An object containing ANSI escape codes for scrolling the console.`,children:o` {
95
+ } `
96
+ }),
97
+ createComponent(Spacing, {}),
98
+ createComponent(VarDeclaration, {
99
+ "const": true,
100
+ "export": true,
101
+ name: "scroll",
102
+ doc: "An object containing ANSI escape codes for scrolling the console.",
103
+ children: code` {
57
104
  up: (count = 1) => "\\x1B[S".repeat(count),
58
105
  down: (count = 1) => "\\x1B[T".repeat(count)
59
- } `}),e(g,{}),e(l,{export:!0,name:`clear`,doc:`A helper function to clear the console based on a count of lines`,parameters:[{name:`current`,type:`string`,doc:`The current console output to be cleared`},{name:`consoleWidth`,type:`number`,doc:`The number of characters per line in the console`}],children:o`if (!consoleWidth) {
106
+ } `
107
+ }),
108
+ createComponent(Spacing, {}),
109
+ createComponent(FunctionDeclaration, {
110
+ "export": true,
111
+ name: "clear",
112
+ doc: "A helper function to clear the console based on a count of lines",
113
+ parameters: [{
114
+ name: "current",
115
+ type: "string",
116
+ doc: "The current console output to be cleared"
117
+ }, {
118
+ name: "consoleWidth",
119
+ type: "number",
120
+ doc: "The number of characters per line in the console"
121
+ }],
122
+ children: code`if (!consoleWidth) {
60
123
  return erase.line + cursor.to(0);
61
124
  }
62
125
 
@@ -66,7 +129,16 @@ import{createComponent as e,createIntrinsic as t,memo as n,mergeProps as r}from"
66
129
  rows += 1 + Math.floor(Math.max([...stripAnsi(line)].length - 1, 0) / consoleWidth);
67
130
  }
68
131
 
69
- return erase.lines(rows); `}),e(g,{})]}function F({ansi16:e,ansi256:t,ansi16m:n,skipBackground:r=!1}){return o` (text: string | number | boolean | null | undefined${r?``:`, background = false`}): string => {
132
+ return erase.lines(rows); `
133
+ }),
134
+ createComponent(Spacing, {})
135
+ ];
136
+ }
137
+ /**
138
+ * A component to generate a console message function in a Shell Shock project.
139
+ */
140
+ function ColorFunction({ ansi16, ansi256, ansi16m, skipBackground = false }) {
141
+ return code` (text: string | number | boolean | null | undefined${skipBackground ? "" : `, background = false`}): string => {
70
142
  try {
71
143
  if (text === undefined || text === null || text === "") {
72
144
  return "";
@@ -77,17 +149,321 @@ import{createComponent as e,createIntrinsic as t,memo as n,mergeProps as r}from"
77
149
  }
78
150
 
79
151
  if (colorSupportLevels.stdout === 1) {
80
- return wrapAnsi(String(text), ${r?`"${e.open}", "${e.close}"`:`background ? "${e.background.open}" : "${e.open}", background ? "${e.background.close}" : "${e.close}"`});
152
+ return wrapAnsi(String(text), ${skipBackground ? `"${ansi16.open}", "${ansi16.close}"` : `background ? "${ansi16.background.open}" : "${ansi16.open}", background ? "${ansi16.background.close}" : "${ansi16.close}"`});
81
153
  } else if (colorSupportLevels.stdout === 2) {
82
- return wrapAnsi(String(text), ${r?`"${t.open}", "${t.close}"`:`background ? "${t.background.open}" : "${t.open}", background ? "${t.background.close}" : "${t.close}"`});
154
+ return wrapAnsi(String(text), ${skipBackground ? `"${ansi256.open}", "${ansi256.close}"` : `background ? "${ansi256.background.open}" : "${ansi256.open}", background ? "${ansi256.background.close}" : "${ansi256.close}"`});
83
155
  }
84
156
 
85
- return wrapAnsi(String(text), ${r?`"${n.open}", "${n.close}"`:`background ? "${n.background.open}" : "${n.open}", background ? "${n.background.close}" : "${n.close}"`});
157
+ return wrapAnsi(String(text), ${skipBackground ? `"${ansi16m.open}", "${ansi16m.close}"` : `background ? "${ansi16m.background.open}" : "${ansi16m.open}", background ? "${ansi16m.background.close}" : "${ansi16m.close}"`});
86
158
  } catch {
87
159
  return String(text);
88
160
  }
89
161
  }
90
- `}function I(r){let{ansi16:s,ansi256:c,ansi16m:l,type:u,subType:d}=r;return e(i,{get each(){return Object.entries(s)},semicolon:!0,doubleHardline:!0,enderPunctuation:!0,children:([r,i])=>[e(a,{get when(){return M(i)},get children(){return e(a,{get when(){return`open`in i&&`close`in i},get fallback(){return[e(x,{heading:`An object containing various ${d?`${d} `:``}${r}${u?` ${u}`:``} theme coloring functions.`}),n(()=>o` ${k(r)}: { `),t(`hbr`,{}),e(I,{get ansi16(){return s[r]},get ansi256(){return c[r]},get ansi16m(){return l[r]},type:d||u,subType:r}),t(`hbr`,{}),o` }`]},get children(){return[e(x,{get heading(){return`A function that applies ${j(r)} ${r}${u?` ${u}`:``}${d?` ${d}`:``} color styling to provided console text.`},get children(){return[e(T,{children:`This function takes a string and an optional boolean indicating whether to apply the color as a background. It returns the input string wrapped in the appropriate ANSI escape codes for ${r}${u?` ${u}`:``}${d?` ${d}`:``} color styling, based on the terminal's color support level. If colors are not supported, it simply returns the input text as a string.`}),t(`hbr`,{}),e(w,{name:`text`,children:`The console text to which the ${r}${u?` ${u}`:``}${d?` ${d}`:``} color styling should be applied.`}),e(w,{name:`background`,children:"A boolean indicating whether to apply the color as a background. Defaults to `false`."}),e(E,{children:`A string with ANSI escape codes applied for ${r}${u?` ${u}`:``}${d?` ${d}`:``} color styling, or the original text if the style is not supported in the current terminal.`})]}}),n(()=>o`${k(r)}: (text: string, background?: boolean) => string`)]}})}})]})}function L(r){let{ansi16:s,ansi256:c,ansi16m:l,type:u,subType:d}=r;return e(i,{get each(){return Object.entries(s)},comma:!0,doubleHardline:!0,enderPunctuation:!0,children:([r,i])=>[e(a,{get when(){return M(i)},get children(){return e(a,{get when(){return`open`in i&&`close`in i},get fallback(){return[e(x,{heading:`An object containing various ${d?`${d} `:``}${r}${u?` ${u}`:``} theme coloring functions.`}),n(()=>o` ${k(r)}: { `),t(`hbr`,{}),e(L,{get ansi16(){return s[r]},get ansi256(){return c[r]},get ansi16m(){return l[r]},type:d||u,subType:r}),t(`hbr`,{}),o` }`]},get children(){return[e(x,{get heading(){return`A function that applies ${j(r)} ${r}${u?` ${u}`:``}${d?` ${d}`:``} color styling to provided console text.`},get children(){return[e(T,{children:`This function takes a string and an optional boolean indicating whether to apply the color as a background. It returns the input string wrapped in the appropriate ANSI escape codes for ${r}${u?` ${u}`:``}${d?` ${d}`:``} color styling, based on the terminal's color support level. If colors are not supported, it simply returns the input text as a string.`}),t(`hbr`,{}),e(w,{name:`text`,children:`The console text to which the ${r}${u?` ${u}`:``}${d?` ${d}`:``} color styling should be applied.`}),e(w,{name:`background`,children:"A boolean indicating whether to apply the color as a background. Defaults to `false`."}),e(E,{children:`A string with ANSI escape codes applied for ${r}${u?` ${u}`:``}${d?` ${d}`:``} color styling, or the original text if the style is not supported in the current terminal.`})]}}),n(()=>o`${k(r)}: `),e(F,{get ansi16(){return s[r]},get ansi256(){return c[r]},get ansi16m(){return l[r]}})]}})}})]})}function R(){let n=re();return[e(i,{each:ae,semicolon:!0,doubleHardline:!0,enderPunctuation:!0,children:t=>[e(x,{get heading(){return`A function that applies ${j(A(t))} ${A(t)} text-style to provided console text.`},get children(){return[e(w,{name:`text`,get children(){return`The console text to which the ${A(t)} text-style should be applied.`}}),e(E,{get children(){return`A string with ANSI escape codes applied for ${A(t)} text-style, or the original text if the style is not supported in the current terminal.`}})]}}),e(m,{const:!0,export:!0,get name(){return k(t)},get initializer(){return e(F,{get ansi16(){return n.ansi16[t]},get ansi256(){return n.ansi256[t]},get ansi16m(){return n.ansi16m[t]},skipBackground:!0})}})]}),e(g,{}),e(i,{each:ie,semicolon:!0,doubleHardline:!0,enderPunctuation:!0,children:r=>[e(x,{get heading(){return`A function that applies ${j(A(r))} ${A(r)} color styling to provided console text.`},get children(){return[e(T,{get children(){return`This function takes a string and an optional boolean indicating whether to apply the color as a background. It returns the input string wrapped in the appropriate ANSI escape codes for ${j(A(r))} ${A(r)} color styling, based on the terminal's color support level. If colors are not supported, it simply returns the input text as a string.`}}),t(`hbr`,{}),e(w,{name:`text`,get children(){return`The console text to which the ${A(r)} color styling should be applied.`}}),e(w,{name:`background`,children:"A boolean indicating whether to apply the color as a background. Defaults to `false`."}),e(E,{get children(){return`A string with ANSI escape codes applied for ${A(r)} color styling, or the original text if the style is not supported in the current terminal.`}})]}}),e(m,{const:!0,export:!0,get name(){return k(r)},get initializer(){return e(F,{get ansi16(){return n.ansi16[r]},get ansi256(){return n.ansi256[r]},get ansi16m(){return n.ansi16m[r]}})}})]}),e(g,{}),e(i,{get each(){return Object.keys(n.ansi16.theme)},semicolon:!0,doubleHardline:!0,enderPunctuation:!0,children:r=>[e(x,{heading:`A nested object containing functions for applying ${r} theme colors to the console.`}),e(m,{export:!0,get name(){return`${k(r)}Colors`},get initializer(){return[o` {`,t(`hbr`,{}),e(L,{get ansi16(){return n.ansi16.theme[r]},get ansi256(){return n.ansi256.theme[r]},get ansi16m(){return n.ansi16m.theme[r]},type:r}),t(`hbr`,{}),o`}`]}})]}),e(g,{})]}function z(){return[e(l,{name:`adjustIndex`,parameters:[{name:`line`,type:`string`,doc:`An input line which may contain ANSI escape codes. This is used to adjust the index for splitting the line based on visible characters rather than raw string length, ensuring that ANSI codes do not cause incorrect splitting of the text.`},{name:`index`,type:`number`,doc:`The index at which to split the line, based on visible characters (does not account for ANSI escape codes).`}],returnType:`number`,children:o`let adjustedIndex = 0;
162
+ `;
163
+ }
164
+ function ThemeColorTypeDefinition(props) {
165
+ const { ansi16, ansi256, ansi16m, type, subType } = props;
166
+ return createComponent(For, {
167
+ get each() {
168
+ return Object.entries(ansi16);
169
+ },
170
+ semicolon: true,
171
+ doubleHardline: true,
172
+ enderPunctuation: true,
173
+ children: ([color, value]) => [createComponent(Show, {
174
+ get when() {
175
+ return isSetObject(value);
176
+ },
177
+ get children() {
178
+ return createComponent(Show, {
179
+ get when() {
180
+ return "open" in value && "close" in value;
181
+ },
182
+ get fallback() {
183
+ return [
184
+ createComponent(TSDoc, { heading: `An object containing various ${subType ? `${subType} ` : ""}${color}${type ? ` ${type}` : ""} theme coloring functions.` }),
185
+ memo(() => code` ${camelCase(color)}: { `),
186
+ createIntrinsic("hbr", {}),
187
+ createComponent(ThemeColorTypeDefinition, {
188
+ get ansi16() {
189
+ return ansi16[color];
190
+ },
191
+ get ansi256() {
192
+ return ansi256[color];
193
+ },
194
+ get ansi16m() {
195
+ return ansi16m[color];
196
+ },
197
+ type: subType || type,
198
+ subType: color
199
+ }),
200
+ createIntrinsic("hbr", {}),
201
+ code` }`
202
+ ];
203
+ },
204
+ get children() {
205
+ return [createComponent(TSDoc, {
206
+ get heading() {
207
+ return `A function that applies ${getIndefiniteArticle(color)} ${color}${type ? ` ${type}` : ""}${subType ? ` ${subType}` : ""} color styling to provided console text.`;
208
+ },
209
+ get children() {
210
+ return [
211
+ createComponent(TSDocRemarks, { children: `This function takes a string and an optional boolean indicating whether to apply the color as a background. It returns the input string wrapped in the appropriate ANSI escape codes for ${color}${type ? ` ${type}` : ""}${subType ? ` ${subType}` : ""} color styling, based on the terminal's color support level. If colors are not supported, it simply returns the input text as a string.` }),
212
+ createIntrinsic("hbr", {}),
213
+ createComponent(TSDocParam, {
214
+ name: "text",
215
+ children: `The console text to which the ${color}${type ? ` ${type}` : ""}${subType ? ` ${subType}` : ""} color styling should be applied.`
216
+ }),
217
+ createComponent(TSDocParam, {
218
+ name: "background",
219
+ children: `A boolean indicating whether to apply the color as a background. Defaults to \`false\`.`
220
+ }),
221
+ createComponent(TSDocReturns, { children: `A string with ANSI escape codes applied for ${color}${type ? ` ${type}` : ""}${subType ? ` ${subType}` : ""} color styling, or the original text if the style is not supported in the current terminal.` })
222
+ ];
223
+ }
224
+ }), memo(() => code`${camelCase(color)}: (text: string, background?: boolean) => string`)];
225
+ }
226
+ });
227
+ }
228
+ })]
229
+ });
230
+ }
231
+ function ThemeColorObjectDefinition(props) {
232
+ const { ansi16, ansi256, ansi16m, type, subType } = props;
233
+ return createComponent(For, {
234
+ get each() {
235
+ return Object.entries(ansi16);
236
+ },
237
+ comma: true,
238
+ doubleHardline: true,
239
+ enderPunctuation: true,
240
+ children: ([color, value]) => [createComponent(Show, {
241
+ get when() {
242
+ return isSetObject(value);
243
+ },
244
+ get children() {
245
+ return createComponent(Show, {
246
+ get when() {
247
+ return "open" in value && "close" in value;
248
+ },
249
+ get fallback() {
250
+ return [
251
+ createComponent(TSDoc, { heading: `An object containing various ${subType ? `${subType} ` : ""}${color}${type ? ` ${type}` : ""} theme coloring functions.` }),
252
+ memo(() => code` ${camelCase(color)}: { `),
253
+ createIntrinsic("hbr", {}),
254
+ createComponent(ThemeColorObjectDefinition, {
255
+ get ansi16() {
256
+ return ansi16[color];
257
+ },
258
+ get ansi256() {
259
+ return ansi256[color];
260
+ },
261
+ get ansi16m() {
262
+ return ansi16m[color];
263
+ },
264
+ type: subType || type,
265
+ subType: color
266
+ }),
267
+ createIntrinsic("hbr", {}),
268
+ code` }`
269
+ ];
270
+ },
271
+ get children() {
272
+ return [
273
+ createComponent(TSDoc, {
274
+ get heading() {
275
+ return `A function that applies ${getIndefiniteArticle(color)} ${color}${type ? ` ${type}` : ""}${subType ? ` ${subType}` : ""} color styling to provided console text.`;
276
+ },
277
+ get children() {
278
+ return [
279
+ createComponent(TSDocRemarks, { children: `This function takes a string and an optional boolean indicating whether to apply the color as a background. It returns the input string wrapped in the appropriate ANSI escape codes for ${color}${type ? ` ${type}` : ""}${subType ? ` ${subType}` : ""} color styling, based on the terminal's color support level. If colors are not supported, it simply returns the input text as a string.` }),
280
+ createIntrinsic("hbr", {}),
281
+ createComponent(TSDocParam, {
282
+ name: "text",
283
+ children: `The console text to which the ${color}${type ? ` ${type}` : ""}${subType ? ` ${subType}` : ""} color styling should be applied.`
284
+ }),
285
+ createComponent(TSDocParam, {
286
+ name: "background",
287
+ children: `A boolean indicating whether to apply the color as a background. Defaults to \`false\`.`
288
+ }),
289
+ createComponent(TSDocReturns, { children: `A string with ANSI escape codes applied for ${color}${type ? ` ${type}` : ""}${subType ? ` ${subType}` : ""} color styling, or the original text if the style is not supported in the current terminal.` })
290
+ ];
291
+ }
292
+ }),
293
+ memo(() => code`${camelCase(color)}: `),
294
+ createComponent(ColorFunction, {
295
+ get ansi16() {
296
+ return ansi16[color];
297
+ },
298
+ get ansi256() {
299
+ return ansi256[color];
300
+ },
301
+ get ansi16m() {
302
+ return ansi16m[color];
303
+ }
304
+ })
305
+ ];
306
+ }
307
+ });
308
+ }
309
+ })]
310
+ });
311
+ }
312
+ /**
313
+ * A component to generate an object containing functions for coloring text in a Shell Shock project.
314
+ */
315
+ function AnsiStyleFunctionsDeclaration() {
316
+ const colors = useColors();
317
+ return [
318
+ createComponent(For, {
319
+ each: modifierKeys,
320
+ semicolon: true,
321
+ doubleHardline: true,
322
+ enderPunctuation: true,
323
+ children: (modifier) => [createComponent(TSDoc, {
324
+ get heading() {
325
+ return `A function that applies ${getIndefiniteArticle(titleCase(modifier))} ${titleCase(modifier)} text-style to provided console text.`;
326
+ },
327
+ get children() {
328
+ return [createComponent(TSDocParam, {
329
+ name: "text",
330
+ get children() {
331
+ return `The console text to which the ${titleCase(modifier)} text-style should be applied.`;
332
+ }
333
+ }), createComponent(TSDocReturns, { get children() {
334
+ return `A string with ANSI escape codes applied for ${titleCase(modifier)} text-style, or the original text if the style is not supported in the current terminal.`;
335
+ } })];
336
+ }
337
+ }), createComponent(VarDeclaration, {
338
+ "const": true,
339
+ "export": true,
340
+ get name() {
341
+ return camelCase(modifier);
342
+ },
343
+ get initializer() {
344
+ return createComponent(ColorFunction, {
345
+ get ansi16() {
346
+ return colors.ansi16[modifier];
347
+ },
348
+ get ansi256() {
349
+ return colors.ansi256[modifier];
350
+ },
351
+ get ansi16m() {
352
+ return colors.ansi16m[modifier];
353
+ },
354
+ skipBackground: true
355
+ });
356
+ }
357
+ })]
358
+ }),
359
+ createComponent(Spacing, {}),
360
+ createComponent(For, {
361
+ each: colorKeys,
362
+ semicolon: true,
363
+ doubleHardline: true,
364
+ enderPunctuation: true,
365
+ children: (color) => [createComponent(TSDoc, {
366
+ get heading() {
367
+ return `A function that applies ${getIndefiniteArticle(titleCase(color))} ${titleCase(color)} color styling to provided console text.`;
368
+ },
369
+ get children() {
370
+ return [
371
+ createComponent(TSDocRemarks, { get children() {
372
+ return `This function takes a string and an optional boolean indicating whether to apply the color as a background. It returns the input string wrapped in the appropriate ANSI escape codes for ${getIndefiniteArticle(titleCase(color))} ${titleCase(color)} color styling, based on the terminal's color support level. If colors are not supported, it simply returns the input text as a string.`;
373
+ } }),
374
+ createIntrinsic("hbr", {}),
375
+ createComponent(TSDocParam, {
376
+ name: "text",
377
+ get children() {
378
+ return `The console text to which the ${titleCase(color)} color styling should be applied.`;
379
+ }
380
+ }),
381
+ createComponent(TSDocParam, {
382
+ name: "background",
383
+ children: `A boolean indicating whether to apply the color as a background. Defaults to \`false\`.`
384
+ }),
385
+ createComponent(TSDocReturns, { get children() {
386
+ return `A string with ANSI escape codes applied for ${titleCase(color)} color styling, or the original text if the style is not supported in the current terminal.`;
387
+ } })
388
+ ];
389
+ }
390
+ }), createComponent(VarDeclaration, {
391
+ "const": true,
392
+ "export": true,
393
+ get name() {
394
+ return camelCase(color);
395
+ },
396
+ get initializer() {
397
+ return createComponent(ColorFunction, {
398
+ get ansi16() {
399
+ return colors.ansi16[color];
400
+ },
401
+ get ansi256() {
402
+ return colors.ansi256[color];
403
+ },
404
+ get ansi16m() {
405
+ return colors.ansi16m[color];
406
+ }
407
+ });
408
+ }
409
+ })]
410
+ }),
411
+ createComponent(Spacing, {}),
412
+ createComponent(For, {
413
+ get each() {
414
+ return Object.keys(colors.ansi16.theme);
415
+ },
416
+ semicolon: true,
417
+ doubleHardline: true,
418
+ enderPunctuation: true,
419
+ children: (type) => [createComponent(TSDoc, { heading: `A nested object containing functions for applying ${type} theme colors to the console.` }), createComponent(VarDeclaration, {
420
+ "export": true,
421
+ get name() {
422
+ return `${camelCase(type)}Colors`;
423
+ },
424
+ get initializer() {
425
+ return [
426
+ code` {`,
427
+ createIntrinsic("hbr", {}),
428
+ createComponent(ThemeColorObjectDefinition, {
429
+ get ansi16() {
430
+ return colors.ansi16.theme[type];
431
+ },
432
+ get ansi256() {
433
+ return colors.ansi256.theme[type];
434
+ },
435
+ get ansi16m() {
436
+ return colors.ansi16m.theme[type];
437
+ },
438
+ type
439
+ }),
440
+ createIntrinsic("hbr", {}),
441
+ code`}`
442
+ ];
443
+ }
444
+ })]
445
+ }),
446
+ createComponent(Spacing, {})
447
+ ];
448
+ }
449
+ /**
450
+ * A component to generate the `splitText` function in the `shell-shock:console` builtin module.
451
+ */
452
+ function SplitTextFunctionDeclaration() {
453
+ return [
454
+ createComponent(FunctionDeclaration, {
455
+ name: "adjustIndex",
456
+ parameters: [{
457
+ name: "line",
458
+ type: "string",
459
+ doc: "An input line which may contain ANSI escape codes. This is used to adjust the index for splitting the line based on visible characters rather than raw string length, ensuring that ANSI codes do not cause incorrect splitting of the text."
460
+ }, {
461
+ name: "index",
462
+ type: "number",
463
+ doc: "The index at which to split the line, based on visible characters (does not account for ANSI escape codes)."
464
+ }],
465
+ returnType: "number",
466
+ children: code`let adjustedIndex = 0;
91
467
  let visibleCount = 0;
92
468
  const ansiRegex = new RegExp([
93
469
  String.raw\`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)\`,
@@ -106,7 +482,20 @@ import{createComponent as e,createIntrinsic as t,memo as n,mergeProps as r}from"
106
482
  }
107
483
  }
108
484
 
109
- return adjustedIndex; `}),e(g,{}),e(l,{name:`breakLine`,parameters:[{name:`line`,type:`string`},{name:`index`,type:`number`}],returnType:`[string, string]`,children:o`const adjustedIndex = adjustIndex(line, index);
485
+ return adjustedIndex; `
486
+ }),
487
+ createComponent(Spacing, {}),
488
+ createComponent(FunctionDeclaration, {
489
+ name: "breakLine",
490
+ parameters: [{
491
+ name: "line",
492
+ type: "string"
493
+ }, {
494
+ name: "index",
495
+ type: "number"
496
+ }],
497
+ returnType: "[string, string]",
498
+ children: code`const adjustedIndex = adjustIndex(line, index);
110
499
  const first = line.slice(0, adjustedIndex);
111
500
  const second = line.slice(adjustedIndex);
112
501
 
@@ -155,7 +544,37 @@ import{createComponent as e,createIntrinsic as t,memo as n,mergeProps as r}from"
155
544
  // Prepend open codes to the start of "second"
156
545
  const openSequence = openCodes.join("");
157
546
 
158
- return [first.replace(/^\\s+/, "").replace(/\\s+$/, "") + closeSequence, openSequence + second.replace(/^\\s+/, "").replace(/\\s+$/, "")]; `}),e(g,{}),e(x,{heading:`Split text into multiple lines based on a maximum length.`,get children(){return[e(T,{children:`This function splits the provided text into multiple lines based on the specified maximum length, ensuring that words are not broken in the middle.`}),t(`hbr`,{}),e(w,{name:`text`,children:`The text to split into multiple lines.`}),e(w,{name:`maxLength`,children:`The maximum length of each line.`})]}}),e(l,{name:`splitText`,export:!0,parameters:[{name:`text`,type:`string`},{name:`maxLength`,type:`number | SizeToken`}],children:o`let line = text;
547
+ return [first.replace(/^\\s+/, "").replace(/\\s+$/, "") + closeSequence, openSequence + second.replace(/^\\s+/, "").replace(/\\s+$/, "")]; `
548
+ }),
549
+ createComponent(Spacing, {}),
550
+ createComponent(TSDoc, {
551
+ heading: "Split text into multiple lines based on a maximum length.",
552
+ get children() {
553
+ return [
554
+ createComponent(TSDocRemarks, { children: `This function splits the provided text into multiple lines based on the specified maximum length, ensuring that words are not broken in the middle.` }),
555
+ createIntrinsic("hbr", {}),
556
+ createComponent(TSDocParam, {
557
+ name: "text",
558
+ children: `The text to split into multiple lines.`
559
+ }),
560
+ createComponent(TSDocParam, {
561
+ name: "maxLength",
562
+ children: `The maximum length of each line.`
563
+ })
564
+ ];
565
+ }
566
+ }),
567
+ createComponent(FunctionDeclaration, {
568
+ name: "splitText",
569
+ "export": true,
570
+ parameters: [{
571
+ name: "text",
572
+ type: "string"
573
+ }, {
574
+ name: "maxLength",
575
+ type: "number | SizeToken"
576
+ }],
577
+ children: code`let line = text;
159
578
  let result = [] as string[];
160
579
 
161
580
  const calculatedMaxLength = isSizeToken(maxLength) ? calculateWidth(maxLength) : maxLength;
@@ -193,35 +612,272 @@ import{createComponent as e,createIntrinsic as t,memo as n,mergeProps as r}from"
193
612
  }
194
613
 
195
614
  result.push(line);
196
- return result; `})]}function B(){return[e(d,{export:!0,name:`WriteOptions`,doc:`Options for writing to the console.`,get children(){return[e(x,{heading:`Console function to use for writing to the console`,get children(){return[e(T,{children:"The console function to use for writing to the console. If not specified, the default console function `console.log` will be used."}),t(`hbr`,{}),e(S,{get type(){return h.method},defaultValue:"`console.log`"})]}}),e(f,{name:`consoleFn`,optional:!0,type:`(text: string) => void`})]}}),e(g,{}),e(x,{heading:`Write to the console.`,get children(){return[e(T,{children:`This function writes to the console, applying the appropriate padding as defined in the current theme configuration and wrapping as needed.`}),t(`hbr`,{}),e(w,{name:`text`,children:`The text to write to the console.`}),e(w,{name:`options`,children:`The options to apply when writing to the console.`})]}}),e(l,{export:!0,name:`write`,parameters:[{name:`text`,type:`string | number | boolean | null`,optional:!0},{name:`options`,type:`WriteOptions`,default:`{}`}],children:o`const consoleFn = options.consoleFn ?? console.log;
615
+ return result; `
616
+ })
617
+ ];
618
+ }
619
+ /**
620
+ * A component to generate the `write` function in the `shell-shock:console` builtin module.
621
+ */
622
+ function WriteFunctionDeclaration() {
623
+ return [
624
+ createComponent(InterfaceDeclaration, {
625
+ "export": true,
626
+ name: "WriteOptions",
627
+ doc: "Options for writing to the console.",
628
+ get children() {
629
+ return [createComponent(TSDoc, {
630
+ heading: "Console function to use for writing to the console",
631
+ get children() {
632
+ return [
633
+ createComponent(TSDocRemarks, { children: `The console function to use for writing to the console. If not specified, the default console function \`console.log\` will be used.` }),
634
+ createIntrinsic("hbr", {}),
635
+ createComponent(TSDocDefaultValue, {
636
+ type: "any",
637
+ defaultValue: `\`console.log\``
638
+ })
639
+ ];
640
+ }
641
+ }), createComponent(InterfaceMember, {
642
+ name: "consoleFn",
643
+ optional: true,
644
+ type: "(text: string) => void"
645
+ })];
646
+ }
647
+ }),
648
+ createComponent(Spacing, {}),
649
+ createComponent(TSDoc, {
650
+ heading: "Write to the console.",
651
+ get children() {
652
+ return [
653
+ createComponent(TSDocRemarks, { children: `This function writes to the console, applying the appropriate padding as defined in the current theme configuration and wrapping as needed.` }),
654
+ createIntrinsic("hbr", {}),
655
+ createComponent(TSDocParam, {
656
+ name: "text",
657
+ children: `The text to write to the console.`
658
+ }),
659
+ createComponent(TSDocParam, {
660
+ name: "options",
661
+ children: `The options to apply when writing to the console.`
662
+ })
663
+ ];
664
+ }
665
+ }),
666
+ createComponent(FunctionDeclaration, {
667
+ "export": true,
668
+ name: "write",
669
+ parameters: [{
670
+ name: "text",
671
+ type: "string | number | boolean | null",
672
+ optional: true
673
+ }, {
674
+ name: "options",
675
+ type: "WriteOptions",
676
+ default: "{}"
677
+ }],
678
+ children: code`const consoleFn = options.consoleFn ?? console.log;
197
679
  if (text === undefined || text === null || text === "") {
198
680
  consoleFn("");
199
681
  return;
200
682
  }
201
683
 
202
- consoleFn(String(text)); `})]}function V(){let n=O();return[e(d,{export:!0,name:`WriteLineOptions`,doc:`Options for writing a line to the console.`,extends:[`WriteOptions`],get children(){return[e(x,{heading:`Padding to apply to the line`,get children(){return e(T,{children:`The amount of padding (in spaces) to apply to the line when writing to the console. This value is applied to both the left and right sides of the line. If not specified, the default padding defined in the current theme configuration will be used.`})}}),e(f,{name:`padding`,optional:!0,type:`number`}),t(`hbr`,{}),e(x,{heading:`Color of the line text`,get children(){return[e(T,{children:`The color to apply to the line text when writing to the console. This can be one of the predefined color themes: "primary", "secondary", or "tertiary". If not specified, no specific coloring will be applied to the text (the default/system terminal text color will likely be used).`}),t(`hbr`,{})]}}),e(f,{name:`color`,optional:!0,type:`"primary" | "secondary" | "tertiary"`})]}}),e(g,{}),e(x,{heading:`Write a line to the console.`,get children(){return[e(T,{children:`This function writes a line to the console, applying the appropriate padding as defined in the current theme configuration and wrapping as needed.`}),t(`hbr`,{}),e(w,{name:`text`,children:`The line text to write to the console.`}),e(w,{name:`options`,children:`The options to apply when writing the line to the console.`})]}}),e(l,{export:!0,name:`writeLine`,parameters:[{name:`text`,type:`string | number | boolean | null`,optional:!0},{name:`options`,type:`WriteLineOptions`,default:`{}`}],get children(){return o`const color = options.color;
684
+ consoleFn(String(text)); `
685
+ })
686
+ ];
687
+ }
688
+ /**
689
+ * A component to generate the `writeLine` function in the `shell-shock:console` builtin module.
690
+ */
691
+ function WriteLineFunctionDeclaration() {
692
+ const theme = useTheme();
693
+ return [
694
+ createComponent(InterfaceDeclaration, {
695
+ "export": true,
696
+ name: "WriteLineOptions",
697
+ doc: "Options for writing a line to the console.",
698
+ "extends": ["WriteOptions"],
699
+ get children() {
700
+ return [
701
+ createComponent(TSDoc, {
702
+ heading: "Padding to apply to the line",
703
+ get children() {
704
+ return createComponent(TSDocRemarks, { children: `The amount of padding (in spaces) to apply to the line when writing to the console. This value is applied to both the left and right sides of the line. If not specified, the default padding defined in the current theme configuration will be used.` });
705
+ }
706
+ }),
707
+ createComponent(InterfaceMember, {
708
+ name: "padding",
709
+ optional: true,
710
+ type: "number"
711
+ }),
712
+ createIntrinsic("hbr", {}),
713
+ createComponent(TSDoc, {
714
+ heading: "Color of the line text",
715
+ get children() {
716
+ return [createComponent(TSDocRemarks, { children: `The color to apply to the line text when writing to the console. This can be one of the predefined color themes: "primary", "secondary", or "tertiary". If not specified, no specific coloring will be applied to the text (the default/system terminal text color will likely be used).` }), createIntrinsic("hbr", {})];
717
+ }
718
+ }),
719
+ createComponent(InterfaceMember, {
720
+ name: "color",
721
+ optional: true,
722
+ type: "\"primary\" | \"secondary\" | \"tertiary\""
723
+ })
724
+ ];
725
+ }
726
+ }),
727
+ createComponent(Spacing, {}),
728
+ createComponent(TSDoc, {
729
+ heading: "Write a line to the console.",
730
+ get children() {
731
+ return [
732
+ createComponent(TSDocRemarks, { children: `This function writes a line to the console, applying the appropriate padding as defined in the current theme configuration and wrapping as needed.` }),
733
+ createIntrinsic("hbr", {}),
734
+ createComponent(TSDocParam, {
735
+ name: "text",
736
+ children: `The line text to write to the console.`
737
+ }),
738
+ createComponent(TSDocParam, {
739
+ name: "options",
740
+ children: `The options to apply when writing the line to the console.`
741
+ })
742
+ ];
743
+ }
744
+ }),
745
+ createComponent(FunctionDeclaration, {
746
+ "export": true,
747
+ name: "writeLine",
748
+ parameters: [{
749
+ name: "text",
750
+ type: "string | number | boolean | null",
751
+ optional: true
752
+ }, {
753
+ name: "options",
754
+ type: "WriteLineOptions",
755
+ default: "{}"
756
+ }],
757
+ get children() {
758
+ return code`const color = options.color;
203
759
  if (text === undefined || text === null || text === "") {
204
760
  write("", options);
205
761
  return;
206
762
  }
207
763
 
208
- write(\`\${" ".repeat(Math.max(options.padding ?? ${n.padding.app}, 0))}\${color ? textColors.body[color](String(text)) : String(text)}\`, options); `}})]}function H(r){let{type:i,variant:s,consoleFnName:c,description:u,prefix:d,parameters:f,timestamp:p,color:m=s}=r,h=O();return[e(x,{get heading(){return`Write ${j(u)} ${u} message to the console.`},get children(){return[e(T,{children:`This function initializes the Powerlines environment configuration object.`}),t(`hbr`,{}),e(w,{name:`message`,children:`The message to write to the console.`}),e(w,{name:`header`,children:`An optional header to display above the message. If not provided, a default header based on the message type and variant will be used if defined in the theme configuration; otherwise, no header will be displayed.`})]}}),e(l,{export:!0,name:i,parameters:f??[{name:`message`,type:`string`,optional:!1},{name:`header`,type:`string`,optional:!0}],get children(){return[e(a,{get when(){return!!d},get children(){return[d,t(`hbr`,{}),t(`hbr`,{})]}}),n(()=>o`
764
+ write(\`\${" ".repeat(Math.max(options.padding ?? ${theme.padding.app}, 0))}\${color ? textColors.body[color](String(text)) : String(text)}\`, options); `;
765
+ }
766
+ })
767
+ ];
768
+ }
769
+ /**
770
+ * A component to generate the message functions in the `shell-shock:console` builtin module.
771
+ */
772
+ function MessageFunctionDeclaration(props) {
773
+ const { type, variant, consoleFnName, description, prefix, parameters, timestamp, color = variant } = props;
774
+ const theme = useTheme();
775
+ return [createComponent(TSDoc, {
776
+ get heading() {
777
+ return `Write ${getIndefiniteArticle(description)} ${description} message to the console.`;
778
+ },
779
+ get children() {
780
+ return [
781
+ createComponent(TSDocRemarks, { children: `This function initializes the Powerlines environment configuration object.` }),
782
+ createIntrinsic("hbr", {}),
783
+ createComponent(TSDocParam, {
784
+ name: "message",
785
+ children: `The message to write to the console.`
786
+ }),
787
+ createComponent(TSDocParam, {
788
+ name: "header",
789
+ children: `An optional header to display above the message. If not provided, a default header based on the message type and variant will be used if defined in the theme configuration; otherwise, no header will be displayed.`
790
+ })
791
+ ];
792
+ }
793
+ }), createComponent(FunctionDeclaration, {
794
+ "export": true,
795
+ name: type,
796
+ parameters: parameters ?? [{
797
+ name: "message",
798
+ type: "string",
799
+ optional: false
800
+ }, {
801
+ name: "header",
802
+ type: "string",
803
+ optional: true
804
+ }],
805
+ get children() {
806
+ return [createComponent(Show, {
807
+ get when() {
808
+ return Boolean(prefix);
809
+ },
810
+ get children() {
811
+ return [
812
+ prefix,
813
+ createIntrinsic("hbr", {}),
814
+ createIntrinsic("hbr", {})
815
+ ];
816
+ }
817
+ }), memo(() => code`
209
818
  if (!message) {
210
819
  return;
211
820
  }
212
821
 
213
- ${!h.labels.message.footer[s]&&p?`const timestamp = \`\${textColors.message.footer.${m}(new Date().toLocaleDateString())} \${borderColors.message.outline.${m}("${h.borderStyles.message.outline[s].bottom}")} \${textColors.message.footer.${m}(new Date().toLocaleTimeString())}\`; `:``}
822
+ ${!theme.labels.message.footer[variant] && timestamp ? `const timestamp = \`\${textColors.message.footer.${color}(new Date().toLocaleDateString())} \${borderColors.message.outline.${color}("${theme.borderStyles.message.outline[variant].bottom}")} \${textColors.message.footer.${color}(new Date().toLocaleTimeString())}\`; ` : ""}
214
823
 
215
- writeLine(borderColors.message.outline.${m}("${h.borderStyles.message.outline[s].topLeft}") + ${h.labels.message.header[s]||h.icons.message.header[s]?`borderColors.message.outline.${m}("${h.borderStyles.message.outline[s].top}".repeat(4)) + " " + ${h.icons.message.header[s]?`borderColors.message.outline.${m}("${h.icons.message.header[s]}") + " " +`:``} bold(textColors.message.header.${m}(header || "${h.labels.message.header[s]}")) + " " + borderColors.message.outline.${m}("${h.borderStyles.message.outline[s].top}".repeat(Math.max(getTerminalSize().columns - ${Math.max(h.padding.app,0)*2+h.borderStyles.message.outline[s].topLeft.length+4+(h.icons.message.header[s]?2+ +!h.labels.message.header[s]:0)+(h.labels.message.header[s]?h.labels.message.header[s].length+2:0)+h.borderStyles.message.outline[s].topRight.length}, 0)))`:`borderColors.message.outline.${m}("${h.borderStyles.message.outline[s].top}".repeat(Math.max(getTerminalSize().columns - ${Math.max(h.padding.app,0)*2+h.borderStyles.message.outline[s].topLeft.length+h.borderStyles.message.outline[s].topRight.length}, 0)))`} + borderColors.message.outline.${m}("${h.borderStyles.message.outline[s].topRight}"), { consoleFn: console.${c} });
824
+ writeLine(borderColors.message.outline.${color}("${theme.borderStyles.message.outline[variant].topLeft}") + ${theme.labels.message.header[variant] || theme.icons.message.header[variant] ? `borderColors.message.outline.${color}("${theme.borderStyles.message.outline[variant].top}".repeat(4)) + " " + ${theme.icons.message.header[variant] ? `borderColors.message.outline.${color}("${theme.icons.message.header[variant]}") + " " +` : ""} bold(textColors.message.header.${color}(header || "${theme.labels.message.header[variant]}")) + " " + borderColors.message.outline.${color}("${theme.borderStyles.message.outline[variant].top}".repeat(Math.max(getTerminalSize().columns - ${Math.max(theme.padding.app, 0) * 2 + theme.borderStyles.message.outline[variant].topLeft.length + 4 + (theme.icons.message.header[variant] ? 2 + (theme.labels.message.header[variant] ? 0 : 1) : 0) + (theme.labels.message.header[variant] ? theme.labels.message.header[variant].length + 2 : 0) + theme.borderStyles.message.outline[variant].topRight.length}, 0)))` : `borderColors.message.outline.${color}("${theme.borderStyles.message.outline[variant].top}".repeat(Math.max(getTerminalSize().columns - ${Math.max(theme.padding.app, 0) * 2 + theme.borderStyles.message.outline[variant].topLeft.length + theme.borderStyles.message.outline[variant].topRight.length}, 0)))`} + borderColors.message.outline.${color}("${theme.borderStyles.message.outline[variant].topRight}"), { consoleFn: console.${consoleFnName} });
216
825
  splitText(
217
826
  message,
218
- Math.max(getTerminalSize().columns - ${(Math.max(h.padding.app,0)+Math.max(h.padding.message,0))*2+h.borderStyles.message.outline[s].left.length+h.borderStyles.message.outline[s].right.length}, 12)
827
+ Math.max(getTerminalSize().columns - ${(Math.max(theme.padding.app, 0) + Math.max(theme.padding.message, 0)) * 2 + theme.borderStyles.message.outline[variant].left.length + theme.borderStyles.message.outline[variant].right.length}, 12)
219
828
  ).forEach(line => {
220
- writeLine(borderColors.message.outline.${m}("${h.borderStyles.message.outline[s].left+` `.repeat(Math.max(h.padding.message,0))}") + textColors.message.description.${m}(line) + " ".repeat(Math.max(getTerminalSize().columns - (stripAnsi(line).length + ${Math.max(h.padding.app,0)*2+Math.max(h.padding.message,0)+h.borderStyles.message.outline[s].left.length+h.borderStyles.message.outline[s].right.length}), 0)) + borderColors.message.outline.${m}("${h.borderStyles.message.outline[s].right}"), { consoleFn: console.${c} });
829
+ writeLine(borderColors.message.outline.${color}("${theme.borderStyles.message.outline[variant].left + " ".repeat(Math.max(theme.padding.message, 0))}") + textColors.message.description.${color}(line) + " ".repeat(Math.max(getTerminalSize().columns - (stripAnsi(line).length + ${Math.max(theme.padding.app, 0) * 2 + Math.max(theme.padding.message, 0) + theme.borderStyles.message.outline[variant].left.length + theme.borderStyles.message.outline[variant].right.length}), 0)) + borderColors.message.outline.${color}("${theme.borderStyles.message.outline[variant].right}"), { consoleFn: console.${consoleFnName} });
221
830
  });
222
- writeLine(borderColors.message.outline.${m}("${h.borderStyles.message.outline[s].bottomLeft}") + ${h.labels.message.footer[s]||p?`borderColors.message.outline.${m}("${h.borderStyles.message.outline[s].bottom}".repeat(Math.max(getTerminalSize().columns - ${Math.max(h.padding.app,0)*2+4+(h.labels.message.footer[s]?h.labels.message.footer[s].length+2:0)+h.borderStyles.message.outline[s].bottomLeft.length+h.borderStyles.message.outline[s].bottomRight.length}${!h.labels.message.footer[s]&&p?` - (stripAnsi(timestamp).length + 2)`:``}, 0))) + " " + ${`bold(textColors.message.footer.${m}(${h.labels.message.footer[s]?`"${h.labels.message.footer[s]}"`:p&&`timestamp`}))`} + " " + borderColors.message.outline.${m}("${h.borderStyles.message.outline[s].bottom}".repeat(4))`:`borderColors.message.outline.${m}("${h.borderStyles.message.outline[s].bottom}".repeat(Math.max(getTerminalSize().columns - ${Math.max(h.padding.app,0)*2+h.borderStyles.message.outline[s].bottomLeft.length+h.borderStyles.message.outline[s].bottomRight.length}, 0)))`} + borderColors.message.outline.${m}("${h.borderStyles.message.outline[s].bottomRight}"), { consoleFn: console.${c} });
223
- `)]}})]}function U(){return[e(x,{heading:`Applies ANSI escape codes to a string.`,get children(){return[e(T,{children:`Split text by /\\\\x1b[\\[|\\]][0-9;]*m/ and wrap non-ANSI parts with open/closing tags.`}),e(C,{children:`const result = wrapAnsi("Hello\\\\x1b[31mWorld\\\\x1b[0mAgain", "\\\\x1b[36m", "\\\\x1b[39");
224
- console.log(result); // "\\\\x1b[36mHello\\\\x1b[39\\\\x1b[31mWorld\\\\x1b[0m\\\\x1b[36mAgain\\\\x1b[39"`}),e(w,{name:`text`,children:`The text to apply ANSI codes to.`}),e(w,{name:`open`,children:`The opening ANSI code.`}),e(w,{name:`close`,children:`The closing ANSI code.`}),e(E,{children:`The text with ANSI codes applied.`})]}}),e(l,{name:`wrapAnsi`,parameters:[{name:`text`,type:`string | number`,optional:!1},{name:`open`,type:`string`,optional:!1},{name:`close`,type:`string`,optional:!1}],children:o`const str = String(text);
831
+ writeLine(borderColors.message.outline.${color}("${theme.borderStyles.message.outline[variant].bottomLeft}") + ${theme.labels.message.footer[variant] || timestamp ? `borderColors.message.outline.${color}("${theme.borderStyles.message.outline[variant].bottom}".repeat(Math.max(getTerminalSize().columns - ${Math.max(theme.padding.app, 0) * 2 + 4 + (theme.labels.message.footer[variant] ? theme.labels.message.footer[variant].length + 2 : 0) + theme.borderStyles.message.outline[variant].bottomLeft.length + theme.borderStyles.message.outline[variant].bottomRight.length}${!theme.labels.message.footer[variant] && timestamp ? " - (stripAnsi(timestamp).length + 2)" : ""}, 0))) + " " + ${`bold(textColors.message.footer.${color}(${theme.labels.message.footer[variant] ? `"${theme.labels.message.footer[variant]}"` : timestamp && "timestamp"}))`} + " " + borderColors.message.outline.${color}("${theme.borderStyles.message.outline[variant].bottom}".repeat(4))` : `borderColors.message.outline.${color}("${theme.borderStyles.message.outline[variant].bottom}".repeat(Math.max(getTerminalSize().columns - ${Math.max(theme.padding.app, 0) * 2 + theme.borderStyles.message.outline[variant].bottomLeft.length + theme.borderStyles.message.outline[variant].bottomRight.length}, 0)))`} + borderColors.message.outline.${color}("${theme.borderStyles.message.outline[variant].bottomRight}"), { consoleFn: console.${consoleFnName} });
832
+ `)];
833
+ }
834
+ })];
835
+ }
836
+ /**
837
+ * A component to generate the `wrapAnsi` function in the `shell-shock:console` builtin module.
838
+ */
839
+ function WrapAnsiFunction() {
840
+ return [createComponent(TSDoc, {
841
+ heading: "Applies ANSI escape codes to a string.",
842
+ get children() {
843
+ return [
844
+ createComponent(TSDocRemarks, { children: `Split text by /\\\\x1b[\\[|\\]][0-9;]*m/ and wrap non-ANSI parts with open/closing tags.` }),
845
+ createComponent(TSDocExample, { children: `const result = wrapAnsi("Hello\\\\x1b[31mWorld\\\\x1b[0mAgain", "\\\\x1b[36m", "\\\\x1b[39");\nconsole.log(result); // "\\\\x1b[36mHello\\\\x1b[39\\\\x1b[31mWorld\\\\x1b[0m\\\\x1b[36mAgain\\\\x1b[39"` }),
846
+ createComponent(TSDocParam, {
847
+ name: "text",
848
+ children: `The text to apply ANSI codes to.`
849
+ }),
850
+ createComponent(TSDocParam, {
851
+ name: "open",
852
+ children: `The opening ANSI code.`
853
+ }),
854
+ createComponent(TSDocParam, {
855
+ name: "close",
856
+ children: `The closing ANSI code.`
857
+ }),
858
+ createComponent(TSDocReturns, { children: `The text with ANSI codes applied.` })
859
+ ];
860
+ }
861
+ }), createComponent(FunctionDeclaration, {
862
+ name: "wrapAnsi",
863
+ parameters: [
864
+ {
865
+ name: "text",
866
+ type: "string | number",
867
+ optional: false
868
+ },
869
+ {
870
+ name: "open",
871
+ type: "string",
872
+ optional: false
873
+ },
874
+ {
875
+ name: "close",
876
+ type: "string",
877
+ optional: false
878
+ }
879
+ ],
880
+ children: code`const str = String(text);
225
881
  const tokens = [] as string[];
226
882
 
227
883
  let last = 0;
@@ -254,15 +910,235 @@ console.log(result); // "\\\\x1b[36mHello\\\\x1b[39\\\\x1b[31mWorld\\\\x1b[0m\\\
254
910
  }
255
911
 
256
912
  return result;
257
- `})]}function W(){return[e(x,{heading:`Removes ANSI escape codes from a string.`,get children(){return[e(C,{children:`const result = stripAnsi("Hello\\\\x1b[31mWorld\\\\x1b[0mAgain"); // "HelloWorldAgain"`}),e(w,{name:`text`,children:`The text to strip ANSI codes from.`}),e(E,{children:`The text with ANSI codes removed.`})]}}),e(l,{export:!0,name:`stripAnsi`,parameters:[{name:`text`,type:`string | number`,optional:!1}],children:o`return String(text).replace(new RegExp([
913
+ `
914
+ })];
915
+ }
916
+ /**
917
+ * A component to generate the `stripAnsi` function in the `shell-shock:console` builtin module.
918
+ */
919
+ function StripAnsiFunctionDeclaration() {
920
+ return [createComponent(TSDoc, {
921
+ heading: "Removes ANSI escape codes from a string.",
922
+ get children() {
923
+ return [
924
+ createComponent(TSDocExample, { children: `const result = stripAnsi("Hello\\\\x1b[31mWorld\\\\x1b[0mAgain"); // "HelloWorldAgain"` }),
925
+ createComponent(TSDocParam, {
926
+ name: "text",
927
+ children: `The text to strip ANSI codes from.`
928
+ }),
929
+ createComponent(TSDocReturns, { children: `The text with ANSI codes removed.` })
930
+ ];
931
+ }
932
+ }), createComponent(FunctionDeclaration, {
933
+ "export": true,
934
+ name: "stripAnsi",
935
+ parameters: [{
936
+ name: "text",
937
+ type: "string | number",
938
+ optional: false
939
+ }],
940
+ children: code`return String(text).replace(new RegExp([
258
941
  String.raw\`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)\`,
259
942
  String.raw\`(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))\`
260
- ].join("|"), "g"), "");`})]}function G(){let n=O();return[e(d,{export:!0,name:`DividerOptions`,doc:`Options for formatting the divider line written to console.`,get children(){return[e(f,{name:`width`,optional:!0,type:`number`,doc:`The width of the divider line. If not specified, the divider will span the full width of the console, minus the padding.`}),t(`hbr`,{}),e(x,{heading:`The border of the divider line. Can be 'primary', 'secondary', 'tertiary', or 'none'. If not specified, the default border style will be used.`,get children(){return[e(T,{children:`The value provided will determine the border style and color based on the current theme configuration.`}),e(S,{get type(){return h.string},defaultValue:`primary`})]}}),e(f,{name:`border`,optional:!0,type:`"primary" | "secondary" | "tertiary"`,doc:`The border style/color of the divider line. Can be 'primary', 'secondary', 'tertiary', or 'none'. If not specified, the default border style will be used.`}),t(`hbr`,{}),e(x,{heading:`Padding to apply to the line`,get children(){return[e(T,{children:`The amount of padding (in spaces) to apply to the line when writing to the console. This value is applied to both the left and right sides of the line. If not specified, the default padding defined in the current theme configuration will be used.`}),e(S,{get type(){return h.number},get defaultValue(){return n.padding.app*4}})]}}),e(f,{name:`padding`,optional:!0,type:`number`})]}}),e(g,{}),e(x,{heading:`Write a horizontal divider line to the console.`,get children(){return[e(C,{children:`divider({ width: 50, border: "primary" }); // Writes a horizontal divider line of width 50 with primary border.`}),e(w,{name:`options`,children:`Options for formatting the divider line.`})]}}),e(l,{export:!0,name:`divider`,parameters:[{name:`options`,type:`DividerOptions`,optional:!1}],get children(){return o`const padding = options.padding ?? ${Math.max(n.padding.app,1)*4};
943
+ ].join("|"), "g"), "");`
944
+ })];
945
+ }
946
+ /**
947
+ * A component to generate the `stripAnsi` function in the `shell-shock:console` builtin module.
948
+ */
949
+ function DividerFunctionDeclaration() {
950
+ const theme = useTheme();
951
+ return [
952
+ createComponent(InterfaceDeclaration, {
953
+ "export": true,
954
+ name: "DividerOptions",
955
+ doc: "Options for formatting the divider line written to console.",
956
+ get children() {
957
+ return [
958
+ createComponent(InterfaceMember, {
959
+ name: "width",
960
+ optional: true,
961
+ type: "number",
962
+ doc: "The width of the divider line. If not specified, the divider will span the full width of the console, minus the padding."
963
+ }),
964
+ createIntrinsic("hbr", {}),
965
+ createComponent(TSDoc, {
966
+ heading: "The border of the divider line. Can be 'primary', 'secondary', 'tertiary', or 'none'. If not specified, the default border style will be used.",
967
+ get children() {
968
+ return [createComponent(TSDocRemarks, { children: `The value provided will determine the border style and color based on the current theme configuration.` }), createComponent(TSDocDefaultValue, {
969
+ type: "string",
970
+ defaultValue: "primary"
971
+ })];
972
+ }
973
+ }),
974
+ createComponent(InterfaceMember, {
975
+ name: "border",
976
+ optional: true,
977
+ type: "\"primary\" | \"secondary\" | \"tertiary\"",
978
+ doc: "The border style/color of the divider line. Can be 'primary', 'secondary', 'tertiary', or 'none'. If not specified, the default border style will be used."
979
+ }),
980
+ createIntrinsic("hbr", {}),
981
+ createComponent(TSDoc, {
982
+ heading: "Padding to apply to the line",
983
+ get children() {
984
+ return [createComponent(TSDocRemarks, { children: `The amount of padding (in spaces) to apply to the line when writing to the console. This value is applied to both the left and right sides of the line. If not specified, the default padding defined in the current theme configuration will be used.` }), createComponent(TSDocDefaultValue, {
985
+ type: "number",
986
+ get defaultValue() {
987
+ return theme.padding.app * 4;
988
+ }
989
+ })];
990
+ }
991
+ }),
992
+ createComponent(InterfaceMember, {
993
+ name: "padding",
994
+ optional: true,
995
+ type: "number"
996
+ })
997
+ ];
998
+ }
999
+ }),
1000
+ createComponent(Spacing, {}),
1001
+ createComponent(TSDoc, {
1002
+ heading: "Write a horizontal divider line to the console.",
1003
+ get children() {
1004
+ return [createComponent(TSDocExample, { children: `divider({ width: 50, border: "primary" }); // Writes a horizontal divider line of width 50 with primary border.` }), createComponent(TSDocParam, {
1005
+ name: "options",
1006
+ children: `Options for formatting the divider line.`
1007
+ })];
1008
+ }
1009
+ }),
1010
+ createComponent(FunctionDeclaration, {
1011
+ "export": true,
1012
+ name: "divider",
1013
+ parameters: [{
1014
+ name: "options",
1015
+ type: "DividerOptions",
1016
+ optional: false
1017
+ }],
1018
+ get children() {
1019
+ return code`const padding = options.padding ?? ${Math.max(theme.padding.app, 1) * 4};
261
1020
  const width = options.width ?? (getTerminalSize().columns - (Math.max(padding, 0) * 2));
262
- const border = options.border === "tertiary" ? borderColors.app.divider.tertiary("${n.borderStyles.app.divider.tertiary.top}") : options.border === "secondary" ? borderColors.app.divider.secondary("${n.borderStyles.app.divider.secondary.top}") : borderColors.app.divider.primary("${n.borderStyles.app.divider.primary.top}");
1021
+ const border = options.border === "tertiary" ? borderColors.app.divider.tertiary("${theme.borderStyles.app.divider.tertiary.top}") : options.border === "secondary" ? borderColors.app.divider.secondary("${theme.borderStyles.app.divider.secondary.top}") : borderColors.app.divider.primary("${theme.borderStyles.app.divider.primary.top}");
263
1022
 
264
- writeLine(" ".repeat(Math.max(padding - ${n.padding.app}, 0)) + border.repeat(Math.max(width / ${n.borderStyles.app.divider.primary.top.length??1}, 0)));
265
- `}})]}function K(){let r=O();return[e(d,{export:!0,name:`LinkOptions`,doc:`Options for formatting a hyperlink in the console.`,get children(){return[e(f,{name:`external`,optional:!0,type:`boolean`,doc:`Whether the link is external. If true, an external link icon will be displayed next to the link text (if supported by the terminal) and the link may be styled differently based on the current theme configuration.`}),e(g,{}),e(f,{name:`text`,optional:!0,type:`string`,doc:`The text to display for the link. If not provided, the URL will be used as the text.`}),e(g,{}),e(f,{name:`useTextWhenUnsupported`,optional:!0,type:`boolean`,doc:`Whether to use the text when the hyperlink is not supported. If true, the text will be displayed even if the terminal does not support hyperlinks.`})]}}),e(g,{}),e(x,{heading:`Render a hyperlink in the console.`,get children(){return[e(w,{name:`url`,children:`The URL to render as a hyperlink.`}),e(w,{name:`options`,children:`Options for formatting the hyperlink.`}),e(E,{children:`The formatted hyperlink string for display in the console.`})]}}),e(l,{export:!0,name:`link`,parameters:[{name:`url`,type:`string`,optional:!1},{name:`options`,type:`LinkOptions`,default:`{}`}],get children(){return[e(u,{condition:o`isHyperlinkSupported()`,get children(){return o`return \`\\x1b]8;;\${url}\\u0007\${options.text ? options.text : url}\\x1b]8;;\\u0007\${options.external === true ? "${r.icons.link.external}" : ""}\`;`}}),t(`hbr`,{}),e(u,{condition:o`isColorSupported`,get children(){return o`return \`\${underline(textColors.body.link(\`\${options.useTextWhenUnsupported && options.text ? options.text : url}\`))}\${options.external === true ? "${r.icons.link.external}" : ""}\`;`}}),t(`hbr`,{}),n(()=>o`return \`\${options.useTextWhenUnsupported && options.text ? options.text : url}\${options.external === true ? "${r.icons.link.external}" : ""}\`;`)]}})]}function q(){let t=O();return[e(g,{}),e(x,{heading:`Format a string with blockquote styling for display in console.`,get children(){return[e(w,{name:`text`,children:`The text to format with blockquote styling.`}),e(E,{children:`The formatted string with blockquote styling.`})]}}),e(l,{export:!0,name:`blockquote`,parameters:[{name:`text`,type:`string | number | boolean | null`,optional:!0}],returnType:`string`,get children(){return o`if (text === undefined || text === null || text === "") {
1023
+ writeLine(" ".repeat(Math.max(padding - ${theme.padding.app}, 0)) + border.repeat(Math.max(width / ${theme.borderStyles.app.divider.primary.top.length ?? 1}, 0)));
1024
+ `;
1025
+ }
1026
+ })
1027
+ ];
1028
+ }
1029
+ /**
1030
+ * A component to generate the `link` function in the `shell-shock:console` builtin module.
1031
+ */
1032
+ function LinkFunctionDeclaration() {
1033
+ const theme = useTheme();
1034
+ return [
1035
+ createComponent(InterfaceDeclaration, {
1036
+ "export": true,
1037
+ name: "LinkOptions",
1038
+ doc: "Options for formatting a hyperlink in the console.",
1039
+ get children() {
1040
+ return [
1041
+ createComponent(InterfaceMember, {
1042
+ name: "external",
1043
+ optional: true,
1044
+ type: "boolean",
1045
+ doc: "Whether the link is external. If true, an external link icon will be displayed next to the link text (if supported by the terminal) and the link may be styled differently based on the current theme configuration."
1046
+ }),
1047
+ createComponent(Spacing, {}),
1048
+ createComponent(InterfaceMember, {
1049
+ name: "text",
1050
+ optional: true,
1051
+ type: "string",
1052
+ doc: "The text to display for the link. If not provided, the URL will be used as the text."
1053
+ }),
1054
+ createComponent(Spacing, {}),
1055
+ createComponent(InterfaceMember, {
1056
+ name: "useTextWhenUnsupported",
1057
+ optional: true,
1058
+ type: "boolean",
1059
+ doc: "Whether to use the text when the hyperlink is not supported. If true, the text will be displayed even if the terminal does not support hyperlinks."
1060
+ })
1061
+ ];
1062
+ }
1063
+ }),
1064
+ createComponent(Spacing, {}),
1065
+ createComponent(TSDoc, {
1066
+ heading: "Render a hyperlink in the console.",
1067
+ get children() {
1068
+ return [
1069
+ createComponent(TSDocParam, {
1070
+ name: "url",
1071
+ children: `The URL to render as a hyperlink.`
1072
+ }),
1073
+ createComponent(TSDocParam, {
1074
+ name: "options",
1075
+ children: `Options for formatting the hyperlink.`
1076
+ }),
1077
+ createComponent(TSDocReturns, { children: `The formatted hyperlink string for display in the console.` })
1078
+ ];
1079
+ }
1080
+ }),
1081
+ createComponent(FunctionDeclaration, {
1082
+ "export": true,
1083
+ name: "link",
1084
+ parameters: [{
1085
+ name: "url",
1086
+ type: "string",
1087
+ optional: false
1088
+ }, {
1089
+ name: "options",
1090
+ type: "LinkOptions",
1091
+ default: "{}"
1092
+ }],
1093
+ get children() {
1094
+ return [
1095
+ createComponent(IfStatement, {
1096
+ condition: code`isHyperlinkSupported()`,
1097
+ get children() {
1098
+ return code`return \`\\x1b]8;;\${url}\\u0007\${options.text ? options.text : url}\\x1b]8;;\\u0007\${options.external === true ? "${theme.icons.link.external}" : ""}\`;`;
1099
+ }
1100
+ }),
1101
+ createIntrinsic("hbr", {}),
1102
+ createComponent(IfStatement, {
1103
+ condition: code`isColorSupported`,
1104
+ get children() {
1105
+ return code`return \`\${underline(textColors.body.link(\`\${options.useTextWhenUnsupported && options.text ? options.text : url}\`))}\${options.external === true ? "${theme.icons.link.external}" : ""}\`;`;
1106
+ }
1107
+ }),
1108
+ createIntrinsic("hbr", {}),
1109
+ memo(() => code`return \`\${options.useTextWhenUnsupported && options.text ? options.text : url}\${options.external === true ? "${theme.icons.link.external}" : ""}\`;`)
1110
+ ];
1111
+ }
1112
+ })
1113
+ ];
1114
+ }
1115
+ /**
1116
+ * A component to generate the `blockquote` function declaration
1117
+ */
1118
+ function BlockquoteFunctionDeclaration() {
1119
+ const theme = useTheme();
1120
+ return [
1121
+ createComponent(Spacing, {}),
1122
+ createComponent(TSDoc, {
1123
+ heading: `Format a string with blockquote styling for display in console.`,
1124
+ get children() {
1125
+ return [createComponent(TSDocParam, {
1126
+ name: "text",
1127
+ children: `The text to format with blockquote styling.`
1128
+ }), createComponent(TSDocReturns, { children: `The formatted string with blockquote styling.` })];
1129
+ }
1130
+ }),
1131
+ createComponent(FunctionDeclaration, {
1132
+ "export": true,
1133
+ name: "blockquote",
1134
+ parameters: [{
1135
+ name: "text",
1136
+ type: "string | number | boolean | null",
1137
+ optional: true
1138
+ }],
1139
+ returnType: "string",
1140
+ get children() {
1141
+ return code`if (text === undefined || text === null || text === "") {
266
1142
  return "";
267
1143
  }
268
1144
 
@@ -271,7 +1147,42 @@ console.log(result); // "\\\\x1b[36mHello\\\\x1b[39\\\\x1b[31mWorld\\\\x1b[0m\\\
271
1147
  Math.max(getTerminalSize().columns, 20) - 6
272
1148
  );
273
1149
 
274
- return lines.map(line => \`\${borderColors.app.blockquote.primary(isUnicodeSupported() ? "${t.borderStyles.app.blockquote.primary.left}" : "|")} \${italic(line)} \`).join("\\n"); `}})]}function J(){let t=O();return[e(g,{}),e(x,{heading:`Format a source code string for display in console.`,get children(){return[e(w,{name:`text`,children:`The source code text to format with code styling.`}),e(E,{children:`The formatted string with code styling.`})]}}),e(l,{export:!0,name:`code`,parameters:[{name:`text`,type:`string | number | boolean | null`,optional:!0},{name:`language`,type:`string`,optional:!0}],returnType:`string`,get children(){return o`if (text === undefined || text === null || text === "") {
1150
+ return lines.map(line => \`\${borderColors.app.blockquote.primary(isUnicodeSupported() ? "${theme.borderStyles.app.blockquote.primary.left}" : "|")} \${italic(line)} \`).join("\\n"); `;
1151
+ }
1152
+ })
1153
+ ];
1154
+ }
1155
+ /**
1156
+ * A component to generate the `code` function declaration
1157
+ */
1158
+ function CodeFunctionDeclaration() {
1159
+ const theme = useTheme();
1160
+ return [
1161
+ createComponent(Spacing, {}),
1162
+ createComponent(TSDoc, {
1163
+ heading: `Format a source code string for display in console.`,
1164
+ get children() {
1165
+ return [createComponent(TSDocParam, {
1166
+ name: "text",
1167
+ children: `The source code text to format with code styling.`
1168
+ }), createComponent(TSDocReturns, { children: `The formatted string with code styling.` })];
1169
+ }
1170
+ }),
1171
+ createComponent(FunctionDeclaration, {
1172
+ "export": true,
1173
+ name: "code",
1174
+ parameters: [{
1175
+ name: "text",
1176
+ type: "string | number | boolean | null",
1177
+ optional: true
1178
+ }, {
1179
+ name: "language",
1180
+ type: "string",
1181
+ optional: true
1182
+ }],
1183
+ returnType: "string",
1184
+ get children() {
1185
+ return code`if (text === undefined || text === null || text === "") {
275
1186
  return "";
276
1187
  }
277
1188
 
@@ -280,12 +1191,185 @@ console.log(result); // "\\\\x1b[36mHello\\\\x1b[39\\\\x1b[31mWorld\\\\x1b[0m\\\
280
1191
  Math.max(getTerminalSize().columns, 20)
281
1192
  );
282
1193
 
283
- return \` \${borderColors.app.divider.primary("${t.borderStyles.app.divider.primary.top}".repeat(4))}\${language ? \` \${borderColors.app.divider.primary(language)} \` : ""}\${borderColors.app.divider.primary("${t.borderStyles.app.divider.primary.top}".repeat(getTerminalSize().columns - (language ? language.length + 2 : 0) - 5))} \\n\${lines.map((line, index) => \` \${" ".repeat(String(lines.length).length - String(index + 1).length)}\${textColors.body.tertiary(index + 1)} \${textColors.body.primary(line)}\`).join("\\n")}\`; `}})]}function Y(){return[e(g,{}),e(x,{heading:`Format a string with inline code styling for display in console.`,get children(){return[e(w,{name:`text`,children:`The text to format with inline code styling.`}),e(E,{children:`The formatted string with inline code styling.`})]}}),e(l,{export:!0,name:`inlineCode`,parameters:[{name:`text`,type:`string | number | boolean | null`,optional:!0}],returnType:`string`,children:o`if (text === undefined || text === null || text === "") {
1194
+ return \` \${borderColors.app.divider.primary("${theme.borderStyles.app.divider.primary.top}".repeat(4))}\${language ? \` \${borderColors.app.divider.primary(language)} \` : ""}\${borderColors.app.divider.primary("${theme.borderStyles.app.divider.primary.top}".repeat(getTerminalSize().columns - (language ? language.length + 2 : 0) - 5))} \\n\${lines.map((line, index) => \` \${" ".repeat(String(lines.length).length - String(index + 1).length)}\${textColors.body.tertiary(index + 1)} \${textColors.body.primary(line)}\`).join("\\n")}\`; `;
1195
+ }
1196
+ })
1197
+ ];
1198
+ }
1199
+ /**
1200
+ * A component to generate the `inlineCode` function declaration
1201
+ */
1202
+ function InlineCodeFunctionDeclaration() {
1203
+ return [
1204
+ createComponent(Spacing, {}),
1205
+ createComponent(TSDoc, {
1206
+ heading: `Format a string with inline code styling for display in console.`,
1207
+ get children() {
1208
+ return [createComponent(TSDocParam, {
1209
+ name: "text",
1210
+ children: `The text to format with inline code styling.`
1211
+ }), createComponent(TSDocReturns, { children: `The formatted string with inline code styling.` })];
1212
+ }
1213
+ }),
1214
+ createComponent(FunctionDeclaration, {
1215
+ "export": true,
1216
+ name: "inlineCode",
1217
+ parameters: [{
1218
+ name: "text",
1219
+ type: "string | number | boolean | null",
1220
+ optional: true
1221
+ }],
1222
+ returnType: "string",
1223
+ children: code`if (text === undefined || text === null || text === "") {
284
1224
  return "";
285
1225
  }
286
1226
 
287
- return inverse(\`\${text}\`); `})]}function X(){let r=O();return[e(p,{name:`WriteStream`,children:`NodeJS.WriteStream;`}),e(g,{}),e(m,{const:!0,name:`activeHooksPerStream`,initializer:`new Set();`}),e(g,{}),e(d,{export:!0,name:`SpinnerOptions`,doc:`Options for configuring the spinner.`,get children(){return[e(f,{name:`message`,optional:!0,type:`string`,doc:`The message text to display next to the spinner. Defaults to an empty string.`}),t(`hbr`,{}),e(f,{name:`stream`,optional:!0,type:`WriteStream`,doc:`The output stream to write the spinner to. Defaults to process.stderr.`}),t(`hbr`,{}),e(f,{name:`spinner`,optional:!0,type:`ThemeSpinnerResolvedConfig | SpinnerPreset`,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.`})]}}),e(g,{}),e(ee,{name:`Spinner`,get children(){return[e(_,{name:`frames`,isPrivateMember:!0,type:`string[]`}),t(`hbr`,{}),e(_,{name:`interval`,isPrivateMember:!0,type:`number`}),t(`hbr`,{}),e(_,{name:`currentFrame`,isPrivateMember:!0,type:`number`,children:o`-1`}),t(`hbr`,{}),e(_,{name:`timer`,isPrivateMember:!0,optional:!0,type:`NodeJS.Timeout`}),t(`hbr`,{}),e(_,{name:`message`,isPrivateMember:!0,type:`string`,children:o`""`}),t(`hbr`,{}),e(_,{name:`stream`,isPrivateMember:!0,type:`WriteStream`,children:o`process.stderr`}),t(`hbr`,{}),e(_,{name:`lines`,isPrivateMember:!0,type:`number`,children:o`0`}),t(`hbr`,{}),e(_,{name:`exitHandlerBound`,isPrivateMember:!0,type:`(signal: any) => void`,children:o`() => {}`}),t(`hbr`,{}),e(_,{name:`lastSpinnerFrameTime`,isPrivateMember:!0,type:`number`,children:o`0`}),t(`hbr`,{}),e(_,{name:`isSpinning`,isPrivateMember:!0,type:`boolean`,children:o`false`}),t(`hbr`,{}),e(_,{name:`hookedStreams`,isPrivateMember:!0,type:`Map<WriteStream, { write?: WriteStream["write"]; originalWrite: WriteStream["write"]; hookedWrite: WriteStream["write"] }>`,children:o`new Map()`}),t(`hbr`,{}),e(_,{name:`isInternalWrite`,isPrivateMember:!0,type:`boolean`,children:o`false`}),t(`hbr`,{}),e(_,{name:`isDeferringRender`,isPrivateMember:!0,type:`boolean`,children:o`false`}),e(g,{}),n(()=>o`constructor(options: SpinnerOptions = {}) {
288
- const spinner = (typeof options.spinner === "string" ? resolveSpinner(options.spinner as SpinnerPreset) : options.spinner) ?? ${JSON.stringify(r.spinner)};
1227
+ return inverse(\`\${text}\`); `
1228
+ })
1229
+ ];
1230
+ }
1231
+ /**
1232
+ * A component to generate the `spinner` function in the `shell-shock:console` builtin module.
1233
+ */
1234
+ function SpinnerFunctionDeclaration() {
1235
+ const theme = useTheme();
1236
+ return [
1237
+ createComponent(TypeDeclaration, {
1238
+ name: "WriteStream",
1239
+ children: `NodeJS.WriteStream;`
1240
+ }),
1241
+ createComponent(Spacing, {}),
1242
+ createComponent(VarDeclaration, {
1243
+ "const": true,
1244
+ name: "activeHooksPerStream",
1245
+ initializer: "new Set();"
1246
+ }),
1247
+ createComponent(Spacing, {}),
1248
+ createComponent(InterfaceDeclaration, {
1249
+ "export": true,
1250
+ name: "SpinnerOptions",
1251
+ doc: "Options for configuring the spinner.",
1252
+ get children() {
1253
+ return [
1254
+ createComponent(InterfaceMember, {
1255
+ name: "message",
1256
+ optional: true,
1257
+ type: "string",
1258
+ doc: "The message text to display next to the spinner. Defaults to an empty string."
1259
+ }),
1260
+ createIntrinsic("hbr", {}),
1261
+ createComponent(InterfaceMember, {
1262
+ name: "stream",
1263
+ optional: true,
1264
+ type: "WriteStream",
1265
+ doc: "The output stream to write the spinner to. Defaults to process.stderr."
1266
+ }),
1267
+ createIntrinsic("hbr", {}),
1268
+ createComponent(InterfaceMember, {
1269
+ name: "spinner",
1270
+ optional: true,
1271
+ type: "ThemeSpinnerResolvedConfig | SpinnerPreset",
1272
+ 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."
1273
+ })
1274
+ ];
1275
+ }
1276
+ }),
1277
+ createComponent(Spacing, {}),
1278
+ createComponent(ClassDeclaration, {
1279
+ name: "Spinner",
1280
+ get children() {
1281
+ return [
1282
+ createComponent(ClassField, {
1283
+ name: "frames",
1284
+ isPrivateMember: true,
1285
+ type: "string[]"
1286
+ }),
1287
+ createIntrinsic("hbr", {}),
1288
+ createComponent(ClassField, {
1289
+ name: "interval",
1290
+ isPrivateMember: true,
1291
+ type: "number"
1292
+ }),
1293
+ createIntrinsic("hbr", {}),
1294
+ createComponent(ClassField, {
1295
+ name: "currentFrame",
1296
+ isPrivateMember: true,
1297
+ type: "number",
1298
+ children: code`-1`
1299
+ }),
1300
+ createIntrinsic("hbr", {}),
1301
+ createComponent(ClassField, {
1302
+ name: "timer",
1303
+ isPrivateMember: true,
1304
+ optional: true,
1305
+ type: "NodeJS.Timeout"
1306
+ }),
1307
+ createIntrinsic("hbr", {}),
1308
+ createComponent(ClassField, {
1309
+ name: "message",
1310
+ isPrivateMember: true,
1311
+ type: "string",
1312
+ children: code`""`
1313
+ }),
1314
+ createIntrinsic("hbr", {}),
1315
+ createComponent(ClassField, {
1316
+ name: "stream",
1317
+ isPrivateMember: true,
1318
+ type: "WriteStream",
1319
+ children: code`process.stderr`
1320
+ }),
1321
+ createIntrinsic("hbr", {}),
1322
+ createComponent(ClassField, {
1323
+ name: "lines",
1324
+ isPrivateMember: true,
1325
+ type: "number",
1326
+ children: code`0`
1327
+ }),
1328
+ createIntrinsic("hbr", {}),
1329
+ createComponent(ClassField, {
1330
+ name: "exitHandlerBound",
1331
+ isPrivateMember: true,
1332
+ type: "(signal: any) => void",
1333
+ children: code`() => {}`
1334
+ }),
1335
+ createIntrinsic("hbr", {}),
1336
+ createComponent(ClassField, {
1337
+ name: "lastSpinnerFrameTime",
1338
+ isPrivateMember: true,
1339
+ type: "number",
1340
+ children: code`0`
1341
+ }),
1342
+ createIntrinsic("hbr", {}),
1343
+ createComponent(ClassField, {
1344
+ name: "isSpinning",
1345
+ isPrivateMember: true,
1346
+ type: "boolean",
1347
+ children: code`false`
1348
+ }),
1349
+ createIntrinsic("hbr", {}),
1350
+ createComponent(ClassField, {
1351
+ name: "hookedStreams",
1352
+ isPrivateMember: true,
1353
+ type: "Map<WriteStream, { write?: WriteStream[\"write\"]; originalWrite: WriteStream[\"write\"]; hookedWrite: WriteStream[\"write\"] }>",
1354
+ children: code`new Map()`
1355
+ }),
1356
+ createIntrinsic("hbr", {}),
1357
+ createComponent(ClassField, {
1358
+ name: "isInternalWrite",
1359
+ isPrivateMember: true,
1360
+ type: "boolean",
1361
+ children: code`false`
1362
+ }),
1363
+ createIntrinsic("hbr", {}),
1364
+ createComponent(ClassField, {
1365
+ name: "isDeferringRender",
1366
+ isPrivateMember: true,
1367
+ type: "boolean",
1368
+ children: code`false`
1369
+ }),
1370
+ createComponent(Spacing, {}),
1371
+ memo(() => code`constructor(options: SpinnerOptions = {}) {
1372
+ const spinner = (typeof options.spinner === "string" ? resolveSpinner(options.spinner as SpinnerPreset) : options.spinner) ?? ${JSON.stringify(theme.spinner)};
289
1373
  this.#frames = spinner.frames;
290
1374
  this.#interval = spinner.interval;
291
1375
 
@@ -489,7 +1573,49 @@ console.log(result); // "\\\\x1b[36mHello\\\\x1b[39\\\\x1b[31mWorld\\\\x1b[0m\\\
489
1573
  }
490
1574
 
491
1575
  process.exit(signal === "SIGINT" ? 130 : (signal === "SIGTERM" ? 143 : 1));
492
- } `),e(y,{public:!0,name:`isSpinning`,type:`boolean`,doc:`Whether the spinner is currently active and spinning.`,children:o`return this.#isSpinning;`}),e(g,{}),e(te,{public:!0,name:`message`,type:`string`,doc:`Set the message displayed by the spinner.`,children:o`this.#message = value;`}),e(g,{}),e(y,{public:!0,name:`message`,type:`string`,doc:`Get the message displayed by the spinner.`,children:o`return this.#message;`}),e(g,{}),e(v,{name:`start`,doc:`Start the spinner animation.`,parameters:[{name:`message`,type:`string`}],get children(){return[e(u,{condition:o`message !== undefined`,children:o`this.#message = message;`}),e(u,{condition:o`this.isSpinning`,children:o`return this;`}),o`this.#isSpinning = true;
1576
+ } `),
1577
+ createComponent(ClassPropertyGet, {
1578
+ "public": true,
1579
+ name: "isSpinning",
1580
+ type: "boolean",
1581
+ doc: "Whether the spinner is currently active and spinning.",
1582
+ children: code`return this.#isSpinning;`
1583
+ }),
1584
+ createComponent(Spacing, {}),
1585
+ createComponent(ClassPropertySet, {
1586
+ "public": true,
1587
+ name: "message",
1588
+ type: "string",
1589
+ doc: "Set the message displayed by the spinner.",
1590
+ children: code`this.#message = value;`
1591
+ }),
1592
+ createComponent(Spacing, {}),
1593
+ createComponent(ClassPropertyGet, {
1594
+ "public": true,
1595
+ name: "message",
1596
+ type: "string",
1597
+ doc: "Get the message displayed by the spinner.",
1598
+ children: code`return this.#message;`
1599
+ }),
1600
+ createComponent(Spacing, {}),
1601
+ createComponent(ClassMethod, {
1602
+ name: "start",
1603
+ doc: "Start the spinner animation.",
1604
+ parameters: [{
1605
+ name: "message",
1606
+ type: "string"
1607
+ }],
1608
+ get children() {
1609
+ return [
1610
+ createComponent(IfStatement, {
1611
+ condition: code`message !== undefined`,
1612
+ children: code`this.#message = message;`
1613
+ }),
1614
+ createComponent(IfStatement, {
1615
+ condition: code`this.isSpinning`,
1616
+ children: code`return this;`
1617
+ }),
1618
+ code`this.#isSpinning = true;
493
1619
  this.#hideCursor();
494
1620
  this.#installHook();
495
1621
  this.#render();
@@ -502,7 +1628,20 @@ console.log(result); // "\\\\x1b[36mHello\\\\x1b[39\\\\x1b[31mWorld\\\\x1b[0m\\\
502
1628
  }
503
1629
 
504
1630
  return this;
505
- `]}}),e(g,{}),e(v,{name:`stop`,doc:`Stop the spinner animation.`,parameters:[{name:`finalMessage`,optional:!0,type:`string`}],children:o`if (!this.isSpinning) {
1631
+ `
1632
+ ];
1633
+ }
1634
+ }),
1635
+ createComponent(Spacing, {}),
1636
+ createComponent(ClassMethod, {
1637
+ name: "stop",
1638
+ doc: "Stop the spinner animation.",
1639
+ parameters: [{
1640
+ name: "finalMessage",
1641
+ optional: true,
1642
+ type: "string"
1643
+ }],
1644
+ children: code`if (!this.isSpinning) {
506
1645
  return this;
507
1646
  }
508
1647
 
@@ -526,7 +1665,13 @@ console.log(result); // "\\\\x1b[36mHello\\\\x1b[39\\\\x1b[31mWorld\\\\x1b[0m\\\
526
1665
 
527
1666
  return this;
528
1667
 
529
- `}),e(g,{}),e(v,{name:`clear`,doc:`Clear the spinner animation.`,children:o`if (!isInteractive) {
1668
+ `
1669
+ }),
1670
+ createComponent(Spacing, {}),
1671
+ createComponent(ClassMethod, {
1672
+ name: "clear",
1673
+ doc: "Clear the spinner animation.",
1674
+ children: code`if (!isInteractive) {
530
1675
  return this;
531
1676
  }
532
1677
 
@@ -547,20 +1692,474 @@ console.log(result); // "\\\\x1b[36mHello\\\\x1b[39\\\\x1b[31mWorld\\\\x1b[0m\\\
547
1692
  });
548
1693
 
549
1694
  this.#lines = 0;
550
- return this; `}),e(g,{}),e(v,{name:`success`,doc:`Mark the spinner as successful.`,parameters:[{name:`message`,type:`string`}],get children(){return o`return this.#stopWithIcon(textColors.spinner.icon.success("${r.icons.spinner.success}"), textColors.spinner.message.success(message)); `}}),e(g,{}),e(v,{name:`error`,doc:`Mark the spinner as failed.`,parameters:[{name:`message`,type:`string`}],get children(){return o`return this.#stopWithIcon(textColors.spinner.icon.error("${r.icons.spinner.error}"), textColors.spinner.message.error(message)); `}}),e(g,{}),e(v,{name:`warning`,doc:`Mark the spinner as warning.`,parameters:[{name:`message`,type:`string`}],get children(){return o`return this.#stopWithIcon(textColors.spinner.icon.warning("${r.icons.spinner.warning}"), textColors.spinner.message.warning(message)); `}}),e(g,{}),e(v,{name:`info`,doc:`Mark the spinner as informational.`,parameters:[{name:`message`,type:`string`}],get children(){return o`return this.#stopWithIcon(textColors.spinner.icon.info("${r.icons.spinner.info}"), textColors.spinner.message.info(message)); `}}),e(g,{}),e(v,{name:`help`,doc:`Mark the spinner as help.`,parameters:[{name:`message`,type:`string`}],get children(){return o`return this.#stopWithIcon(textColors.spinner.icon.help("${r.icons.spinner.help}"), textColors.spinner.message.help(message)); `}}),e(g,{})]}}),e(g,{}),e(x,{heading:`Render a spinner in the console.`,get children(){return[e(w,{name:`options`,children:`Options for configuring the spinner, including the message to display, the output stream to write to, and the spinner animation to use.`}),e(E,{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.).`})]}}),e(l,{export:!0,name:`createSpinner`,parameters:[{name:`options`,type:`SpinnerOptions`,optional:!0}],children:o`return new Spinner(options);`})]}function Z(e,t){return`borderOptions.${e} === "primary" ? borderColors.app.table.primary("${t.borderStyles.app.table.primary[e]}") : borderOptions.${e} === "secondary" ? borderColors.app.table.secondary("${t.borderStyles.app.table.secondary[e]}") : borderOptions.${e} === "tertiary" ? borderColors.app.table.tertiary("${t.borderStyles.app.table.tertiary[e]}") : !borderOptions.${e} || borderOptions.${e} === "none" ? "" : borderOptions.${e}`}function Q(e,t){return`borderOptions === "primary" ? borderColors.app.table.primary("${t.borderStyles.app.table.primary[e]}") : borderOptions === "secondary" ? borderColors.app.table.secondary("${t.borderStyles.app.table.secondary[e]}") : borderOptions === "tertiary" ? borderColors.app.table.tertiary("${t.borderStyles.app.table.tertiary[e]}") : !borderOptions || borderOptions === "none" ? "" : borderOptions`}function $(i){let a=O();return[e(p,{export:!0,name:`SizeToken`,doc:`A type representing the width size of an item in the console.`,children:o`"full" | "1/1" | "1/2" | "1/3" | "1/4" | "1/5" | "1/6" | "1/12" | "1/24" | "100%" | "50%" | "33.33%" | "25%" | "20%" | "10%" | "5%" | "2.5%"`}),e(g,{}),e(x,{heading:`Determine if a value is a valid size token.`,get children(){return[e(T,{children:`This function checks if the provided value is a valid size token, which can be one of the predefined strings representing common width sizes (e.g., "full", "1/2", "1/3", etc.) or percentage strings (e.g., "50%").`}),e(w,{name:`value`,children:`The value to check for being a valid size token.`}),e(E,{children:`True if the value is a valid size token, false otherwise.`})]}}),e(l,{export:!0,doc:`Determines if the provided value is a valid size token.`,name:`isSizeToken`,parameters:[{name:`value`,type:`any`}],returnType:`value is SizeToken`,get children(){return[e(u,{condition:o`["full", "1/1", "1/2", "1/3", "1/4", "1/5", "1/6", "1/12", "1/24", "100%", "50%", "33.33%", "25%", "20%", "10%", "5%", "2.5%"].includes(value)`,children:o`return true; `}),o`return false; `]}}),e(g,{}),e(x,{heading:`Calculate the width in characters based on the provided width size.`,get children(){return[e(T,{children:`This function calculates the width in characters based on the provided width size, which can be a predefined string (e.g., "full", "1/2", "1/3", etc.) or a percentage string (e.g., "50%"). The calculation is based on the current width of the console (getTerminalSize().columns).`}),e(w,{name:`size`,children:`The width size to calculate. This can be a predefined string (e.g., "full", "1/2", "1/3", etc.) or a percentage string (e.g., "50%").`}),e(E,{children:`The calculated width in characters.`})]}}),e(l,{export:!0,name:`calculateWidth`,parameters:[{name:`size`,type:`SizeToken`,optional:!1}],returnType:`number`,get children(){return[e(u,{condition:o`["full", "100%", "1/1"]. includes(size)`,children:o`return getTerminalSize().columns;`}),e(c,{condition:o`["1/2", "50%"].includes(size)`,children:o`return Math.round(getTerminalSize().columns / 2);`}),e(c,{condition:o`["1/3", "33.33%"].includes(size)`,children:o`return Math.round(getTerminalSize().columns / 3);`}),e(c,{condition:o`["1/4", "25%"].includes(size)`,children:o`return Math.round(getTerminalSize().columns / 4);`}),e(c,{condition:o`["1/5", "20%"].includes(size)`,children:o`return Math.round(getTerminalSize().columns / 5);`}),e(c,{condition:o`["1/6", "10%"].includes(size)`,children:o`return Math.round(getTerminalSize().columns / 6);`}),e(c,{condition:o`["1/12", "5%"].includes(size)`,children:o`return Math.round(getTerminalSize().columns / 12);`}),e(c,{condition:o`["1/24", "2.5%"].includes(size)`,children:o`return Math.round(getTerminalSize().columns / 24);`}),e(s,{children:o`
1695
+ return this; `
1696
+ }),
1697
+ createComponent(Spacing, {}),
1698
+ createComponent(ClassMethod, {
1699
+ name: "success",
1700
+ doc: "Mark the spinner as successful.",
1701
+ parameters: [{
1702
+ name: "message",
1703
+ type: "string"
1704
+ }],
1705
+ get children() {
1706
+ return code`return this.#stopWithIcon(textColors.spinner.icon.success("${theme.icons.spinner.success}"), textColors.spinner.message.success(message)); `;
1707
+ }
1708
+ }),
1709
+ createComponent(Spacing, {}),
1710
+ createComponent(ClassMethod, {
1711
+ name: "error",
1712
+ doc: "Mark the spinner as failed.",
1713
+ parameters: [{
1714
+ name: "message",
1715
+ type: "string"
1716
+ }],
1717
+ get children() {
1718
+ return code`return this.#stopWithIcon(textColors.spinner.icon.error("${theme.icons.spinner.error}"), textColors.spinner.message.error(message)); `;
1719
+ }
1720
+ }),
1721
+ createComponent(Spacing, {}),
1722
+ createComponent(ClassMethod, {
1723
+ name: "warning",
1724
+ doc: "Mark the spinner as warning.",
1725
+ parameters: [{
1726
+ name: "message",
1727
+ type: "string"
1728
+ }],
1729
+ get children() {
1730
+ return code`return this.#stopWithIcon(textColors.spinner.icon.warning("${theme.icons.spinner.warning}"), textColors.spinner.message.warning(message)); `;
1731
+ }
1732
+ }),
1733
+ createComponent(Spacing, {}),
1734
+ createComponent(ClassMethod, {
1735
+ name: "info",
1736
+ doc: "Mark the spinner as informational.",
1737
+ parameters: [{
1738
+ name: "message",
1739
+ type: "string"
1740
+ }],
1741
+ get children() {
1742
+ return code`return this.#stopWithIcon(textColors.spinner.icon.info("${theme.icons.spinner.info}"), textColors.spinner.message.info(message)); `;
1743
+ }
1744
+ }),
1745
+ createComponent(Spacing, {}),
1746
+ createComponent(ClassMethod, {
1747
+ name: "help",
1748
+ doc: "Mark the spinner as help.",
1749
+ parameters: [{
1750
+ name: "message",
1751
+ type: "string"
1752
+ }],
1753
+ get children() {
1754
+ return code`return this.#stopWithIcon(textColors.spinner.icon.help("${theme.icons.spinner.help}"), textColors.spinner.message.help(message)); `;
1755
+ }
1756
+ }),
1757
+ createComponent(Spacing, {})
1758
+ ];
1759
+ }
1760
+ }),
1761
+ createComponent(Spacing, {}),
1762
+ createComponent(TSDoc, {
1763
+ heading: "Render a spinner in the console.",
1764
+ get children() {
1765
+ return [createComponent(TSDocParam, {
1766
+ name: "options",
1767
+ children: `Options for configuring the spinner, including the message to display, the output stream to write to, and the spinner animation to use.`
1768
+ }), 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.).` })];
1769
+ }
1770
+ }),
1771
+ createComponent(FunctionDeclaration, {
1772
+ "export": true,
1773
+ name: "createSpinner",
1774
+ parameters: [{
1775
+ name: "options",
1776
+ type: "SpinnerOptions",
1777
+ optional: true
1778
+ }],
1779
+ children: code`return new Spinner(options);`
1780
+ })
1781
+ ];
1782
+ }
1783
+ function extractBorderOptionsObject(direction, theme) {
1784
+ return `borderOptions.${direction} === "primary" ? borderColors.app.table.primary("${theme.borderStyles.app.table.primary[direction]}") : borderOptions.${direction} === "secondary" ? borderColors.app.table.secondary("${theme.borderStyles.app.table.secondary[direction]}") : borderOptions.${direction} === "tertiary" ? borderColors.app.table.tertiary("${theme.borderStyles.app.table.tertiary[direction]}") : !borderOptions.${direction} || borderOptions.${direction} === "none" ? "" : borderOptions.${direction}`;
1785
+ }
1786
+ function extractBorderOptionsString(direction, theme) {
1787
+ return `borderOptions === "primary" ? borderColors.app.table.primary("${theme.borderStyles.app.table.primary[direction]}") : borderOptions === "secondary" ? borderColors.app.table.secondary("${theme.borderStyles.app.table.secondary[direction]}") : borderOptions === "tertiary" ? borderColors.app.table.tertiary("${theme.borderStyles.app.table.tertiary[direction]}") : !borderOptions || borderOptions === "none" ? "" : borderOptions`;
1788
+ }
1789
+ /**
1790
+ * Props for the TableFunctionDeclaration component.
1791
+ */
1792
+ /**
1793
+ * A component to generate the table functions in the `shell-shock:console` builtin module.
1794
+ */
1795
+ function TableFunctionDeclaration(props) {
1796
+ const theme = useTheme();
1797
+ return [
1798
+ createComponent(TypeDeclaration, {
1799
+ "export": true,
1800
+ name: "SizeToken",
1801
+ doc: "A type representing the width size of an item in the console.",
1802
+ children: code`"full" | "1/1" | "1/2" | "1/3" | "1/4" | "1/5" | "1/6" | "1/12" | "1/24" | "100%" | "50%" | "33.33%" | "25%" | "20%" | "10%" | "5%" | "2.5%"`
1803
+ }),
1804
+ createComponent(Spacing, {}),
1805
+ createComponent(TSDoc, {
1806
+ heading: "Determine if a value is a valid size token.",
1807
+ get children() {
1808
+ return [
1809
+ createComponent(TSDocRemarks, { children: `This function checks if the provided value is a valid size token, which can be one of the predefined strings representing common width sizes (e.g., "full", "1/2", "1/3", etc.) or percentage strings (e.g., "50%").` }),
1810
+ createComponent(TSDocParam, {
1811
+ name: "value",
1812
+ children: `The value to check for being a valid size token.`
1813
+ }),
1814
+ createComponent(TSDocReturns, { children: `True if the value is a valid size token, false otherwise.` })
1815
+ ];
1816
+ }
1817
+ }),
1818
+ createComponent(FunctionDeclaration, {
1819
+ "export": true,
1820
+ doc: "Determines if the provided value is a valid size token.",
1821
+ name: "isSizeToken",
1822
+ parameters: [{
1823
+ name: "value",
1824
+ type: "any"
1825
+ }],
1826
+ returnType: "value is SizeToken",
1827
+ get children() {
1828
+ return [createComponent(IfStatement, {
1829
+ condition: code`["full", "1/1", "1/2", "1/3", "1/4", "1/5", "1/6", "1/12", "1/24", "100%", "50%", "33.33%", "25%", "20%", "10%", "5%", "2.5%"].includes(value)`,
1830
+ children: code`return true; `
1831
+ }), code`return false; `];
1832
+ }
1833
+ }),
1834
+ createComponent(Spacing, {}),
1835
+ createComponent(TSDoc, {
1836
+ heading: "Calculate the width in characters based on the provided width size.",
1837
+ get children() {
1838
+ return [
1839
+ createComponent(TSDocRemarks, { children: `This function calculates the width in characters based on the provided width size, which can be a predefined string (e.g., "full", "1/2", "1/3", etc.) or a percentage string (e.g., "50%"). The calculation is based on the current width of the console (getTerminalSize().columns).` }),
1840
+ createComponent(TSDocParam, {
1841
+ name: "size",
1842
+ children: `The width size to calculate. This can be a predefined string (e.g., "full", "1/2", "1/3", etc.) or a percentage string (e.g., "50%").`
1843
+ }),
1844
+ createComponent(TSDocReturns, { children: `The calculated width in characters.` })
1845
+ ];
1846
+ }
1847
+ }),
1848
+ createComponent(FunctionDeclaration, {
1849
+ "export": true,
1850
+ name: "calculateWidth",
1851
+ parameters: [{
1852
+ name: "size",
1853
+ type: "SizeToken",
1854
+ optional: false
1855
+ }],
1856
+ returnType: "number",
1857
+ get children() {
1858
+ return [
1859
+ createComponent(IfStatement, {
1860
+ condition: code`["full", "100%", "1/1"]. includes(size)`,
1861
+ children: code`return getTerminalSize().columns;`
1862
+ }),
1863
+ createComponent(ElseIfClause, {
1864
+ condition: code`["1/2", "50%"].includes(size)`,
1865
+ children: code`return Math.round(getTerminalSize().columns / 2);`
1866
+ }),
1867
+ createComponent(ElseIfClause, {
1868
+ condition: code`["1/3", "33.33%"].includes(size)`,
1869
+ children: code`return Math.round(getTerminalSize().columns / 3);`
1870
+ }),
1871
+ createComponent(ElseIfClause, {
1872
+ condition: code`["1/4", "25%"].includes(size)`,
1873
+ children: code`return Math.round(getTerminalSize().columns / 4);`
1874
+ }),
1875
+ createComponent(ElseIfClause, {
1876
+ condition: code`["1/5", "20%"].includes(size)`,
1877
+ children: code`return Math.round(getTerminalSize().columns / 5);`
1878
+ }),
1879
+ createComponent(ElseIfClause, {
1880
+ condition: code`["1/6", "10%"].includes(size)`,
1881
+ children: code`return Math.round(getTerminalSize().columns / 6);`
1882
+ }),
1883
+ createComponent(ElseIfClause, {
1884
+ condition: code`["1/12", "5%"].includes(size)`,
1885
+ children: code`return Math.round(getTerminalSize().columns / 12);`
1886
+ }),
1887
+ createComponent(ElseIfClause, {
1888
+ condition: code`["1/24", "2.5%"].includes(size)`,
1889
+ children: code`return Math.round(getTerminalSize().columns / 24);`
1890
+ }),
1891
+ createComponent(ElseClause, { children: code`
551
1892
  const match = size.match(/(\\d+(\\.\\d+)?)%/);
552
1893
  if (match) {
553
1894
  return Math.round((getTerminalSize().columns * parseFloat(match[1])) / 100);
554
1895
  }
555
1896
 
556
1897
  throw new Error(\`Invalid width size: \${size}\`);
557
- `}),e(g,{})]}}),e(p,{export:!0,name:`BorderOption`,doc:`The border options applied to table cells.`,children:o`"primary" | "secondary" | "tertiary" | "none" | string; `}),e(g,{}),e(d,{export:!0,name:`TableOutputOptions`,doc:`Options to customize the output of the {@link table} function.`,get children(){return[e(x,{heading:`Border variant for the table cell.`,get children(){return[e(T,{children:`The border variant to use for the table cell. This determines the color and style of the border around the cell.`}),t(`hbr`,{}),e(S,{get type(){return h.property},defaultValue:`primary`})]}}),e(f,{name:`border`,optional:!0,type:`BorderOption | { top?: BorderOption; right?: BorderOption; bottom?: BorderOption; left?: BorderOption; topLeft?: BorderOption; topRight?: BorderOption; bottomLeft?: BorderOption; bottomRight?: BorderOption; }`}),t(`hbr`,{}),e(x,{heading:`Padding for the table cell.`,get children(){return[e(T,{children:`The amount of padding (in spaces) to apply to the table cell. This value is applied to both the left and right sides of the cell. If not specified, the default table padding defined in the current theme configuration will be used.`}),t(`hbr`,{}),e(S,{get type(){return h.property},get defaultValue(){return`\`${a.padding.table}\``}})]}}),e(f,{name:`padding`,optional:!0,type:`number`}),t(`hbr`,{}),e(x,{heading:`Alignment for the table cell.`,get children(){return[e(T,{children:`The alignment for the table cell. This determines how the text within the cell is aligned. If not specified, the default alignment is "left".`}),t(`hbr`,{}),e(S,{get type(){return h.property},defaultValue:`left`})]}}),e(f,{name:`align`,optional:!0,type:`"left" | "right" | "center"`}),t(`hbr`,{})]}}),e(g,{}),e(d,{export:!0,name:`TableCellOptions`,extends:`TableOutputOptions`,doc:`Options for a specific table cell provided to the {@link table} function.`,get children(){return[e(f,{name:`value`,optional:!0,type:`string`,doc:`The actual string value of the table cell.`}),t(`hbr`,{}),e(x,{heading:`Width of the table cell.`,get children(){return e(T,{children:`The width of the table cell (where 1 is a single character in the terminal). If not specified, the width will be determined based on the content of the cell and the available space in the console.`})}}),e(f,{name:`maxWidth`,type:`number | SizeToken | undefined`}),t(`hbr`,{})]}}),e(g,{}),e(d,{export:!0,name:`TableRowOptions`,extends:`TableOutputOptions`,doc:`Options for a specific table row provided to the {@link table} function.`,get children(){return[e(f,{name:`values`,optional:!0,type:`(string | TableCellOptions)[]`,doc:`The actual string values of the table row's cells.`}),t(`hbr`,{})]}}),e(g,{}),e(d,{export:!0,name:`TableOptions`,extends:`TableOutputOptions`,doc:`Options for a specific table cell provided to the {@link table} function.`,get children(){return[e(f,{name:`values`,optional:!0,type:`(string | TableCellOptions)[][]`,doc:`The actual string values of the table's rows' cells.`}),t(`hbr`,{})]}}),e(g,{}),e(d,{name:`Dimensions`,doc:`The height and width for a specific table/cell used internally in the {@link table} function.`,get children(){return[e(f,{name:`height`,type:`number`,doc:`The height of the row/cell (where 1 is a single line in the terminal).`}),t(`hbr`,{}),e(f,{name:`width`,type:`number`,doc:`The width of the row/cell (where 1 is a single character in the terminal).`}),t(`hbr`,{})]}}),e(g,{}),e(d,{name:`TableCellBorder`,doc:`The resolved complete border styles for a table cell.`,get children(){return[e(f,{name:`top`,type:`string`,doc:`The top border style of the table cell.`}),t(`hbr`,{}),e(f,{name:`bottom`,type:`string`,doc:`The bottom border style of the table cell.`}),t(`hbr`,{}),e(f,{name:`right`,type:`string`,doc:`The right border style of the table cell.`}),t(`hbr`,{}),e(f,{name:`left`,type:`string`,doc:`The left border style of the table cell.`}),t(`hbr`,{}),e(f,{name:`topLeft`,type:`string`,doc:`The top-left border style of the table cell.`}),t(`hbr`,{}),e(f,{name:`topRight`,type:`string`,doc:`The top-right border style of the table cell.`}),t(`hbr`,{}),e(f,{name:`bottomLeft`,type:`string`,doc:`The bottom-left border style of the table cell.`}),t(`hbr`,{}),e(f,{name:`bottomRight`,type:`string`,doc:`The bottom-right border style of the table cell.`}),t(`hbr`,{})]}}),e(g,{}),e(p,{name:`TableCell`,doc:`The internal state of a formatted table cell in the {@link table} function.`,children:o`Required<Omit<TableCellOptions, "maxWidth" | "border">> & Dimensions & {
1898
+ ` }),
1899
+ createComponent(Spacing, {})
1900
+ ];
1901
+ }
1902
+ }),
1903
+ createComponent(TypeDeclaration, {
1904
+ "export": true,
1905
+ name: "BorderOption",
1906
+ doc: "The border options applied to table cells.",
1907
+ children: code`"primary" | "secondary" | "tertiary" | "none" | string; `
1908
+ }),
1909
+ createComponent(Spacing, {}),
1910
+ createComponent(InterfaceDeclaration, {
1911
+ "export": true,
1912
+ name: "TableOutputOptions",
1913
+ doc: "Options to customize the output of the {@link table} function.",
1914
+ get children() {
1915
+ return [
1916
+ createComponent(TSDoc, {
1917
+ heading: "Border variant for the table cell.",
1918
+ get children() {
1919
+ return [
1920
+ createComponent(TSDocRemarks, { children: `The border variant to use for the table cell. This determines the color and style of the border around the cell.` }),
1921
+ createIntrinsic("hbr", {}),
1922
+ createComponent(TSDocDefaultValue, {
1923
+ type: "any",
1924
+ defaultValue: "primary"
1925
+ })
1926
+ ];
1927
+ }
1928
+ }),
1929
+ createComponent(InterfaceMember, {
1930
+ name: "border",
1931
+ optional: true,
1932
+ type: "BorderOption | { top?: BorderOption; right?: BorderOption; bottom?: BorderOption; left?: BorderOption; topLeft?: BorderOption; topRight?: BorderOption; bottomLeft?: BorderOption; bottomRight?: BorderOption; }"
1933
+ }),
1934
+ createIntrinsic("hbr", {}),
1935
+ createComponent(TSDoc, {
1936
+ heading: "Padding for the table cell.",
1937
+ get children() {
1938
+ return [
1939
+ createComponent(TSDocRemarks, { children: `The amount of padding (in spaces) to apply to the table cell. This value is applied to both the left and right sides of the cell. If not specified, the default table padding defined in the current theme configuration will be used.` }),
1940
+ createIntrinsic("hbr", {}),
1941
+ createComponent(TSDocDefaultValue, {
1942
+ type: "any",
1943
+ get defaultValue() {
1944
+ return `\`${theme.padding.table}\``;
1945
+ }
1946
+ })
1947
+ ];
1948
+ }
1949
+ }),
1950
+ createComponent(InterfaceMember, {
1951
+ name: "padding",
1952
+ optional: true,
1953
+ type: "number"
1954
+ }),
1955
+ createIntrinsic("hbr", {}),
1956
+ createComponent(TSDoc, {
1957
+ heading: "Alignment for the table cell.",
1958
+ get children() {
1959
+ return [
1960
+ createComponent(TSDocRemarks, { children: `The alignment for the table cell. This determines how the text within the cell is aligned. If not specified, the default alignment is "left".` }),
1961
+ createIntrinsic("hbr", {}),
1962
+ createComponent(TSDocDefaultValue, {
1963
+ type: "any",
1964
+ defaultValue: "left"
1965
+ })
1966
+ ];
1967
+ }
1968
+ }),
1969
+ createComponent(InterfaceMember, {
1970
+ name: "align",
1971
+ optional: true,
1972
+ type: "\"left\" | \"right\" | \"center\""
1973
+ }),
1974
+ createIntrinsic("hbr", {})
1975
+ ];
1976
+ }
1977
+ }),
1978
+ createComponent(Spacing, {}),
1979
+ createComponent(InterfaceDeclaration, {
1980
+ "export": true,
1981
+ name: "TableCellOptions",
1982
+ "extends": "TableOutputOptions",
1983
+ doc: "Options for a specific table cell provided to the {@link table} function.",
1984
+ get children() {
1985
+ return [
1986
+ createComponent(InterfaceMember, {
1987
+ name: "value",
1988
+ optional: true,
1989
+ type: "string",
1990
+ doc: "The actual string value of the table cell."
1991
+ }),
1992
+ createIntrinsic("hbr", {}),
1993
+ createComponent(TSDoc, {
1994
+ heading: "Width of the table cell.",
1995
+ get children() {
1996
+ return createComponent(TSDocRemarks, { children: `The width of the table cell (where 1 is a single character in the terminal). If not specified, the width will be determined based on the content of the cell and the available space in the console.` });
1997
+ }
1998
+ }),
1999
+ createComponent(InterfaceMember, {
2000
+ name: "maxWidth",
2001
+ type: "number | SizeToken | undefined"
2002
+ }),
2003
+ createIntrinsic("hbr", {})
2004
+ ];
2005
+ }
2006
+ }),
2007
+ createComponent(Spacing, {}),
2008
+ createComponent(InterfaceDeclaration, {
2009
+ "export": true,
2010
+ name: "TableRowOptions",
2011
+ "extends": "TableOutputOptions",
2012
+ doc: "Options for a specific table row provided to the {@link table} function.",
2013
+ get children() {
2014
+ return [createComponent(InterfaceMember, {
2015
+ name: "values",
2016
+ optional: true,
2017
+ type: "(string | TableCellOptions)[]",
2018
+ doc: "The actual string values of the table row's cells."
2019
+ }), createIntrinsic("hbr", {})];
2020
+ }
2021
+ }),
2022
+ createComponent(Spacing, {}),
2023
+ createComponent(InterfaceDeclaration, {
2024
+ "export": true,
2025
+ name: "TableOptions",
2026
+ "extends": "TableOutputOptions",
2027
+ doc: "Options for a specific table cell provided to the {@link table} function.",
2028
+ get children() {
2029
+ return [createComponent(InterfaceMember, {
2030
+ name: "values",
2031
+ optional: true,
2032
+ type: "(string | TableCellOptions)[][]",
2033
+ doc: "The actual string values of the table's rows' cells."
2034
+ }), createIntrinsic("hbr", {})];
2035
+ }
2036
+ }),
2037
+ createComponent(Spacing, {}),
2038
+ createComponent(InterfaceDeclaration, {
2039
+ name: "Dimensions",
2040
+ doc: "The height and width for a specific table/cell used internally in the {@link table} function.",
2041
+ get children() {
2042
+ return [
2043
+ createComponent(InterfaceMember, {
2044
+ name: "height",
2045
+ type: "number",
2046
+ doc: "The height of the row/cell (where 1 is a single line in the terminal)."
2047
+ }),
2048
+ createIntrinsic("hbr", {}),
2049
+ createComponent(InterfaceMember, {
2050
+ name: "width",
2051
+ type: "number",
2052
+ doc: "The width of the row/cell (where 1 is a single character in the terminal)."
2053
+ }),
2054
+ createIntrinsic("hbr", {})
2055
+ ];
2056
+ }
2057
+ }),
2058
+ createComponent(Spacing, {}),
2059
+ createComponent(InterfaceDeclaration, {
2060
+ name: "TableCellBorder",
2061
+ doc: "The resolved complete border styles for a table cell.",
2062
+ get children() {
2063
+ return [
2064
+ createComponent(InterfaceMember, {
2065
+ name: "top",
2066
+ type: "string",
2067
+ doc: "The top border style of the table cell."
2068
+ }),
2069
+ createIntrinsic("hbr", {}),
2070
+ createComponent(InterfaceMember, {
2071
+ name: "bottom",
2072
+ type: "string",
2073
+ doc: "The bottom border style of the table cell."
2074
+ }),
2075
+ createIntrinsic("hbr", {}),
2076
+ createComponent(InterfaceMember, {
2077
+ name: "right",
2078
+ type: "string",
2079
+ doc: "The right border style of the table cell."
2080
+ }),
2081
+ createIntrinsic("hbr", {}),
2082
+ createComponent(InterfaceMember, {
2083
+ name: "left",
2084
+ type: "string",
2085
+ doc: "The left border style of the table cell."
2086
+ }),
2087
+ createIntrinsic("hbr", {}),
2088
+ createComponent(InterfaceMember, {
2089
+ name: "topLeft",
2090
+ type: "string",
2091
+ doc: "The top-left border style of the table cell."
2092
+ }),
2093
+ createIntrinsic("hbr", {}),
2094
+ createComponent(InterfaceMember, {
2095
+ name: "topRight",
2096
+ type: "string",
2097
+ doc: "The top-right border style of the table cell."
2098
+ }),
2099
+ createIntrinsic("hbr", {}),
2100
+ createComponent(InterfaceMember, {
2101
+ name: "bottomLeft",
2102
+ type: "string",
2103
+ doc: "The bottom-left border style of the table cell."
2104
+ }),
2105
+ createIntrinsic("hbr", {}),
2106
+ createComponent(InterfaceMember, {
2107
+ name: "bottomRight",
2108
+ type: "string",
2109
+ doc: "The bottom-right border style of the table cell."
2110
+ }),
2111
+ createIntrinsic("hbr", {})
2112
+ ];
2113
+ }
2114
+ }),
2115
+ createComponent(Spacing, {}),
2116
+ createComponent(TypeDeclaration, {
2117
+ name: "TableCell",
2118
+ doc: "The internal state of a formatted table cell in the {@link table} function.",
2119
+ children: code`Required<Omit<TableCellOptions, "maxWidth" | "border">> & Dimensions & {
558
2120
  border: TableCellBorder;
559
2121
  maxWidth?: number;
560
2122
  };
561
- `}),e(g,{}),e(x,{heading:`Write a table to the console.`,get children(){return[e(T,{children:`This function writes a table to the console, applying the appropriate padding as defined in the current theme configuration and wrapping as needed.`}),t(`hbr`,{}),e(w,{name:`options`,children:`Options to customize the table output.`})]}}),e(l,r({export:!0},i,{name:`table`,parameters:[{name:`options`,type:`TableOptions | TableRowOptions[] | TableCellOptions[][] | string[] | string[][]`,optional:!1}],get children(){return[e(u,{condition:o`!options ||
2123
+ `
2124
+ }),
2125
+ createComponent(Spacing, {}),
2126
+ createComponent(TSDoc, {
2127
+ heading: "Write a table to the console.",
2128
+ get children() {
2129
+ return [
2130
+ createComponent(TSDocRemarks, { children: `This function writes a table to the console, applying the appropriate padding as defined in the current theme configuration and wrapping as needed.` }),
2131
+ createIntrinsic("hbr", {}),
2132
+ createComponent(TSDocParam, {
2133
+ name: "options",
2134
+ children: `Options to customize the table output.`
2135
+ })
2136
+ ];
2137
+ }
2138
+ }),
2139
+ createComponent(FunctionDeclaration, mergeProps({ "export": true }, props, {
2140
+ name: "table",
2141
+ parameters: [{
2142
+ name: "options",
2143
+ type: "TableOptions | TableRowOptions[] | TableCellOptions[][] | string[] | string[][]",
2144
+ optional: false
2145
+ }],
2146
+ get children() {
2147
+ return [
2148
+ createComponent(IfStatement, {
2149
+ condition: code`!options ||
562
2150
  (!Array.isArray(options) && (typeof options !== "object" || !options.values || !Array.isArray(options.values) || options.values.length === 0)) ||
563
- (Array.isArray(options) && !options.every(item => typeof item === "object" || typeof item === "string" || Array.isArray(item))) `,children:o`return;`}),e(g,{}),e(m,{let:!0,name:`cells`,type:`TableCell[][]`,initializer:o`[];`}),t(`hbr`,{}),n(()=>o`
2151
+ (Array.isArray(options) && !options.every(item => typeof item === "object" || typeof item === "string" || Array.isArray(item))) `,
2152
+ children: code`return;`
2153
+ }),
2154
+ createComponent(Spacing, {}),
2155
+ createComponent(VarDeclaration, {
2156
+ "let": true,
2157
+ name: "cells",
2158
+ type: `TableCell[][]`,
2159
+ initializer: code`[];`
2160
+ }),
2161
+ createIntrinsic("hbr", {}),
2162
+ memo(() => code`
564
2163
  const extractTableCell = (cell: string | TableCellOptions, columnIndex: number, rowLength: number, opts?: TableOutputOptions): TableCell => {
565
2164
  if (typeof cell === "string") {
566
2165
  const borderOptions = opts?.border || "primary";
@@ -568,27 +2167,27 @@ console.log(result); // "\\\\x1b[36mHello\\\\x1b[39\\\\x1b[31mWorld\\\\x1b[0m\\\
568
2167
  let border = {} as TableCellBorder;
569
2168
  if (typeof borderOptions === "object") {
570
2169
  border = {
571
- top: ${Z(`top`,a)},
572
- bottom: ${Z(`bottom`,a)},
573
- left: ${Z(`left`,a)},
574
- right: ${Z(`right`,a)},
575
- topLeft: ${Z(`topLeft`,a)},
576
- topRight: ${Z(`topRight`,a)},
577
- bottomLeft: ${Z(`bottomLeft`,a)},
578
- bottomRight: ${Z(`bottomRight`,a)},
2170
+ top: ${extractBorderOptionsObject("top", theme)},
2171
+ bottom: ${extractBorderOptionsObject("bottom", theme)},
2172
+ left: ${extractBorderOptionsObject("left", theme)},
2173
+ right: ${extractBorderOptionsObject("right", theme)},
2174
+ topLeft: ${extractBorderOptionsObject("topLeft", theme)},
2175
+ topRight: ${extractBorderOptionsObject("topRight", theme)},
2176
+ bottomLeft: ${extractBorderOptionsObject("bottomLeft", theme)},
2177
+ bottomRight: ${extractBorderOptionsObject("bottomRight", theme)},
579
2178
  };
580
2179
  } else {
581
- border.top = ${Q(`top`,a)};
582
- border.bottom = ${Q(`bottom`,a)};
583
- border.left = ${Q(`left`,a)};
584
- border.right = ${Q(`right`,a)};
585
- border.topLeft = ${Q(`topLeft`,a)};
586
- border.topRight = ${Q(`topRight`,a)};
587
- border.bottomLeft = ${Q(`bottomLeft`,a)};
588
- border.bottomRight = ${Q(`bottomRight`,a)};
2180
+ border.top = ${extractBorderOptionsString("top", theme)};
2181
+ border.bottom = ${extractBorderOptionsString("bottom", theme)};
2182
+ border.left = ${extractBorderOptionsString("left", theme)};
2183
+ border.right = ${extractBorderOptionsString("right", theme)};
2184
+ border.topLeft = ${extractBorderOptionsString("topLeft", theme)};
2185
+ border.topRight = ${extractBorderOptionsString("topRight", theme)};
2186
+ border.bottomLeft = ${extractBorderOptionsString("bottomLeft", theme)};
2187
+ border.bottomRight = ${extractBorderOptionsString("bottomRight", theme)};
589
2188
  }
590
2189
 
591
- const padding = Math.max(0, opts?.padding ?? ${a.padding.table}) * (columnIndex === 0 || columnIndex === rowLength - 1 ? 2 : 1);
2190
+ const padding = Math.max(0, opts?.padding ?? ${theme.padding.table}) * (columnIndex === 0 || columnIndex === rowLength - 1 ? 2 : 1);
592
2191
  const value = cell ?? "";
593
2192
  const width = stripAnsi(value).length + padding * 2;
594
2193
 
@@ -606,27 +2205,27 @@ console.log(result); // "\\\\x1b[36mHello\\\\x1b[39\\\\x1b[31mWorld\\\\x1b[0m\\\
606
2205
  let border = {} as TableCellBorder;
607
2206
  if (typeof borderOptions === "object") {
608
2207
  border = {
609
- top: ${Z(`top`,a)},
610
- bottom: ${Z(`bottom`,a)},
611
- left: ${Z(`left`,a)},
612
- right: ${Z(`right`,a)},
613
- topLeft: ${Z(`topLeft`,a)},
614
- topRight: ${Z(`topRight`,a)},
615
- bottomLeft: ${Z(`bottomLeft`,a)},
616
- bottomRight: ${Z(`bottomRight`,a)},
2208
+ top: ${extractBorderOptionsObject("top", theme)},
2209
+ bottom: ${extractBorderOptionsObject("bottom", theme)},
2210
+ left: ${extractBorderOptionsObject("left", theme)},
2211
+ right: ${extractBorderOptionsObject("right", theme)},
2212
+ topLeft: ${extractBorderOptionsObject("topLeft", theme)},
2213
+ topRight: ${extractBorderOptionsObject("topRight", theme)},
2214
+ bottomLeft: ${extractBorderOptionsObject("bottomLeft", theme)},
2215
+ bottomRight: ${extractBorderOptionsObject("bottomRight", theme)},
617
2216
  };
618
2217
  } else {
619
- border.top = ${Q(`top`,a)};
620
- border.bottom = ${Q(`bottom`,a)};
621
- border.left = ${Q(`left`,a)};
622
- border.right = ${Q(`right`,a)};
623
- border.topLeft = ${Q(`topLeft`,a)};
624
- border.topRight = ${Q(`topRight`,a)};
625
- border.bottomLeft = ${Q(`bottomLeft`,a)};
626
- border.bottomRight = ${Q(`bottomRight`,a)};
2218
+ border.top = ${extractBorderOptionsString("top", theme)};
2219
+ border.bottom = ${extractBorderOptionsString("bottom", theme)};
2220
+ border.left = ${extractBorderOptionsString("left", theme)};
2221
+ border.right = ${extractBorderOptionsString("right", theme)};
2222
+ border.topLeft = ${extractBorderOptionsString("topLeft", theme)};
2223
+ border.topRight = ${extractBorderOptionsString("topRight", theme)};
2224
+ border.bottomLeft = ${extractBorderOptionsString("bottomLeft", theme)};
2225
+ border.bottomRight = ${extractBorderOptionsString("bottomRight", theme)};
627
2226
  }
628
2227
 
629
- const padding = Math.max(0, cell.padding ?? opts?.padding ?? ${a.padding.table});
2228
+ const padding = Math.max(0, cell.padding ?? opts?.padding ?? ${theme.padding.table});
630
2229
  const value = cell.value ?? "";
631
2230
  const width = stripAnsi(value).length + padding * 2;
632
2231
  const maxWidth = cell.maxWidth ? typeof cell.maxWidth === "number" ? cell.maxWidth : calculateWidth(cell.maxWidth) : undefined;
@@ -644,7 +2243,15 @@ console.log(result); // "\\\\x1b[36mHello\\\\x1b[39\\\\x1b[31mWorld\\\\x1b[0m\\\
644
2243
  };
645
2244
 
646
2245
  let colMaxWidths = [] as (number | undefined)[];
647
- `),t(`hbr`,{}),e(u,{condition:o`Array.isArray(options)`,get children(){return[e(u,{condition:o`options.every(row => typeof row === "string" || (typeof row === "object" && !Array.isArray(row) && !("values" in row)))`,children:o`cells.push(options.map((cell, index) => extractTableCell(cell as string | TableCellOptions, index, options.length)));`}),e(s,{children:o`
2246
+ `),
2247
+ createIntrinsic("hbr", {}),
2248
+ createComponent(IfStatement, {
2249
+ condition: code`Array.isArray(options)`,
2250
+ get children() {
2251
+ return [createComponent(IfStatement, {
2252
+ condition: code`options.every(row => typeof row === "string" || (typeof row === "object" && !Array.isArray(row) && !("values" in row)))`,
2253
+ children: code`cells.push(options.map((cell, index) => extractTableCell(cell as string | TableCellOptions, index, options.length)));`
2254
+ }), createComponent(ElseClause, { children: code`
648
2255
  cells.push(
649
2256
  ...options.map(row => Array.isArray(row)
650
2257
  ? row.reduce((cellRow, cell, index) => {
@@ -671,7 +2278,10 @@ console.log(result); // "\\\\x1b[36mHello\\\\x1b[39\\\\x1b[31mWorld\\\\x1b[0m\\\
671
2278
  }, [] as TableCell[]) ?? []
672
2279
  )
673
2280
  );
674
- `})]}}),e(s,{children:o`
2281
+ ` })];
2282
+ }
2283
+ }),
2284
+ createComponent(ElseClause, { children: code`
675
2285
  cells.push(
676
2286
  ...options.values!.map(row => Array.isArray(row)
677
2287
  ? row.reduce((cellRow, cell, index) => {
@@ -699,7 +2309,9 @@ console.log(result); // "\\\\x1b[36mHello\\\\x1b[39\\\\x1b[31mWorld\\\\x1b[0m\\\
699
2309
  )
700
2310
  );
701
2311
 
702
- `}),t(`hbr`,{}),n(()=>o`
2312
+ ` }),
2313
+ createIntrinsic("hbr", {}),
2314
+ memo(() => code`
703
2315
  cells = cells.filter(row => row.length > 0);
704
2316
  if (cells.length === 0) {
705
2317
  return;
@@ -760,7 +2372,7 @@ do {
760
2372
  }
761
2373
 
762
2374
  rowDims.forEach((row, rowIndex) => {
763
- if (!recalculate && row.width > Math.max(getTerminalSize().columns - ${Math.max(a.padding.app,0)*2}, 0)) {
2375
+ if (!recalculate && row.width > Math.max(getTerminalSize().columns - ${Math.max(theme.padding.app, 0) * 2}, 0)) {
764
2376
  const cell = cells[rowIndex]!.reduce((largestCell, cell) => {
765
2377
  if (cell.width > largestCell.width) {
766
2378
  return cell;
@@ -770,7 +2382,7 @@ do {
770
2382
 
771
2383
  const lines = splitText(
772
2384
  cell.value,
773
- Math.min(Math.max(getTerminalSize().columns - ${Math.max(a.padding.app,0)*2} - (row.width - (cell.width - cell.padding * 2)), 0),
2385
+ Math.min(Math.max(getTerminalSize().columns - ${Math.max(theme.padding.app, 0) * 2} - (row.width - (cell.width - cell.padding * 2)), 0),
774
2386
  cell.maxWidth ?? Number.POSITIVE_INFINITY)
775
2387
  );
776
2388
 
@@ -782,7 +2394,7 @@ do {
782
2394
  }
783
2395
  });
784
2396
 
785
- if (!recalculate && colWidths.reduce((a, b) => a + b, 0) > Math.max(getTerminalSize().columns - ${Math.max(a.padding.app,0)*2}, 0)) {
2397
+ if (!recalculate && colWidths.reduce((a, b) => a + b, 0) > Math.max(getTerminalSize().columns - ${Math.max(theme.padding.app, 0) * 2}, 0)) {
786
2398
  let colIndex = 0;
787
2399
  const cell = cells.reduce((ret, row) => {
788
2400
  return row.reduce((largest, current, index) => {
@@ -796,7 +2408,7 @@ do {
796
2408
 
797
2409
  const lines = splitText(
798
2410
  cell.value,
799
- Math.min(Math.max(getTerminalSize().columns - ${Math.max(a.padding.app,0)*2} - (colWidths.filter((_, i) => i !== colIndex).reduce((a, b) => a + b, 0)) - cell.padding * 2, 0),
2411
+ Math.min(Math.max(getTerminalSize().columns - ${Math.max(theme.padding.app, 0) * 2} - (colWidths.filter((_, i) => i !== colIndex).reduce((a, b) => a + b, 0)) - cell.padding * 2, 0),
800
2412
  cell.maxWidth ?? Number.POSITIVE_INFINITY)
801
2413
  );
802
2414
 
@@ -846,7 +2458,167 @@ cells.forEach((row, rowIndex) => {
846
2458
  writeLine(outputs.map(output => output[index] ?? "").join(""));
847
2459
  }
848
2460
  });
849
- `)]}}))]}function oe(t){let{children:n,imports:r,builtinImports:i}=t;return e(b,{id:`console`,description:`A collection of helper utilities to assist in generating content meant for display in the console.`,get imports(){return N(r,{"@shell-shock/plugin-theme/types/theme":[`ThemeSpinnerResolvedConfig`],"@shell-shock/plugin-theme/helpers/spinners":[`SpinnerPreset`,`resolveSpinner`],"node:util":[`stripVTControlCharacters`]})},get builtinImports(){return N(i,{utils:[`isInteractive`,`isColorSupported`,`colorSupportLevels`,`isUnicodeSupported`,`isHyperlinkSupported`,`getTerminalSize`],env:[`env`,`isDevelopment`,`isDebug`],state:[`hasFlag`]})},get children(){return[e(P,{}),e(g,{}),e(W,{}),e(g,{}),e(U,{}),e(g,{}),e(R,{}),e(g,{}),e(B,{}),e(g,{}),e(V,{}),e(g,{}),e(z,{}),e(g,{}),e(K,{}),e(g,{}),e(G,{}),e(g,{}),e(X,{}),e(g,{}),e(H,{type:`help`,variant:`help`,consoleFnName:`log`,description:`help`}),e(g,{}),e(H,{type:`success`,variant:`success`,consoleFnName:`info`,description:`success`}),e(g,{}),e(H,{type:`info`,variant:`info`,consoleFnName:`info`,description:`informational`}),e(g,{}),e(H,{type:`debug`,variant:`debug`,consoleFnName:`debug`,description:`debug`,timestamp:!0,get prefix(){return e(u,{get condition(){return e(ne,{})},children:o`return; `})}}),e(g,{}),e(H,{type:`verbose`,variant:`info`,color:`debug`,consoleFnName:`debug`,description:`verbose`,timestamp:!0,get prefix(){return e(u,{get condition(){return e(D,{})},children:o`return; `})}}),e(g,{}),e(H,{type:`warn`,variant:`warning`,consoleFnName:`warn`,description:`warning`}),e(g,{}),e(H,{type:`danger`,variant:`danger`,consoleFnName:`error`,description:`destructive/danger`}),e(g,{}),e(H,{type:`error`,variant:`error`,consoleFnName:`error`,description:`error`,timestamp:!0,parameters:[{name:`err`,type:`string | { message: string; stack?: string }`,optional:!1},{name:`header`,type:`string`,optional:!0}],get prefix(){return[e(m,{let:!0,name:`message`,type:`string | undefined`}),e(g,{}),e(u,{condition:o`(err as { message: string; stack?: string })?.message`,children:o`message = (err as { message: string; stack?: string }).message;`}),e(s,{children:o`message = String(err);`}),e(g,{}),e(u,{condition:o`env.STACKTRACE && typeof err === "object" && (err as { stack?: string })?.stack`,children:o`message += " \\n\\n" + (err as { stack: string }).stack.split("\\n").slice(1).map(line => {
2461
+ `)
2462
+ ];
2463
+ }
2464
+ }))
2465
+ ];
2466
+ }
2467
+ /**
2468
+ * A built-in console utilities module for Shell Shock.
2469
+ */
2470
+ function ConsoleBuiltin(props) {
2471
+ const { children, imports, builtinImports } = props;
2472
+ return createComponent(BuiltinFile, {
2473
+ id: "console",
2474
+ description: "A collection of helper utilities to assist in generating content meant for display in the console.",
2475
+ get imports() {
2476
+ return defu(imports, {
2477
+ "@shell-shock/plugin-theme/types/theme": ["ThemeSpinnerResolvedConfig"],
2478
+ "@shell-shock/plugin-theme/helpers/spinners": ["SpinnerPreset", "resolveSpinner"],
2479
+ "node:util": ["stripVTControlCharacters"]
2480
+ });
2481
+ },
2482
+ get builtinImports() {
2483
+ return defu(builtinImports, {
2484
+ utils: [
2485
+ "isInteractive",
2486
+ "isColorSupported",
2487
+ "colorSupportLevels",
2488
+ "isUnicodeSupported",
2489
+ "isHyperlinkSupported",
2490
+ "getTerminalSize"
2491
+ ],
2492
+ env: [
2493
+ "env",
2494
+ "isDevelopment",
2495
+ "isDebug"
2496
+ ],
2497
+ state: ["hasFlag"]
2498
+ });
2499
+ },
2500
+ get children() {
2501
+ return [
2502
+ createComponent(AnsiHelpersDeclarations, {}),
2503
+ createComponent(Spacing, {}),
2504
+ createComponent(StripAnsiFunctionDeclaration, {}),
2505
+ createComponent(Spacing, {}),
2506
+ createComponent(WrapAnsiFunction, {}),
2507
+ createComponent(Spacing, {}),
2508
+ createComponent(AnsiStyleFunctionsDeclaration, {}),
2509
+ createComponent(Spacing, {}),
2510
+ createComponent(WriteFunctionDeclaration, {}),
2511
+ createComponent(Spacing, {}),
2512
+ createComponent(WriteLineFunctionDeclaration, {}),
2513
+ createComponent(Spacing, {}),
2514
+ createComponent(SplitTextFunctionDeclaration, {}),
2515
+ createComponent(Spacing, {}),
2516
+ createComponent(LinkFunctionDeclaration, {}),
2517
+ createComponent(Spacing, {}),
2518
+ createComponent(DividerFunctionDeclaration, {}),
2519
+ createComponent(Spacing, {}),
2520
+ createComponent(SpinnerFunctionDeclaration, {}),
2521
+ createComponent(Spacing, {}),
2522
+ createComponent(MessageFunctionDeclaration, {
2523
+ type: "help",
2524
+ variant: "help",
2525
+ consoleFnName: "log",
2526
+ description: "help"
2527
+ }),
2528
+ createComponent(Spacing, {}),
2529
+ createComponent(MessageFunctionDeclaration, {
2530
+ type: "success",
2531
+ variant: "success",
2532
+ consoleFnName: "info",
2533
+ description: "success"
2534
+ }),
2535
+ createComponent(Spacing, {}),
2536
+ createComponent(MessageFunctionDeclaration, {
2537
+ type: "info",
2538
+ variant: "info",
2539
+ consoleFnName: "info",
2540
+ description: "informational"
2541
+ }),
2542
+ createComponent(Spacing, {}),
2543
+ createComponent(MessageFunctionDeclaration, {
2544
+ type: "debug",
2545
+ variant: "debug",
2546
+ consoleFnName: "debug",
2547
+ description: "debug",
2548
+ timestamp: true,
2549
+ get prefix() {
2550
+ return createComponent(IfStatement, {
2551
+ get condition() {
2552
+ return createComponent(IsNotDebug, {});
2553
+ },
2554
+ children: code`return; `
2555
+ });
2556
+ }
2557
+ }),
2558
+ createComponent(Spacing, {}),
2559
+ createComponent(MessageFunctionDeclaration, {
2560
+ type: "verbose",
2561
+ variant: "info",
2562
+ color: "debug",
2563
+ consoleFnName: "debug",
2564
+ description: "verbose",
2565
+ timestamp: true,
2566
+ get prefix() {
2567
+ return createComponent(IfStatement, {
2568
+ get condition() {
2569
+ return createComponent(IsNotVerbose, {});
2570
+ },
2571
+ children: code`return; `
2572
+ });
2573
+ }
2574
+ }),
2575
+ createComponent(Spacing, {}),
2576
+ createComponent(MessageFunctionDeclaration, {
2577
+ type: "warn",
2578
+ variant: "warning",
2579
+ consoleFnName: "warn",
2580
+ description: "warning"
2581
+ }),
2582
+ createComponent(Spacing, {}),
2583
+ createComponent(MessageFunctionDeclaration, {
2584
+ type: "danger",
2585
+ variant: "danger",
2586
+ consoleFnName: "error",
2587
+ description: "destructive/danger"
2588
+ }),
2589
+ createComponent(Spacing, {}),
2590
+ createComponent(MessageFunctionDeclaration, {
2591
+ type: "error",
2592
+ variant: "error",
2593
+ consoleFnName: "error",
2594
+ description: "error",
2595
+ timestamp: true,
2596
+ parameters: [{
2597
+ name: "err",
2598
+ type: "string | { message: string; stack?: string }",
2599
+ optional: false
2600
+ }, {
2601
+ name: "header",
2602
+ type: "string",
2603
+ optional: true
2604
+ }],
2605
+ get prefix() {
2606
+ return [
2607
+ createComponent(VarDeclaration, {
2608
+ "let": true,
2609
+ name: "message",
2610
+ type: "string | undefined"
2611
+ }),
2612
+ createComponent(Spacing, {}),
2613
+ createComponent(IfStatement, {
2614
+ condition: code`(err as { message: string; stack?: string })?.message`,
2615
+ children: code`message = (err as { message: string; stack?: string }).message;`
2616
+ }),
2617
+ createComponent(ElseClause, { children: code`message = String(err);` }),
2618
+ createComponent(Spacing, {}),
2619
+ createComponent(IfStatement, {
2620
+ condition: code`env.STACKTRACE && typeof err === "object" && (err as { stack?: string })?.stack`,
2621
+ children: code`message += " \\n\\n" + (err as { stack: string }).stack.split("\\n").slice(1).map(line => {
850
2622
  const match = line.match(/at (?:(.+?)\\s+\\()?(?:(.+?):(\\d+)(?::(\\d+))?|([^)]+))\\)?/);
851
2623
  if (match) {
852
2624
  const filePath = match[2] || match[5] || "<unknown>";
@@ -854,5 +2626,27 @@ cells.forEach((row, rowIndex) => {
854
2626
  }
855
2627
 
856
2628
  return line.trim();
857
- }).join("\\n"); `})]}}),e(g,{}),e($,{}),e(g,{}),e(q,{}),e(g,{}),e(J,{}),e(g,{}),e(Y,{}),e(g,{}),n,e(g,{})]}})}export{P as AnsiHelpersDeclarations,R as AnsiStyleFunctionsDeclaration,q as BlockquoteFunctionDeclaration,J as CodeFunctionDeclaration,oe as ConsoleBuiltin,G as DividerFunctionDeclaration,Y as InlineCodeFunctionDeclaration,K as LinkFunctionDeclaration,H as MessageFunctionDeclaration,X as SpinnerFunctionDeclaration,z as SplitTextFunctionDeclaration,W as StripAnsiFunctionDeclaration,$ as TableFunctionDeclaration,L as ThemeColorObjectDefinition,I as ThemeColorTypeDefinition,U as WrapAnsiFunction,B as WriteFunctionDeclaration,V as WriteLineFunctionDeclaration};
2629
+ }).join("\\n"); `
2630
+ })
2631
+ ];
2632
+ }
2633
+ }),
2634
+ createComponent(Spacing, {}),
2635
+ createComponent(TableFunctionDeclaration, {}),
2636
+ createComponent(Spacing, {}),
2637
+ createComponent(BlockquoteFunctionDeclaration, {}),
2638
+ createComponent(Spacing, {}),
2639
+ createComponent(CodeFunctionDeclaration, {}),
2640
+ createComponent(Spacing, {}),
2641
+ createComponent(InlineCodeFunctionDeclaration, {}),
2642
+ createComponent(Spacing, {}),
2643
+ children,
2644
+ createComponent(Spacing, {})
2645
+ ];
2646
+ }
2647
+ });
2648
+ }
2649
+
2650
+ //#endregion
2651
+ export { AnsiHelpersDeclarations, AnsiStyleFunctionsDeclaration, BlockquoteFunctionDeclaration, CodeFunctionDeclaration, ConsoleBuiltin, DividerFunctionDeclaration, InlineCodeFunctionDeclaration, LinkFunctionDeclaration, MessageFunctionDeclaration, SpinnerFunctionDeclaration, SplitTextFunctionDeclaration, StripAnsiFunctionDeclaration, TableFunctionDeclaration, ThemeColorObjectDefinition, ThemeColorTypeDefinition, WrapAnsiFunction, WriteFunctionDeclaration, WriteLineFunctionDeclaration };
858
2652
  //# sourceMappingURL=console-builtin.mjs.map