1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | import { Interface as ReadlineInterface } from 'readline';
|
17 | import { Observable } from 'rxjs';
|
18 | import Choice = require('./lib/objects/choice');
|
19 | import Choices = require('./lib/objects/choices');
|
20 | import Separator = require('./lib/objects/separator');
|
21 | import './lib/prompts/base';
|
22 | import './lib/prompts/checkbox';
|
23 | import './lib/prompts/confirm';
|
24 | import './lib/prompts/editor';
|
25 | import './lib/prompts/expand';
|
26 | import './lib/prompts/input';
|
27 | import './lib/prompts/list';
|
28 | import './lib/prompts/number';
|
29 | import './lib/prompts/password';
|
30 | import './lib/prompts/rawlist';
|
31 | import './lib/utils/events';
|
32 | import './lib/utils/paginator';
|
33 | import './lib/utils/readline';
|
34 | import './lib/utils/screen-manager';
|
35 | import './lib/utils/utils';
|
36 | import BottomBar = require('./lib/ui/bottom-bar');
|
37 | import PromptUI = require('./lib/ui/prompt');
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | type LiteralUnion<T extends F, F = string> = T | (F & {});
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | interface PromptModuleBase {
|
54 | |
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | registerPrompt(name: string, prompt: inquirer.prompts.PromptConstructor): void;
|
64 |
|
65 | |
66 |
|
67 |
|
68 | restoreDefaultPrompts(): void;
|
69 | }
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 | interface ListQuestionOptionsBase<T extends inquirer.Answers, TChoiceMap extends inquirer.Answers> extends inquirer.Question<T> {
|
81 | |
82 |
|
83 |
|
84 | choices?: inquirer.AsyncDynamicQuestionProperty<ReadonlyArray<inquirer.DistinctChoice<TChoiceMap>>, T> | undefined;
|
85 |
|
86 | |
87 |
|
88 |
|
89 | pageSize?: number | undefined;
|
90 | }
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | declare namespace inquirer {
|
96 | |
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 | type KeyUnion<T> = LiteralUnion<Extract<keyof T, string>>;
|
103 |
|
104 | |
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 | type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
111 |
|
112 | |
113 |
|
114 |
|
115 | interface StreamOptions {
|
116 | |
117 |
|
118 |
|
119 | input?: NodeJS.ReadStream | undefined;
|
120 |
|
121 | |
122 |
|
123 |
|
124 | output?: NodeJS.WriteStream | undefined;
|
125 | }
|
126 |
|
127 | |
128 |
|
129 |
|
130 | interface PromptModule extends PromptModuleBase {
|
131 | |
132 |
|
133 |
|
134 | prompts: prompts.PromptCollection;
|
135 |
|
136 | |
137 |
|
138 |
|
139 | <T extends Answers = Answers>(questions: QuestionCollection<T>, initialAnswers?: Partial<T>): Promise<T> & { ui: PromptUI<T> };
|
140 |
|
141 | |
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 | registerPrompt(name: string, prompt: prompts.PromptConstructor): this;
|
151 | }
|
152 |
|
153 | interface Inquirer extends PromptModuleBase {
|
154 | |
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 | registerPrompt(name: string, prompt: prompts.PromptConstructor): void;
|
164 |
|
165 | |
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 | createPromptModule(opt?: StreamOptions): PromptModule;
|
175 |
|
176 | |
177 |
|
178 |
|
179 | prompt: PromptModule;
|
180 |
|
181 | |
182 |
|
183 |
|
184 |
|
185 |
|
186 | prompts: {};
|
187 |
|
188 | |
189 |
|
190 |
|
191 | Separator: typeof Separator;
|
192 |
|
193 | |
194 |
|
195 |
|
196 | ui: {
|
197 | |
198 |
|
199 |
|
200 | BottomBar: typeof BottomBar;
|
201 |
|
202 | |
203 |
|
204 |
|
205 | Prompt: typeof PromptUI;
|
206 | };
|
207 | }
|
208 |
|
209 | |
210 |
|
211 |
|
212 | interface Answers extends Record<string, any> {}
|
213 |
|
214 | |
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 | type Validator<T extends Answers = Answers> = Question<T>['validate'];
|
221 |
|
222 | |
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 | type Transformer<T extends Answers = Answers> = InputQuestionOptions<T>['transformer'];
|
229 |
|
230 | |
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 | type DynamicQuestionProperty<T, TAnswers extends Answers = Answers> = T | ((answers: TAnswers) => T);
|
240 |
|
241 | /**
|
242 | * Represents a dynamic property for a question which can be fetched asynchronously.
|
243 | *
|
244 | * @template T
|
245 | * The type of the property.
|
246 | *
|
247 | * @template TAnswers
|
248 | * The type of the answers.
|
249 | */
|
250 | type AsyncDynamicQuestionProperty<T, TAnswers extends Answers = Answers> = DynamicQuestionProperty<
|
251 | T | Promise<T>,
|
252 | TAnswers
|
253 | >;
|
254 |
|
255 | /**
|
256 | * Provides options for a question.
|
257 | *
|
258 | * @template T
|
259 | * The type of the answers.
|
260 | */
|
261 | interface Question<T extends Answers = Answers> {
|
262 | /**
|
263 | * The type of the question.
|
264 | */
|
265 | type?: string | undefined;
|
266 |
|
267 | /**
|
268 | * The key to save the answer to the answers-hash.
|
269 | */
|
270 | name?: KeyUnion<T> | undefined;
|
271 |
|
272 | /**
|
273 | * The message to show to the user.
|
274 | */
|
275 | message?: AsyncDynamicQuestionProperty<string, T> | undefined;
|
276 |
|
277 | /**
|
278 | * The default value of the question.
|
279 | */
|
280 | default?: AsyncDynamicQuestionProperty<any, T> | undefined;
|
281 |
|
282 | /**
|
283 | * The prefix of the `message`.
|
284 | */
|
285 | prefix?: string | undefined;
|
286 |
|
287 | /**
|
288 | * The suffix of the `message`.
|
289 | */
|
290 | suffix?: string | undefined;
|
291 |
|
292 | /**
|
293 | * Post-processes the answer.
|
294 | *
|
295 | * @param input
|
296 | * The answer provided by the user.
|
297 | *
|
298 | * @param answers
|
299 | * The answers provided by the user.
|
300 | */
|
301 | filter?(input: any, answers: T): any;
|
302 |
|
303 | /**
|
304 | * A value indicating whether the question should be prompted.
|
305 | */
|
306 | when?: AsyncDynamicQuestionProperty<boolean, T> | undefined;
|
307 |
|
308 | /**
|
309 | * Validates the integrity of the answer.
|
310 | *
|
311 | * @param input
|
312 | * The answer provided by the user.
|
313 | *
|
314 | * @param answers
|
315 | * The answers provided by the user.
|
316 | *
|
317 | * @returns
|
318 | * Either a value indicating whether the answer is valid or a `string` which describes the error.
|
319 | */
|
320 | validate?(input: any, answers?: T): boolean | string | Promise<boolean | string>;
|
321 |
|
322 | /**
|
323 | * Force to prompt the question if the answer already exists.
|
324 | */
|
325 | askAnswered?: boolean;
|
326 | }
|
327 |
|
328 | /**
|
329 | * Represents the possible answers of each question in the prompt
|
330 | */
|
331 | type QuestionAnswer<T extends Answers = Answers> = {
|
332 | [K in keyof T]: {
|
333 | name: K;
|
334 | answer: T[K]
|
335 | }
|
336 | }[keyof T];
|
337 |
|
338 | /**
|
339 | * Represents a choice-item.
|
340 | */
|
341 | interface ChoiceBase {
|
342 | /**
|
343 | * The type of the choice.
|
344 | */
|
345 | type?: string | undefined;
|
346 | }
|
347 |
|
348 | /**
|
349 | * Provides options for a choice.
|
350 | */
|
351 | interface ChoiceOptions extends ChoiceBase {
|
352 | /**
|
353 | * @inheritdoc
|
354 | */
|
355 | type?: 'choice' | undefined;
|
356 |
|
357 | /**
|
358 | * The name of the choice to show to the user.
|
359 | */
|
360 | name?: string | undefined;
|
361 |
|
362 | /**
|
363 | * The value of the choice.
|
364 | */
|
365 | value?: any;
|
366 |
|
367 | /**
|
368 | * The short form of the name of the choice.
|
369 | */
|
370 | short?: string | undefined;
|
371 |
|
372 | /**
|
373 | * The extra properties of the choice.
|
374 | */
|
375 | extra?: any;
|
376 | }
|
377 |
|
378 | /**
|
379 | * Provides options for a choice of the `ListPrompt`.
|
380 | *
|
381 | * @template T
|
382 | * The type of the answers.
|
383 | */
|
384 | interface ListChoiceOptions<T extends Answers = Answers> extends ChoiceOptions {
|
385 | /**
|
386 | * A value indicating whether the choice is disabled.
|
387 | */
|
388 | disabled?: DynamicQuestionProperty<boolean | string, T> | undefined;
|
389 | }
|
390 |
|
391 | /**
|
392 | * Provides options for a choice of the `CheckboxPrompt`.
|
393 | *
|
394 | * @template T
|
395 | * The type of the answers.
|
396 | */
|
397 | interface CheckboxChoiceOptions<T extends Answers = Answers> extends ListChoiceOptions<T> {
|
398 | /**
|
399 | * A value indicating whether the choice should be initially checked.
|
400 | */
|
401 | checked?: boolean | undefined;
|
402 | }
|
403 |
|
404 | /**
|
405 | * Provides options for a choice of the `ExpandPrompt`.
|
406 | */
|
407 | interface ExpandChoiceOptions extends ChoiceOptions {
|
408 | /**
|
409 | * The key to press for selecting the choice.
|
410 | */
|
411 | key?: string | undefined;
|
412 | }
|
413 |
|
414 | /**
|
415 | * Represents a separator.
|
416 | */
|
417 | interface SeparatorOptions extends ChoiceBase {
|
418 | /**
|
419 | * Gets the type of the choice.
|
420 | */
|
421 | type: 'separator';
|
422 |
|
423 | /**
|
424 | * Gets or sets the text of the separator.
|
425 | */
|
426 | line?: string | undefined;
|
427 | }
|
428 |
|
429 | /**
|
430 | * Provides all valid choice-types for any kind of question.
|
431 | *
|
432 | * @template T
|
433 | * The type of the answers.
|
434 | */
|
435 | interface BaseChoiceMap<T extends Answers = Answers> {
|
436 | Choice: Choice<T>;
|
437 | ChoiceOptions: ChoiceOptions;
|
438 | SeparatorOptions: SeparatorOptions;
|
439 | Separator: Separator;
|
440 | }
|
441 |
|
442 | /**
|
443 | * Provides all valid choice-types for the `ListQuestion`.
|
444 | *
|
445 | * @template T
|
446 | * The type of the answers.
|
447 | */
|
448 | interface ListChoiceMap<T extends Answers = Answers> extends BaseChoiceMap<T> {
|
449 | ListChoiceOptions: ListChoiceOptions<T>;
|
450 | }
|
451 |
|
452 | /**
|
453 | * Provides all valid choice-types for the `CheckboxQuestion`.
|
454 | *
|
455 | * @template T
|
456 | * The type of the answers.
|
457 | */
|
458 | interface CheckboxChoiceMap<T extends Answers = Answers> extends BaseChoiceMap<T> {
|
459 | CheckboxChoiceOptions: CheckboxChoiceOptions<T>;
|
460 | }
|
461 |
|
462 | /**
|
463 | * Provides all valid choice-types for the `ExpandQuestion`.
|
464 | *
|
465 | * @template T
|
466 | * The type of the answers.
|
467 | */
|
468 | interface ExpandChoiceMap<T extends Answers = Answers> extends BaseChoiceMap<T> {
|
469 | ExpandChoiceOptions: ExpandChoiceOptions;
|
470 | }
|
471 |
|
472 | /**
|
473 | * Provides all valid choice-types.
|
474 | *
|
475 | * @template T
|
476 | * The type of the answers.
|
477 | */
|
478 | interface AllChoiceMap<T extends Answers = Answers> {
|
479 | BaseChoiceMap: BaseChoiceMap<T>[keyof BaseChoiceMap<T>];
|
480 | ListChoiceMap: ListChoiceMap<T>[keyof ListChoiceMap<T>];
|
481 | CheckboxChoiceMap: CheckboxChoiceMap<T>[keyof CheckboxChoiceMap<T>];
|
482 | ExpandChoiceMap: ExpandChoiceMap<T>[keyof ExpandChoiceMap<T>];
|
483 | }
|
484 |
|
485 | /**
|
486 | * Provides valid choices for the question of the `TChoiceMap`.
|
487 | *
|
488 | * @template TAnswers
|
489 | * The type of the answers.
|
490 | *
|
491 | * @template TChoiceMap
|
492 | * The choice-types to provide.
|
493 | */
|
494 | type DistinctChoice<TAnswers extends Answers = Answers, TChoiceMap = AllChoiceMap<TAnswers>> =
|
495 | | string
|
496 | | TChoiceMap[keyof TChoiceMap];
|
497 |
|
498 | /**
|
499 | * Represents a set of choices.
|
500 | *
|
501 | * @template T
|
502 | * The type of the answers.
|
503 | */
|
504 | type ChoiceCollection<T extends Answers = Answers> = Array<DistinctChoice<AllChoiceMap<T>>>;
|
505 |
|
506 | /**
|
507 | * Provides options for a question for the `InputPrompt`.
|
508 | *
|
509 | * @template T
|
510 | * The type of the answers.
|
511 | */
|
512 | interface InputQuestionOptions<T extends Answers = Answers> extends Question<T> {
|
513 | /**
|
514 | * Transforms the value to display to the user.
|
515 | *
|
516 | * @param input
|
517 | * The input provided by the user.
|
518 | *
|
519 | * @param answers
|
520 | * The answers provided by the users.
|
521 | *
|
522 | * @param flags
|
523 | * Additional information about the value.
|
524 | *
|
525 | * @returns
|
526 | * The value to display to the user.
|
527 | */
|
528 | transformer?(input: any, answers: T, flags: { isFinal?: boolean | undefined }): string | Promise<string>;
|
529 | }
|
530 |
|
531 | /**
|
532 | * Provides options for a question for the `InputPrompt`.
|
533 | *
|
534 | * @template T
|
535 | * The type of the answers.
|
536 | */
|
537 | interface InputQuestion<T extends Answers = Answers> extends InputQuestionOptions<T> {
|
538 | /**
|
539 | * @inheritdoc
|
540 | */
|
541 | type?: 'input' | undefined;
|
542 | }
|
543 |
|
544 | /**
|
545 | * Provides options for a question for the `NumberPrompt`.
|
546 | *
|
547 | * @template T
|
548 | * The type of the answers.
|
549 | */
|
550 | interface NumberQuestionOptions<T extends Answers = Answers> extends InputQuestionOptions<T> {}
|
551 |
|
552 | /**
|
553 | * Provides options for a question for the `NumberPrompt`.
|
554 | *
|
555 | * @template T
|
556 | * The type of the answers.
|
557 | */
|
558 | interface NumberQuestion<T extends Answers = Answers> extends NumberQuestionOptions<T> {
|
559 | /**
|
560 | * @inheritdoc
|
561 | */
|
562 | type: 'number';
|
563 | }
|
564 |
|
565 | /**
|
566 | * Provides options for a question for the `PasswordPrompt`.
|
567 | *
|
568 | * @template T
|
569 | * The type of the answers.
|
570 | */
|
571 | interface PasswordQuestionOptions<T extends Answers = Answers> extends InputQuestionOptions<T> {
|
572 | /**
|
573 | * The character to replace the user-input.
|
574 | */
|
575 | mask?: string | undefined;
|
576 | }
|
577 |
|
578 | /**
|
579 | * Provides options for a question for the `PasswordPrompt`.
|
580 | *
|
581 | * @template T
|
582 | * The type of the answers.
|
583 | */
|
584 | interface PasswordQuestion<T extends Answers = Answers> extends PasswordQuestionOptions<T> {
|
585 | /**
|
586 | * @inheritdoc
|
587 | */
|
588 | type: 'password';
|
589 | }
|
590 |
|
591 | /**
|
592 | * Represents a list-based question that can loop.
|
593 | *
|
594 | * @template T
|
595 | * The type of the answers.
|
596 | *
|
597 | * @template TChoiceMap
|
598 | * The valid choices for the question.
|
599 | */
|
600 | interface LoopableListQuestionOptionsBase<T extends Answers, TChoiceMap extends Answers> extends ListQuestionOptionsBase<T, TChoiceMap> {
|
601 | /**
|
602 | * A value indicating whether choices in a list should be looped.
|
603 | */
|
604 | loop?: boolean | undefined;
|
605 | }
|
606 |
|
607 | /**
|
608 | * Provides options for a question for the `ListPrompt`.
|
609 | *
|
610 | * @template T
|
611 | * The type of the answers.
|
612 | */
|
613 | interface ListQuestionOptions<T extends Answers = Answers>
|
614 | extends LoopableListQuestionOptionsBase<T, ListChoiceMap<T>> {}
|
615 |
|
616 | /**
|
617 | * Provides options for a question for the `ListPrompt`.
|
618 | *
|
619 | * @template T
|
620 | * The type of the answers.
|
621 | */
|
622 | interface ListQuestion<T extends Answers = Answers> extends ListQuestionOptions<T> {
|
623 | /**
|
624 | * @inheritdoc
|
625 | */
|
626 | type: 'list';
|
627 | }
|
628 |
|
629 | /**
|
630 | * Provides options for a question for the `RawListPrompt`.
|
631 | *
|
632 | * @template T
|
633 | * The type of the answers.
|
634 | */
|
635 | interface RawListQuestionOptions<T extends Answers = Answers> extends ListQuestionOptions<T> {}
|
636 |
|
637 | /**
|
638 | * Provides options for a question for the `RawListPrompt`.
|
639 | *
|
640 | * @template T
|
641 | * The type of the answers.
|
642 | */
|
643 | interface RawListQuestion<T extends Answers = Answers> extends RawListQuestionOptions<T> {
|
644 | /**
|
645 | * @inheritdoc
|
646 | */
|
647 | type: 'rawlist';
|
648 | }
|
649 |
|
650 | /**
|
651 | * Provides options for a question for the `ExpandPrompt`.
|
652 | *
|
653 | * @template T
|
654 | * The type of the answers.
|
655 | */
|
656 | interface ExpandQuestionOptions<T extends Answers = Answers>
|
657 | extends ListQuestionOptionsBase<T, ExpandChoiceMap<T>> {}
|
658 |
|
659 | /**
|
660 | * Provides options for a question for the `ExpandPrompt`.
|
661 | *
|
662 | * @template T
|
663 | * The type of the answers.
|
664 | */
|
665 | interface ExpandQuestion<T extends Answers = Answers> extends ExpandQuestionOptions<T> {
|
666 | /**
|
667 | * @inheritdoc
|
668 | */
|
669 | type: 'expand';
|
670 | }
|
671 |
|
672 | /**
|
673 | * Provides options for a question for the `CheckboxPrompt`.
|
674 | *
|
675 | * @template T
|
676 | * The type of the answers.
|
677 | */
|
678 | interface CheckboxQuestionOptions<T extends Answers = Answers>
|
679 | extends LoopableListQuestionOptionsBase<T, CheckboxChoiceMap<T>> {}
|
680 |
|
681 | /**
|
682 | * Provides options for a question for the `CheckboxPrompt`.
|
683 | *
|
684 | * @template T
|
685 | * The type of the answers.
|
686 | */
|
687 | interface CheckboxQuestion<T extends Answers = Answers> extends CheckboxQuestionOptions<T> {
|
688 | /**
|
689 | * @inheritdoc
|
690 | */
|
691 | type: 'checkbox';
|
692 | }
|
693 |
|
694 | /**
|
695 | * Provides options for a question for the `ConfirmPrompt`.
|
696 | *
|
697 | * @template T
|
698 | * The type of the answers.
|
699 | */
|
700 | interface ConfirmQuestionOptions<T extends Answers = Answers> extends Question<T> {}
|
701 |
|
702 | /**
|
703 | * Provides options for a question for the `ConfirmPrompt`.
|
704 | *
|
705 | * @template T
|
706 | * The type of the answers.
|
707 | */
|
708 | interface ConfirmQuestion<T extends Answers = Answers> extends ConfirmQuestionOptions<T> {
|
709 | /**
|
710 | * @inheritdoc
|
711 | */
|
712 | type: 'confirm';
|
713 | }
|
714 |
|
715 | /**
|
716 | * Provides options for a question for the `EditorPrompt`.
|
717 | *
|
718 | * @template T
|
719 | * The type of the answers.
|
720 | */
|
721 | interface EditorQuestionOptions<T extends Answers = Answers> extends Question<T> {}
|
722 |
|
723 | /**
|
724 | * Provides options for a question for the `EditorPrompt`.
|
725 | *
|
726 | * @template T
|
727 | * The type of the answers.
|
728 | */
|
729 | interface EditorQuestion<T extends Answers = Answers> extends EditorQuestionOptions<T> {
|
730 | /**
|
731 | * @inheritdoc
|
732 | */
|
733 | type: 'editor';
|
734 | }
|
735 |
|
736 | /**
|
737 | * Provides the available question-types.
|
738 | *
|
739 | * @template T
|
740 | * The type of the answers.
|
741 | */
|
742 | interface QuestionMap<T extends Answers = Answers> {
|
743 | /**
|
744 | * The `InputQuestion` type.
|
745 | */
|
746 | input: InputQuestion<T>;
|
747 |
|
748 | /**
|
749 | * The `NumberQuestion` type.
|
750 | */
|
751 | number: NumberQuestion<T>;
|
752 |
|
753 | /**
|
754 | * The `PasswordQuestion` type.
|
755 | */
|
756 | password: PasswordQuestion<T>;
|
757 |
|
758 | /**
|
759 | * The `ListQuestion` type.
|
760 | */
|
761 | list: ListQuestion<T>;
|
762 |
|
763 | /**
|
764 | * The `RawListQuestion` type.
|
765 | */
|
766 | rawList: RawListQuestion<T>;
|
767 |
|
768 | /**
|
769 | * The `ExpandQuestion` type.
|
770 | */
|
771 | expand: ExpandQuestion<T>;
|
772 |
|
773 | /**
|
774 | * The `CheckboxQuestion` type.
|
775 | */
|
776 | checkbox: CheckboxQuestion<T>;
|
777 |
|
778 | /**
|
779 | * The `ConfirmQuestion` type.
|
780 | */
|
781 | confirm: ConfirmQuestion<T>;
|
782 |
|
783 | /**
|
784 | * The `EditorQuestion` type.
|
785 | */
|
786 | editor: EditorQuestion<T>;
|
787 | }
|
788 |
|
789 | /**
|
790 | * Represents one of the available questions.
|
791 | *
|
792 | * @template T
|
793 | * The type of the answers.
|
794 | */
|
795 | type DistinctQuestion<T extends Answers = Answers> = QuestionMap<T>[keyof QuestionMap<T>];
|
796 |
|
797 | /**
|
798 | * Indicates the type of a question
|
799 | */
|
800 | type QuestionTypeName = DistinctQuestion['type'];
|
801 |
|
802 | /**
|
803 | * Represents a collection of questions.
|
804 | *
|
805 | * @template T
|
806 | * The type of the answers.
|
807 | */
|
808 | type QuestionCollection<T extends Answers = Answers> =
|
809 | | DistinctQuestion<T>
|
810 | | ReadonlyArray<DistinctQuestion<T>>
|
811 | | Observable<DistinctQuestion<T>>;
|
812 |
|
813 | /**
|
814 | * Provides components for the prompts.
|
815 | */
|
816 | namespace prompts {
|
817 | /**
|
818 | * Provides a base for and prompt-options.
|
819 | *
|
820 | * @template T
|
821 | * The type of the answers.
|
822 | */
|
823 | type PromptOptions<T extends Question = Question> = T & {
|
824 | /**
|
825 | * The choices of the prompt.
|
826 | */
|
827 | choices: Choices;
|
828 | };
|
829 |
|
830 | /**
|
831 | * Represents the state of a prompt.
|
832 | */
|
833 | type PromptState = LiteralUnion<'pending' | 'idle' | 'loading' | 'answered' | 'done'>;
|
834 |
|
835 | /**
|
836 | * Represents a prompt.
|
837 | */
|
838 | interface PromptBase {
|
839 | /**
|
840 | * Gets or sets a string which represents the state of the prompt.
|
841 | */
|
842 | status: PromptState;
|
843 |
|
844 | /**
|
845 | * Runs the prompt.
|
846 | *
|
847 | * @returns
|
848 | * The result of the prompt.
|
849 | */
|
850 | run(): Promise<any>;
|
851 | }
|
852 |
|
853 | /**
|
854 | * Provides the functionality to initialize new prompts.
|
855 | */
|
856 | interface PromptConstructor {
|
857 | /**
|
858 | * Initializes a new instance of a prompt.
|
859 | *
|
860 | * @param question
|
861 | * The question to prompt.
|
862 | *
|
863 | * @param readLine
|
864 | * An object for reading from the command-line.
|
865 | *
|
866 | * @param answers
|
867 | * The answers provided by the user.
|
868 | */
|
869 | new (question: any, readLine: ReadlineInterface, answers: Answers): PromptBase;
|
870 | }
|
871 |
|
872 | /**
|
873 | * Provides a set of prompt-constructors.
|
874 | */
|
875 | type PromptCollection = Record<string, PromptConstructor>;
|
876 |
|
877 | /**
|
878 | * Provides data about the state of a prompt.
|
879 | */
|
880 | interface PromptStateData {
|
881 | /**
|
882 | * Either a string which describes the error of the prompt or a boolean indicating whether the prompt-value is valid.
|
883 | */
|
884 | isValid: string | boolean;
|
885 | }
|
886 |
|
887 | /**
|
888 | * Provides data about the successful state of a prompt.
|
889 | *
|
890 | * @param T
|
891 | * The type of the answer.
|
892 | */
|
893 | interface SuccessfulPromptStateData<T = any> extends PromptStateData {
|
894 | /**
|
895 | * @inheritdoc
|
896 | */
|
897 | isValid: true;
|
898 |
|
899 | /**
|
900 | * The value of the prompt.
|
901 | */
|
902 | value: T;
|
903 | }
|
904 |
|
905 | /**
|
906 | * Provides data about the failed state of a prompt.
|
907 | */
|
908 | interface FailedPromptStateData extends PromptStateData {
|
909 | /**
|
910 | * @inheritdoc
|
911 | */
|
912 | isValid: false | string;
|
913 | }
|
914 |
|
915 | /**
|
916 | * Provides pipes for handling events of a prompt.
|
917 | *
|
918 | * @param T
|
919 | * The type of the answer.
|
920 | */
|
921 | interface PromptEventPipes<T = any> {
|
922 | /**
|
923 | * A pypeline for succesful inputs.
|
924 | */
|
925 | success: Observable<SuccessfulPromptStateData<T>>;
|
926 |
|
927 | /**
|
928 | * An object representing an error.
|
929 | */
|
930 | error: Observable<FailedPromptStateData>;
|
931 | }
|
932 | }
|
933 |
|
934 | /**
|
935 | * Provides components for the ui.
|
936 | */
|
937 | namespace ui {
|
938 | /**
|
939 | * Provides options for the bottom-bar UI.
|
940 | */
|
941 | interface BottomBarOptions extends StreamOptions {
|
942 | /**
|
943 | * The initial text to display.
|
944 | */
|
945 | bottomBar?: string | undefined;
|
946 | }
|
947 |
|
948 | /**
|
949 | * Represents a fetched answer.
|
950 | *
|
951 | * @template T
|
952 | * The type of the answers.
|
953 | */
|
954 | type FetchedQuestion<T extends Answers = Answers> = DistinctQuestion<T> & {
|
955 | /**
|
956 | * The type of the question.
|
957 | */
|
958 | type: string;
|
959 |
|
960 | /**
|
961 | * The message to show to the user.
|
962 | */
|
963 | message: string;
|
964 |
|
965 | /**
|
966 | * The default value of the question.
|
967 | */
|
968 | default: any;
|
969 |
|
970 | /**
|
971 | * The choices of the question.
|
972 | */
|
973 | choices: ChoiceCollection<T>;
|
974 | };
|
975 |
|
976 | /**
|
977 | * Represents a fetched answer.
|
978 | */
|
979 | interface FetchedAnswer {
|
980 | /**
|
981 | * The name of the answer.
|
982 | */
|
983 | name: string;
|
984 |
|
985 | /**
|
986 | * The value of the answer.
|
987 | */
|
988 | answer: any;
|
989 | }
|
990 | }
|
991 | }
|
992 |
|
993 | /**
|
994 | * Provides the functionality to prompt questions.
|
995 | */
|
996 | declare var inquirer: inquirer.Inquirer;
|
997 | export = inquirer;
|
998 |
|
\ | No newline at end of file |