1 | import { EventEmitter } from "events";
|
2 |
|
3 | interface BasePromptOptions {
|
4 | name: string | (() => string)
|
5 | type: string | (() => string)
|
6 | message: string | (() => string) | (() => Promise<string>)
|
7 | prefix?: string
|
8 | initial?: any
|
9 | required?: boolean
|
10 | enabled?: boolean | string
|
11 | disabled?: boolean | string
|
12 | format?(value: string): string | Promise<string>
|
13 | result?(value: string): string | Promise<string>
|
14 | skip?: ((state: object) => boolean | Promise<boolean>) | boolean
|
15 | validate?(value: string): boolean | string | Promise<boolean | string>
|
16 | onSubmit?(name: string, value: any, prompt: Enquirer.Prompt): boolean | Promise<boolean>
|
17 | onCancel?(name: string, value: any, prompt: Enquirer.Prompt): boolean | Promise<boolean>
|
18 | stdin?: NodeJS.ReadStream
|
19 | stdout?: NodeJS.WriteStream
|
20 | }
|
21 |
|
22 | interface Choice {
|
23 | name: string
|
24 | message?: string
|
25 | value?: unknown
|
26 | hint?: string
|
27 | role?: string
|
28 | enabled?: boolean
|
29 | disabled?: boolean | string
|
30 | }
|
31 |
|
32 | interface ArrayPromptOptions extends BasePromptOptions {
|
33 | type:
|
34 | | 'autocomplete'
|
35 | | 'editable'
|
36 | | 'form'
|
37 | | 'multiselect'
|
38 | | 'select'
|
39 | | 'survey'
|
40 | | 'list'
|
41 | | 'scale'
|
42 | choices: (string | Choice)[]
|
43 | maxChoices?: number
|
44 | multiple?: boolean
|
45 | initial?: number
|
46 | delay?: number
|
47 | separator?: boolean
|
48 | sort?: boolean
|
49 | linebreak?: boolean
|
50 | edgeLength?: number
|
51 | align?: 'left' | 'right'
|
52 | scroll?: boolean
|
53 | }
|
54 |
|
55 | interface BooleanPromptOptions extends BasePromptOptions {
|
56 | type: 'confirm'
|
57 | initial?: boolean
|
58 | }
|
59 |
|
60 | interface StringPromptOptions extends BasePromptOptions {
|
61 | type: 'input' | 'invisible' | 'list' | 'password' | 'text'
|
62 | initial?: string
|
63 | multiline?: boolean
|
64 | }
|
65 |
|
66 | interface NumberPromptOptions extends BasePromptOptions {
|
67 | type: 'numeral'
|
68 | min?: number
|
69 | max?: number
|
70 | delay?: number
|
71 | float?: boolean
|
72 | round?: boolean
|
73 | major?: number
|
74 | minor?: number
|
75 | initial?: number
|
76 | }
|
77 |
|
78 | interface SnippetPromptOptions extends BasePromptOptions {
|
79 | type: 'snippet'
|
80 | newline?: string
|
81 | template?: string
|
82 | }
|
83 |
|
84 | interface SortPromptOptions extends BasePromptOptions {
|
85 | type: 'sort'
|
86 | hint?: string
|
87 | drag?: boolean
|
88 | numbered?: boolean
|
89 | }
|
90 |
|
91 | type PromptOptions =
|
92 | | BasePromptOptions
|
93 | | ArrayPromptOptions
|
94 | | BooleanPromptOptions
|
95 | | StringPromptOptions
|
96 | | NumberPromptOptions
|
97 | | SnippetPromptOptions
|
98 | | SortPromptOptions
|
99 |
|
100 | declare class BasePrompt extends EventEmitter {
|
101 | constructor(options?: PromptOptions);
|
102 |
|
103 | render(): void;
|
104 |
|
105 | run(): Promise<any>;
|
106 | }
|
107 |
|
108 | declare class Enquirer<T = object> extends EventEmitter {
|
109 | constructor(options?: object, answers?: T);
|
110 |
|
111 | /**
|
112 | * Register a custom prompt type.
|
113 | *
|
114 | * @param type
|
115 | * @param fn `Prompt` class, or a function that returns a `Prompt` class.
|
116 | */
|
117 | register(type: string, fn: typeof BasePrompt | (() => typeof BasePrompt)): this;
|
118 |
|
119 | /**
|
120 | * Register a custom prompt type.
|
121 | */
|
122 | register(type: { [key: string]: typeof BasePrompt | (() => typeof BasePrompt) }): this;
|
123 |
|
124 | /**
|
125 | * Prompt function that takes a "question" object or array of question objects,
|
126 | * and returns an object with responses from the user.
|
127 | *
|
128 | * @param questions Options objects for one or more prompts to run.
|
129 | */
|
130 | prompt(
|
131 | questions:
|
132 | | PromptOptions
|
133 | | ((this: Enquirer) => PromptOptions)
|
134 | | (PromptOptions | ((this: Enquirer) => PromptOptions))[]
|
135 | ): Promise<T>;
|
136 |
|
137 | /**
|
138 | * Use an enquirer plugin.
|
139 | *
|
140 | * @param plugin Plugin function that takes an instance of Enquirer.
|
141 | */
|
142 | use(plugin: (this: this, enquirer: this) => void): this;
|
143 | }
|
144 |
|
145 | declare namespace Enquirer {
|
146 | function prompt<T = object>(
|
147 | questions:
|
148 | | PromptOptions
|
149 | | ((this: Enquirer) => PromptOptions)
|
150 | | (PromptOptions | ((this: Enquirer) => PromptOptions))[]
|
151 | ): Promise<T>;
|
152 |
|
153 | class Prompt extends BasePrompt {}
|
154 | }
|
155 |
|
156 | export = Enquirer;
|
157 |
|
\ | No newline at end of file |