@shell-shock/preset-script 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +2 -2
  2. package/dist/components/args-parser-logic.d.cts +7 -7
  3. package/dist/components/args-parser-logic.d.cts.map +1 -1
  4. package/dist/components/bin-entry.cjs +0 -1
  5. package/dist/components/bin-entry.cjs.map +1 -1
  6. package/dist/components/bin-entry.d.cts.map +1 -1
  7. package/dist/components/bin-entry.d.mts.map +1 -1
  8. package/dist/components/bin-entry.mjs +0 -1
  9. package/dist/components/bin-entry.mjs.map +1 -1
  10. package/dist/components/command-entry.d.cts +4 -4
  11. package/dist/components/command-entry.d.mts +4 -4
  12. package/dist/components/command-entry.d.mts.map +1 -1
  13. package/dist/components/command-router.cjs +5 -7
  14. package/dist/components/command-router.cjs.map +1 -1
  15. package/dist/components/command-router.mjs +5 -7
  16. package/dist/components/command-router.mjs.map +1 -1
  17. package/dist/components/console-builtin.cjs +314 -82
  18. package/dist/components/console-builtin.cjs.map +1 -1
  19. package/dist/components/console-builtin.d.cts +12 -2
  20. package/dist/components/console-builtin.d.cts.map +1 -1
  21. package/dist/components/console-builtin.d.mts +12 -2
  22. package/dist/components/console-builtin.d.mts.map +1 -1
  23. package/dist/components/console-builtin.mjs +315 -84
  24. package/dist/components/console-builtin.mjs.map +1 -1
  25. package/dist/components/help.cjs +35 -23
  26. package/dist/components/help.cjs.map +1 -1
  27. package/dist/components/help.d.cts +19 -11
  28. package/dist/components/help.d.cts.map +1 -1
  29. package/dist/components/help.d.mts +19 -11
  30. package/dist/components/help.d.mts.map +1 -1
  31. package/dist/components/help.mjs +36 -24
  32. package/dist/components/help.mjs.map +1 -1
  33. package/dist/components/index.cjs +1 -0
  34. package/dist/components/index.d.cts +3 -3
  35. package/dist/components/index.d.mts +3 -3
  36. package/dist/components/index.mjs +2 -2
  37. package/dist/components/utils-builtin.cjs +18 -16
  38. package/dist/components/utils-builtin.cjs.map +1 -1
  39. package/dist/components/utils-builtin.d.cts +7 -7
  40. package/dist/components/utils-builtin.d.cts.map +1 -1
  41. package/dist/components/utils-builtin.d.mts +7 -7
  42. package/dist/components/utils-builtin.d.mts.map +1 -1
  43. package/dist/components/utils-builtin.mjs +18 -16
  44. package/dist/components/utils-builtin.mjs.map +1 -1
  45. package/dist/components/virtual-command-entry.d.cts +3 -3
  46. package/dist/components/virtual-command-entry.d.cts.map +1 -1
  47. package/dist/helpers/ansi-utils.cjs +74 -10
  48. package/dist/helpers/ansi-utils.cjs.map +1 -1
  49. package/dist/helpers/ansi-utils.mjs +74 -10
  50. package/dist/helpers/ansi-utils.mjs.map +1 -1
  51. package/dist/helpers/get-default-options.cjs +20 -0
  52. package/dist/helpers/get-default-options.cjs.map +1 -1
  53. package/dist/helpers/get-default-options.mjs +20 -0
  54. package/dist/helpers/get-default-options.mjs.map +1 -1
  55. package/dist/index.cjs +97 -75
  56. package/dist/index.cjs.map +1 -1
  57. package/dist/index.d.cts.map +1 -1
  58. package/dist/index.d.mts.map +1 -1
  59. package/dist/index.mjs +99 -77
  60. package/dist/index.mjs.map +1 -1
  61. package/package.json +10 -10
@@ -1,10 +1,14 @@
1
1
  import { useColors, useTheme } from "../contexts/theme.mjs";
2
2
  import { createComponent, createIntrinsic, memo, mergeProps } from "@alloy-js/core/jsx-runtime";
3
- import { For, Show, code } from "@alloy-js/core";
3
+ import { For, Show, code, computed } from "@alloy-js/core";
4
4
  import { ElseClause, FunctionDeclaration, IfStatement, InterfaceDeclaration, InterfaceMember, TypeDeclaration, VarDeclaration } from "@alloy-js/typescript";
5
+ import { getAppDescription, getAppTitle } from "@shell-shock/core/plugin-utils/context-helpers";
6
+ import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
5
7
  import { TSDoc, TSDocDefaultValue, TSDocExample, TSDocParam, TSDocRemarks, TSDocReturns } from "@powerlines/plugin-alloy/typescript/components/tsdoc";
6
8
  import { ReflectionKind } from "@powerlines/deepkit/vendor/type";
9
+ import { useCommand } from "@shell-shock/core/contexts/command";
7
10
  import { BuiltinFile } from "@powerlines/plugin-alloy/typescript/components/builtin-file";
11
+ import { getIndefiniteArticle } from "@stryke/string-format/vowels";
8
12
 
9
13
  //#region src/components/console-builtin.tsx
