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