@shell-shock/preset-script 0.1.1 → 0.2.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 (134) hide show
  1. package/README.md +1 -1
  2. package/dist/components/args-parser-logic.cjs +678 -0
  3. package/dist/components/args-parser-logic.cjs.map +1 -0
  4. package/dist/components/args-parser-logic.d.cts +45 -0
  5. package/dist/components/args-parser-logic.d.cts.map +1 -0
  6. package/dist/components/args-parser-logic.d.mts +45 -0
  7. package/dist/components/args-parser-logic.d.mts.map +1 -0
  8. package/dist/components/args-parser-logic.mjs +672 -0
  9. package/dist/components/args-parser-logic.mjs.map +1 -0
  10. package/dist/components/bin-entry.cjs +188 -0
  11. package/dist/components/bin-entry.cjs.map +1 -0
  12. package/dist/components/{entry/bin.d.cts → bin-entry.d.cts} +9 -3
  13. package/dist/components/bin-entry.d.cts.map +1 -0
  14. package/dist/components/{entry/bin.d.mts → bin-entry.d.mts} +9 -3
  15. package/dist/components/bin-entry.d.mts.map +1 -0
  16. package/dist/components/bin-entry.mjs +185 -0
  17. package/dist/components/bin-entry.mjs.map +1 -0
  18. package/dist/components/command-entry.cjs +162 -0
  19. package/dist/components/command-entry.cjs.map +1 -0
  20. package/dist/components/command-entry.d.cts +24 -0
  21. package/dist/components/command-entry.d.cts.map +1 -0
  22. package/dist/components/command-entry.d.mts +24 -0
  23. package/dist/components/command-entry.d.mts.map +1 -0
  24. package/dist/components/command-entry.mjs +158 -0
  25. package/dist/components/command-entry.mjs.map +1 -0
  26. package/dist/components/command-router.cjs +129 -74
  27. package/dist/components/command-router.cjs.map +1 -1
  28. package/dist/components/command-router.d.cts +13 -4
  29. package/dist/components/command-router.d.cts.map +1 -0
  30. package/dist/components/command-router.d.mts +13 -4
  31. package/dist/components/command-router.d.mts.map +1 -0
  32. package/dist/components/command-router.mjs +128 -73
  33. package/dist/components/command-router.mjs.map +1 -1
  34. package/dist/components/console-builtin.cjs +2086 -0
  35. package/dist/components/console-builtin.cjs.map +1 -0
  36. package/dist/components/console-builtin.d.cts +56 -0
  37. package/dist/components/console-builtin.d.cts.map +1 -0
  38. package/dist/components/console-builtin.d.mts +56 -0
  39. package/dist/components/console-builtin.d.mts.map +1 -0
  40. package/dist/components/console-builtin.mjs +2077 -0
  41. package/dist/components/console-builtin.mjs.map +1 -0
  42. package/dist/components/help.cjs +130 -0
  43. package/dist/components/help.cjs.map +1 -0
  44. package/dist/components/help.d.cts +57 -0
  45. package/dist/components/help.d.cts.map +1 -0
  46. package/dist/components/help.d.mts +57 -0
  47. package/dist/components/help.d.mts.map +1 -0
  48. package/dist/components/help.mjs +126 -0
  49. package/dist/components/help.mjs.map +1 -0
  50. package/dist/components/index.cjs +39 -15
  51. package/dist/components/index.d.cts +9 -7
  52. package/dist/components/index.d.mts +9 -7
  53. package/dist/components/index.mjs +8 -6
  54. package/dist/components/utils-builtin.cjs +612 -0
  55. package/dist/components/utils-builtin.cjs.map +1 -0
  56. package/dist/components/utils-builtin.d.cts +32 -0
  57. package/dist/components/utils-builtin.d.cts.map +1 -0
  58. package/dist/components/utils-builtin.d.mts +32 -0
  59. package/dist/components/utils-builtin.d.mts.map +1 -0
  60. package/dist/components/utils-builtin.mjs +605 -0
  61. package/dist/components/utils-builtin.mjs.map +1 -0
  62. package/dist/components/virtual-command-entry.cjs +140 -0
  63. package/dist/components/virtual-command-entry.cjs.map +1 -0
  64. package/dist/components/virtual-command-entry.d.cts +21 -0
  65. package/dist/components/virtual-command-entry.d.cts.map +1 -0
  66. package/dist/components/virtual-command-entry.d.mts +21 -0
  67. package/dist/components/virtual-command-entry.d.mts.map +1 -0
  68. package/dist/components/virtual-command-entry.mjs +137 -0
  69. package/dist/components/virtual-command-entry.mjs.map +1 -0
  70. package/dist/contexts/index.cjs +4 -0
  71. package/dist/contexts/index.d.cts +2 -0
  72. package/dist/contexts/index.d.mts +2 -0
  73. package/dist/contexts/index.mjs +3 -0
  74. package/dist/contexts/theme.d.cts +20 -0
  75. package/dist/contexts/theme.d.cts.map +1 -0
  76. package/dist/contexts/theme.d.mts +20 -0
  77. package/dist/contexts/theme.d.mts.map +1 -0
  78. package/dist/helpers/ansi-utils.cjs +28 -4
  79. package/dist/helpers/ansi-utils.cjs.map +1 -1
  80. package/dist/helpers/ansi-utils.d.cts +68 -0
  81. package/dist/helpers/ansi-utils.d.cts.map +1 -0
  82. package/dist/helpers/ansi-utils.d.mts +68 -0
  83. package/dist/helpers/ansi-utils.d.mts.map +1 -0
  84. package/dist/helpers/ansi-utils.mjs +28 -4
  85. package/dist/helpers/ansi-utils.mjs.map +1 -1
  86. package/dist/helpers/get-default-options.cjs +6 -13
  87. package/dist/helpers/get-default-options.cjs.map +1 -1
  88. package/dist/helpers/get-default-options.mjs +6 -13
  89. package/dist/helpers/get-default-options.mjs.map +1 -1
  90. package/dist/index.cjs +117 -29
  91. package/dist/index.cjs.map +1 -1
  92. package/dist/index.d.cts.map +1 -0
  93. package/dist/index.d.mts.map +1 -0
  94. package/dist/index.mjs +118 -28
  95. package/dist/index.mjs.map +1 -1
  96. package/dist/types/plugin.d.cts +1 -6
  97. package/dist/types/plugin.d.cts.map +1 -0
  98. package/dist/types/plugin.d.mts +1 -6
  99. package/dist/types/plugin.d.mts.map +1 -0
  100. package/package.json +163 -71
  101. package/dist/components/builtin/console.cjs +0 -1232
  102. package/dist/components/builtin/console.cjs.map +0 -1
  103. package/dist/components/builtin/console.d.cts +0 -37
  104. package/dist/components/builtin/console.d.mts +0 -37
  105. package/dist/components/builtin/console.mjs +0 -1225
  106. package/dist/components/builtin/console.mjs.map +0 -1
  107. package/dist/components/builtin/index.cjs +0 -9
  108. package/dist/components/builtin/index.d.cts +0 -2
  109. package/dist/components/builtin/index.d.mts +0 -2
  110. package/dist/components/builtin/index.mjs +0 -3
  111. package/dist/components/entry/bin.cjs +0 -92
  112. package/dist/components/entry/bin.cjs.map +0 -1
  113. package/dist/components/entry/bin.mjs +0 -91
  114. package/dist/components/entry/bin.mjs.map +0 -1
  115. package/dist/components/entry/command.cjs +0 -54
  116. package/dist/components/entry/command.cjs.map +0 -1
  117. package/dist/components/entry/command.d.cts +0 -15
  118. package/dist/components/entry/command.d.mts +0 -15
  119. package/dist/components/entry/command.mjs +0 -53
  120. package/dist/components/entry/command.mjs.map +0 -1
  121. package/dist/components/entry/index.cjs +0 -3
  122. package/dist/components/entry/index.d.cts +0 -2
  123. package/dist/components/entry/index.d.mts +0 -2
  124. package/dist/components/entry/index.mjs +0 -3
  125. package/dist/components/shutdown.cjs +0 -93
  126. package/dist/components/shutdown.cjs.map +0 -1
  127. package/dist/components/shutdown.d.cts +0 -14
  128. package/dist/components/shutdown.d.mts +0 -14
  129. package/dist/components/shutdown.mjs +0 -91
  130. package/dist/components/shutdown.mjs.map +0 -1
  131. package/dist/contexts/command.cjs +0 -21
  132. package/dist/contexts/command.cjs.map +0 -1
  133. package/dist/contexts/command.mjs +0 -19
  134. package/dist/contexts/command.mjs.map +0 -1