10
14
  /**
@@ -103,61 +107,216 @@ function ColorsDeclaration() {
103
107
  createIntrinsic("hbr", {}),
104
108
  code`text: {
105
109
  banner: {
106
- title: ${createComponent(ColorFunction, {
110
+ header: {
111
+ primary: ${createComponent(ColorFunction, {
107
112
  get ansi16() {
108
- return colors.ansi16.theme.text.banner.title;
113
+ return colors.ansi16.theme.text.banner.header.primary;
109
114
  },
110
115
  get ansi256() {
111
- return colors.ansi256.theme.text.banner.title;
116
+ return colors.ansi256.theme.text.banner.header.primary;
112
117
  },
113
118
  get ansi16m() {
114
- return colors.ansi16m.theme.text.banner.title;
119
+ return colors.ansi16m.theme.text.banner.header.primary;
115
120
  }
116
121
  })},
117
- header: ${createComponent(ColorFunction, {
122
+ secondary: ${createComponent(ColorFunction, {
118
123
  get ansi16() {
119
- return colors.ansi16.theme.text.banner.header;
124
+ return colors.ansi16.theme.text.banner.header.secondary;
120
125
  },
121
126
  get ansi256() {
122
- return colors.ansi256.theme.text.banner.header;
127
+ return colors.ansi256.theme.text.banner.header.secondary;
123
128
  },
124
129
  get ansi16m() {
125
- return colors.ansi16m.theme.text.banner.header;
130
+ return colors.ansi16m.theme.text.banner.header.secondary;
126
131
  }
127
132
  })},
128
- footer: ${createComponent(ColorFunction, {
133
+ tertiary: ${createComponent(ColorFunction, {
134
+ get ansi16() {
135
+ return colors.ansi16.theme.text.banner.header.tertiary;
136
+ },
137
+ get ansi256() {
138
+ return colors.ansi256.theme.text.banner.header.tertiary;
139
+ },
140
+ get ansi16m() {
141
+ return colors.ansi16m.theme.text.banner.header.tertiary;
142
+ }
143
+ })}
144
+ },
145
+ footer: {
146
+ primary: ${createComponent(ColorFunction, {
129
147
  get ansi16() {
130
- return colors.ansi16.theme.text.banner.footer;
148
+ return colors.ansi16.theme.text.banner.footer.primary;
131
149
  },
132
150
  get ansi256() {
133
- return colors.ansi256.theme.text.banner.footer;
151
+ return colors.ansi256.theme.text.banner.footer.primary;
134
152
  },
135
153
  get ansi16m() {
136
- return colors.ansi16m.theme.text.banner.footer;
154
+ return colors.ansi16m.theme.text.banner.footer.primary;
137
155
  }
138
156
  })},
139
- command: ${createComponent(ColorFunction, {
157
+ secondary: ${createComponent(ColorFunction, {
140
158
  get ansi16() {
141
- return colors.ansi16.theme.text.banner.command;
159
+ return colors.ansi16.theme.text.banner.footer.secondary;
142
160
  },
143
161
  get ansi256() {
144
- return colors.ansi256.theme.text.banner.command;
162
+ return colors.ansi256.theme.text.banner.footer.secondary;
145
163
  },
146
164
  get ansi16m() {
147
- return colors.ansi16m.theme.text.banner.command;
165
+ return colors.ansi16m.theme.text.banner.footer.secondary;
148
166
  }
149
167
  })},
150
- description: ${createComponent(ColorFunction, {
168
+ tertiary: ${createComponent(ColorFunction, {
151
169
  get ansi16() {
152
- return colors.ansi16.theme.text.banner.description;
170
+ return colors.ansi16.theme.text.banner.footer.tertiary;
153
171
  },
154
172
  get ansi256() {
155
- return colors.ansi256.theme.text.banner.description;
173
+ return colors.ansi256.theme.text.banner.footer.tertiary;
156
174
  },
157
175
  get ansi16m() {
158
- return colors.ansi16m.theme.text.banner.description;
176
+ return colors.ansi16m.theme.text.banner.footer.tertiary;
159
177
  }
160
178
  })}
179
+ },
180
+ command: {
181
+ primary: ${createComponent(ColorFunction, {
182
+ get ansi16() {
183
+ return colors.ansi16.theme.text.banner.command.primary;
184
+ },
185
+ get ansi256() {
186
+ return colors.ansi256.theme.text.banner.command.primary;
187
+ },
188
+ get ansi16m() {
189
+ return colors.ansi16m.theme.text.banner.command.primary;
190
+ }
191
+ })},
192
+ secondary: ${createComponent(ColorFunction, {
193
+ get ansi16() {
194
+ return colors.ansi16.theme.text.banner.command.secondary;
195
+ },
196
+ get ansi256() {
197
+ return colors.ansi256.theme.text.banner.command.secondary;
198
+ },
199
+ get ansi16m() {
200
+ return colors.ansi16m.theme.text.banner.command.secondary;
201
+ }
202
+ })},
203
+ tertiary: ${createComponent(ColorFunction, {
204
+ get ansi16() {
205
+ return colors.ansi16.theme.text.banner.command.tertiary;
206
+ },
207
+ get ansi256() {
208
+ return colors.ansi256.theme.text.banner.command.tertiary;
209
+ },
210
+ get ansi16m() {
211
+ return colors.ansi16m.theme.text.banner.command.tertiary;
212
+ }
213
+ })},
214
+ },
215
+ title: {
216
+ primary: ${createComponent(ColorFunction, {
217
+ get ansi16() {
218
+ return colors.ansi16.theme.text.banner.title.primary;
219
+ },
220
+ get ansi256() {
221
+ return colors.ansi256.theme.text.banner.title.primary;
222
+ },
223
+ get ansi16m() {
224
+ return colors.ansi16m.theme.text.banner.title.primary;
225
+ }
226
+ })},
227
+ secondary: ${createComponent(ColorFunction, {
228
+ get ansi16() {
229
+ return colors.ansi16.theme.text.banner.title.secondary;
230
+ },
231
+ get ansi256() {
232
+ return colors.ansi256.theme.text.banner.title.secondary;
233
+ },
234
+ get ansi16m() {
235
+ return colors.ansi16m.theme.text.banner.title.secondary;
236
+ }
237
+ })},
238
+ tertiary: ${createComponent(ColorFunction, {
239
+ get ansi16() {
240
+ return colors.ansi16.theme.text.banner.title.tertiary;
241
+ },
242
+ get ansi256() {
243
+ return colors.ansi256.theme.text.banner.title.tertiary;
244
+ },
245
+ get ansi16m() {
246
+ return colors.ansi16m.theme.text.banner.title.tertiary;
247
+ }
248
+ })},
249
+ },
250
+ link: {
251
+ primary: ${createComponent(ColorFunction, {
252
+ get ansi16() {
253
+ return colors.ansi16.theme.text.banner.link.primary;
254
+ },
255
+ get ansi256() {
256
+ return colors.ansi256.theme.text.banner.link.primary;
257
+ },
258
+ get ansi16m() {
259
+ return colors.ansi16m.theme.text.banner.link.primary;
260
+ }
261
+ })},
262
+ secondary: ${createComponent(ColorFunction, {
263
+ get ansi16() {
264
+ return colors.ansi16.theme.text.banner.link.secondary;
265
+ },
266
+ get ansi256() {
267
+ return colors.ansi256.theme.text.banner.link.secondary;
268
+ },
269
+ get ansi16m() {
270
+ return colors.ansi16m.theme.text.banner.link.secondary;
271
+ }
272
+ })},
273
+ tertiary: ${createComponent(ColorFunction, {
274
+ get ansi16() {
275
+ return colors.ansi16.theme.text.banner.link.tertiary;
276
+ },
277
+ get ansi256() {
278
+ return colors.ansi256.theme.text.banner.link.tertiary;
279
+ },
280
+ get ansi16m() {
281
+ return colors.ansi16m.theme.text.banner.link.tertiary;
282
+ }
283
+ })},
284
+ },
285
+ description: {
286
+ primary: ${createComponent(ColorFunction, {
287
+ get ansi16() {
288
+ return colors.ansi16.theme.text.banner.description.primary;
289
+ },
290
+ get ansi256() {
291
+ return colors.ansi256.theme.text.banner.description.primary;
292
+ },
293
+ get ansi16m() {
294
+ return colors.ansi16m.theme.text.banner.description.primary;
295
+ }
296
+ })},
297
+ secondary: ${createComponent(ColorFunction, {
298
+ get ansi16() {
299
+ return colors.ansi16.theme.text.banner.description.secondary;
300
+ },
301
+ get ansi256() {
302
+ return colors.ansi256.theme.text.banner.description.secondary;
303
+ },
304
+ get ansi16m() {
305
+ return colors.ansi16m.theme.text.banner.description.secondary;
306
+ }
307
+ })},
308
+ tertiary: ${createComponent(ColorFunction, {
309
+ get ansi16() {
310
+ return colors.ansi16.theme.text.banner.description.tertiary;
311
+ },
312
+ get ansi256() {
313
+ return colors.ansi256.theme.text.banner.description.tertiary;
314
+ },
315
+ get ansi16m() {
316
+ return colors.ansi16m.theme.text.banner.description.tertiary;
317
+ }
318
+ })},
319
+ }
161
320
  },
162
321
  heading: {
163
322
  primary: ${createComponent(ColorFunction, {
@@ -192,7 +351,7 @@ function ColorsDeclaration() {
192
351
  get ansi16m() {
193
352
  return colors.ansi16m.theme.text.heading.tertiary;
194
353
  }
195
- })}
354
+ })},
196
355
  },
197
356
  body: {
198
357
  primary: ${createComponent(ColorFunction, {
@@ -983,7 +1142,7 @@ function WriteLineFunctionDeclaration() {
983
1142
  } else {
984
1143
  const index = [" ", "/", "\\\\", ".", ",", "-", ":", "|", "@", "+"].reduce((ret, split) => {
985
1144
  let current = ret;
986
- while (stripAnsi(line).indexOf(split, current + 1) !== -1 && stripAnsi(line).indexOf(split, current + 1) <= maxLength) {
1145
+ while (stripAnsi(line).indexOf(split, current + 1) !== -1 && stripAnsi(line).indexOf(split, current + 1) <= maxLength && (!/.*\\([^)]*$/.test(stripAnsi(line).slice(0, line.indexOf(split, current + 1))) || !/^[^(]*\\).*/.test(stripAnsi(line).slice(line.indexOf(split, current + 1) + 1)) || stripAnsi(line).slice(line.indexOf(split, current + 1) + 1).replace(/^.*\\)/, "").indexOf(split) !== -1)) {
987
1146
  current = line.indexOf(split, current + 1);
988
1147
  }
