@shell-shock/plugin-prompts 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.
@@ -0,0 +1,2729 @@
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 __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
6
+ let __powerlines_plugin_alloy_core_components_spacing = require("@powerlines/plugin-alloy/core/components/spacing");
7
+ let __powerlines_plugin_alloy_typescript_components_builtin_file = require("@powerlines/plugin-alloy/typescript/components/builtin-file");
8
+ let __powerlines_plugin_alloy_typescript_components_class_declaration = require("@powerlines/plugin-alloy/typescript/components/class-declaration");
9
+ let __powerlines_plugin_alloy_typescript_components_interface_declaration = require("@powerlines/plugin-alloy/typescript/components/interface-declaration");
10
+ let __powerlines_plugin_alloy_typescript_components_tsdoc = require("@powerlines/plugin-alloy/typescript/components/tsdoc");
11
+ let __powerlines_plugin_alloy_typescript_components_type_declaration = require("@powerlines/plugin-alloy/typescript/components/type-declaration");
12
+ let __shell_shock_preset_script_contexts_theme = require("@shell-shock/preset-script/contexts/theme");
13
+ let defu = require("defu");
14
+ defu = require_rolldown_runtime.__toESM(defu);
15
+
16
+ //#region src/components/prompts-builtin.tsx
17
+ /**
18
+ * A component that generates TypeScript declarations for built-in prompt types and related utilities, such as the base Prompt class, specific prompt types like TextPrompt and SelectPrompt, and utility functions for handling prompt cancellations. This component serves as a central place to define the types and interfaces for prompts used in the Shell Shock CLI, providing a consistent API for creating and managing prompts throughout the application.
19
+ */
20
+ function BasePromptDeclarations() {
21
+ const theme = (0, __shell_shock_preset_script_contexts_theme.useTheme)();
22
+ return [
23
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
24
+ heading: "A utility function to pause execution for a specified duration, which can be used in prompt interactions to create delays or timeouts. The function returns a promise that resolves after the specified duration in milliseconds, allowing it to be used with async/await syntax for easier handling of asynchronous prompt logic.",
25
+ get children() {
26
+ return [(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
27
+ name: "duration",
28
+ children: `The duration to sleep in milliseconds.`
29
+ }), (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: `A promise that resolves after the specified duration, allowing for asynchronous delays in prompt interactions.` })];
30
+ }
31
+ }),
32
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
33
+ "export": true,
34
+ name: "sleep",
35
+ parameters: [{
36
+ name: "duration",
37
+ type: "number"
38
+ }],
39
+ returnType: "Promise<void>",
40
+ children: __alloy_js_core.code`return new Promise((resolve) => setTimeout(resolve, duration)); `
41
+ }),
42
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
43
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_type_declaration.TypeDeclaration, {
44
+ "export": true,
45
+ name: "PromptParser",
46
+ typeParameters: [{
47
+ name: "TValue",
48
+ default: "string"
49
+ }],
50
+ doc: "A type for a custom prompt input parser, which can be used to create custom input styles for prompts. The function should return the parsed value for the given input string.",
51
+ children: __alloy_js_core.code`(this: Prompt<TValue>, input: string) => TValue; `
52
+ }),
53
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
54
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_type_declaration.TypeDeclaration, {
55
+ "export": true,
56
+ name: "PromptFormatter",
57
+ typeParameters: [{
58
+ name: "TValue",
59
+ default: "string"
60
+ }],
61
+ doc: "A type for a custom prompt input formatter, which can be used to create custom display styles for prompts. The function should return the formatted string to display for the given input value.",
62
+ children: __alloy_js_core.code`(this: Prompt<TValue>, input: TValue) => string; `
63
+ }),
64
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
65
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
66
+ "export": true,
67
+ name: "noMask",
68
+ doc: "A built-in prompt mask function that just returns the input as is, making it invisible",
69
+ parameters: [{
70
+ name: "input",
71
+ type: "string"
72
+ }],
73
+ returnType: "string",
74
+ children: __alloy_js_core.code`return input; `
75
+ }),
76
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
77
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
78
+ "export": true,
79
+ name: "invisibleMask",
80
+ doc: "A built-in prompt mask function that makes input invisible",
81
+ parameters: [{
82
+ name: "input",
83
+ type: "string"
84
+ }],
85
+ returnType: "string",
86
+ children: __alloy_js_core.code`return " ".repeat(input.length); `
87
+ }),
88
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
89
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceDeclaration, {
90
+ "export": true,
91
+ name: "PromptState",
92
+ doc: "The current state of a prompt",
93
+ typeParameters: [{
94
+ name: "TValue",
95
+ default: "string"
96
+ }],
97
+ get children() {
98
+ return [
99
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
100
+ name: "value",
101
+ type: "TValue",
102
+ doc: "The current value of the prompt"
103
+ }),
104
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
105
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
106
+ name: "isError",
107
+ type: "boolean",
108
+ doc: "Indicates whether the prompt is in an error state"
109
+ }),
110
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
111
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
112
+ name: "errorMessage",
113
+ optional: true,
114
+ type: "string",
115
+ doc: "If the prompt is in an error state, this will contain the error message to display"
116
+ }),
117
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
118
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
119
+ name: "isSubmitted",
120
+ type: "boolean",
121
+ doc: "Indicates whether the prompt is submitted"
122
+ }),
123
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
124
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
125
+ name: "isCancelled",
126
+ type: "boolean",
127
+ doc: "Indicates whether the prompt is cancelled"
128
+ }),
129
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
130
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
131
+ name: "isCompleted",
132
+ type: "boolean",
133
+ doc: "Indicates whether the prompt is completed, which can be used to indicate that the prompt interaction is finished regardless of whether it was submitted or cancelled"
134
+ }),
135
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {})
136
+ ];
137
+ }
138
+ }),
139
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
140
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceDeclaration, {
141
+ name: "PromptConfig",
142
+ doc: "Configuration options for creating a prompt",
143
+ typeParameters: [{
144
+ name: "TValue",
145
+ default: "string"
146
+ }],
147
+ get children() {
148
+ return [
149
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
150
+ name: "input",
151
+ optional: true,
152
+ type: "NodeJS.ReadStream",
153
+ doc: "The readable stream to use for prompt input, defaults to process.stdin"
154
+ }),
155
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
156
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
157
+ name: "output",
158
+ optional: true,
159
+ type: "NodeJS.WriteStream",
160
+ doc: "The writable stream to use for prompt output, defaults to process.stdout"
161
+ }),
162
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
163
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
164
+ name: "message",
165
+ type: "string",
166
+ doc: "The prompt message to display"
167
+ }),
168
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
169
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
170
+ name: "description",
171
+ optional: true,
172
+ type: "string",
173
+ doc: "The prompt description message to display"
174
+ }),
175
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
176
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
177
+ name: "initialValue",
178
+ optional: true,
179
+ type: "TValue",
180
+ doc: "The initial value of the prompt"
181
+ }),
182
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
183
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
184
+ name: "validate",
185
+ optional: true,
186
+ type: "(value: TValue) => boolean | string | { type: 'error' | 'warning'; message: string } | null | undefined | Promise<boolean | string | { type: 'error' | 'warning'; message: string } | null | undefined>",
187
+ doc: "A validation function that returns true if the input is valid, false or a string error message if the input is invalid"
188
+ }),
189
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
190
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
191
+ name: "parse",
192
+ optional: true,
193
+ type: "PromptParser<TValue>",
194
+ doc: "A function that parses the input value and returns the parsed result or throws an error if the input is invalid"
195
+ }),
196
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
197
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
198
+ name: "format",
199
+ optional: true,
200
+ type: "PromptFormatter<TValue>",
201
+ doc: "A function that formats the input value and returns the formatted result or throws an error if the input is invalid"
202
+ }),
203
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
204
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
205
+ name: "mask",
206
+ optional: true,
207
+ type: "(input: string) => string",
208
+ doc: "A function that masks the input value and returns the masked result. This can be used to create password inputs or other sensitive input types where the actual input value should not be displayed. If not provided, the prompt will display the input as is without masking."
209
+ }),
210
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
211
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
212
+ name: "maskSubmitted",
213
+ optional: true,
214
+ type: "(input: string) => string",
215
+ doc: "A function that masks the value submitted by the user so that it can then be used in the console output or elsewhere without exposing sensitive information. If not provided, the prompt will use the same mask function for both input and submitted value masking."
216
+ }),
217
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
218
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
219
+ name: "defaultErrorMessage",
220
+ optional: true,
221
+ type: "string",
222
+ doc: "The default error message to display when validation fails"
223
+ }),
224
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
225
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
226
+ name: "timeout",
227
+ optional: true,
228
+ type: "number",
229
+ doc: "The timeout duration in milliseconds for the prompt. If none is provided, the prompt will not time out."
230
+ })
231
+ ];
232
+ }
233
+ }),
234
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
235
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassDeclaration, {
236
+ abstract: true,
237
+ name: "Prompt",
238
+ doc: "Base prompt class that other prompt types can extend from",
239
+ "extends": "EventEmitter",
240
+ typeParameters: [{
241
+ name: "TValue",
242
+ default: "string"
243
+ }],
244
+ get children() {
245
+ return [
246
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
247
+ name: "readline",
248
+ isPrivateMember: true,
249
+ type: "readline.Interface"
250
+ }),
251
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
252
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
253
+ name: "value",
254
+ isPrivateMember: true,
255
+ optional: true,
256
+ type: "TValue"
257
+ }),
258
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
259
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
260
+ name: "isClosed",
261
+ isPrivateMember: true,
262
+ type: "boolean",
263
+ children: __alloy_js_core.code`false; `
264
+ }),
265
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
266
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
267
+ name: "initialValue",
268
+ abstract: true,
269
+ "protected": true,
270
+ type: "TValue"
271
+ }),
272
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
273
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
274
+ name: "input",
275
+ "protected": true,
276
+ type: "NodeJS.ReadStream",
277
+ children: __alloy_js_core.code`process.stdin; `
278
+ }),
279
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
280
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
281
+ name: "output",
282
+ "protected": true,
283
+ type: "NodeJS.WriteStream",
284
+ children: __alloy_js_core.code`process.stdout; `
285
+ }),
286
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
287
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
288
+ name: "message",
289
+ "protected": true,
290
+ type: "string",
291
+ children: __alloy_js_core.code`""; `
292
+ }),
293
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
294
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
295
+ name: "description",
296
+ "protected": true,
297
+ type: "string",
298
+ children: __alloy_js_core.code`""; `
299
+ }),
300
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
301
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
302
+ name: "errorMessage",
303
+ "protected": true,
304
+ type: "string | null",
305
+ children: __alloy_js_core.code`null; `
306
+ }),
307
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
308
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
309
+ name: "defaultErrorMessage",
310
+ "protected": true,
311
+ type: "string",
312
+ children: __alloy_js_core.code`"An invalid value was provided"; `
313
+ }),
314
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
315
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
316
+ name: "isSubmitted",
317
+ "protected": true,
318
+ type: "boolean",
319
+ children: __alloy_js_core.code`false; `
320
+ }),
321
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
322
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
323
+ name: "isCancelled",
324
+ "protected": true,
325
+ type: "boolean",
326
+ children: __alloy_js_core.code`false; `
327
+ }),
328
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
329
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
330
+ name: "isInitial",
331
+ "protected": true,
332
+ type: "boolean",
333
+ children: __alloy_js_core.code`true; `
334
+ }),
335
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
336
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
337
+ name: "consoleOutput",
338
+ "protected": true,
339
+ type: "string",
340
+ children: __alloy_js_core.code`""; `
341
+ }),
342
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
343
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
344
+ name: "consoleStatus",
345
+ "protected": true,
346
+ type: "string",
347
+ children: __alloy_js_core.code`""; `
348
+ }),
349
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
350
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
351
+ name: "displayValue",
352
+ "protected": true,
353
+ type: "string",
354
+ children: __alloy_js_core.code`""; `
355
+ }),
356
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
357
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
358
+ name: "validator",
359
+ "protected": true,
360
+ type: "(value: TValue) => boolean | string | null | undefined | Promise<boolean | string | null | undefined>",
361
+ children: __alloy_js_core.code`() => true; `
362
+ }),
363
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
364
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
365
+ name: "parser",
366
+ "protected": true,
367
+ type: "PromptParser<TValue>",
368
+ children: __alloy_js_core.code`(value: string) => value as TValue; `
369
+ }),
370
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
371
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
372
+ name: "formatter",
373
+ "protected": true,
374
+ type: "PromptFormatter<TValue>",
375
+ children: __alloy_js_core.code`(value: TValue) => String(value); `
376
+ }),
377
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
378
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
379
+ name: "mask",
380
+ "protected": true,
381
+ type: "(input: string) => string",
382
+ children: __alloy_js_core.code`noMask; `
383
+ }),
384
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
385
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
386
+ name: "maskSubmitted",
387
+ "protected": true,
388
+ type: "(input: string) => string"
389
+ }),
390
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
391
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
392
+ name: "cursor",
393
+ "protected": true,
394
+ type: "number",
395
+ children: __alloy_js_core.code`0; `
396
+ }),
397
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
398
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
399
+ name: "cursorOffset",
400
+ "protected": true,
401
+ type: "number",
402
+ children: __alloy_js_core.code`0; `
403
+ }),
404
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
405
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
406
+ name: "cursorHidden",
407
+ "protected": true,
408
+ type: "boolean",
409
+ children: __alloy_js_core.code`false; `
410
+ }),
411
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
412
+ __alloy_js_core.code`constructor(protected config: PromptConfig<TValue>) {
413
+ super();
414
+
415
+ if (config.input) {
416
+ this.input = config.input;
417
+ }
418
+ if (config.output) {
419
+ this.output = config.output;
420
+ }
421
+ if (config.defaultErrorMessage) {
422
+ this.defaultErrorMessage = config.defaultErrorMessage;
423
+ }
424
+ if (config.description) {
425
+ this.description = config.description;
426
+ }
427
+ if (config.validate) {
428
+ this.validator = config.validate;
429
+ }
430
+ if (config.parse) {
431
+ this.parser = config.parse.bind(this);
432
+ }
433
+ if (config.format) {
434
+ this.formatter = config.format.bind(this);
435
+ }
436
+
437
+ if (config.maskSubmitted) {
438
+ this.maskSubmitted = config.maskSubmitted;
439
+ }
440
+ if (config.mask) {
441
+ this.mask = config.mask;
442
+ }
443
+ if (!this.maskSubmitted) {
444
+ this.maskSubmitted = this.mask;
445
+ }
446
+
447
+ if (config.timeout !== undefined && !Number.isNaN(config.timeout)) {
448
+ setTimeout(() => {
449
+ if (!this.isCompleted) {
450
+ this.cancel();
451
+ }
452
+ }, config.timeout);
453
+ }
454
+
455
+ this.message = config.message;
456
+
457
+ this.#readline = readline.createInterface({
458
+ input: this.input,
459
+ escapeCodeTimeout: 50
460
+ });
461
+ readline.emitKeypressEvents(this.input, this.#readline);
462
+
463
+ if (this.input.isTTY) {
464
+ this.input.setRawMode(true);
465
+ }
466
+
467
+ this.input.on("keypress", this.onKeypress.bind(this));
468
+ } `,
469
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
470
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassPropertyGet, {
471
+ "public": true,
472
+ name: "value",
473
+ type: "TValue",
474
+ doc: "A getter for the prompt value that returns the current value or the initial value if the current value is not set",
475
+ children: __alloy_js_core.code`return this.#value || this.initialValue; `
476
+ }),
477
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
478
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassPropertyGet, {
479
+ "public": true,
480
+ name: "isError",
481
+ type: "boolean",
482
+ children: __alloy_js_core.code`return !!this.errorMessage; `
483
+ }),
484
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
485
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassPropertyGet, {
486
+ "protected": true,
487
+ name: "isSelect",
488
+ type: "boolean",
489
+ children: __alloy_js_core.code`return false; `
490
+ }),
491
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
492
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassPropertyGet, {
493
+ "protected": true,
494
+ name: "isCompleted",
495
+ type: "boolean",
496
+ children: __alloy_js_core.code`return this.isCancelled || this.isSubmitted; `
497
+ }),
498
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
499
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassPropertyGet, {
500
+ "protected": true,
501
+ name: "isPlaceholder",
502
+ type: "boolean",
503
+ children: __alloy_js_core.code`return this.config.initialValue !== undefined && this.displayValue === this.formatter(this.initialValue); `
504
+ }),
505
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
506
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassPropertyGet, {
507
+ "protected": true,
508
+ name: "status",
509
+ type: "string",
510
+ children: __alloy_js_core.code`return this.isCompleted ? "" : \` \\n \${
511
+ colors.italic(
512
+ this.isError
513
+ ? colors.text.prompt.description.error(splitText(this.errorMessage, "3/4").join("\\n"))
514
+ : this.description
515
+ ? colors.text.prompt.description.active(splitText(this.description, "3/4").join("\\n"))
516
+ : ""
517
+ )
518
+ }\`; `
519
+ }),
520
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
521
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
522
+ doc: "A method to change the prompt value, which also updates the display value and fires a state update event. This method can be called by subclasses whenever the prompt value needs to be updated based on user input or other interactions.",
523
+ name: "changeValue",
524
+ "protected": true,
525
+ parameters: [{
526
+ name: "value",
527
+ type: "TValue"
528
+ }],
529
+ children: __alloy_js_core.code`let updatedValue = value;
530
+ if (value === undefined || value === "") {
531
+ updatedValue = this.initialValue;
532
+ } else {
533
+ updatedValue = value;
534
+ }
535
+
536
+ this.displayValue = this.mask(this.formatter(updatedValue));
537
+ this.#value = updatedValue;
538
+ setTimeout(() => {
539
+ Promise.resolve(this.validate(updatedValue)).then(() => this.sync());
540
+ }, 0);
541
+
542
+ this.sync(); `
543
+ }),
544
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
545
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
546
+ doc: "A method to emit the current state",
547
+ name: "sync",
548
+ "protected": true,
549
+ children: __alloy_js_core.code`this.emit("state", {
550
+ value: this.value,
551
+ errorMessage: this.errorMessage,
552
+ isError: this.isError,
553
+ isSubmitted: this.isSubmitted,
554
+ isCancelled: this.isCancelled,
555
+ isCompleted: this.isCompleted
556
+ });
557
+ this.invokeRender(); `
558
+ }),
559
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
560
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
561
+ doc: "A method to ring the bell",
562
+ name: "bell",
563
+ "protected": true,
564
+ children: __alloy_js_core.code`this.output.write(beep); `
565
+ }),
566
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
567
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
568
+ doc: "A method to handle keypress events and determine the corresponding action",
569
+ name: "onKeypress",
570
+ "protected": true,
571
+ parameters: [{
572
+ name: "char",
573
+ type: "string"
574
+ }, {
575
+ name: "key",
576
+ type: "readline.Key"
577
+ }],
578
+ children: __alloy_js_core.code`if (this.#isClosed) {
579
+ return;
580
+ }
581
+
582
+ return this.keypress(char, key); `
583
+ }),
584
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
585
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
586
+ doc: "A method to handle keypress events and determine the corresponding action",
587
+ name: "keypress",
588
+ "protected": true,
589
+ parameters: [{
590
+ name: "char",
591
+ type: "string"
592
+ }, {
593
+ name: "key",
594
+ type: "readline.Key"
595
+ }],
596
+ children: __alloy_js_core.code`const action = this.getAction(key);
597
+ if (!action) {
598
+ this.bell();
599
+ } else if (typeof (this as any)[action] === "function") {
600
+ (this as any)[action](key);
601
+ } `
602
+ }),
603
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
604
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
605
+ doc: "A method to close the prompt and clean up resources, which also emits a submit or cancel event based on the prompt state. This method should be called when the prompt interaction is finished and the prompt needs to be closed.",
606
+ name: "close",
607
+ async: true,
608
+ "protected": true,
609
+ children: __alloy_js_core.code`this.output.write(cursor.show);
610
+ this.input.removeListener("keypress", this.onKeypress);
611
+
612
+ if (this.input.isTTY) {
613
+ this.input.setRawMode(false);
614
+ }
615
+
616
+ this.#readline.close();
617
+ this.emit(this.isSubmitted ? "submit" : "cancel", this.value);
618
+ this.#isClosed = true; `
619
+ }),
620
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
621
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
622
+ doc: "A method to validate the prompt input using the provided validator function, which updates the error message and error state based on the validation result. This method is called whenever the prompt value changes and needs to be validated.",
623
+ name: "validate",
624
+ async: true,
625
+ "protected": true,
626
+ parameters: [{
627
+ name: "value",
628
+ type: "TValue"
629
+ }],
630
+ children: __alloy_js_core.code`let result = await this.validator(value);
631
+ if (typeof result === "string") {
632
+ this.errorMessage = result;
633
+ } else if (typeof result === "boolean") {
634
+ this.errorMessage = result ? null : this.defaultErrorMessage;
635
+ } else {
636
+ this.errorMessage = null;
637
+ } `
638
+ }),
639
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
640
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
641
+ doc: "A method to route keypress events to specific prompt actions based on the key pressed. This method maps various key combinations and keys to corresponding actions that can be handled by the prompt, such as submitting, cancelling, navigating, etc.",
642
+ name: "getAction",
643
+ "protected": true,
644
+ parameters: [{
645
+ name: "key",
646
+ type: "readline.Key"
647
+ }],
648
+ returnType: "string | false",
649
+ children: __alloy_js_core.code`if (key.meta && key.name !== "escape") {
650
+ return false;
651
+ }
652
+
653
+ let action: string | undefined;
654
+ if (key.ctrl) {
655
+ if (key.name === "a") action = "first";
656
+ if (key.name === "c") action = "cancel";
657
+ if (key.name === "d") action = "cancel";
658
+ if (key.name === "e") action = "last";
659
+ if (key.name === "g") action = "reset";
660
+ }
661
+
662
+ if (key.name === "return") action = "submit";
663
+ if (key.name === "enter") action = "submit";
664
+ if (key.name === "backspace") action = "delete";
665
+ if (key.name === "delete") action = "deleteForward";
666
+ if (key.name === "cancel") action = "cancel";
667
+ if (key.name === "escape") action = "cancel";
668
+ if (key.name === "tab") action = "next";
669
+ if (key.name === "pagedown") action = "nextPage";
670
+ if (key.name === "pageup") action = "prevPage";
671
+ if (key.name === "home") action = "home";
672
+ if (key.name === "end") action = "end";
673
+
674
+ if (key.name === "up") action = "up";
675
+ if (key.name === "down") action = "down";
676
+ if (key.name === "right") action = "right";
677
+ if (key.name === "left") action = "left";
678
+
679
+ return action || false; `
680
+ }),
681
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
682
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
683
+ doc: "A method to reset the prompt input",
684
+ name: "reset",
685
+ "protected": true,
686
+ children: __alloy_js_core.code`this.changeValue(this.initialValue);
687
+ this.cursorOffset = 0;
688
+
689
+ this.errorMessage = null;
690
+ this.isCancelled = false;
691
+ this.isSubmitted = false;
692
+
693
+ this.sync(); `
694
+ }),
695
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
696
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
697
+ doc: "A method to cancel the prompt input",
698
+ name: "cancel",
699
+ "protected": true,
700
+ children: __alloy_js_core.code`this.errorMessage = null;
701
+ this.isCancelled = true;
702
+ this.isSubmitted = false;
703
+
704
+ this.sync();
705
+ this.output.write("\\n");
706
+ this.close(); `
707
+ }),
708
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
709
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
710
+ doc: "A method to submit the prompt input",
711
+ name: "submit",
712
+ async: true,
713
+ "protected": true,
714
+ children: __alloy_js_core.code`this.cursorOffset = 0;
715
+ this.cursor = this.displayValue.length;
716
+
717
+ await this.validate(this.value);
718
+ if (this.isError) {
719
+ this.sync();
720
+ this.bell();
721
+ } else {
722
+ this.isSubmitted = true;
723
+ this.isCancelled = false;
724
+
725
+ this.sync();
726
+ this.output.write("\\n");
727
+ this.close();
728
+ } `
729
+ }),
730
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
731
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
732
+ doc: "A method to render the prompt",
733
+ name: "invokeRender",
734
+ "protected": true,
735
+ get children() {
736
+ return __alloy_js_core.code`if (this.#isClosed) {
737
+ return;
738
+ }
739
+
740
+ if (!this.isInitial) {
741
+ if (this.consoleStatus) {
742
+ this.output.write(cursor.down(stripAnsi(this.consoleStatus).split(/\\r?\\n/).map(line => Math.ceil(line.length / this.output.columns)).reduce((a, b) => a + b) - 1) + clear(this.consoleStatus, this.output.columns));
743
+ }
744
+
745
+ this.output.write(clear(this.consoleOutput, this.output.columns));
746
+ } else if (this.cursorHidden) {
747
+ this.output.write(cursor.hide);
748
+ }
749
+
750
+ this.consoleOutput = \` \${
751
+ this.isSubmitted
752
+ ? colors.text.prompt.icon.submitted("${theme.icons.prompt.submitted}")
753
+ : this.isCancelled
754
+ ? colors.text.prompt.icon.cancelled("${theme.icons.prompt.cancelled}")
755
+ : this.isError
756
+ ? colors.text.prompt.icon.error("${theme.icons.prompt.error}")
757
+ : colors.text.prompt.icon.active("${theme.icons.prompt.active}")
758
+ } \${
759
+ this.isCompleted
760
+ ? colors.text.prompt.message.submitted(this.message)
761
+ : colors.bold(colors.text.prompt.message.active(this.message))
762
+ } \${
763
+ colors.border.app.divider.tertiary(
764
+ this.isCompleted
765
+ ? (process.platform === "win32" ? "..." : "…")
766
+ : (process.platform === "win32" ? "»" : "›")
767
+ )
768
+ } \`;
769
+ this.consoleOutput += this.render();
770
+
771
+ if (this.isInitial) {
772
+ this.isInitial = false;
773
+ }
774
+
775
+ this.output.write(erase.line + cursor.to(0) + this.consoleOutput + (this.status ? cursor.save + this.status + cursor.restore + cursor.move(this.cursorOffset, 0) : cursor.save));
776
+ this.consoleStatus = this.status; `;
777
+ }
778
+ }),
779
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
780
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
781
+ doc: "A method to render the prompt",
782
+ name: "render",
783
+ "protected": true,
784
+ returnType: "string",
785
+ children: __alloy_js_core.code`return this.isPlaceholder
786
+ ? colors.text.prompt.input.disabled(this.displayValue)
787
+ : this.isError
788
+ ? colors.text.prompt.input.error(this.displayValue)
789
+ : this.isSubmitted
790
+ ? colors.text.prompt.input.submitted(this.maskSubmitted(this.displayValue))
791
+ : this.isCancelled
792
+ ? colors.text.prompt.input.cancelled(this.displayValue)
793
+ : colors.bold(colors.text.prompt.input.active(this.displayValue)); `
794
+ })
795
+ ];
796
+ }
797
+ }),
798
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
799
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceDeclaration, {
800
+ name: "PromptFactoryConfig",
801
+ "extends": "PromptConfig<TValue>",
802
+ doc: "Configuration options for creating a prompt with a prompt factory function",
803
+ typeParameters: [{
804
+ name: "TValue",
805
+ default: "string"
806
+ }],
807
+ get children() {
808
+ return [
809
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
810
+ name: "onState",
811
+ optional: true,
812
+ type: "(state: PromptState<TValue>) => any",
813
+ doc: "A function that is called when the prompt state changes, useful for updating the prompt message or other properties dynamically"
814
+ }),
815
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
816
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
817
+ name: "onSubmit",
818
+ optional: true,
819
+ type: "(value: TValue) => any",
820
+ doc: "A function that is called when the prompt is submitted, useful for handling the submitted value or performing actions based on the prompt state"
821
+ }),
822
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
823
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
824
+ name: "onCancel",
825
+ optional: true,
826
+ type: "(event: any) => any",
827
+ doc: "A function that is called when the prompt is canceled, useful for handling the canceled value or performing actions based on the prompt state"
828
+ })
829
+ ];
830
+ }
831
+ }),
832
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
833
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "A unique symbol used to indicate that a prompt was cancelled, which can be returned from a prompt function to signal that the prompt interaction should be cancelled and any pending promises should be rejected with this symbol. This allows for a consistent way to handle prompt cancellations across different prompt types and interactions." }),
834
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
835
+ "export": true,
836
+ name: "CANCEL_SYMBOL",
837
+ children: __alloy_js_core.code`Symbol("shell-shock:prompts:cancel"); `
838
+ }),
839
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
840
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
841
+ heading: "A utility function to check if a given value is the {@link CANCEL_SYMBOL | cancel symbol}, which can be used to determine if a prompt interaction was cancelled based on the value returned from a prompt factory function. This function checks if the provided value is strictly equal to the {@link CANCEL_SYMBOL | CANCEL_SYMBOL}, allowing for a consistent way to handle prompt cancellations across different prompt types and interactions.",
842
+ get children() {
843
+ return [(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
844
+ name: "value",
845
+ children: `The value to check.`
846
+ }), (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: `A boolean indicating whether the provided value is the {@link CANCEL_SYMBOL | cancel symbol}, which can be used to determine if a prompt interaction was cancelled.` })];
847
+ }
848
+ }),
849
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
850
+ name: "isCancel",
851
+ "export": true,
852
+ parameters: [{
853
+ name: "value",
854
+ type: "any"
855
+ }],
856
+ returnType: "value is typeof CANCEL_SYMBOL",
857
+ children: __alloy_js_core.code`return value === CANCEL_SYMBOL; `
858
+ })
859
+ ];
860
+ }
861
+ /**
862
+ * Declarations for a text-based prompt that allows users to input and edit text, with support for cursor movement, deletion, and custom masking. This prompt type can be used for various text input scenarios, such as entering a username, password, or any other string input. The TextPrompt class extends the base Prompt class and implements specific logic for handling text input and editing interactions.
863
+ */
864
+ function TextPromptDeclarations() {
865
+ return [
866
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceDeclaration, {
867
+ name: "StringPromptConfig",
868
+ "extends": "PromptConfig<string>",
869
+ doc: "Configuration options for creating a text-based prompt",
870
+ get children() {
871
+ return [
872
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
873
+ name: "initialValue",
874
+ optional: true,
875
+ type: "string",
876
+ doc: "The initial value of the prompt"
877
+ }),
878
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
879
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
880
+ name: "mask",
881
+ optional: true,
882
+ type: "(input: string) => string",
883
+ doc: "A function that masks the input value and returns the masked result"
884
+ })
885
+ ];
886
+ }
887
+ }),
888
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
889
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassDeclaration, {
890
+ name: "StringPrompt",
891
+ doc: "A prompt for text input",
892
+ "extends": "Prompt<string>",
893
+ get children() {
894
+ return [
895
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
896
+ name: "isInvalid",
897
+ isPrivateMember: true,
898
+ type: "boolean",
899
+ children: __alloy_js_core.code`false; `
900
+ }),
901
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
902
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
903
+ name: "initialValue",
904
+ "protected": true,
905
+ override: true,
906
+ type: "string",
907
+ children: __alloy_js_core.code`""; `
908
+ }),
909
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
910
+ __alloy_js_core.code`constructor(config: StringPromptConfig) {
911
+ super(config);
912
+
913
+ if (config.initialValue) {
914
+ this.initialValue = config.initialValue;
915
+ }
916
+
917
+ this.cursor = 0;
918
+ this.sync();
919
+ this.first();
920
+ } `,
921
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
922
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
923
+ doc: "A method to handle keypress events and determine the corresponding action",
924
+ name: "keypress",
925
+ override: true,
926
+ "protected": true,
927
+ parameters: [{
928
+ name: "char",
929
+ type: "string"
930
+ }, {
931
+ name: "key",
932
+ type: "readline.Key"
933
+ }],
934
+ children: __alloy_js_core.code`const action = this.getAction(key);
935
+ if (action && typeof (this as any)[action] === "function") {
936
+ return (this as any)[action]();
937
+ }
938
+
939
+ if (!char || char.length === 0) {
940
+ return this.bell();
941
+ }
942
+
943
+ const value = \`\${this.value.slice(0, this.cursor)}\${char}\${this.value.slice(this.cursor)}\`;
944
+ this.#isInvalid = false;
945
+ this.cursor = this.isPlaceholder ? 0 : this.value.slice(0, this.cursor).length + 1;
946
+
947
+ this.changeValue(value);
948
+ this.sync(); `
949
+ }),
950
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
951
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
952
+ doc: "A method to reset the prompt input",
953
+ name: "reset",
954
+ override: true,
955
+ "protected": true,
956
+ children: __alloy_js_core.code`this.#isInvalid = false;
957
+ this.cursor = Number(!!this.initialValue);
958
+ super.reset(); `
959
+ }),
960
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
961
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
962
+ doc: "A method to cancel the prompt input",
963
+ name: "cancel",
964
+ override: true,
965
+ "protected": true,
966
+ children: __alloy_js_core.code`this.#isInvalid = false;
967
+ super.cancel(); `
968
+ }),
969
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
970
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
971
+ doc: "A method to validate the prompt input",
972
+ name: "validate",
973
+ override: true,
974
+ async: true,
975
+ "protected": true,
976
+ children: __alloy_js_core.code`await super.validate(this.value);
977
+ this.#isInvalid = this.isError; `
978
+ }),
979
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
980
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
981
+ doc: "A method to move the cursor to the end of the input",
982
+ name: "next",
983
+ "protected": true,
984
+ children: __alloy_js_core.code`if (!this.isPlaceholder) {
985
+ return this.bell();
986
+ }
987
+
988
+ this.changeValue(this.initialValue);
989
+ this.cursor = this.displayValue.length;
990
+ this.sync(); `
991
+ }),
992
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
993
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
994
+ doc: "A method to move the cursor to the left or right by a \\`count\\` of positions",
995
+ name: "moveCursor",
996
+ parameters: [{
997
+ name: "count",
998
+ type: "number"
999
+ }],
1000
+ "protected": true,
1001
+ children: __alloy_js_core.code`if (this.isPlaceholder) {
1002
+ return;
1003
+ }
1004
+
1005
+ this.cursor = this.cursor + count;
1006
+ this.cursorOffset += count; `
1007
+ }),
1008
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1009
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1010
+ doc: "A method to delete the character backward of the cursor",
1011
+ name: "delete",
1012
+ "protected": true,
1013
+ children: __alloy_js_core.code`if (this.isCursorAtStart()) {
1014
+ return this.bell();
1015
+ }
1016
+
1017
+ this.changeValue(\`\${this.value.slice(0, this.cursor - 1)}\${this.value.slice(this.cursor)}\`);
1018
+ this.#isInvalid = false;
1019
+
1020
+ if (this.isCursorAtStart()) {
1021
+ this.cursorOffset = 0
1022
+ } else {
1023
+ this.cursorOffset++;
1024
+ this.moveCursor(-1);
1025
+ }
1026
+
1027
+ this.sync(); `
1028
+ }),
1029
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1030
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1031
+ doc: "A method to delete the character forward of the cursor",
1032
+ name: "deleteForward",
1033
+ "protected": true,
1034
+ children: __alloy_js_core.code`if (this.cursor >= this.displayValue.length || this.isPlaceholder) {
1035
+ return this.bell();
1036
+ }
1037
+
1038
+ this.changeValue(\`\${
1039
+ this.value.slice(0, this.cursor)
1040
+ }\${
1041
+ this.value.slice(this.cursor + 1)
1042
+ }\`);
1043
+ this.#isInvalid = false;
1044
+
1045
+ if (this.isCursorAtEnd()) {
1046
+ this.cursorOffset = 0;
1047
+ } else {
1048
+ this.cursorOffset++;
1049
+ }
1050
+
1051
+ this.sync(); `
1052
+ }),
1053
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1054
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1055
+ doc: "A method to move the cursor to the start",
1056
+ name: "first",
1057
+ "protected": true,
1058
+ children: __alloy_js_core.code`this.cursor = 0;
1059
+ this.sync(); `
1060
+ }),
1061
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1062
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1063
+ doc: "A method to move the cursor to the end",
1064
+ name: "last",
1065
+ "protected": true,
1066
+ children: __alloy_js_core.code`this.cursor = this.value.length;
1067
+ this.sync(); `
1068
+ }),
1069
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1070
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1071
+ doc: "A method to move the cursor to the left",
1072
+ name: "left",
1073
+ "protected": true,
1074
+ children: __alloy_js_core.code`if (this.cursor <= 0 || this.isPlaceholder) {
1075
+ return this.bell();
1076
+ }
1077
+
1078
+ this.moveCursor(-1);
1079
+ this.sync(); `
1080
+ }),
1081
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1082
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1083
+ doc: "A method to move the cursor to the right",
1084
+ name: "right",
1085
+ "protected": true,
1086
+ children: __alloy_js_core.code`if (this.cursor >= this.displayValue.length || this.isPlaceholder) {
1087
+ return this.bell();
1088
+ }
1089
+
1090
+ this.moveCursor(1);
1091
+ this.sync(); `
1092
+ }),
1093
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1094
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1095
+ doc: "A method to check if the cursor is at the start",
1096
+ name: "isCursorAtStart",
1097
+ "protected": true,
1098
+ children: __alloy_js_core.code`return this.cursor === 0 || (this.isPlaceholder && this.cursor === 1); `
1099
+ }),
1100
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1101
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1102
+ doc: "A method to check if the cursor is at the end",
1103
+ name: "isCursorAtEnd",
1104
+ "protected": true,
1105
+ children: __alloy_js_core.code`return this.cursor === this.displayValue.length || (this.isPlaceholder && this.cursor === this.displayValue.length + 1); `
1106
+ }),
1107
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1108
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1109
+ doc: "A method to render the prompt",
1110
+ name: "render",
1111
+ override: true,
1112
+ "protected": true,
1113
+ returnType: "string",
1114
+ children: __alloy_js_core.code`return this.isPlaceholder
1115
+ ? colors.text.prompt.input.disabled(this.displayValue)
1116
+ : this.#isInvalid
1117
+ ? colors.text.prompt.input.error(this.displayValue)
1118
+ : this.isSubmitted
1119
+ ? colors.text.prompt.input.submitted(this.displayValue)
1120
+ : this.isCancelled
1121
+ ? colors.text.prompt.input.cancelled(this.displayValue)
1122
+ : colors.bold(colors.text.prompt.input.active(this.displayValue)); `
1123
+ })
1124
+ ];
1125
+ }
1126
+ }),
1127
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1128
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "A type definition for the configuration options to pass to the text prompt, which extends the base PromptConfig with additional options specific to text prompts. This type can be used when creating a text prompt using the {@link text | text prompt factory function} or when manually creating an instance of the TextPrompt class. The TextConfig type includes all the properties of the base PromptConfig, such as message, description, initialValue, validate, parse, format, mask, etc., as well as any additional properties that are specific to text prompts." }),
1129
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_type_declaration.TypeDeclaration, {
1130
+ name: "TextConfig",
1131
+ "export": true,
1132
+ children: __alloy_js_core.code`PromptFactoryConfig<string> & StringPromptConfig; `
1133
+ }),
1134
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1135
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
1136
+ heading: "A function to create and run a text prompt, which returns a promise that resolves with the submitted value or rejects with a {@link CANCEL_SYMBOL | cancel symbol} if the prompt is cancelled.",
1137
+ get children() {
1138
+ return [
1139
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocRemarks, { children: __alloy_js_core.code`This function can be used to easily create and run a text prompt without needing to manually create an instance of the TextPrompt class and handle its events. The function accepts a configuration object that extends the base PromptFactoryConfig with additional options specific to text prompts, such as the initial value and mask function. The returned promise allows for easy handling of the prompt result using async/await syntax or traditional promise chaining.` }),
1140
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocExample, { children: `import { text, isCancel } from "shell-shock:prompts";
1141
+
1142
+ async function run() {
1143
+ const name = await text({
1144
+ message: "What is your name?",
1145
+ description: "Please enter your full name",
1146
+ validate: value => value.trim().length > 0 || "Name cannot be empty"
1147
+ });
1148
+ if (isCancel(name)) {
1149
+ console.log("Prompt was cancelled");
1150
+ return;
1151
+ }
1152
+
1153
+ console.log("Hello, " + name + "!");
1154
+ }
1155
+
1156
+ run(); ` }),
1157
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1158
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
1159
+ name: "config",
1160
+ children: `The configuration options to pass to the text prompt, which extends the base PromptConfig with additional options specific to text prompts`
1161
+ }),
1162
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: `A promise that resolves with the submitted value or rejects with a {@link CANCEL_SYMBOL | cancel symbol} if the prompt is cancelled` })
1163
+ ];
1164
+ }
1165
+ }),
1166
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
1167
+ name: "text",
1168
+ "export": true,
1169
+ parameters: [{
1170
+ name: "config",
1171
+ type: "TextConfig"
1172
+ }],
1173
+ returnType: "Promise<string | symbol>",
1174
+ children: __alloy_js_core.code`return new Promise<string | symbol>((response, reject) => {
1175
+ const prompt = new StringPrompt(config);
1176
+
1177
+ prompt.on("state", state => config.onState?.(state));
1178
+ prompt.on("submit", value => response(value));
1179
+ prompt.on("cancel", event => reject(CANCEL_SYMBOL));
1180
+ });`
1181
+ })
1182
+ ];
1183
+ }
1184
+ /**
1185
+ * Declarations for a select prompt that allows users to choose from a list of options, with support for pagination, option descriptions, and disabled options. This prompt type can be used for scenarios where the user needs to select one option from a predefined list, such as choosing a color, selecting a file, or picking an item from a menu. The SelectPrompt class extends the base Prompt class and implements specific logic for handling option selection and navigation interactions.
1186
+ */
1187
+ function SelectPromptDeclarations() {
1188
+ return [
1189
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceDeclaration, {
1190
+ name: "PromptOptionConfig",
1191
+ doc: "Configuration for an option the user can select from the select prompt",
1192
+ typeParameters: [{
1193
+ name: "TValue",
1194
+ default: "string"
1195
+ }],
1196
+ get children() {
1197
+ return [
1198
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
1199
+ name: "label",
1200
+ optional: true,
1201
+ type: "string",
1202
+ doc: "The message label for the option"
1203
+ }),
1204
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1205
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
1206
+ name: "icon",
1207
+ optional: true,
1208
+ type: "string",
1209
+ doc: "An icon for the option"
1210
+ }),
1211
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1212
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
1213
+ name: "value",
1214
+ type: "TValue",
1215
+ doc: "The value of the option"
1216
+ }),
1217
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1218
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
1219
+ name: "description",
1220
+ optional: true,
1221
+ type: "string",
1222
+ doc: "The description of the option"
1223
+ }),
1224
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1225
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
1226
+ name: "selected",
1227
+ optional: true,
1228
+ type: "boolean",
1229
+ doc: "Whether the option is selected"
1230
+ }),
1231
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1232
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
1233
+ name: "disabled",
1234
+ optional: true,
1235
+ type: "boolean",
1236
+ doc: "Whether the option is disabled"
1237
+ })
1238
+ ];
1239
+ }
1240
+ }),
1241
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1242
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceDeclaration, {
1243
+ "export": true,
1244
+ name: "PromptOption",
1245
+ "extends": "PromptOptionConfig<TValue>",
1246
+ doc: "An option the user can select from the select prompt",
1247
+ typeParameters: [{
1248
+ name: "TValue",
1249
+ default: "string"
1250
+ }],
1251
+ get children() {
1252
+ return [
1253
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
1254
+ name: "label",
1255
+ type: "string",
1256
+ doc: "The message label for the option"
1257
+ }),
1258
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
1259
+ name: "index",
1260
+ type: "number",
1261
+ doc: "The index of the option"
1262
+ }),
1263
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1264
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
1265
+ name: "selected",
1266
+ type: "boolean",
1267
+ doc: "Whether the option is selected"
1268
+ }),
1269
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1270
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
1271
+ name: "disabled",
1272
+ type: "boolean",
1273
+ doc: "Whether the option is disabled"
1274
+ })
1275
+ ];
1276
+ }
1277
+ }),
1278
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1279
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceDeclaration, {
1280
+ name: "SelectPromptConfig",
1281
+ "extends": "PromptConfig<TValue>",
1282
+ doc: "An options object for configuring a select prompt",
1283
+ typeParameters: [{
1284
+ name: "TValue",
1285
+ default: "string"
1286
+ }],
1287
+ get children() {
1288
+ return [
1289
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
1290
+ name: "hint",
1291
+ optional: true,
1292
+ type: "string",
1293
+ doc: "A hint to display to the user"
1294
+ }),
1295
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1296
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
1297
+ name: "options",
1298
+ type: "Array<string | PromptOptionConfig<TValue>>",
1299
+ doc: "The options available for the select prompt"
1300
+ }),
1301
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1302
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
1303
+ name: "optionsPerPage",
1304
+ optional: true,
1305
+ type: "number",
1306
+ doc: "The number of options to display per page, defaults to 8"
1307
+ })
1308
+ ];
1309
+ }
1310
+ }),
1311
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1312
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassDeclaration, {
1313
+ name: "SelectPrompt",
1314
+ doc: "A prompt for selecting an option from a list",
1315
+ "extends": "Prompt<TValue>",
1316
+ typeParameters: [{
1317
+ name: "TValue",
1318
+ default: "string"
1319
+ }],
1320
+ get children() {
1321
+ return [
1322
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
1323
+ name: "initialValue",
1324
+ "protected": true,
1325
+ override: true,
1326
+ type: "TValue"
1327
+ }),
1328
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
1329
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
1330
+ name: "optionsPerPage",
1331
+ "protected": true,
1332
+ type: "number",
1333
+ children: __alloy_js_core.code`8; `
1334
+ }),
1335
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
1336
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
1337
+ name: "options",
1338
+ "protected": true,
1339
+ type: "PromptOption<TValue>[]",
1340
+ children: __alloy_js_core.code`[]; `
1341
+ }),
1342
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
1343
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
1344
+ name: "cursorHidden",
1345
+ "protected": true,
1346
+ override: true,
1347
+ type: "boolean",
1348
+ children: __alloy_js_core.code`true; `
1349
+ }),
1350
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1351
+ __alloy_js_core.code`constructor(config: SelectPromptConfig<TValue>) {
1352
+ super(config);
1353
+
1354
+ if (config.initialValue) {
1355
+ this.initialValue = config.initialValue as TValue;
1356
+ } else {
1357
+ this.initialValue = undefined as unknown as TValue;
1358
+ }
1359
+
1360
+ this.options = config.options.map((opt, index) => {
1361
+ let option = {} as Partial<PromptOption<TValue>>;
1362
+ if (typeof opt === "string") {
1363
+ option = { label: opt, value: opt as TValue, selected: false, disabled: false };
1364
+ } else if (typeof opt === "object") {
1365
+ option = opt;
1366
+ } else {
1367
+ throw new Error(\`Invalid option provided to SelectPrompt at index #\${index}\`);
1368
+ }
1369
+
1370
+ return {
1371
+ label: String(option.value) || "",
1372
+ ...option,
1373
+ description: option.description,
1374
+ selected: !!option.selected || (this.initialValue !== undefined && option.value === this.initialValue),
1375
+ disabled: !!option.disabled
1376
+ } as PromptOption<TValue>;
1377
+ }).sort((a, b) => a.label.localeCompare(b.label)).map((option, index) => ({ ...option, index }));
1378
+
1379
+ const selected = this.options.findIndex(option => option.selected);
1380
+ if (selected > -1) {
1381
+ this.cursor = selected;
1382
+ if (this.options[this.cursor]) {
1383
+ this.initialValue = this.options[this.cursor].value as TValue;
1384
+ }
1385
+ }
1386
+
1387
+ if (this.initialValue === undefined && this.options.length > 0 && this.options[0]) {
1388
+ this.initialValue = this.options[0].value as TValue;
1389
+ }
1390
+
1391
+ if (config.optionsPerPage) {
1392
+ this.optionsPerPage = config.optionsPerPage;
1393
+ }
1394
+
1395
+ this.sync();
1396
+ } `,
1397
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1398
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassPropertyGet, {
1399
+ doc: "Returns the currently selected option",
1400
+ name: "selectedOption",
1401
+ type: "PromptOption<TValue> | null",
1402
+ "protected": true,
1403
+ children: __alloy_js_core.code`return this.options.find(option => option.value === this.value) ?? null; `
1404
+ }),
1405
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1406
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1407
+ doc: "A method to route keypress events to specific prompt actions based on the key pressed. This method maps various key combinations and keys to corresponding actions that can be handled by the prompt, such as submitting, cancelling, navigating, etc.",
1408
+ name: "getAction",
1409
+ override: true,
1410
+ "protected": true,
1411
+ parameters: [{
1412
+ name: "key",
1413
+ type: "readline.Key"
1414
+ }],
1415
+ returnType: "string | false",
1416
+ children: __alloy_js_core.code`let action = super.getAction(key);
1417
+ if (!action) {
1418
+ if (key.name === "j") action = "down";
1419
+ if (key.name === "k") action = "up";
1420
+ }
1421
+
1422
+ return action || false; `
1423
+ }),
1424
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1425
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1426
+ doc: "A method to reset the prompt input",
1427
+ name: "reset",
1428
+ override: true,
1429
+ "protected": true,
1430
+ children: __alloy_js_core.code`this.moveCursor(0);
1431
+ super.reset(); `
1432
+ }),
1433
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1434
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1435
+ doc: "A method to submit the prompt input",
1436
+ name: "submit",
1437
+ async: true,
1438
+ override: true,
1439
+ "protected": true,
1440
+ children: __alloy_js_core.code`if (!this.selectedOption?.disabled) {
1441
+ await super.submit();
1442
+ } else {
1443
+ this.bell();
1444
+ } `
1445
+ }),
1446
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1447
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1448
+ doc: "A method to move the cursor to the end of the input",
1449
+ name: "next",
1450
+ "protected": true,
1451
+ children: __alloy_js_core.code`this.moveCursor((this.cursor + 1) % this.options.length);
1452
+ this.sync(); `
1453
+ }),
1454
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1455
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1456
+ doc: "A method to move the cursor to the left or right by a \\`count\\` of positions",
1457
+ name: "moveCursor",
1458
+ parameters: [{
1459
+ name: "count",
1460
+ type: "number"
1461
+ }],
1462
+ "protected": true,
1463
+ children: __alloy_js_core.code`this.cursor = count;
1464
+
1465
+ this.changeValue(this.options[count]!.value);
1466
+ this.sync(); `
1467
+ }),
1468
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1469
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1470
+ doc: "A method to move the cursor to the first option",
1471
+ name: "first",
1472
+ "protected": true,
1473
+ children: __alloy_js_core.code`this.moveCursor(0);
1474
+ this.sync(); `
1475
+ }),
1476
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1477
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1478
+ doc: "A method to move the cursor to the last option",
1479
+ name: "last",
1480
+ "protected": true,
1481
+ children: __alloy_js_core.code`this.moveCursor(this.options.length - 1);
1482
+ this.sync(); `
1483
+ }),
1484
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1485
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1486
+ doc: "A method to move the cursor to the start",
1487
+ name: "first",
1488
+ "protected": true,
1489
+ children: __alloy_js_core.code`this.cursor = 0;
1490
+ this.sync(); `
1491
+ }),
1492
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1493
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1494
+ doc: "A method to move the cursor to the up",
1495
+ name: "up",
1496
+ "protected": true,
1497
+ children: __alloy_js_core.code`if (this.cursor === 0) {
1498
+ this.moveCursor(this.options.length - 1);
1499
+ } else {
1500
+ this.moveCursor(this.cursor - 1);
1501
+ }
1502
+
1503
+ this.sync(); `
1504
+ }),
1505
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1506
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1507
+ doc: "A method to move the cursor to the down",
1508
+ name: "down",
1509
+ "protected": true,
1510
+ children: __alloy_js_core.code`if (this.cursor === this.options.length - 1) {
1511
+ this.moveCursor(0);
1512
+ } else {
1513
+ this.moveCursor(this.cursor + 1);
1514
+ }
1515
+
1516
+ this.sync(); `
1517
+ }),
1518
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1519
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1520
+ doc: "A method to render the prompt",
1521
+ name: "render",
1522
+ override: true,
1523
+ "protected": true,
1524
+ children: __alloy_js_core.code`const spacing = Math.max(...this.options.map(option => option.label?.length || 0)) + 2;
1525
+
1526
+ const startIndex = Math.max(Math.min(this.options.length - this.optionsPerPage, this.cursor - Math.floor(this.optionsPerPage / 2)), 0);
1527
+ const endIndex = Math.min(startIndex + this.optionsPerPage, this.options.length);
1528
+
1529
+ let output = "";
1530
+ if (!this.isCompleted) {
1531
+ output += " \\n";
1532
+ for (let index = startIndex; index < endIndex; index++) {
1533
+ output += \`\${
1534
+ this.options[index].disabled
1535
+ ? this.cursor === index
1536
+ ? colors.bold(colors.text.prompt.input.disabled(">"))
1537
+ : index === startIndex
1538
+ ? colors.border.app.divider.tertiary("↑")
1539
+ : index === endIndex - 1
1540
+ ? colors.border.app.divider.tertiary("↓")
1541
+ : " "
1542
+ : this.cursor === index
1543
+ ? colors.bold(colors.text.prompt.input.active(">"))
1544
+ : index === startIndex
1545
+ ? colors.border.app.divider.tertiary("↑")
1546
+ : index === endIndex - 1
1547
+ ? colors.border.app.divider.tertiary("↓")
1548
+ : " "
1549
+ } \${
1550
+ this.options[index]!.disabled
1551
+ ? this.cursor === index
1552
+ ? colors.bold(colors.text.prompt.input.disabled(this.options[index]!.icon ? colors.underline(\`\${this.options[index]!.icon} \`) : ""))
1553
+ : colors.strikethrough(colors.text.prompt.input.disabled(this.options[index]!.icon ? \`\${this.options[index].icon} \` : ""))
1554
+ : this.cursor === index
1555
+ ? colors.bold(colors.text.prompt.input.active(this.options[index]!.icon ? colors.underline(\`\${this.options[index]!.icon} \`) : ""))
1556
+ : colors.text.prompt.input.inactive(this.options[index]!.icon ? \`\${this.options[index].icon} \` : "")
1557
+ }\${
1558
+ this.options[index]!.disabled
1559
+ ? this.cursor === index
1560
+ ? colors.bold(colors.underline(colors.text.prompt.input.disabled(this.options[index].label)))
1561
+ : colors.strikethrough(colors.text.prompt.input.disabled(this.options[index]!.label))
1562
+ : this.cursor === index
1563
+ ? colors.bold(colors.underline(colors.text.prompt.input.active(this.options[index]!.label)))
1564
+ : colors.text.prompt.input.inactive(this.options[index]!.label)
1565
+ } \${" ".repeat(spacing - this.options[index]!.label.length - (this.options[index]!.icon ? this.options[index]!.icon!.length + 1 : 0))}\${
1566
+ this.options[index]!.description && this.cursor === index
1567
+ ? colors.italic(colors.text.prompt.description.active(this.options[index]!.description))
1568
+ : ""
1569
+ } \\n\`;
1570
+ }
1571
+ } else {
1572
+ this.displayValue = this.selectedOption?.label || String(this.value);
1573
+ output += super.render();
1574
+ }
1575
+
1576
+ return output; `
1577
+ })
1578
+ ];
1579
+ }
1580
+ }),
1581
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1582
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
1583
+ heading: "A type definition for the configuration options to pass to the select prompt, which extends the base PromptConfig with additional options specific to select prompts. This type can be used when creating a select prompt using the {@link select | select prompt factory function}.",
1584
+ get children() {
1585
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocRemarks, { children: `The Select Config type includes all the properties of the base PromptConfig, such as message, description, initialValue, validate, parse, format, etc., as well as any additional properties that are specific to select prompts, such as the list of options and pagination settings.` });
1586
+ }
1587
+ }),
1588
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_type_declaration.TypeDeclaration, {
1589
+ "export": true,
1590
+ name: "SelectConfig",
1591
+ children: __alloy_js_core.code`PromptFactoryConfig<string> & SelectPromptConfig; `
1592
+ }),
1593
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1594
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
1595
+ heading: "A function to create and run a select prompt, which returns a promise that resolves with the submitted value or rejects with a {@link CANCEL_SYMBOL | cancel symbol} if the prompt is cancelled.",
1596
+ get children() {
1597
+ return [
1598
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocExample, { children: `import { select, isCancel } from "shell-shock:prompts";
1599
+
1600
+ async function run() {
1601
+ const color = await select({
1602
+ message: "What is your favorite color?",
1603
+ description: "Please select your favorite color",
1604
+ validate: value => value.trim().length > 0 || "Color cannot be empty",
1605
+ options: [
1606
+ { label: "Red", value: "red", description: "The color of fire and blood" },
1607
+ { label: "Green", value: "green", description: "The color of nature and growth" },
1608
+ { label: "Blue", value: "blue", description: "The color of the sky and sea" },
1609
+ { label: "Yellow", value: "yellow", description: "The color of sunshine and happiness" }
1610
+ ]
1611
+ });
1612
+ if (isCancel(color)) {
1613
+ console.log("Prompt was cancelled");
1614
+ return;
1615
+ }
1616
+
1617
+ console.log("Your favorite color is " + color + "!");
1618
+ }
1619
+
1620
+ run(); ` }),
1621
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1622
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
1623
+ name: "config",
1624
+ children: `The configuration options to pass to the select prompt, which extends the base PromptConfig with additional options specific to select prompts`
1625
+ }),
1626
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: `A promise that resolves with the submitted value or rejects with a {@link CANCEL_SYMBOL | cancel symbol} if the prompt is cancelled` })
1627
+ ];
1628
+ }
1629
+ }),
1630
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
1631
+ name: "select",
1632
+ "export": true,
1633
+ parameters: [{
1634
+ name: "config",
1635
+ type: "SelectConfig"
1636
+ }],
1637
+ returnType: "Promise<string | symbol>",
1638
+ children: __alloy_js_core.code`return new Promise<string | symbol>((response, reject) => {
1639
+ const prompt = new SelectPrompt(config);
1640
+
1641
+ prompt.on("state", state => config.onState?.(state));
1642
+ prompt.on("submit", value => response(value));
1643
+ prompt.on("cancel", event => reject(CANCEL_SYMBOL));
1644
+ });`
1645
+ })
1646
+ ];
1647
+ }
1648
+ /**
1649
+ * A component that renders the declarations for the built-in numeric prompt, which allows users to input and select numeric values with various configuration options such as floating point support, precision, increment, and min/max values.
1650
+ */
1651
+ function NumericPromptDeclarations() {
1652
+ return [
1653
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceDeclaration, {
1654
+ name: "NumberPromptConfig",
1655
+ "extends": "PromptConfig<number>",
1656
+ doc: "Configuration options for creating a numeric prompt",
1657
+ get children() {
1658
+ return [
1659
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
1660
+ name: "isFloat",
1661
+ optional: true,
1662
+ type: "boolean",
1663
+ doc: "Whether the prompt should accept floating point numbers"
1664
+ }),
1665
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1666
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
1667
+ name: "precision",
1668
+ optional: true,
1669
+ type: "number",
1670
+ doc: "The number of decimal places to round the input to, defaults to 2"
1671
+ }),
1672
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1673
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
1674
+ name: "increment",
1675
+ optional: true,
1676
+ type: "number",
1677
+ doc: "The increment value for the number prompt, defaults to 1"
1678
+ }),
1679
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1680
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
1681
+ name: "min",
1682
+ optional: true,
1683
+ type: "number",
1684
+ doc: "The minimum value for the number prompt, defaults to -Infinity"
1685
+ }),
1686
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1687
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
1688
+ name: "max",
1689
+ optional: true,
1690
+ type: "number",
1691
+ doc: "The maximum value for the number prompt, defaults to Infinity"
1692
+ })
1693
+ ];
1694
+ }
1695
+ }),
1696
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1697
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassDeclaration, {
1698
+ name: "NumberPrompt",
1699
+ doc: "A prompt for selecting a number input",
1700
+ "extends": "Prompt<number>",
1701
+ get children() {
1702
+ return [
1703
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
1704
+ name: "isInvalid",
1705
+ isPrivateMember: true,
1706
+ type: "boolean",
1707
+ children: __alloy_js_core.code`false; `
1708
+ }),
1709
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1710
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
1711
+ name: "initialValue",
1712
+ "protected": true,
1713
+ override: true,
1714
+ type: "number",
1715
+ children: __alloy_js_core.code`0; `
1716
+ }),
1717
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
1718
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
1719
+ name: "defaultErrorMessage",
1720
+ "protected": true,
1721
+ override: true,
1722
+ type: "string",
1723
+ children: __alloy_js_core.code`"A valid numeric value must be provided"; `
1724
+ }),
1725
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
1726
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
1727
+ name: "isFloat",
1728
+ "protected": true,
1729
+ type: "boolean",
1730
+ children: __alloy_js_core.code`false; `
1731
+ }),
1732
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
1733
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
1734
+ name: "precision",
1735
+ "protected": true,
1736
+ type: "number",
1737
+ children: __alloy_js_core.code`2; `
1738
+ }),
1739
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
1740
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
1741
+ name: "increment",
1742
+ "protected": true,
1743
+ type: "number",
1744
+ children: __alloy_js_core.code`1; `
1745
+ }),
1746
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
1747
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
1748
+ name: "min",
1749
+ "protected": true,
1750
+ type: "number",
1751
+ children: __alloy_js_core.code`Number.NEGATIVE_INFINITY; `
1752
+ }),
1753
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
1754
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
1755
+ name: "max",
1756
+ "protected": true,
1757
+ type: "number",
1758
+ children: __alloy_js_core.code`Number.POSITIVE_INFINITY; `
1759
+ }),
1760
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
1761
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
1762
+ name: "currentInput",
1763
+ "protected": true,
1764
+ type: "string",
1765
+ children: __alloy_js_core.code`""; `
1766
+ }),
1767
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
1768
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
1769
+ name: "inputTimestamp",
1770
+ "protected": true,
1771
+ type: "number",
1772
+ children: __alloy_js_core.code`0; `
1773
+ }),
1774
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1775
+ __alloy_js_core.code`constructor(config: NumberPromptConfig) {
1776
+ super(config);
1777
+
1778
+ if (config.initialValue) {
1779
+ this.initialValue = config.initialValue;
1780
+ }
1781
+
1782
+ this.isFloat = !!config.isFloat;
1783
+ if (config.precision !== undefined) {
1784
+ this.precision = config.precision;
1785
+ }
1786
+ if (config.increment !== undefined) {
1787
+ this.increment = config.increment;
1788
+ }
1789
+ if (config.min !== undefined) {
1790
+ this.min = config.min;
1791
+ }
1792
+ if (config.max !== undefined) {
1793
+ this.max = config.max;
1794
+ }
1795
+
1796
+ if (config.parse) {
1797
+ this.parser = config.parse.bind(this);
1798
+ } else {
1799
+ const parser = (value: string) => this.isFloat ? Math.round(Math.pow(10, this.precision) * Number.parseFloat(value)) / Math.pow(10, this.precision) : Number.parseInt(value);
1800
+ this.parser = parser.bind(this);
1801
+ }
1802
+
1803
+ if (config.validate) {
1804
+ this.validator = config.validate.bind(this);
1805
+ } else {
1806
+ const validator = (value: number) => !Number.isNaN(value) && value >= this.min && value <= this.max;
1807
+ this.validator = validator.bind(this);
1808
+ }
1809
+
1810
+ this.sync();
1811
+ this.last();
1812
+ } `,
1813
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1814
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1815
+ doc: "A method to reset the prompt input",
1816
+ name: "reset",
1817
+ override: true,
1818
+ "protected": true,
1819
+ children: __alloy_js_core.code`super.reset();
1820
+ this.currentInput = "";
1821
+ `
1822
+ }),
1823
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1824
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1825
+ doc: "A method to handle keypress events and determine the corresponding action",
1826
+ name: "keypress",
1827
+ override: true,
1828
+ "protected": true,
1829
+ parameters: [{
1830
+ name: "char",
1831
+ type: "string"
1832
+ }, {
1833
+ name: "key",
1834
+ type: "readline.Key"
1835
+ }],
1836
+ children: __alloy_js_core.code`const action = this.getAction(key);
1837
+ if (action && typeof (this as any)[action] === "function") {
1838
+ return (this as any)[action]();
1839
+ }
1840
+
1841
+ if (char !== "-" && !(char === "." && this.isFloat) && !/[0-9]/.test(char)) {
1842
+ return this.bell();
1843
+ }
1844
+
1845
+ this.displayValue += char;
1846
+ if ((char === "-" || char === ".") && this.displayValue.length === 1) {
1847
+ return this.sync();
1848
+ }
1849
+
1850
+ let value = Math.min(this.parser(this.displayValue), this.max);
1851
+ if (value > this.max) {
1852
+ value = this.max;
1853
+ }
1854
+ if (value < this.min) {
1855
+ value = this.min;
1856
+ }
1857
+
1858
+ this.changeValue(value);
1859
+ this.sync(); `
1860
+ }),
1861
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1862
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1863
+ doc: "A method to move the cursor to the end of the input",
1864
+ name: "next",
1865
+ "protected": true,
1866
+ children: __alloy_js_core.code`this.changeValue(this.initialValue);
1867
+ this.sync(); `
1868
+ }),
1869
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1870
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1871
+ doc: "A method to move the cursor to the up",
1872
+ name: "up",
1873
+ "protected": true,
1874
+ children: __alloy_js_core.code`let value = this.value;
1875
+ if (this.displayValue === "") {
1876
+ value = this.min < 0 ? 0 : this.min;
1877
+ } else if (value >= this.max) {
1878
+ return this.bell();
1879
+ }
1880
+
1881
+ this.changeValue(value + this.increment);
1882
+ this.sync(); `
1883
+ }),
1884
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1885
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1886
+ doc: "A method to move the cursor to the down",
1887
+ name: "down",
1888
+ "protected": true,
1889
+ children: __alloy_js_core.code`let value = this.value;
1890
+ if (this.displayValue === "") {
1891
+ value = this.min < 0 ? 0 : this.min;
1892
+ } else if (value <= this.min) {
1893
+ return this.bell();
1894
+ }
1895
+
1896
+ this.changeValue(value === this.min ? this.min : value - this.increment);
1897
+ this.sync(); `
1898
+ }),
1899
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1900
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1901
+ doc: "A method to move the cursor to the left",
1902
+ name: "left",
1903
+ "protected": true,
1904
+ children: __alloy_js_core.code`if (this.cursor <= 0 || this.isPlaceholder) {
1905
+ return this.bell();
1906
+ }
1907
+
1908
+ this.moveCursor(-1);
1909
+ this.sync(); `
1910
+ }),
1911
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1912
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1913
+ doc: "A method to move the cursor to the right",
1914
+ name: "right",
1915
+ "protected": true,
1916
+ children: __alloy_js_core.code`if (this.cursor >= this.displayValue.length || this.isPlaceholder) {
1917
+ return this.bell();
1918
+ }
1919
+
1920
+ this.moveCursor(1);
1921
+ this.sync(); `
1922
+ }),
1923
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1924
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1925
+ doc: "A method to move the cursor to the left or right by a \\`count\\` of positions",
1926
+ name: "moveCursor",
1927
+ parameters: [{
1928
+ name: "count",
1929
+ type: "number"
1930
+ }],
1931
+ "protected": true,
1932
+ children: __alloy_js_core.code`if (this.isPlaceholder) {
1933
+ return;
1934
+ }
1935
+
1936
+ this.cursor = this.cursor + count;
1937
+ this.cursorOffset += count; `
1938
+ }),
1939
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1940
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1941
+ doc: "A method to delete the character backward of the cursor",
1942
+ name: "delete",
1943
+ "protected": true,
1944
+ children: __alloy_js_core.code`if (this.isCursorAtStart()) {
1945
+ return this.bell();
1946
+ }
1947
+
1948
+ if (this.displayValue === "") {
1949
+ return this.bell();
1950
+ }
1951
+
1952
+ this.changeValue(\`\${this.displayValue.slice(0, this.cursor - 1)}\${this.displayValue.slice(this.cursor)}\`);
1953
+ this.#isInvalid = false;
1954
+
1955
+ if (this.isCursorAtStart()) {
1956
+ this.cursorOffset = 0
1957
+ } else {
1958
+ this.cursorOffset++;
1959
+ this.moveCursor(-1);
1960
+ }
1961
+
1962
+ this.sync(); `
1963
+ }),
1964
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1965
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1966
+ doc: "A method to delete the character forward of the cursor",
1967
+ name: "deleteForward",
1968
+ "protected": true,
1969
+ children: __alloy_js_core.code`if (this.cursor >= this.displayValue.length || this.isPlaceholder) {
1970
+ return this.bell();
1971
+ }
1972
+
1973
+ this.changeValue(\`\${
1974
+ this.displayValue.slice(0, this.cursor)
1975
+ }\${
1976
+ this.displayValue.slice(this.cursor + 1)
1977
+ }\`);
1978
+ this.#isInvalid = false;
1979
+
1980
+ if (this.isCursorAtEnd()) {
1981
+ this.cursorOffset = 0;
1982
+ } else {
1983
+ this.cursorOffset++;
1984
+ }
1985
+
1986
+ this.sync(); `
1987
+ }),
1988
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1989
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1990
+ doc: "A method to move the cursor to the start",
1991
+ name: "first",
1992
+ "protected": true,
1993
+ children: __alloy_js_core.code`this.cursor = 0;
1994
+ this.sync(); `
1995
+ }),
1996
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1997
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
1998
+ doc: "A method to move the cursor to the end",
1999
+ name: "last",
2000
+ "protected": true,
2001
+ children: __alloy_js_core.code`this.cursor = this.displayValue.length;
2002
+ this.sync(); `
2003
+ }),
2004
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2005
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
2006
+ doc: "A method to check if the cursor is at the start",
2007
+ name: "isCursorAtStart",
2008
+ "protected": true,
2009
+ children: __alloy_js_core.code`return this.cursor === 0 || (this.isPlaceholder && this.cursor === 1); `
2010
+ }),
2011
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2012
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
2013
+ doc: "A method to check if the cursor is at the end",
2014
+ name: "isCursorAtEnd",
2015
+ "protected": true,
2016
+ children: __alloy_js_core.code`return this.cursor === this.displayValue.length || (this.isPlaceholder && this.cursor === this.displayValue.length + 1); `
2017
+ })
2018
+ ];
2019
+ }
2020
+ }),
2021
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2022
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "An object representing the configuration options for a numeric prompt." }),
2023
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_type_declaration.TypeDeclaration, {
2024
+ name: "NumericConfig",
2025
+ "export": true,
2026
+ children: __alloy_js_core.code`PromptFactoryConfig<number> & NumberPromptConfig; `
2027
+ }),
2028
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2029
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
2030
+ heading: "A function to create and run a numeric prompt, which returns a promise that resolves with the submitted value or rejects with a {@link CANCEL_SYMBOL | cancel symbol} if the prompt is cancelled.",
2031
+ get children() {
2032
+ return [
2033
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocExample, { children: `import { numeric, isCancel } from "shell-shock:prompts";
2034
+
2035
+ async function run() {
2036
+ const age = await numeric({
2037
+ message: "How old are you?",
2038
+ description: "Please enter your age in years",
2039
+ validate: value => value < 21 ? "You must be at least 21 years old" : true,
2040
+ });
2041
+ if (isCancel(age)) {
2042
+ console.log("Prompt was cancelled");
2043
+ return;
2044
+ }
2045
+
2046
+ console.log("Your age is " + age + "!");
2047
+ }
2048
+
2049
+ run(); ` }),
2050
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2051
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
2052
+ name: "config",
2053
+ children: `The configuration options to pass to the numeric prompt, which extends the base PromptFactoryConfig with additional options specific to numeric prompts`
2054
+ }),
2055
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: `A promise that resolves with the submitted value or rejects with a {@link CANCEL_SYMBOL | cancel symbol} if the prompt is cancelled` })
2056
+ ];
2057
+ }
2058
+ }),
2059
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
2060
+ name: "numeric",
2061
+ "export": true,
2062
+ parameters: [{
2063
+ name: "config",
2064
+ type: "NumericConfig"
2065
+ }],
2066
+ returnType: "Promise<number | symbol>",
2067
+ children: __alloy_js_core.code`return new Promise<number | symbol>((response, reject) => {
2068
+ const prompt = new NumberPrompt(config);
2069
+
2070
+ prompt.on("state", state => config.onState?.(state));
2071
+ prompt.on("submit", value => response(value));
2072
+ prompt.on("cancel", event => reject(CANCEL_SYMBOL));
2073
+ });`
2074
+ })
2075
+ ];
2076
+ }
2077
+ /**
2078
+ * A component that renders the declarations for the built-in toggle prompt, which allows users to select a boolean value (true/false) with support for custom messages for the true and false states. This prompt type can be used for scenarios where the user needs to toggle a setting on or off, such as enabling or disabling a feature. The TogglePrompt class extends the base Prompt class and implements specific logic for handling boolean input and rendering interactions.
2079
+ */
2080
+ function TogglePromptDeclarations() {
2081
+ return [
2082
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceDeclaration, {
2083
+ "export": true,
2084
+ name: "TogglePromptConfig",
2085
+ "extends": "PromptConfig<boolean>",
2086
+ doc: "Configuration options for creating a boolean toggle prompt",
2087
+ get children() {
2088
+ return [
2089
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
2090
+ name: "trueMessage",
2091
+ optional: true,
2092
+ type: "string",
2093
+ doc: "The message for the true state of the prompt"
2094
+ }),
2095
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2096
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
2097
+ name: "falseMessage",
2098
+ optional: true,
2099
+ type: "string",
2100
+ doc: "The message for the false state of the prompt"
2101
+ }),
2102
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {})
2103
+ ];
2104
+ }
2105
+ }),
2106
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2107
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassDeclaration, {
2108
+ "export": true,
2109
+ name: "TogglePrompt",
2110
+ doc: "A prompt for toggling a boolean input",
2111
+ "extends": "Prompt<boolean>",
2112
+ get children() {
2113
+ return [
2114
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
2115
+ name: "initialValue",
2116
+ "protected": true,
2117
+ override: true,
2118
+ type: "boolean",
2119
+ children: __alloy_js_core.code`false; `
2120
+ }),
2121
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
2122
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
2123
+ name: "trueMessage",
2124
+ "protected": true,
2125
+ type: "string",
2126
+ children: __alloy_js_core.code`"Yes"; `
2127
+ }),
2128
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
2129
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
2130
+ name: "falseMessage",
2131
+ "protected": true,
2132
+ type: "string",
2133
+ children: __alloy_js_core.code`"No"; `
2134
+ }),
2135
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
2136
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
2137
+ name: "cursorHidden",
2138
+ "protected": true,
2139
+ override: true,
2140
+ type: "boolean",
2141
+ children: __alloy_js_core.code`true; `
2142
+ }),
2143
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2144
+ __alloy_js_core.code`constructor(config: TogglePromptConfig) {
2145
+ super(config);
2146
+
2147
+ if (config.initialValue) {
2148
+ this.initialValue = config.initialValue;
2149
+ }
2150
+
2151
+ if (config.trueMessage) {
2152
+ this.trueMessage = config.trueMessage;
2153
+ }
2154
+ if (config.falseMessage) {
2155
+ this.falseMessage = config.falseMessage;
2156
+ }
2157
+
2158
+ this.sync();
2159
+ } `,
2160
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2161
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
2162
+ doc: "Update the toggle value to a checked state based on user input",
2163
+ name: "check",
2164
+ "protected": true,
2165
+ children: __alloy_js_core.code`if (this.value === true) {
2166
+ return this.bell();
2167
+ }
2168
+
2169
+ this.changeValue(true);
2170
+ this.sync(); `
2171
+ }),
2172
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2173
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
2174
+ doc: "Update the toggle value to an unchecked state based on user input",
2175
+ name: "uncheck",
2176
+ "protected": true,
2177
+ children: __alloy_js_core.code`if (this.value === false) {
2178
+ return this.bell();
2179
+ }
2180
+
2181
+ this.changeValue(false);
2182
+ this.sync(); `
2183
+ }),
2184
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2185
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
2186
+ doc: "A method to handle keypress events and determine the corresponding action",
2187
+ name: "keypress",
2188
+ override: true,
2189
+ "protected": true,
2190
+ parameters: [{
2191
+ name: "char",
2192
+ type: "string"
2193
+ }, {
2194
+ name: "key",
2195
+ type: "readline.Key"
2196
+ }],
2197
+ children: __alloy_js_core.code`const action = this.getAction(key);
2198
+ if (action && typeof (this as any)[action] === "function") {
2199
+ return (this as any)[action]();
2200
+ }
2201
+
2202
+ if (char === " ") {
2203
+ this.changeValue(!this.value);
2204
+ } else if (char === "1") {
2205
+ this.changeValue(true);
2206
+ } else if (char === "0") {
2207
+ this.changeValue(false);
2208
+ } else {
2209
+ return this.bell();
2210
+ }
2211
+
2212
+ this.sync(); `
2213
+ }),
2214
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2215
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
2216
+ doc: "A method to delete the character backward of the cursor",
2217
+ name: "delete",
2218
+ "protected": true,
2219
+ children: __alloy_js_core.code`this.uncheck(); `
2220
+ }),
2221
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2222
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
2223
+ doc: "A method to move the cursor to the left",
2224
+ name: "left",
2225
+ "protected": true,
2226
+ children: __alloy_js_core.code`this.uncheck(); `
2227
+ }),
2228
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2229
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
2230
+ doc: "A method to move the cursor to the right",
2231
+ name: "right",
2232
+ "protected": true,
2233
+ children: __alloy_js_core.code`this.check(); `
2234
+ }),
2235
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2236
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
2237
+ doc: "A method to move the cursor to down",
2238
+ name: "down",
2239
+ "protected": true,
2240
+ children: __alloy_js_core.code`this.uncheck(); `
2241
+ }),
2242
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2243
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
2244
+ doc: "A method to move the cursor to up",
2245
+ name: "up",
2246
+ "protected": true,
2247
+ children: __alloy_js_core.code`this.check(); `
2248
+ }),
2249
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2250
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
2251
+ doc: "A method to move to the next value",
2252
+ name: "next",
2253
+ "protected": true,
2254
+ children: __alloy_js_core.code`this.changeValue(!this.value);
2255
+ this.sync(); `
2256
+ }),
2257
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2258
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
2259
+ doc: "A method to render the prompt",
2260
+ name: "render",
2261
+ override: true,
2262
+ "protected": true,
2263
+ returnType: "string",
2264
+ children: __alloy_js_core.code`return this.isSubmitted
2265
+ ? colors.text.prompt.input.submitted(this.value ? this.trueMessage : this.falseMessage)
2266
+ : this.isCancelled
2267
+ ? colors.text.prompt.input.cancelled(this.value ? this.trueMessage : this.falseMessage)
2268
+ : \`\${
2269
+ this.value ? colors.text.prompt.input.inactive(this.falseMessage) : colors.underline(colors.bold(colors.text.prompt.input.active(this.falseMessage)))
2270
+ } \${colors.border.app.divider.tertiary("/")} \${
2271
+ this.value ? colors.underline(colors.bold(colors.text.prompt.input.active(this.trueMessage))) : colors.text.prompt.input.inactive(this.trueMessage)
2272
+ }\`; `
2273
+ })
2274
+ ];
2275
+ }
2276
+ }),
2277
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2278
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "An object representing the configuration options for a toggle prompt, which extends the base PromptFactoryConfig with additional options specific to the toggle prompt." }),
2279
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_type_declaration.TypeDeclaration, {
2280
+ name: "ToggleConfig",
2281
+ "export": true,
2282
+ children: __alloy_js_core.code`PromptFactoryConfig<boolean> & TogglePromptConfig; `
2283
+ }),
2284
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2285
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
2286
+ heading: "A function to create and run a toggle prompt, which returns a promise that resolves with the submitted value or rejects with a {@link CANCEL_SYMBOL | cancel symbol} if the prompt is cancelled.",
2287
+ get children() {
2288
+ return [
2289
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocExample, { children: `import { toggle, isCancel } from "shell-shock:prompts";
2290
+
2291
+ async function run() {
2292
+ const likesIceCream = await toggle({
2293
+ message: "Do you like ice cream?"
2294
+ });
2295
+ if (isCancel(likesIceCream)) {
2296
+ console.log("Prompt was cancelled");
2297
+ return;
2298
+ }
2299
+
2300
+ console.log("You" + (likesIceCream ? " like ice cream" : " don't like ice cream") + "!");
2301
+ }
2302
+
2303
+ run(); ` }),
2304
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2305
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
2306
+ name: "config",
2307
+ children: `The configuration options to pass to the toggle prompt, which extends the base PromptFactoryConfig with additional options specific to the toggle prompt`
2308
+ }),
2309
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: `A promise that resolves with the submitted value or rejects with a {@link CANCEL_SYMBOL | cancel symbol} if the prompt is cancelled` })
2310
+ ];
2311
+ }
2312
+ }),
2313
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
2314
+ name: "toggle",
2315
+ "export": true,
2316
+ parameters: [{
2317
+ name: "config",
2318
+ type: "ToggleConfig"
2319
+ }],
2320
+ returnType: "Promise<boolean | symbol>",
2321
+ children: __alloy_js_core.code`return new Promise<boolean | symbol>((response, reject) => {
2322
+ const prompt = new TogglePrompt(config);
2323
+
2324
+ prompt.on("state", state => config.onState?.(state));
2325
+ prompt.on("submit", value => response(value));
2326
+ prompt.on("cancel", event => reject(CANCEL_SYMBOL));
2327
+ });`
2328
+ })
2329
+ ];
2330
+ }
2331
+ /**
2332
+ * A component that renders the declarations for the built-in confirm prompt, which allows users to select a boolean value (true/false) with support for custom messages for the true and false states. This prompt type can be used for scenarios where the user needs to toggle a setting on or off, such as enabling or disabling a feature. The ConfirmPrompt class extends the base Prompt class and implements specific logic for handling boolean input and rendering interactions.
2333
+ */
2334
+ function ConfirmPromptDeclarations() {
2335
+ return [
2336
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceDeclaration, {
2337
+ "export": true,
2338
+ name: "ConfirmPromptConfig",
2339
+ "extends": "PromptConfig<boolean>",
2340
+ doc: "Configuration options for creating a boolean confirm prompt",
2341
+ get children() {
2342
+ return [
2343
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
2344
+ heading: "The message for the \\`Yes\\` state of the prompt",
2345
+ get children() {
2346
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocDefaultValue, {
2347
+ get type() {
2348
+ return __powerlines_deepkit_vendor_type.ReflectionKind.string;
2349
+ },
2350
+ defaultValue: "Yes"
2351
+ });
2352
+ }
2353
+ }),
2354
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
2355
+ name: "yesMessage",
2356
+ optional: true,
2357
+ type: "string"
2358
+ }),
2359
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2360
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
2361
+ heading: "The \\`Yes\\` option when choosing between yes/no",
2362
+ get children() {
2363
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocDefaultValue, {
2364
+ get type() {
2365
+ return __powerlines_deepkit_vendor_type.ReflectionKind.string;
2366
+ },
2367
+ defaultValue: "1"
2368
+ });
2369
+ }
2370
+ }),
2371
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
2372
+ name: "yesOption",
2373
+ optional: true,
2374
+ type: "string"
2375
+ }),
2376
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2377
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
2378
+ heading: "The message for the \\`No\\` state of the prompt",
2379
+ get children() {
2380
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocDefaultValue, {
2381
+ get type() {
2382
+ return __powerlines_deepkit_vendor_type.ReflectionKind.string;
2383
+ },
2384
+ defaultValue: "(Y/n)"
2385
+ });
2386
+ }
2387
+ }),
2388
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
2389
+ name: "noMessage",
2390
+ optional: true,
2391
+ type: "string"
2392
+ }),
2393
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2394
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
2395
+ heading: "The \\`No\\` option when choosing between yes/no",
2396
+ get children() {
2397
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocDefaultValue, {
2398
+ get type() {
2399
+ return __powerlines_deepkit_vendor_type.ReflectionKind.string;
2400
+ },
2401
+ defaultValue: "(y/N)"
2402
+ });
2403
+ }
2404
+ }),
2405
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_interface_declaration.InterfaceMember, {
2406
+ name: "noOption",
2407
+ optional: true,
2408
+ type: "string"
2409
+ })
2410
+ ];
2411
+ }
2412
+ }),
2413
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2414
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassDeclaration, {
2415
+ "export": true,
2416
+ name: "ConfirmPrompt",
2417
+ doc: "A prompt for confirming a boolean input",
2418
+ "extends": "Prompt<boolean>",
2419
+ get children() {
2420
+ return [
2421
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
2422
+ name: "initialValue",
2423
+ "protected": true,
2424
+ override: true,
2425
+ type: "boolean",
2426
+ children: __alloy_js_core.code`false; `
2427
+ }),
2428
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
2429
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
2430
+ name: "yesMessage",
2431
+ "protected": true,
2432
+ type: "string",
2433
+ children: __alloy_js_core.code`"Yes"; `
2434
+ }),
2435
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
2436
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
2437
+ name: "yesOption",
2438
+ "protected": true,
2439
+ type: "string",
2440
+ children: __alloy_js_core.code`"(Y/n)"; `
2441
+ }),
2442
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
2443
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
2444
+ name: "noMessage",
2445
+ "protected": true,
2446
+ type: "string",
2447
+ children: __alloy_js_core.code`"No"; `
2448
+ }),
2449
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
2450
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
2451
+ name: "noOption",
2452
+ "protected": true,
2453
+ type: "string",
2454
+ children: __alloy_js_core.code`"(y/N)"; `
2455
+ }),
2456
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
2457
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
2458
+ name: "cursorHidden",
2459
+ "protected": true,
2460
+ override: true,
2461
+ type: "boolean",
2462
+ children: __alloy_js_core.code`true; `
2463
+ }),
2464
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2465
+ __alloy_js_core.code`constructor(config: ConfirmPromptConfig) {
2466
+ super(config);
2467
+
2468
+ if (config.initialValue) {
2469
+ this.initialValue = config.initialValue;
2470
+ }
2471
+
2472
+ if (config.yesMessage) {
2473
+ this.yesMessage = config.yesMessage;
2474
+ }
2475
+ if (config.yesOption) {
2476
+ this.yesOption = config.yesOption;
2477
+ }
2478
+ if (config.noMessage) {
2479
+ this.noMessage = config.noMessage;
2480
+ }
2481
+ if (config.noOption) {
2482
+ this.noOption = config.noOption;
2483
+ }
2484
+
2485
+ this.sync();
2486
+ } `,
2487
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2488
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
2489
+ doc: "A method to handle keypress events and determine the corresponding action",
2490
+ name: "keypress",
2491
+ override: true,
2492
+ "protected": true,
2493
+ parameters: [{
2494
+ name: "char",
2495
+ type: "string"
2496
+ }, {
2497
+ name: "key",
2498
+ type: "readline.Key"
2499
+ }],
2500
+ children: __alloy_js_core.code`const action = this.getAction(key);
2501
+ if (action && typeof (this as any)[action] === "function") {
2502
+ return (this as any)[action]();
2503
+ }
2504
+
2505
+ if (char.toLowerCase() === "y" || char.toLowerCase() === "t" || char.toLowerCase() === "0") {
2506
+ this.value = true;
2507
+ return this.submit();
2508
+ } else if (char.toLowerCase() === "n" || char.toLowerCase() === "f" || char.toLowerCase() === "1") {
2509
+ this.value = false;
2510
+ return this.submit();
2511
+ } else {
2512
+ return this.bell();
2513
+ }
2514
+
2515
+ this.sync(); `
2516
+ }),
2517
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2518
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
2519
+ doc: "A method to render the prompt",
2520
+ name: "render",
2521
+ override: true,
2522
+ "protected": true,
2523
+ returnType: "string",
2524
+ children: __alloy_js_core.code`return this.isSubmitted
2525
+ ? colors.text.prompt.input.submitted(this.value ? this.yesMessage : this.noMessage)
2526
+ : this.isCancelled
2527
+ ? colors.text.prompt.input.cancelled(this.value ? this.yesMessage : this.noMessage)
2528
+ : colors.text.prompt.input.inactive(this.initialValue ? this.yesOption : this.noOption); `
2529
+ })
2530
+ ];
2531
+ }
2532
+ }),
2533
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2534
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "An object representing the configuration options for a confirm prompt, which extends the base PromptFactoryConfig with additional options specific to the confirm prompt." }),
2535
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_type_declaration.TypeDeclaration, {
2536
+ name: "ConfirmConfig",
2537
+ "export": true,
2538
+ children: __alloy_js_core.code`PromptFactoryConfig<boolean> & ConfirmPromptConfig; `
2539
+ }),
2540
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2541
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
2542
+ heading: "A function to create and run a confirm prompt, which returns a promise that resolves with the submitted value or rejects with a {@link CANCEL_SYMBOL | cancel symbol} if the prompt is cancelled.",
2543
+ get children() {
2544
+ return [
2545
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocExample, { children: `import { confirm, isCancel } from "shell-shock:prompts";
2546
+
2547
+ async function run() {
2548
+ const likesIceCream = await confirm({
2549
+ message: "Do you like ice cream?"
2550
+ });
2551
+ if (isCancel(likesIceCream)) {
2552
+ console.log("Prompt was cancelled");
2553
+ return;
2554
+ }
2555
+
2556
+ console.log("You" + (likesIceCream ? " like ice cream" : " don't like ice cream") + "!");
2557
+ }
2558
+
2559
+ run(); ` }),
2560
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2561
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
2562
+ name: "config",
2563
+ children: `The configuration options to pass to the confirm prompt, which extends the base PromptFactoryConfig with additional options specific to the confirm prompt`
2564
+ }),
2565
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: `A promise that resolves with the submitted value or rejects with a {@link CANCEL_SYMBOL | cancel symbol} if the prompt is cancelled` })
2566
+ ];
2567
+ }
2568
+ }),
2569
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
2570
+ name: "confirm",
2571
+ "export": true,
2572
+ parameters: [{
2573
+ name: "config",
2574
+ type: "ConfirmConfig"
2575
+ }],
2576
+ returnType: "Promise<boolean | symbol>",
2577
+ children: __alloy_js_core.code`return new Promise<boolean | symbol>((response, reject) => {
2578
+ const prompt = new ConfirmPrompt(config);
2579
+
2580
+ prompt.on("state", state => config.onState?.(state));
2581
+ prompt.on("submit", value => response(value));
2582
+ prompt.on("cancel", event => reject(CANCEL_SYMBOL));
2583
+ }); `
2584
+ })
2585
+ ];
2586
+ }
2587
+ /**
2588
+ * Declarations for a password prompt that allows users to input and edit text, with support for cursor movement, deletion, and custom masking. This prompt type can be used for various text input scenarios, such as entering a password or any other string input. The PasswordPrompt class extends the base Prompt class and implements specific logic for handling password input and editing interactions.
2589
+ */
2590
+ function PasswordPromptDeclaration() {
2591
+ return [
2592
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
2593
+ "export": true,
2594
+ name: "passwordMask",
2595
+ doc: "A built-in prompt mask function that masks input with asterisks",
2596
+ parameters: [{
2597
+ name: "input",
2598
+ type: "string"
2599
+ }],
2600
+ returnType: "string",
2601
+ children: __alloy_js_core.code`return "*".repeat(input.length); `
2602
+ }),
2603
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2604
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "An object representing the configuration options for a password prompt, which extends the base PromptFactoryConfig with additional options specific to password prompts." }),
2605
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_type_declaration.TypeDeclaration, {
2606
+ name: "PasswordConfig",
2607
+ "export": true,
2608
+ children: __alloy_js_core.code`Omit<TextConfig, "mask" | "maskSubmitted">; `
2609
+ }),
2610
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2611
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
2612
+ heading: "A function to create and run a password prompt, which returns a promise that resolves with the submitted value or rejects with a {@link CANCEL_SYMBOL | cancel symbol} if the prompt is cancelled.",
2613
+ get children() {
2614
+ return [
2615
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocRemarks, { children: __alloy_js_core.code`This function creates an instance of the TextPrompt class with the provided configuration options and a custom mask function to handle password input. It sets up event listeners for state updates, submission, and cancellation to handle the prompt interactions and return the appropriate results. The password prompt allows users to input text that is masked for privacy, making it suitable for scenarios like entering passwords or sensitive information.` }),
2616
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2617
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocExample, { children: `import { password, isCancel } from "shell-shock:prompts";
2618
+
2619
+ async function run() {
2620
+ const userPassword = await password({
2621
+ message: "Enter your password"
2622
+ });
2623
+ if (isCancel(userPassword)) {
2624
+ console.log("Prompt was cancelled");
2625
+ return;
2626
+ }
2627
+
2628
+ console.log("You entered a password!");
2629
+ }
2630
+
2631
+ run(); ` }),
2632
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2633
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
2634
+ name: "config",
2635
+ children: `The configuration options to pass to the password prompt, which extends the base PromptConfig with additional options specific to password prompts`
2636
+ }),
2637
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: `A promise that resolves with the submitted value or rejects with a {@link CANCEL_SYMBOL | cancel symbol} if the prompt is cancelled` })
2638
+ ];
2639
+ }
2640
+ }),
2641
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
2642
+ name: "password",
2643
+ "export": true,
2644
+ parameters: [{
2645
+ name: "config",
2646
+ type: "PasswordConfig"
2647
+ }],
2648
+ returnType: "Promise<string | symbol>",
2649
+ children: __alloy_js_core.code`return text({
2650
+ ...config,
2651
+ mask: passwordMask,
2652
+ maskSubmitted: () => "*******"
2653
+ });`
2654
+ })
2655
+ ];
2656
+ }
2657
+ /**
2658
+ * A built-in prompts module for Shell Shock.
2659
+ */
2660
+ function PromptsBuiltin(props) {
2661
+ const [{ children }, rest] = (0, __alloy_js_core.splitProps)(props, ["children"]);
2662
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_builtin_file.BuiltinFile, (0, __alloy_js_core_jsx_runtime.mergeProps)({
2663
+ id: "prompts",
2664
+ description: "A collection of prompts that allow for interactive input in command-line applications."
2665
+ }, rest, {
2666
+ get imports() {
2667
+ return (0, defu.default)(rest.imports ?? {}, {
2668
+ "node:events": "EventEmitter",
2669
+ "node:readline": "readline"
2670
+ });
2671
+ },
2672
+ get builtinImports() {
2673
+ return (0, defu.default)(rest.builtinImports ?? {}, {
2674
+ console: [
2675
+ "erase",
2676
+ "beep",
2677
+ "cursor",
2678
+ "colors",
2679
+ "clear",
2680
+ "stripAnsi",
2681
+ "splitText"
2682
+ ],
2683
+ env: [
2684
+ "env",
2685
+ "isCI",
2686
+ "isTest",
2687
+ "isWindows",
2688
+ "isDevelopment",
2689
+ "isDebug"
2690
+ ]
2691
+ });
2692
+ },
2693
+ get children() {
2694
+ return [
2695
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2696
+ (0, __alloy_js_core_jsx_runtime.createComponent)(BasePromptDeclarations, {}),
2697
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2698
+ (0, __alloy_js_core_jsx_runtime.createComponent)(TextPromptDeclarations, {}),
2699
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2700
+ (0, __alloy_js_core_jsx_runtime.createComponent)(SelectPromptDeclarations, {}),
2701
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2702
+ (0, __alloy_js_core_jsx_runtime.createComponent)(NumericPromptDeclarations, {}),
2703
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2704
+ (0, __alloy_js_core_jsx_runtime.createComponent)(TogglePromptDeclarations, {}),
2705
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2706
+ (0, __alloy_js_core_jsx_runtime.createComponent)(PasswordPromptDeclaration, {}),
2707
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2708
+ (0, __alloy_js_core_jsx_runtime.createComponent)(ConfirmPromptDeclarations, {}),
2709
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
2710
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
2711
+ get when() {
2712
+ return Boolean(children);
2713
+ },
2714
+ children
2715
+ })
2716
+ ];
2717
+ }
2718
+ }));
2719
+ }
2720
+
2721
+ //#endregion
2722
+ exports.BasePromptDeclarations = BasePromptDeclarations;
2723
+ exports.ConfirmPromptDeclarations = ConfirmPromptDeclarations;
2724
+ exports.NumericPromptDeclarations = NumericPromptDeclarations;
2725
+ exports.PasswordPromptDeclaration = PasswordPromptDeclaration;
2726
+ exports.PromptsBuiltin = PromptsBuiltin;
2727
+ exports.SelectPromptDeclarations = SelectPromptDeclarations;
2728
+ exports.TextPromptDeclarations = TextPromptDeclarations;
2729
+ exports.TogglePromptDeclarations = TogglePromptDeclarations;