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