989
1148
 
@@ -1114,17 +1273,11 @@ consoleFn(\`\${" ".repeat(Math.max(options.padding ?? ${theme.padding.app}, 0))}
1114
1273
  * A component to generate the message functions in the `shell-shock:console` builtin module.
1115
1274
  */
1116
1275
  function MessageFunctionDeclaration(props) {
1117
- const { type, variant, consoleFnName, description, prefix, parameters } = props;
1276
+ const { type, variant, consoleFnName, description, prefix, parameters, timestamp } = props;
1118
1277
  const theme = useTheme();
1119
1278
  return [createComponent(TSDoc, {
1120
1279
  get heading() {
1121
- return `Write ${[
1122
- "a",
1123
- "e",
1124
- "i",
1125
- "o",
1126
- "u"
1127
- ].includes(description.charAt(0)) ? "an" : "a"} ${description} message to the console.`;
1280
+ return `Write ${getIndefiniteArticle(description)} ${description} message to the console.`;
1128
1281
  },
1129
1282
  get children() {
1130
1283
  return [
@@ -1161,19 +1314,69 @@ function MessageFunctionDeclaration(props) {
1161
1314
  return;
1162
1315
  }
1163
1316
 
1164
- writeLine(colors.border.message.outline.${variant}("${theme.borderStyles.message.outline[variant].topLeft}") + colors.border.message.outline.${variant}("${theme.borderStyles.message.outline[variant].top}".repeat(Math.max(process.stdout.columns - ${(Math.max(theme.padding.app, 0) + Math.max(theme.padding.message, 0)) * 2 + theme.borderStyles.message.outline[variant].topLeft.length + theme.borderStyles.message.outline[variant].topRight.length}, 0) / ${theme.borderStyles.message.outline[variant].top.length ?? 1})) + colors.border.message.outline.${variant}("${theme.borderStyles.message.outline[variant].topRight}"), { consoleFn: console.${consoleFnName} });
1317
+ ${!theme.labels.message.footer[variant] && timestamp ? `const timestamp = \`\${colors.text.message.footer.${variant}(new Date().toLocaleDateString())} \${colors.border.message.outline.${variant}("${theme.borderStyles.message.outline[variant].bottom}")} \${colors.text.message.footer.${variant}(new Date().toLocaleTimeString())}\`; ` : ""}
1318
+ writeLine(colors.border.message.outline.${variant}("${theme.borderStyles.message.outline[variant].topLeft}") + ${theme.labels.message.header[variant] || theme.icons.message.header[variant] ? `colors.border.message.outline.${variant}("${theme.borderStyles.message.outline[variant].top}".repeat(4)) + " " + ${theme.icons.message.header[variant] ? `colors.border.message.outline.${variant}("${theme.icons.message.header[variant]}") + " " +` : ""} colors.text.message.header.${variant}("${theme.labels.message.header[variant]}") + " " + colors.border.message.outline.${variant}("${theme.borderStyles.message.outline[variant].top}".repeat(Math.max(process.stdout.columns - ${Math.max(theme.padding.app, 0) * 2 + 4 + (theme.icons.message.header[variant] ? theme.icons.message.header[variant].length + 1 + (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].topLeft.length + theme.borderStyles.message.outline[variant].topRight.length}, 0)))` : `colors.border.message.outline.${variant}("${theme.borderStyles.message.outline[variant].top}".repeat(Math.max(process.stdout.columns - ${Math.max(theme.padding.app, 0) * 2 + theme.borderStyles.message.outline[variant].topLeft.length + theme.borderStyles.message.outline[variant].topRight.length}, 0)))`} + colors.border.message.outline.${variant}("${theme.borderStyles.message.outline[variant].topRight}"), { consoleFn: console.${consoleFnName} });
1165
1319
  splitText(
1166
1320
  message,
1167
1321
  Math.max(process.stdout.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}, 0)