@@ -0,0 +1,612 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ let __alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
3
+ let __alloy_js_core = require("@alloy-js/core");
4
+ let __alloy_js_typescript = require("@alloy-js/typescript");
5
+ let __shell_shock_core_plugin_utils_context_helpers = require("@shell-shock/core/plugin-utils/context-helpers");
6
+ let __powerlines_plugin_alloy_core_contexts_context = require("@powerlines/plugin-alloy/core/contexts/context");
7
+ let __powerlines_plugin_alloy_typescript_components_tsdoc = require("@powerlines/plugin-alloy/typescript/components/tsdoc");
8
+ let defu = require("defu");
9
+ defu = require_rolldown_runtime.__toESM(defu);
10
+ let __powerlines_plugin_alloy_typescript_components_builtin_file = require("@powerlines/plugin-alloy/typescript/components/builtin-file");
11
+
12
+ //#region src/components/utils-builtin.tsx
13
+ /**
14
+ * Generates utilities for detecting terminal color support.
15
+ */
16
+ function EnvSupportUtilities() {
17
+ return [
18
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
19
+ "export": true,
20
+ "const": true,
21
+ name: "isTTY",
22
+ doc: "Detect if stdout.TTY is available",
23
+ initializer: __alloy_js_core.code`Boolean(process.stdout && process.stdout.isTTY);`
24
+ }),
25
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
26
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
27
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
28
+ "export": true,
29
+ "const": true,
30
+ name: "isMinimal",
31
+ doc: "Detect if the current environment is minimal (CI, non-TTY, etc.)",
32
+ initializer: __alloy_js_core.code` env.MINIMAL || isCI || isTest || !isTTY; `
33
+ }),
34
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
35
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
36
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
37
+ "export": true,
38
+ "const": true,
39
+ name: "isInteractive",
40
+ doc: "Detect if the current environment is interactive",
41
+ initializer: __alloy_js_core.code` !isMinimal && process.stdin?.isTTY && env.TERM !== "dumb"; `
42
+ })
43
+ ];
44
+ }
45
+ /**
46
+ * Generates utilities for detecting terminal color support.
47
+ */
48
+ function ColorSupportUtilities() {
49
+ return [
50
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceDeclaration, {
51
+ "export": true,
52
+ name: "GetColorSupportLevelOptions",
53
+ doc: "Options for the getColorSupportLevel function",
54
+ get children() {
55
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceMember, {
56
+ name: "ignoreFlags",
57
+ type: "boolean",
58
+ doc: "Indicates if the function should skip checking command-line flags for color support"
59
+ });
60
+ }
61
+ }),
62
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
63
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
64
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
65
+ heading: "Checks if a specific flag is present in the command line arguments.",
66
+ get children() {
67
+ return [
68
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocLink, { children: "https://github.com/sindresorhus/has-flag/blob/main/index.js" }),
69
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
70
+ name: "flag",
71
+ children: "The flag to check for, e.g., \"color\", \"no-color\"."
72
+ }),
73
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
74
+ name: "argv",
75
+ children: "The command line arguments to check against. Defaults to global Deno args or process args."
76
+ }),
77
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: "True if the flag is present, false otherwise." })
78
+ ];
79
+ }
80
+ }),
81
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
82
+ "export": true,
83
+ name: "getColorSupportLevel",
84
+ parameters: [{
85
+ name: "stream",
86
+ type: "NodeJS.WriteStream & { fd: 1 | 2; }"
87
+ }, {
88
+ name: "options",
89
+ type: "GetColorSupportLevelOptions",
90
+ default: "{ ignoreFlags: false }"
91
+ }],
92
+ children: __alloy_js_core.code`const { ignoreFlags } = options;
93
+
94
+ let forceColor: number | undefined;
95
+ if (env.FORCE_COLOR !== undefined) {
96
+ forceColor = !env.FORCE_COLOR
97
+ ? 0
98
+ : typeof env.FORCE_COLOR === "boolean"
99
+ ? 1
100
+ : typeof env.FORCE_COLOR === "number" &&
101
+ [0, 1, 2, 3].includes(Math.min(env.FORCE_COLOR as number, 3))
102
+ ? Math.min(env.FORCE_COLOR as number, 3)
103
+ : undefined;
104
+ }
105
+
106
+ if (ignoreFlags !== true && forceColor === undefined) {
107
+ forceColor = hasFlag("no-color") ||
108
+ hasFlag("no-colors") ||
109
+ hasFlag("color=false") ||
110
+ hasFlag("color=never")
111
+ ? 0
112
+ : hasFlag("color") ||
113
+ hasFlag("colors") ||
114
+ hasFlag("color=true") ||
115
+ hasFlag("color=always")
116
+ ? 1
117
+ : 0;
118
+ }
119
+
120
+ if (forceColor === 0) {
121
+ return 0;
122
+ }
123
+
124
+ if (ignoreFlags !== true) {
125
+ if (hasFlag("color=16m") ||
126
+ hasFlag("color=full") ||
127
+ hasFlag("color=truecolor")) {
128
+ return 3;
129
+ }
130
+
131
+ if (hasFlag("color=256")) {
132
+ return 2;
133
+ }
134
+ }
135
+
136
+ const level = Boolean(env.TF_BUILD) || Boolean(env.AGENT_NAME)
137
+ ? 1
138
+ : stream &&
139
+ !(isTTY || (stream && stream.isTTY)) &&
140
+ forceColor === undefined
141
+ ? 0
142
+ : env.TERM === "dumb"
143
+ ? forceColor || 0
144
+ : isWindows
145
+ ? Number(os.release().split(".")[0]) >= 10 &&
146
+ Number(os.release().split(".")[2]) >= 10_586
147
+ ? Number(os.release().split(".")[2]) >= 14_931
148
+ ? 3
149
+ : 2
150
+ : 1
151
+ : isCI
152
+ ? Boolean(env.GITHUB_ACTIONS) ||
153
+ Boolean(env.GITEA_ACTIONS) ||
154
+ Boolean(env.CIRCLECI)
155
+ ? 3
156
+ : Boolean(env.TRAVIS) ||
157
+ Boolean(env.APPVEYOR) ||
158
+ Boolean(env.GITLAB_CI) ||
159
+ Boolean(env.BUILDKITE) ||
160
+ Boolean(env.DRONE) ||
161
+ env.CI_NAME === "codeship"
162
+ ? 1
163
+ : forceColor || 0
164
+ : Boolean(env.TEAMCITY_VERSION)
165
+ ? /^(?:9\.0*[1-9]\d*\.|\d{2,}\.)/.test(String(env.TEAMCITY_VERSION) || "")
166
+ ? 1
167
+ : 0
168
+ : String(env.COLORTERM) === "truecolor" ||
169
+ env.TERM === "xterm-kitty"
170
+ ? 3
171
+ : Boolean(env.TERM_PROGRAM)
172
+ ? env.TERM_PROGRAM === "iTerm.app"
173
+ ? Number.parseInt(
174
+ (env.TERM_PROGRAM_VERSION || "").split(".")[0] as string,
175
+ 10
176
+ ) >= 3
177
+ ? 3
178
+ : 2
179
+ : env.TERM_PROGRAM === "Apple_Terminal"
180
+ ? 2
181
+ : 0
182
+ : /-256(?:color)?$/i.test(env.TERM || "")
183
+ ? 2
184
+ : /^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(
185
+ env.TERM || ""
186
+ )
187
+ ? 1
188
+ : Boolean(env.COLORTERM);
189
+
190
+ return typeof level === "boolean" || level === 0
191
+ ? false
192
+ : {
193
+ level,
194
+ hasBasic: true,
195
+ has256: level >= 2,
196
+ has16m: level >= 3,
197
+ };
198
+
199
+ `
200
+ }),
201
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
202
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
203
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
204
+ "export": true,
205
+ "const": true,
206
+ name: "colorSupportLevels",
207
+ doc: "Detect the terminal color support level in the current environment",
208
+ initializer: __alloy_js_core.code` {
209
+ stdout: getColorSupportLevel(process.stdout),
210
+ stderr: getColorSupportLevel(process.stderr),
211
+ }; `
212
+ }),
213
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
214
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
215
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
216
+ "export": true,
217
+ "const": true,
218
+ name: "isColorSupported",
219
+ doc: "Detect if terminal color is supported in the current environment",
220
+ initializer: __alloy_js_core.code` Boolean(colorSupportLevels.stdout); `
221
+ }),
222
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
223
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
224
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
225
+ "export": true,
226
+ "const": true,
227
+ name: "isUnicodeSupported",
228
+ doc: "Detect if Unicode characters are supported in the current environment",
229
+ initializer: __alloy_js_core.code` !isWindows
230
+ ? env.TERM !== "linux"
231
+ : Boolean(env.WT_SESSION) ||
232
+ Boolean(env.TERMINUS_SUBLIME) ||
233
+ env.ConEmuTask === "{cmd::Cmder}" ||
234
+ env.TERM_PROGRAM === "Terminus-Sublime" ||
235
+ env.TERM_PROGRAM === "vscode" ||
236
+ env.TERM === "xterm-256color" ||
237
+ env.TERM === "alacritty" ||
238
+ env.TERM === "rxvt-unicode" ||
239
+ env.TERM === "rxvt-unicode-256color" ||
240
+ env.TERMINAL_EMULATOR === "JetBrains-JediTerm"; `
241
+ })
242
+ ];
243
+ }
244
+ /**
245
+ * Generates utilities for detecting terminal color support.
246
+ */
247
+ function HyperlinkSupportUtilities() {
248
+ return [
249
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
250
+ name: "parseVersion",
251
+ parameters: [{
252
+ name: "version",
253
+ type: "string",
254
+ default: "\"\""
255
+ }],
256
+ children: __alloy_js_core.code`if (/^\d{3,4}$/.test(version)) {
257
+ const match = /(\d{1,2})(\d{2})/.exec(version) ?? [];
258
+
259
+ return {
260
+ major: 0,
261
+ minor: Number.parseInt(match[1]!, 10),
262
+ patch: Number.parseInt(match[2]!, 10)
263
+ };
264
+ }
265
+
266
+ const versionParts = (version ?? "")
267
+ .split(".")
268
+ .map(n => Number.parseInt(n, 10));
269
+
270
+ return {
271
+ major: versionParts[0],
272
+ minor: versionParts[1],
273
+ patch: versionParts[2]
274
+ }; `
275
+ }),
276
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
277
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
278
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
279
+ heading: "Check if the current environment/terminal supports hyperlinks in the terminal.",
280
+ get children() {
281
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: "True if the current environment/terminal supports hyperlinks." });
282
+ }
283
+ }),
284
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
285
+ "export": true,
286
+ name: "isHyperlinkSupported",
287
+ returnType: "boolean",
288
+ children: __alloy_js_core.code`if (Boolean(env.FORCE_HYPERLINK)) {
289
+ return true;
290
+ }
291
+
292
+ if (Boolean(env.NETLIFY)) {
293
+ return true;
294
+ } else if (isColorSupported || isTTY) {
295
+ return false;
296
+ } else if (Boolean(env.WT_SESSION)) {
297
+ return true;
298
+ } else if (isWindows || isMinimal || Boolean(env.TEAMCITY_VERSION)) {
299
+ return false;
300
+ } else if (Boolean(env.TERM_PROGRAM)) {
301
+ const version = parseVersion(env.TERM_PROGRAM_VERSION);
302
+
303
+ switch (String(env.TERM_PROGRAM)) {
304
+ case "iTerm.app": {
305
+ if (version.major === 3) {
306
+ return version.minor !== undefined && version.minor >= 1;
307
+ }
308
+
309
+ return version.major !== undefined && version.major > 3;
310
+ }
311
+ case "WezTerm": {
312
+ return version.major !== undefined && version.major >= 20_200_620;
313
+ }
314
+
315
+ case "vscode": {
316
+ if (Boolean(env.CURSOR_TRACE_ID)) {
317
+ return true;
318
+ }
319
+
320
+ return (
321
+ version.minor !== undefined &&
322
+ version.major !== undefined &&
323
+ (version.major > 1 || (version.major === 1 && version.minor >= 72))
324
+ );
325
+ }
326
+
327
+ case "ghostty": {
328
+ return true;
329
+ }
330
+ }
331
+ }
332
+
333
+ if (Boolean(env.VTE_VERSION)) {
334
+ if (env.VTE_VERSION === "0.50.0") {
335
+ return false;
336
+ }
337
+
338
+ const version = parseVersion(env.VTE_VERSION);
339
+ return (
340
+ (version.major !== undefined && version.major > 0) ||
341
+ (version.minor !== undefined && version.minor >= 50)
342
+ );
343
+ }
344
+
345
+ if (String(env.TERM) === "alacritty") {
346
+ return true;
347
+ }
348
+
349
+ return false; `
350
+ })
351
+ ];
352
+ }
353
+ /**
354
+ * Generates utilities for detecting terminal color support.
355
+ */
356
+ function ArgsUtilities() {
357
+ return [
358
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
359
+ heading: "Retrieves the command line arguments from Deno or Node.js environments.",
360
+ get children() {
361
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: "An array of command line arguments from Deno or Node.js environments." });
362
+ }
363
+ }),
364
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
365
+ "export": true,
366
+ name: "getArgs",
367
+ children: __alloy_js_core.code`return ((globalThis as { Deno?: { args: string[] } })?.Deno?.args ?? process.argv ?? []) as string[];`
368
+ }),
369
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
370
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
371
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
372
+ heading: "Checks if a specific flag is present in the command line arguments.",
373
+ get children() {
374
+ return [
375
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocLink, { children: "https://github.com/sindresorhus/has-flag/blob/main/index.js" }),
376
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
377
+ name: "flag",
378
+ children: "The flag (or an array of flags/aliases) to check for, e.g., \"color\", \"no-color\"."
379
+ }),
380
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
381
+ name: "argv",
382
+ children: "The command line arguments to check against. Defaults to global Deno args or process args."
383
+ }),
384
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: "True if the flag is present, false otherwise." })
385
+ ];
386
+ }
387
+ }),
388
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
389
+ "export": true,
390
+ name: "hasFlag",
391
+ parameters: [{
392
+ name: "flag",
393
+ type: "string | string[]"
394
+ }, {
395
+ name: "argv",
396
+ type: "string[]",
397
+ default: "getArgs()"
398
+ }],
399
+ get children() {
400
+ return [
401
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
402
+ "const": true,
403
+ name: "position",
404
+ type: "number",
405
+ initializer: __alloy_js_core.code`(Array.isArray(flag) ? flag : [flag]).reduce((ret, f) => {
406
+ const pos = argv.findIndex(arg => (f.startsWith("-") ? "" : (f.length === 1 ? "-" : "--") + f)?.toLowerCase() === arg?.toLowerCase() || arg?.toLowerCase().startsWith((f.length === 1 ? "-" : "--") + f + "="));
407
+ return pos !== -1 ? pos : ret;
408
+ }, -1);`
409
+ }),
410
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
411
+ __alloy_js_core.code`return position !== -1 && argv.indexOf("--") === -1 || position < argv.indexOf("--");`
412
+ ];
413
+ }
414
+ })
415
+ ];
416
+ }
417
+ /**
418
+ * The `exit` handler function declaration code for the Shell Shock project.
419
+ */
420
+ function ExitFunctionDeclaration() {
421
+ const context = (0, __powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
422
+ return [
423
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceDeclaration, {
424
+ "export": true,
425
+ name: "ExitOptions",
426
+ doc: "Options for the exit handler function.",
427
+ get children() {
428
+ return [
429
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceMember, {
430
+ name: "exception",
431
+ optional: true,
432
+ type: "string | Error",
433
+ doc: "An optional exception that caused the exit. This can be a string message or an Error object."
434
+ }),
435
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
436
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceMember, {
437
+ name: "skipProcessExit",
438
+ optional: true,
439
+ type: "boolean",
440
+ doc: "Indicates whether the exit function should manually exit the process or not. If set to true, the exit function will not call process.exit() and will allow the application to continue running. If set to false or not specified, the exit function will call process.exit() to terminate the application."
441
+ }),
442
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
443
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceMember, {
444
+ name: "isSynchronous",
445
+ optional: true,
446
+ type: "boolean",
447
+ doc: "Indicates whether the exit function should perform synchronous operations only. If set to true, the exit function will avoid any asynchronous operations during exit. If set to false or not specified, the exit function may perform asynchronous operations as needed."
448
+ }),
449
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
450
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceMember, {
451
+ name: "signal",
452
+ optional: true,
453
+ type: "number",
454
+ doc: "The signal number that triggered the exit. This is typically used when the shutdown is initiated by a system signal (e.g., SIGINT, SIGTERM)."
455
+ })
456
+ ];
457
+ }
458
+ }),
459
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
460
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
461
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
462
+ "let": true,
463
+ name: "isExiting",
464
+ type: "boolean",
465
+ initializer: __alloy_js_core.code`false;`
466
+ }),
467
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
468
+ "const": true,
469
+ name: "callbackAsyncQueue",
470
+ type: "Array<[(code: number | string) => Promise<void> | void, number]>",
471
+ initializer: __alloy_js_core.code`[];`
472
+ }),
473
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
474
+ "const": true,
475
+ name: "callbackSyncQueue",
476
+ type: "Array<(code: number | string) => void>",
477
+ initializer: __alloy_js_core.code`[];`
478
+ }),
479
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
480
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
481
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
482
+ "export": true,
483
+ async: true,
484
+ name: "exit",
485
+ parameters: [{
486
+ name: "options",
487
+ type: "ExitOptions",
488
+ default: "{}"
489
+ }],
490
+ get children() {
491
+ return __alloy_js_core.code`
492
+ try {
493
+ if (isExiting) {
494
+ return;
495
+ }
496
+
497
+ isExiting = true;
498
+
499
+ let exitCode: number | string = 0;
500
+ if ((options.signal !== undefined && options.signal > 0) || options.exception) {
501
+ exitCode = 128 + (options.signal ?? 1);
502
+ } else if (typeof process.exitCode === "number" || typeof process.exitCode === "string") {
503
+ exitCode = process.exitCode;
504
+ }
505
+
506
+ if (options.exception) {
507
+ error(\`A fatal error occured while running the application - please contact the ${(0, __shell_shock_core_plugin_utils_context_helpers.getAppTitle)(context)} support team: \\n\${typeof options.exception === "string" ? options.exception : options.exception.message}\`);
508
+ }
509
+
510
+ const terminate = (force = false) => {
511
+ verbose(\`The ${(0, __shell_shock_core_plugin_utils_context_helpers.getAppTitle)(context)} application exited \${options.exception ? \`early due to an exception\` : "successfully"}...\`);
512
+ if (!options.skipProcessExit) {
513
+ process.exit(exitCode);
514
+ }
515
+ };
516
+
517
+ for (const callbackSync of callbackSyncQueue) {
518
+ callbackSync(exitCode);
519
+ }
520
+
521
+ if (!options.isSynchronous) {
522
+ const promises = [];
523
+ let forceAfter = 0;
524
+ for (const [callbackAsync, wait] of callbackAsyncQueue) {
525
+ forceAfter = Math.max(forceAfter, wait);
526
+ promises.push(Promise.resolve(callbackAsync(exitCode)));
527
+ }
528
+
529
+ const asyncTimer = setTimeout(() => {
530
+ terminate(true);
531
+ }, forceAfter);
532
+ await Promise.all(promises);
533
+ clearTimeout(asyncTimer);
534
+ }
535
+
536
+ terminate();
537
+ } catch (err) {
538
+ error(\`The exit process failed to complete\${(err as Error).message ? \` - (err as Error).message\` : ""}. Please contact the ${(0, __shell_shock_core_plugin_utils_context_helpers.getAppTitle)(context)} support team.\`);
539
+
540
+ if (!options.skipProcessExit) {
541
+ process.exit(1);
542
+ }
543
+ }
544
+ `;
545
+ }
546
+ })
547
+ ];
548
+ }
549
+ /**
550
+ * A built-in utilities module for Shell Shock.
551
+ */
552
+ function UtilsBuiltin(props) {
553
+ const [{ children }, rest] = (0, __alloy_js_core.splitProps)(props, ["children"]);
554
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_builtin_file.BuiltinFile, (0, __alloy_js_core_jsx_runtime.mergeProps)({
555
+ id: "utils",
556
+ description: "A collection of helper utilities that ease command-line application development."
557
+ }, rest, {
558
+ get imports() {
559
+ return (0, defu.default)(rest.imports ?? {}, {
560
+ "node:os": "os",
561
+ "node:process": "process"
562
+ });
563
+ },
564
+ get builtinImports() {
565
+ return (0, defu.default)(rest.builtinImports ?? {}, {
566
+ console: ["error", "verbose"],
567
+ env: [
568
+ "env",
569
+ "isCI",
570
+ "isTest",
571
+ "isWindows"
572
+ ]
573
+ });
574
+ },
575
+ get children() {
576
+ return [
577
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
578
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
579
+ (0, __alloy_js_core_jsx_runtime.createComponent)(ArgsUtilities, {}),
580
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
581
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
582
+ (0, __alloy_js_core_jsx_runtime.createComponent)(EnvSupportUtilities, {}),
583
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
584
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
585
+ (0, __alloy_js_core_jsx_runtime.createComponent)(HyperlinkSupportUtilities, {}),
586
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
587
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
588
+ (0, __alloy_js_core_jsx_runtime.createComponent)(ColorSupportUtilities, {}),
589
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
590
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
591
+ (0, __alloy_js_core_jsx_runtime.createComponent)(ExitFunctionDeclaration, {}),
592
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
593
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
594
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
595
+ get when() {
596
+ return Boolean(children);
597
+ },
598
+ children
599
+ })
600
+ ];
601
+ }
602
+ }));
603
+ }
604
+
605
+ //#endregion
606
+ exports.ArgsUtilities = ArgsUtilities;
607
+ exports.ColorSupportUtilities = ColorSupportUtilities;
608
+ exports.EnvSupportUtilities = EnvSupportUtilities;
609
+ exports.ExitFunctionDeclaration = ExitFunctionDeclaration;
610
+ exports.HyperlinkSupportUtilities = HyperlinkSupportUtilities;
611
+ exports.UtilsBuiltin = UtilsBuiltin;
612
+ //# sourceMappingURL=utils-builtin.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils-builtin.cjs","names":["code","Show","splitProps","FunctionDeclaration","InterfaceDeclaration","InterfaceMember","VarDeclaration","usePowerlines","BuiltinFile","TSDoc","TSDocLink","TSDocParam","TSDocReturns","getAppTitle","defu","EnvSupportUtilities","_$createComponent","name","doc","initializer","_$createIntrinsic","ColorSupportUtilities","children","type","heading","parameters","default","HyperlinkSupportUtilities","returnType","ArgsUtilities","ExitFunctionDeclaration","context","optional","async","UtilsBuiltin","props","rest","_$mergeProps","id","description","imports","builtinImports","console","env","when","Boolean"],"sources":["../../src/components/utils-builtin.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { code, Show, splitProps } from \"@alloy-js/core\";\nimport {\n FunctionDeclaration,\n InterfaceDeclaration,\n InterfaceMember,\n VarDeclaration\n} from \"@alloy-js/typescript\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts/context\";\nimport type { BuiltinFileProps } from \"@powerlines/plugin-alloy/typescript/components/builtin-file\";\nimport { BuiltinFile } from \"@powerlines/plugin-alloy/typescript/components/builtin-file\";\nimport {\n TSDoc,\n TSDocLink,\n TSDocParam,\n TSDocReturns\n} from \"@powerlines/plugin-alloy/typescript/components/tsdoc\";\nimport { getAppTitle } from \"@shell-shock/core/plugin-utils/context-helpers\";\nimport defu from \"defu\";\nimport type { ScriptPresetContext } from \"../types/plugin\";\n\nexport interface UtilsBuiltinProps extends Omit<\n BuiltinFileProps,\n \"id\" | \"description\"\n> {}\n\n/**\n * Generates utilities for detecting terminal color support.\n */\n\nexport function EnvSupportUtilities() {\n return (\n <>\n <VarDeclaration\n export\n const\n name=\"isTTY\"\n doc=\"Detect if stdout.TTY is available\"\n initializer={code`Boolean(process.stdout && process.stdout.isTTY);`}\n />\n <hbr />\n <hbr />\n <VarDeclaration\n export\n const\n name=\"isMinimal\"\n doc=\"Detect if the current environment is minimal (CI, non-TTY, etc.)\"\n initializer={code` env.MINIMAL || isCI || isTest || !isTTY; `}\n />\n <hbr />\n <hbr />\n <VarDeclaration\n export\n const\n name=\"isInteractive\"\n doc=\"Detect if the current environment is interactive\"\n initializer={code` !isMinimal && process.stdin?.isTTY && env.TERM !== \"dumb\"; `}\n />\n </>\n );\n}\n\n/**\n * Generates utilities for detecting terminal color support.\n */\nexport function ColorSupportUtilities() {\n return (\n <>\n <InterfaceDeclaration\n export\n name=\"GetColorSupportLevelOptions\"\n doc=\"Options for the getColorSupportLevel function\">\n <InterfaceMember\n name=\"ignoreFlags\"\n type=\"boolean\"\n doc=\"Indicates if the function should skip checking command-line flags for color support\"\n />\n </InterfaceDeclaration>\n <hbr />\n <hbr />\n <TSDoc heading=\"Checks if a specific flag is present in the command line arguments.\">\n <TSDocLink>\n {\"https://github.com/sindresorhus/has-flag/blob/main/index.js\"}\n </TSDocLink>\n <TSDocParam name=\"flag\">\n {'The flag to check for, e.g., \"color\", \"no-color\".'}\n </TSDocParam>\n <TSDocParam name=\"argv\">\n {\n \"The command line arguments to check against. Defaults to global Deno args or process args.\"\n }\n </TSDocParam>\n <TSDocReturns>\n {\"True if the flag is present, false otherwise.\"}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n name=\"getColorSupportLevel\"\n parameters={[\n { name: \"stream\", type: \"NodeJS.WriteStream & { fd: 1 | 2; }\" },\n {\n name: \"options\",\n type: \"GetColorSupportLevelOptions\",\n default: \"{ ignoreFlags: false }\"\n }\n ]}>\n {code`const { ignoreFlags } = options;\n\n let forceColor: number | undefined;\n if (env.FORCE_COLOR !== undefined) {\n forceColor = !env.FORCE_COLOR\n ? 0\n : typeof env.FORCE_COLOR === \"boolean\"\n ? 1\n : typeof env.FORCE_COLOR === \"number\" &&\n [0, 1, 2, 3].includes(Math.min(env.FORCE_COLOR as number, 3))\n ? Math.min(env.FORCE_COLOR as number, 3)\n : undefined;\n }\n\n if (ignoreFlags !== true && forceColor === undefined) {\n forceColor = hasFlag(\"no-color\") ||\n hasFlag(\"no-colors\") ||\n hasFlag(\"color=false\") ||\n hasFlag(\"color=never\")\n ? 0\n : hasFlag(\"color\") ||\n hasFlag(\"colors\") ||\n hasFlag(\"color=true\") ||\n hasFlag(\"color=always\")\n ? 1\n : 0;\n }\n\n if (forceColor === 0) {\n return 0;\n }\n\n if (ignoreFlags !== true) {\n if (hasFlag(\"color=16m\") ||\n hasFlag(\"color=full\") ||\n hasFlag(\"color=truecolor\")) {\n return 3;\n }\n\n if (hasFlag(\"color=256\")) {\n return 2;\n }\n }\n\n const level = Boolean(env.TF_BUILD) || Boolean(env.AGENT_NAME)\n ? 1\n : stream &&\n !(isTTY || (stream && stream.isTTY)) &&\n forceColor === undefined\n ? 0\n : env.TERM === \"dumb\"\n ? forceColor || 0\n : isWindows\n ? Number(os.release().split(\".\")[0]) >= 10 &&\n Number(os.release().split(\".\")[2]) >= 10_586\n ? Number(os.release().split(\".\")[2]) >= 14_931\n ? 3\n : 2\n : 1\n : isCI\n ? Boolean(env.GITHUB_ACTIONS) ||\n Boolean(env.GITEA_ACTIONS) ||\n Boolean(env.CIRCLECI)\n ? 3\n : Boolean(env.TRAVIS) ||\n Boolean(env.APPVEYOR) ||\n Boolean(env.GITLAB_CI) ||\n Boolean(env.BUILDKITE) ||\n Boolean(env.DRONE) ||\n env.CI_NAME === \"codeship\"\n ? 1\n : forceColor || 0\n : Boolean(env.TEAMCITY_VERSION)\n ? /^(?:9\\.0*[1-9]\\d*\\.|\\d{2,}\\.)/.test(String(env.TEAMCITY_VERSION) || \"\")\n ? 1\n : 0\n : String(env.COLORTERM) === \"truecolor\" ||\n env.TERM === \"xterm-kitty\"\n ? 3\n : Boolean(env.TERM_PROGRAM)\n ? env.TERM_PROGRAM === \"iTerm.app\"\n ? Number.parseInt(\n (env.TERM_PROGRAM_VERSION || \"\").split(\".\")[0] as string,\n 10\n ) >= 3\n ? 3\n : 2\n : env.TERM_PROGRAM === \"Apple_Terminal\"\n ? 2\n : 0\n : /-256(?:color)?$/i.test(env.TERM || \"\")\n ? 2\n : /^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(\n env.TERM || \"\"\n )\n ? 1\n : Boolean(env.COLORTERM);\n\n return typeof level === \"boolean\" || level === 0\n ? false\n : {\n level,\n hasBasic: true,\n has256: level >= 2,\n has16m: level >= 3,\n };\n\n `}\n </FunctionDeclaration>\n <hbr />\n <hbr />\n <VarDeclaration\n export\n const\n name=\"colorSupportLevels\"\n doc=\"Detect the terminal color support level in the current environment\"\n initializer={code` {\n stdout: getColorSupportLevel(process.stdout),\n stderr: getColorSupportLevel(process.stderr),\n }; `}\n />\n <hbr />\n <hbr />\n <VarDeclaration\n export\n const\n name=\"isColorSupported\"\n doc=\"Detect if terminal color is supported in the current environment\"\n initializer={code` Boolean(colorSupportLevels.stdout); `}\n />\n <hbr />\n <hbr />\n <VarDeclaration\n export\n const\n name=\"isUnicodeSupported\"\n doc=\"Detect if Unicode characters are supported in the current environment\"\n initializer={code` !isWindows\n ? env.TERM !== \"linux\"\n : Boolean(env.WT_SESSION) ||\n Boolean(env.TERMINUS_SUBLIME) ||\n env.ConEmuTask === \"{cmd::Cmder}\" ||\n env.TERM_PROGRAM === \"Terminus-Sublime\" ||\n env.TERM_PROGRAM === \"vscode\" ||\n env.TERM === \"xterm-256color\" ||\n env.TERM === \"alacritty\" ||\n env.TERM === \"rxvt-unicode\" ||\n env.TERM === \"rxvt-unicode-256color\" ||\n env.TERMINAL_EMULATOR === \"JetBrains-JediTerm\"; `}\n />\n </>\n );\n}\n\n/**\n * Generates utilities for detecting terminal color support.\n */\n\nexport function HyperlinkSupportUtilities() {\n return (\n <>\n <FunctionDeclaration\n name=\"parseVersion\"\n parameters={[{ name: \"version\", type: \"string\", default: '\"\"' }]}>\n {code`if (/^\\d{3,4}$/.test(version)) {\n const match = /(\\d{1,2})(\\d{2})/.exec(version) ?? [];\n\n return {\n major: 0,\n minor: Number.parseInt(match[1]!, 10),\n patch: Number.parseInt(match[2]!, 10)\n };\n }\n\n const versionParts = (version ?? \"\")\n .split(\".\")\n .map(n => Number.parseInt(n, 10));\n\n return {\n major: versionParts[0],\n minor: versionParts[1],\n patch: versionParts[2]\n }; `}\n </FunctionDeclaration>\n <hbr />\n <hbr />\n <TSDoc heading=\"Check if the current environment/terminal supports hyperlinks in the terminal.\">\n <TSDocReturns>\n {\"True if the current environment/terminal supports hyperlinks.\"}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n name=\"isHyperlinkSupported\"\n returnType=\"boolean\">\n {code`if (Boolean(env.FORCE_HYPERLINK)) {\n return true;\n }\n\n if (Boolean(env.NETLIFY)) {\n return true;\n } else if (isColorSupported || isTTY) {\n return false;\n } else if (Boolean(env.WT_SESSION)) {\n return true;\n } else if (isWindows || isMinimal || Boolean(env.TEAMCITY_VERSION)) {\n return false;\n } else if (Boolean(env.TERM_PROGRAM)) {\n const version = parseVersion(env.TERM_PROGRAM_VERSION);\n\n switch (String(env.TERM_PROGRAM)) {\n case \"iTerm.app\": {\n if (version.major === 3) {\n return version.minor !== undefined && version.minor >= 1;\n }\n\n return version.major !== undefined && version.major > 3;\n }\n case \"WezTerm\": {\n return version.major !== undefined && version.major >= 20_200_620;\n }\n\n case \"vscode\": {\n if (Boolean(env.CURSOR_TRACE_ID)) {\n return true;\n }\n\n return (\n version.minor !== undefined &&\n version.major !== undefined &&\n (version.major > 1 || (version.major === 1 && version.minor >= 72))\n );\n }\n\n case \"ghostty\": {\n return true;\n }\n }\n }\n\n if (Boolean(env.VTE_VERSION)) {\n if (env.VTE_VERSION === \"0.50.0\") {\n return false;\n }\n\n const version = parseVersion(env.VTE_VERSION);\n return (\n (version.major !== undefined && version.major > 0) ||\n (version.minor !== undefined && version.minor >= 50)\n );\n }\n\n if (String(env.TERM) === \"alacritty\") {\n return true;\n }\n\n return false; `}\n </FunctionDeclaration>\n </>\n );\n}\n\n/**\n * Generates utilities for detecting terminal color support.\n */\nexport function ArgsUtilities() {\n return (\n <>\n <TSDoc heading=\"Retrieves the command line arguments from Deno or Node.js environments.\">\n <TSDocReturns>\n {\n \"An array of command line arguments from Deno or Node.js environments.\"\n }\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration export name=\"getArgs\">\n {code`return ((globalThis as { Deno?: { args: string[] } })?.Deno?.args ?? process.argv ?? []) as string[];`}\n </FunctionDeclaration>\n <hbr />\n <hbr />\n <TSDoc heading=\"Checks if a specific flag is present in the command line arguments.\">\n <TSDocLink>\n {\"https://github.com/sindresorhus/has-flag/blob/main/index.js\"}\n </TSDocLink>\n <TSDocParam name=\"flag\">\n {\n 'The flag (or an array of flags/aliases) to check for, e.g., \"color\", \"no-color\".'\n }\n </TSDocParam>\n <TSDocParam name=\"argv\">\n {\n \"The command line arguments to check against. Defaults to global Deno args or process args.\"\n }\n </TSDocParam>\n <TSDocReturns>\n {\"True if the flag is present, false otherwise.\"}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n name=\"hasFlag\"\n parameters={[\n { name: \"flag\", type: \"string | string[]\" },\n {\n name: \"argv\",\n type: \"string[]\",\n default: \"getArgs()\"\n }\n ]}>\n <VarDeclaration\n const\n name=\"position\"\n type=\"number\"\n initializer={code`(Array.isArray(flag) ? flag : [flag]).reduce((ret, f) => {\n const pos = argv.findIndex(arg => (f.startsWith(\"-\") ? \"\" : (f.length === 1 ? \"-\" : \"--\") + f)?.toLowerCase() === arg?.toLowerCase() || arg?.toLowerCase().startsWith((f.length === 1 ? \"-\" : \"--\") + f + \"=\"));\n return pos !== -1 ? pos : ret;\n }, -1);`}\n />\n <hbr />\n {code`return position !== -1 && argv.indexOf(\"--\") === -1 || position < argv.indexOf(\"--\");`}\n </FunctionDeclaration>\n </>\n );\n}\n\n/**\n * The `exit` handler function declaration code for the Shell Shock project.\n */\nexport function ExitFunctionDeclaration() {\n const context = usePowerlines<ScriptPresetContext>();\n\n return (\n <>\n <InterfaceDeclaration\n export\n name=\"ExitOptions\"\n doc=\"Options for the exit handler function.\">\n <InterfaceMember\n name=\"exception\"\n optional\n type=\"string | Error\"\n doc=\"An optional exception that caused the exit. This can be a string message or an Error object.\"\n />\n <hbr />\n <InterfaceMember\n name=\"skipProcessExit\"\n optional\n type=\"boolean\"\n doc=\"Indicates whether the exit function should manually exit the process or not. If set to true, the exit function will not call process.exit() and will allow the application to continue running. If set to false or not specified, the exit function will call process.exit() to terminate the application.\"\n />\n <hbr />\n <InterfaceMember\n name=\"isSynchronous\"\n optional\n type=\"boolean\"\n doc=\"Indicates whether the exit function should perform synchronous operations only. If set to true, the exit function will avoid any asynchronous operations during exit. If set to false or not specified, the exit function may perform asynchronous operations as needed.\"\n />\n <hbr />\n <InterfaceMember\n name=\"signal\"\n optional\n type=\"number\"\n doc=\"The signal number that triggered the exit. This is typically used when the shutdown is initiated by a system signal (e.g., SIGINT, SIGTERM).\"\n />\n </InterfaceDeclaration>\n <hbr />\n <hbr />\n <VarDeclaration\n let\n name=\"isExiting\"\n type=\"boolean\"\n initializer={code`false;`}\n />\n <VarDeclaration\n const\n name=\"callbackAsyncQueue\"\n type=\"Array<[(code: number | string) => Promise<void> | void, number]>\"\n initializer={code`[];`}\n />\n <VarDeclaration\n const\n name=\"callbackSyncQueue\"\n type=\"Array<(code: number | string) => void>\"\n initializer={code`[];`}\n />\n <hbr />\n <hbr />\n <FunctionDeclaration\n export\n async\n name=\"exit\"\n parameters={[\n {\n name: \"options\",\n type: \"ExitOptions\",\n default: \"{}\"\n }\n ]}>\n {code`\n try {\n if (isExiting) {\n return;\n }\n\n isExiting = true;\n\n let exitCode: number | string = 0;\n if ((options.signal !== undefined && options.signal > 0) || options.exception) {\n exitCode = 128 + (options.signal ?? 1);\n } else if (typeof process.exitCode === \"number\" || typeof process.exitCode === \"string\") {\n exitCode = process.exitCode;\n }\n\n if (options.exception) {\n error(\\`A fatal error occured while running the application - please contact the ${getAppTitle(\n context\n )} support team: \\\\n\\${typeof options.exception === \"string\" ? options.exception : options.exception.message}\\`);\n }\n\n const terminate = (force = false) => {\n verbose(\\`The ${getAppTitle(\n context\n )} application exited \\${options.exception ? \\`early due to an exception\\` : \"successfully\"}...\\`);\n if (!options.skipProcessExit) {\n process.exit(exitCode);\n }\n };\n\n for (const callbackSync of callbackSyncQueue) {\n callbackSync(exitCode);\n }\n\n if (!options.isSynchronous) {\n const promises = [];\n let forceAfter = 0;\n for (const [callbackAsync, wait] of callbackAsyncQueue) {\n forceAfter = Math.max(forceAfter, wait);\n promises.push(Promise.resolve(callbackAsync(exitCode)));\n }\n\n const asyncTimer = setTimeout(() => {\n terminate(true);\n }, forceAfter);\n await Promise.all(promises);\n clearTimeout(asyncTimer);\n }\n\n terminate();\n } catch (err) {\n error(\\`The exit process failed to complete\\${(err as Error).message ? \\` - (err as Error).message\\` : \"\"}. Please contact the ${getAppTitle(\n context\n )} support team.\\`);\n\n if (!options.skipProcessExit) {\n process.exit(1);\n }\n }\n `}\n </FunctionDeclaration>\n </>\n );\n}\n\n/**\n * A built-in utilities module for Shell Shock.\n */\nexport function UtilsBuiltin(props: UtilsBuiltinProps) {\n const [{ children }, rest] = splitProps(props, [\"children\"]);\n\n return (\n <BuiltinFile\n id=\"utils\"\n description=\"A collection of helper utilities that ease command-line application development.\"\n {...rest}\n imports={defu(rest.imports ?? {}, {\n \"node:os\": \"os\",\n \"node:process\": \"process\"\n })}\n builtinImports={defu(rest.builtinImports ?? {}, {\n console: [\"error\", \"verbose\"],\n env: [\"env\", \"isCI\", \"isTest\", \"isWindows\"]\n })}>\n <hbr />\n <hbr />\n <ArgsUtilities />\n <hbr />\n <hbr />\n <EnvSupportUtilities />\n <hbr />\n <hbr />\n <HyperlinkSupportUtilities />\n <hbr />\n <hbr />\n <ColorSupportUtilities />\n <hbr />\n <hbr />\n <ExitFunctionDeclaration />\n <hbr />\n <hbr />\n <Show when={Boolean(children)}>{children}</Show>\n </BuiltinFile>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AA+CA,SAAgBe,sBAAsB;AACpC,QAAA;mDAE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