@topcli/prompts 1.9.0 → 1.10.1
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.
- package/README.md +51 -24
- package/dist/index.cjs +239 -172
- package/dist/index.d.cts +22 -16
- package/dist/index.d.ts +22 -16
- package/dist/index.js +239 -172
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="./public/banner.png" alt="@topcli/prompts">
|
|
2
3
|
|
|
3
|
-

|
|
4
|
-
[](https://github.com/TopCli/prompts/commit-activity)
|
|
5
|
-
[](https://github.com/TopCli/prompts/blob/main/LICENSE)
|
|
6
|
-

|
|
7
|
-
|
|
8
|
-
Node.js user prompt library for command-line interfaces.
|
|
4
|
+

|
|
5
|
+
[](https://github.com/TopCli/prompts/commit-activity)
|
|
6
|
+
[](https://github.com/TopCli/prompts/blob/main/LICENSE)
|
|
7
|
+

|
|
8
|
+
</div>
|
|
9
9
|
|
|
10
10
|
## Requirements
|
|
11
11
|
- [Node.js](https://nodejs.org/en/) v18 or higher
|
|
@@ -49,9 +49,13 @@ question(message: string, options?: PromptOptions): Promise<string>
|
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
Simple prompt, similar to `rl.question()` with an improved UI.
|
|
52
|
+
|
|
52
53
|
Use `options.secure` if you need to hide both input and answer.
|
|
54
|
+
|
|
53
55
|
Use `options.validators` to handle user input.
|
|
54
56
|
|
|
57
|
+
Use `options.signal` to set an `AbortSignal` (throws a [AbortError](#aborterror)).
|
|
58
|
+
|
|
55
59
|
**Example**
|
|
56
60
|
|
|
57
61
|
```js
|
|
@@ -84,12 +88,17 @@ select(message: string, options: SelectOptions): Promise<string>
|
|
|
84
88
|
```
|
|
85
89
|
|
|
86
90
|
Scrollable select depending `maxVisible` (default `8`).
|
|
91
|
+
|
|
87
92
|
Use `ignoreValues` to skip result render & clear lines after a selected one.
|
|
88
93
|
|
|
94
|
+
Use `validators` to handle user input.
|
|
95
|
+
|
|
89
96
|
Use `autocomplete` to allow filtered choices. This can be useful for a large list of choices.
|
|
90
97
|
|
|
91
98
|
Use `caseSensitive` to make autocomplete filters case sensitive. Default `false`
|
|
92
99
|
|
|
100
|
+
Use `options.signal` to set an `AbortSignal` (throws a [AbortError](#aborterror)).
|
|
101
|
+
|
|
93
102
|
### `multiselect()`
|
|
94
103
|
|
|
95
104
|
```ts
|
|
@@ -103,18 +112,11 @@ Use `validators` to handle user input.
|
|
|
103
112
|
|
|
104
113
|
Use `showHint: false` to disable hint (this option is truthy by default).
|
|
105
114
|
|
|
106
|
-
**Example**
|
|
107
|
-
|
|
108
|
-
```js
|
|
109
|
-
const os = await multiselect('Choose OS', {
|
|
110
|
-
choices: ["linux", "mac", "windows"]
|
|
111
|
-
validators: [required()]
|
|
112
|
-
});
|
|
113
|
-
```
|
|
114
|
-
|
|
115
115
|
Use `autocomplete` to allow filtered choices. This can be useful for a large list of choices.
|
|
116
116
|
|
|
117
|
-
Use `caseSensitive` to make autocomplete filters case sensitive. Default `false
|
|
117
|
+
Use `caseSensitive` to make autocomplete filters case sensitive. Default `false`.
|
|
118
|
+
|
|
119
|
+
Use `options.signal` to set an `AbortSignal` (throws a [AbortError](#aborterror)).
|
|
118
120
|
|
|
119
121
|
### `confirm()`
|
|
120
122
|
|
|
@@ -124,6 +126,8 @@ confirm(message: string, options?: ConfirmOptions): Promise<boolean>
|
|
|
124
126
|
|
|
125
127
|
Boolean prompt, return `options.initial` if user input is different from `y`/`yes`/`n`/`no` (case insensitive), (default `false`).
|
|
126
128
|
|
|
129
|
+
Use `options.signal` to set an `AbortSignal` (throws a [AbortError](#aborterror)).
|
|
130
|
+
|
|
127
131
|
### `PromptAgent`
|
|
128
132
|
|
|
129
133
|
The `PromptAgent` class allows to programmatically set the next answers for any prompt function, this can be useful for testing.
|
|
@@ -145,16 +149,35 @@ assert.equal(input, "John");
|
|
|
145
149
|
> - etc<br>
|
|
146
150
|
> **Use with caution**
|
|
147
151
|
|
|
152
|
+
## Errors
|
|
153
|
+
|
|
154
|
+
### `AbortError`
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
export class AbortError extends Error {
|
|
158
|
+
constructor(message: string) {
|
|
159
|
+
super(message);
|
|
160
|
+
this.name = "AbortError";
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
148
165
|
## Interfaces
|
|
149
166
|
|
|
150
167
|
```ts
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
168
|
+
type Stdin = NodeJS.ReadStream & {
|
|
169
|
+
fd: 0;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
type Stdout = NodeJS.WriteStream & {
|
|
173
|
+
fd: 1;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface AbstractPromptOptions {
|
|
177
|
+
stdin?: Stdin;
|
|
178
|
+
stdout?: Stdout;
|
|
179
|
+
message: string;
|
|
180
|
+
sginal?: AbortSignal;
|
|
158
181
|
}
|
|
159
182
|
|
|
160
183
|
export interface PromptValidator<T = string | string[] | boolean> {
|
|
@@ -178,6 +201,7 @@ export interface SelectOptions extends SharedOptions {
|
|
|
178
201
|
choices: (Choice | string)[];
|
|
179
202
|
maxVisible?: number;
|
|
180
203
|
ignoreValues?: (string | number | boolean)[];
|
|
204
|
+
validators?: Validator[];
|
|
181
205
|
autocomplete?: boolean;
|
|
182
206
|
caseSensitive?: boolean;
|
|
183
207
|
}
|
|
@@ -213,6 +237,9 @@ export interface ConfirmOptions extends SharedOptions {
|
|
|
213
237
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ncukondo"><img src="https://avatars.githubusercontent.com/u/17022138?v=4?s=100" width="100px;" alt="Takeshi Kondo"/><br /><sub><b>Takeshi Kondo</b></sub></a><br /><a href="#maintenance-ncukondo" title="Maintenance">🚧</a></td>
|
|
214
238
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/FredGuiou"><img src="https://avatars.githubusercontent.com/u/99122562?v=4?s=100" width="100px;" alt="FredGuiou"/><br /><sub><b>FredGuiou</b></sub></a><br /><a href="https://github.com/TopCli/prompts/commits?author=FredGuiou" title="Code">💻</a> <a href="https://github.com/TopCli/prompts/commits?author=FredGuiou" title="Tests">⚠️</a> <a href="https://github.com/TopCli/prompts/commits?author=FredGuiou" title="Documentation">📖</a></td>
|
|
215
239
|
</tr>
|
|
240
|
+
<tr>
|
|
241
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/noxify"><img src="https://avatars.githubusercontent.com/u/521777?v=4?s=100" width="100px;" alt="Marcus Reinhardt"/><br /><sub><b>Marcus Reinhardt</b></sub></a><br /><a href="https://github.com/TopCli/prompts/commits?author=noxify" title="Code">💻</a> <a href="https://github.com/TopCli/prompts/commits?author=noxify" title="Tests">⚠️</a> <a href="https://github.com/TopCli/prompts/commits?author=noxify" title="Documentation">📖</a></td>
|
|
242
|
+
</tr>
|
|
216
243
|
</tbody>
|
|
217
244
|
</table>
|
|
218
245
|
|