1168
1322
  ).forEach((line) => {
1169
- writeLine(colors.border.message.outline.${variant}("${theme.borderStyles.message.outline[variant].left + " ".repeat(Math.max(theme.padding.message, 0))}") + line + colors.border.message.outline.${variant}("${" ".repeat(Math.max(theme.padding.message, 0)) + theme.borderStyles.message.outline[variant].right}"), { consoleFn: console.${consoleFnName} });
1323
+ writeLine(colors.border.message.outline.${variant}("${theme.borderStyles.message.outline[variant].left + " ".repeat(Math.max(theme.padding.message, 0))}") + colors.text.message.description.${variant}(line) + " ".repeat(Math.max(process.stdout.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)) + colors.border.message.outline.${variant}("${theme.borderStyles.message.outline[variant].right}"), { consoleFn: console.${consoleFnName} });
1170
1324
  });
1171
- writeLine(colors.border.message.outline.${variant}("${theme.borderStyles.message.outline[variant].bottomLeft}") + colors.border.message.outline.${variant}("${theme.borderStyles.message.outline[variant].bottom}".repeat(Math.max(process.stdout.columns - ${(Math.max(theme.padding.app, 0) + Math.max(theme.padding.message, 0)) * 2 + theme.borderStyles.message.outline[variant].bottomLeft.length + theme.borderStyles.message.outline[variant].bottomRight.length}, 0) / ${theme.borderStyles.message.outline[variant].bottom.length ?? 1})) + colors.border.message.outline.${variant}("${theme.borderStyles.message.outline[variant].bottomRight}"), { consoleFn: console.${consoleFnName} });
1325
+ writeLine(colors.border.message.outline.${variant}("${theme.borderStyles.message.outline[variant].bottomLeft}") + ${theme.labels.message.footer[variant] || timestamp ? `colors.border.message.outline.${variant}("${theme.borderStyles.message.outline[variant].bottom}".repeat(Math.max(process.stdout.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))) + " " + ${theme.labels.message.footer[variant] ? `colors.text.message.footer.${variant}("${theme.labels.message.footer[variant]}")` : timestamp && "timestamp"} + " " + colors.border.message.outline.${variant}("${theme.borderStyles.message.outline[variant].bottom}".repeat(4))` : `colors.border.message.outline.${variant}("${theme.borderStyles.message.outline[variant].bottom}".repeat(Math.max(process.stdout.columns - ${Math.max(theme.padding.app, 0) * 2 + theme.borderStyles.message.outline[variant].bottomLeft.length + theme.borderStyles.message.outline[variant].bottomRight.length}, 0)))`} + colors.border.message.outline.${variant}("${theme.borderStyles.message.outline[variant].bottomRight}"), { consoleFn: console.${consoleFnName} });
1172
1326
  `)];
1173
1327
  }
1174
1328
  })];
1175
1329
  }
1176
1330
  /**
1331
+ * A component to generate the `banner` function in the `shell-shock:console` builtin module.
1332
+ */
1333
+ function BannerFunctionDeclaration(props) {
1334
+ const { consoleFnName = "log", variant = "primary", title: titleProp } = props;
1335
+ const theme = useTheme();
1336
+ const context = usePowerlines();
1337
+ const command = useCommand();
1338
+ const header = computed(() => `${theme.labels.banner.header[variant] || getAppTitle(context)} v${context.packageJson.version || "1.0.0"}`);
1339
+ const description = computed(() => command?.description || getAppDescription(context));
1340
+ const footer = computed(() => theme.labels.banner.footer[variant]);
1341
+ const title = computed(() => titleProp || /(?:cli|command-line|command line)\s+(?:application|app)?$/.test(header.value.toLowerCase()) ? header.value.replace(`v${context.packageJson.version || "1.0.0"}`, "").trim() : `${header.value.replace(`v${context.packageJson.version || "1.0.0"}`, "").trim()} Command-Line Application`);
1342
+ const bannerPadding = computed(() => Math.max(theme.padding.app, 0) * 2 + theme.borderStyles.banner.outline[variant].left.length + theme.borderStyles.banner.outline[variant].right.length);
1343
+ const totalPadding = computed(() => Math.max(theme.padding.banner, 0) * 2 + bannerPadding.value);
1344
+ return [createComponent(FunctionDeclaration, {
1345
+ "export": true,
1346
+ name: "banner",
1347
+ doc: "Write the application banner to the console.",
1348
+ get children() {
1349
+ return code`
1350
+ if (hasFlag("no-banner") || hasFlag("hide-banner") || isCI || isMinimal) {
1351
+ return;
1352
+ }
1353
+
1354
+ writeLine(colors.border.banner.outline.${variant}("${theme.borderStyles.banner.outline[variant].topLeft}") + ${theme.icons.banner.header[variant] ? `colors.border.banner.outline.${variant}("${theme.borderStyles.banner.outline[variant].top}".repeat(4)) + " " + ${theme.icons.banner.header[variant] ? `colors.border.banner.outline.${variant}("${theme.icons.banner.header[variant]}") + " " + colors.text.banner.header.${variant}("${theme.borderStyles.banner.outline[variant].top}") + " " +` : ""} colors.text.banner.header.${variant}("${header.value}") + " " + colors.border.banner.outline.${variant}("${theme.borderStyles.banner.outline[variant].top}".repeat(Math.max(process.stdout.columns - ${4 + (theme.icons.banner.header[variant] ? theme.icons.banner.header[variant].length + 3 : 0) + (header.value ? header.value.length + 2 : 0) + bannerPadding.value}, 0)))` : `colors.border.banner.outline.${variant}("${theme.borderStyles.banner.outline[variant].top}".repeat(Math.max(process.stdout.columns - ${bannerPadding.value}, 0)))`} + colors.border.banner.outline.${variant}("${theme.borderStyles.banner.outline[variant].topRight}"), { consoleFn: console.${consoleFnName} });
1355
+
1356
+ splitText(
1357
+ colors.text.banner.title.${variant}("${title.value}"),
1358
+ Math.max(process.stdout.columns - ${totalPadding.value}, 0)
1359
+ ).forEach((line) => {
1360
+ writeLine(colors.border.banner.outline.${variant}("${theme.borderStyles.banner.outline[variant].left}") + " ".repeat(Math.max(Math.floor((process.stdout.columns - (stripAnsi(line).length + ${bannerPadding.value})) / 2), 0)) + colors.text.banner.description.${variant}(line) + " ".repeat(Math.max(Math.ceil((process.stdout.columns - (stripAnsi(line).length + ${bannerPadding.value})) / 2), 0)) + colors.border.banner.outline.${variant}("${theme.borderStyles.banner.outline[variant].right}"), { consoleFn: console.${consoleFnName} });
1361
+ });
1362
+
1363
+ ${command?.title ? `writeLine(colors.border.banner.outline.${variant}("${theme.borderStyles.banner.outline[variant].bottomLeft}") + " ".repeat(Math.max(process.stdout.columns - ${bannerPadding.value})) + colors.border.banner.outline.${variant}("${theme.borderStyles.banner.outline[variant].bottomRight}"), { consoleFn: console.${consoleFnName} });
1364
+
1365
+ writeLine(colors.border.banner.outline.${variant}("${theme.borderStyles.banner.outline[variant].left}") + " ".repeat(Math.max(Math.floor((process.stdout.columns - (stripAnsi(line).length + ${bannerPadding.value})) / 2), 0)) + colors.text.banner.command.${variant}("${command.title}") + " ".repeat(Math.max(Math.ceil((process.stdout.columns - (stripAnsi(line).length + ${bannerPadding.value})) / 2), 0)) + colors.border.banner.outline.${variant}("${theme.borderStyles.banner.outline[variant].right}"), { consoleFn: console.${consoleFnName} }); ` : ""}
1366
+
1367
+ splitText(
1368
+ ${command?.title ? "colors.text.banner.description" : "colors.text.banner.command"}.${variant}("${description.value.replace(/"/g, "\\\"")}"),
1369
+ Math.max(process.stdout.columns - ${totalPadding.value}, 0)
1370
+ ).forEach((line) => {
1371
+ writeLine(colors.border.banner.outline.${variant}("${theme.borderStyles.banner.outline[variant].left}") + " ".repeat(Math.max(Math.floor((process.stdout.columns - (stripAnsi(line).length + ${bannerPadding.value})) / 2), 0)) + colors.text.banner.description.${variant}(line) + " ".repeat(Math.max(Math.ceil((process.stdout.columns - (stripAnsi(line).length + ${bannerPadding.value})) / 2), 0)) + colors.border.banner.outline.${variant}("${theme.borderStyles.banner.outline[variant].right}"), { consoleFn: console.${consoleFnName} });
1372
+ });
1373
+
1374
+ writeLine(colors.border.banner.outline.${variant}("${theme.borderStyles.banner.outline[variant].bottomLeft}") + ${footer.value ? `colors.border.banner.outline.${variant}("${theme.borderStyles.banner.outline[variant].bottom}".repeat(Math.max(process.stdout.columns - ${4 + (footer.value ? footer.value.length : 0) + bannerPadding.value}, 0))) + " " + ${footer.value ? `colors.text.banner.footer.${variant}("${footer.value}")` : ""} + " " + colors.border.banner.outline.${variant}("${theme.borderStyles.banner.outline[variant].bottom}".repeat(4))` : `colors.border.banner.outline.${variant}("${theme.borderStyles.banner.outline[variant].bottom}".repeat(Math.max(process.stdout.columns - ${bannerPadding.value}, 0)))`} + colors.border.banner.outline.${variant}("${theme.borderStyles.banner.outline[variant].bottomRight}"), { consoleFn: console.${consoleFnName} });
1375
+ `;
1376
+ }
1377
+ })];
1378
+ }
1379
+ /**
1177
1380
  * A component to generate the `wrapAnsi` function in the `shell-shock:console` builtin module.
1178
1381
  */
1179
1382
  function WrapAnsiFunction() {
@@ -1361,11 +1564,11 @@ function DividerFunctionDeclaration() {
1361
1564
  optional: false
1362
1565
  }],
1363
1566
  get children() {
1364
- return code`const padding = options.padding ?? ${theme.padding.app * 4};
1567
+ return code`const padding = options.padding ?? ${Math.max(theme.padding.app, 1) * 4};
1365
1568
  const width = options.width ?? (process.stdout.columns - (Math.max(padding, 0) * 2));
1366
1569
  const border = options.border === "tertiary" ? colors.border.app.divider.tertiary("${theme.borderStyles.app.divider.tertiary.top}") : options.border === "secondary" ? colors.border.app.divider.secondary("${theme.borderStyles.app.divider.secondary.top}") : colors.border.app.divider.primary("${theme.borderStyles.app.divider.primary.top}");
1367
1570
 
1368
- writeLine(" ".repeat(padding) + border.repeat(Math.max(width / ${theme.borderStyles.app.divider.primary.top.length ?? 1}, 0)));
1571
+ writeLine(" ".repeat(Math.max(padding - ${theme.padding.app}, 0)) + border.repeat(Math.max(width / ${theme.borderStyles.app.divider.primary.top.length ?? 1}, 0)));
1369
1572
  `;
