@shell-shock/plugin-prompts 0.3.49 → 0.3.51

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