1370
1573
  }
1371
1574
  })
@@ -1824,14 +2027,17 @@ let colWidths = [] as number[];
1824
2027
  let rowDims = [] as Dimensions[];
1825
2028
 
1826
2029
  const calculateRowDimensions = () => {
2030
+ colWidths = [];
1827
2031
  return cells.reduce((dims, row) => {
1828
- dims.push(row.reduce((dim, cell) => {
1829
- if (cell.width > dim.width) {
1830
- dim.width = cell.width;
1831
- }
2032
+ dims.push(row.reduce((dim, cell, index) => {
2033
+ dim.width += cell.width;
1832
2034
  if (cell.height > dim.height) {
1833
2035
  dim.height = cell.height;
1834
2036
  }
2037
+ if (!colWidths[index] || cell.width > colWidths[index]!) {
2038
+ colWidths[index] = cell.width;
2039
+ }
2040
+
1835
2041
  return dim;
1836
2042
  }, { width: 0, height: 0 } as Dimensions));
1837
2043
 
@@ -1839,14 +2045,13 @@ const calculateRowDimensions = () => {
1839
2045
  }, [] as Dimensions[]);
1840
2046
  }
1841
2047
 
1842
- rowDims = calculateRowDimensions();
1843
-
1844
- /*
1845
2048
  let recalculate!: boolean;
1846
2049
  do {
1847
2050
  recalculate = false;
1848
- rowDims.map((row, rowIndex) => {
1849
- if (row.width > Math.max(process.stdout.columns - ${Math.max(theme.padding.app, 0) * 2}, 0)) {
2051
+ rowDims = calculateRowDimensions();
2052
+
2053
+ rowDims.forEach((row, rowIndex) => {
2054
+ if (!recalculate && row.width > Math.max(process.stdout.columns - ${Math.max(theme.padding.app, 0) * 2}, 0)) {
1850
2055
  const cell = cells[rowIndex]!.reduce((largestCell, cell) => {
1851
2056
  if (cell.width > largestCell.width) {
1852
2057
  return cell;
@@ -1856,7 +2061,7 @@ do {
1856
2061
 
1857
2062
  const lines = splitText(
1858
2063
  cell.value,
1859
- Math.max(process.stdout.columns - ${Math.max(theme.padding.app, 0) * 2}, 0) - row.width - cell.width
2064
+ Math.max(process.stdout.columns - ${Math.max(theme.padding.app, 0) * 2} - (row.width - (cell.width - cell.padding * 2)), 0)
1860
2065
  );
1861
2066
 
1862
2067
  cell.value = lines.join("\\n");
@@ -1867,50 +2072,68 @@ do {
1867
2072
  }
1868
2073
  });
1869
2074
 
1870
- if (recalculate) {
1871
- rowDims = calculateRowDimensions();
2075
+ if (!recalculate && colWidths.reduce((a, b) => a + b, 0) > Math.max(process.stdout.columns - ${Math.max(theme.padding.app, 0) * 2}, 0)) {
2076
+ let colIndex = 0;
2077
+ const cell = cells.reduce((ret, row) => {
2078
+ return row.reduce((largest, current, i) => {
2079
+ if (largest.width < current.width) {
2080
+ colIndex = i;
2081
+ return current;
2082
+ }
2083
+ return largest;
2084
+ }, ret);
2085
+ }, cells[0]![0]!);
2086
+
2087
+ const lines = splitText(
2088
+ cell.value,
2089
+ Math.max(process.stdout.columns - ${Math.max(theme.padding.app, 0) * 2} - (colWidths.filter((_, i) => i !== colIndex).reduce((a, b) => a + b, 0)) - cell.padding * 2, 0)
2090
+ );
2091
+
2092
+ cell.value = lines.join("\\n");
2093
+ cell.height = lines.length;
2094
+ cell.width = Math.max(...lines.map(line => stripAnsi(line).length)) + cell.padding * 2;
2095
+
2096
+ recalculate = true;
1872
2097
  }
1873
2098
  } while (recalculate);
1874
- */
1875
-
1876
- rowDims.map((row, rowIndex) => {
1877
- cells[rowIndex]!.forEach(cell => {
1878
- cell.height = row.height;
1879
- });
1880
- });
1881
2099
 
1882
2100
  // Render table
1883
- cells.forEach(row => {
1884
- let line = "";
2101
+ cells.forEach((row, rowIndex) => {
2102
+ const outputs = [] as string[][];
1885
2103
  row.forEach((cell, colIndex) => {
1886
- const cellContent = cell.value;
1887
- let paddedContent = "";
1888
- const totalPadding = cell.padding * 2;
1889
- const contentLength = stripAnsi(cellContent).length;
1890
- const totalWidth = colWidths[colIndex] ?? contentLength + totalPadding;
1891
-
1892
- switch (cell.align) {
1893
- case "right":
1894
- paddedContent = " ".repeat(totalWidth - contentLength - totalPadding) + cellContent + " ".repeat(totalPadding);
1895
- break;
1896
- case "center":
1897
- const leftPadding = Math.floor((totalWidth - contentLength - totalPadding) / 2);
1898
- const rightPadding = totalWidth - contentLength - totalPadding - leftPadding;
1899
- paddedContent = " ".repeat(leftPadding) + cellContent + " ".repeat(rightPadding + totalPadding);
1900
- break;
1901
- case "left":
1902
- default:
1903
- paddedContent = " ".repeat(totalPadding) + cellContent + " ".repeat(totalWidth - contentLength - totalPadding);
1904
- break;
2104
+ const lines = cell.value.split("\\n");
2105
+ while (lines.length < rowDims[rowIndex]!.height) {
2106
+ lines.push("");
1905
2107
  }
1906
2108
 
1907
- line += cell.border.left + paddedContent;
1908
- if (colIndex === row.length - 1) {
1909
- line += paddedContent + cell.border.right;
1910
- }
2109
+ outputs.push(lines.map(line => {
2110
+ let paddedContent = "";
2111
+ switch (cell.align) {
2112
+ case "right":
2113
+ paddedContent = " ".repeat(Math.max(colWidths[colIndex] - stripAnsi(line).length - cell.padding, 0)) + line + " ".repeat(cell.padding);
2114
+ break;
2115
+ case "center":
2116
+ const leftPadding = Math.floor((colWidths[colIndex] - stripAnsi(line).length - cell.padding) / 2);
2117
+ const rightPadding = colWidths[colIndex] - stripAnsi(line).length - leftPadding;
2118
+ paddedContent = " ".repeat(leftPadding) + line + " ".repeat(rightPadding);
2119
+ break;
2120
+ case "left":
2121
+ default:
2122
+ paddedContent = " ".repeat(cell.padding) + line + " ".repeat(Math.max(colWidths[colIndex] - stripAnsi(line).length - cell.padding, 0));
2123
+ break;
2124
+ }
2125
+
2126
+ if (colIndex === row.length - 1) {
2127
+ return cell.border.left + paddedContent + cell.border.right;
2128
+ } else {
2129
+ return cell.border.left + paddedContent;
2130
+ }
2131
+ }));
1911
2132
  });
1912
2133
 
1913
- writeLine(line);
2134
+ for (let index = 0; index < rowDims[rowIndex]!.height; index++) {
2135
+ writeLine(outputs.map(output => output[index] ?? "").join(""));
2136
+ }
1914
2137
  });
1915
2138
  `)
1916
2139
  ];
@@ -1932,6 +2155,7 @@ function ConsoleBuiltin() {
1932
2155
  builtinImports: {
1933
2156
  utils: [
1934
2157
  "hasFlag",
2158
+ "isMinimal",
1935
2159
  "isColorSupported",
1936
2160
  "colorSupportLevels",
1937
2161
  "isHyperlinkSupported"
@@ -1939,7 +2163,8 @@ function ConsoleBuiltin() {
1939
2163
  env: [
1940
2164
  "env",
1941
2165
  "isDevelopment",
1942
- "isDebug"
2166
+ "isDebug",
2167
+ "isCI"
1943
2168
  ]
1944
2169
  },
1945
2170
  get children() {
@@ -1962,6 +2187,9 @@ function ConsoleBuiltin() {
1962
2187
  createComponent(DividerFunctionDeclaration, {}),
1963
2188
  createIntrinsic("hbr", {}),
1964
2189
  createIntrinsic("hbr", {}),
2190
+ createComponent(BannerFunctionDeclaration, {}),
2191
+ createIntrinsic("hbr", {}),
2192
+ createIntrinsic("hbr", {}),
1965
2193
  createComponent(MessageFunctionDeclaration, {
1966
2194
  type: "help",
1967
2195
  variant: "help",
@@ -1991,6 +2219,7 @@ function ConsoleBuiltin() {
1991
2219
  variant: "debug",
1992
2220
  consoleFnName: "debug",
1993
2221
  description: "debug",
2222
+ timestamp: true,
1994
2223
  get prefix() {
1995
2224
  return createComponent(IfStatement, {
1996
2225
  condition: code`!isDevelopment && !isDebug && env.LOG_LEVEL !== "debug"`,
@@ -2005,9 +2234,10 @@ function ConsoleBuiltin() {
2005
2234
  variant: "debug",
2006
2235
  consoleFnName: "debug",
2007
2236
  description: "verbose",
2237
+ timestamp: true,
2008
2238
  get prefix() {
2009
2239
  return createComponent(IfStatement, {
2010
- condition: code`!(isDevelopment || isDebug || env.LOG_LEVEL === "debug" || hasFlag(["verbose", "verbose=true", "verbose=always", "debug", "debug=true", "debug=always"]))`,
2240
+ condition: code`!(isDevelopment || isDebug || env.LOG_LEVEL === "debug" || hasFlag(["verbose", "verbose=true", "verbose=always"]))`,
2011
2241
  children: code`return; `
2012
2242
  });
2013
2243
  }
@@ -2035,6 +2265,7 @@ function ConsoleBuiltin() {
2035
2265
  variant: "error",
2036
2266
  consoleFnName: "error",
2037
2267
  description: "error",
2268
+ timestamp: true,
2038
2269
  parameters: [{
2039
2270
  name: "err",
2040
2271
  type: "string | Error",
@@ -2073,5 +2304,5 @@ function ConsoleBuiltin() {
2073
2304
  }
2074
2305
 
2075
2306
  //#endregion
2076
- export { ColorsDeclaration, ConsoleBuiltin, DividerFunctionDeclaration, LinkFunctionDeclaration, MessageFunctionDeclaration, StripAnsiFunctionDeclaration, TableFunctionDeclaration, WrapAnsiFunction, WriteLineFunctionDeclaration };
2307
+ export { BannerFunctionDeclaration, ColorsDeclaration, ConsoleBuiltin, DividerFunctionDeclaration, LinkFunctionDeclaration, MessageFunctionDeclaration, StripAnsiFunctionDeclaration, TableFunctionDeclaration, WrapAnsiFunction, WriteLineFunctionDeclaration };
2077
2308
  //# sourceMappingURL=console-builtin.mjs.map