@inquirer/prompts 5.3.7 → 5.4.0
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 +33 -20
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -169,6 +169,7 @@ The context options are:
|
|
|
169
169
|
| input | `NodeJS.ReadableStream` | no | The stdin stream (defaults to `process.stdin`) |
|
|
170
170
|
| output | `NodeJS.WritableStream` | no | The stdout stream (defaults to `process.stdout`) |
|
|
171
171
|
| clearPromptOnDone | `boolean` | no | If true, we'll clear the screen after the prompt is answered |
|
|
172
|
+
| signal | `AbortSignal` | no | An AbortSignal to cancel prompts asynchronously |
|
|
172
173
|
|
|
173
174
|
Example:
|
|
174
175
|
|
|
@@ -191,16 +192,37 @@ const allowEmail = await confirm(
|
|
|
191
192
|
|
|
192
193
|
## Canceling prompt
|
|
193
194
|
|
|
194
|
-
|
|
195
|
+
This can preferably be done with either an `AbortController` or `AbortSignal`.
|
|
196
|
+
|
|
197
|
+
```js
|
|
198
|
+
// Example 1: using built-in AbortSignal utilities
|
|
199
|
+
import { confirm } from '@inquirer/prompts';
|
|
200
|
+
|
|
201
|
+
const answer = await confirm({ ... }, { signal: AbortSignal.timeout(5000) });
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
```js
|
|
205
|
+
// Example 1: implementing custom cancellation logic
|
|
206
|
+
import { confirm } from '@inquirer/prompts';
|
|
207
|
+
|
|
208
|
+
const controller = new AbortController();
|
|
209
|
+
setTimeout(() => {
|
|
210
|
+
controller.abort(); // This will reject the promise
|
|
211
|
+
}, 5000);
|
|
212
|
+
|
|
213
|
+
const answer = await confirm({ ... }, { signal: controller.signal });
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Alternatively, all prompt functions are returning a cancelable promise. This special promise type has a `cancel` method that'll cancel and cleanup the prompt.
|
|
195
217
|
|
|
196
218
|
On calling `cancel`, the answer promise will become rejected.
|
|
197
219
|
|
|
198
220
|
```js
|
|
199
221
|
import { confirm } from '@inquirer/prompts';
|
|
200
222
|
|
|
201
|
-
const
|
|
223
|
+
const promise = confirm(...); // Warning: for this pattern to work, `await` cannot be used.
|
|
202
224
|
|
|
203
|
-
|
|
225
|
+
promise.cancel();
|
|
204
226
|
```
|
|
205
227
|
|
|
206
228
|
# Recipes
|
|
@@ -238,27 +260,18 @@ if (allowEmail) {
|
|
|
238
260
|
## Get default value after timeout
|
|
239
261
|
|
|
240
262
|
```js
|
|
241
|
-
import { setTimeout } from 'node:timers/promises';
|
|
242
263
|
import { input } from '@inquirer/prompts';
|
|
243
264
|
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
ac.abort();
|
|
252
|
-
})
|
|
253
|
-
// Silencing the cancellation error.
|
|
254
|
-
.catch(() => {});
|
|
265
|
+
const answer = await input(
|
|
266
|
+
{ message: 'Enter a value (timing out in 5 seconds)' },
|
|
267
|
+
{ signal: AbortSignal.timeout(5000) },
|
|
268
|
+
).catch((error) => {
|
|
269
|
+
if (error.name === 'AbortPromptError') {
|
|
270
|
+
return 'Default value';
|
|
271
|
+
}
|
|
255
272
|
|
|
256
|
-
|
|
257
|
-
prompt.cancel();
|
|
258
|
-
return 'Timed out!';
|
|
273
|
+
throw error;
|
|
259
274
|
});
|
|
260
|
-
|
|
261
|
-
const answer = await Promise.race([defaultValue, prompt]);
|
|
262
275
|
```
|
|
263
276
|
|
|
264
277
|
## Using as pre-commit/git hooks, or scripts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/prompts",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.0",
|
|
4
4
|
"description": "Inquirer prompts, combined in a single package",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"typings": "./dist/cjs/types/index.d.ts",
|
|
@@ -76,21 +76,21 @@
|
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"@inquirer/checkbox": "^2.
|
|
80
|
-
"@inquirer/confirm": "^3.
|
|
81
|
-
"@inquirer/editor": "^2.
|
|
82
|
-
"@inquirer/expand": "^2.
|
|
83
|
-
"@inquirer/input": "^2.
|
|
84
|
-
"@inquirer/number": "^1.0
|
|
85
|
-
"@inquirer/password": "^2.
|
|
86
|
-
"@inquirer/rawlist": "^2.
|
|
87
|
-
"@inquirer/search": "^1.0
|
|
88
|
-
"@inquirer/select": "^2.
|
|
79
|
+
"@inquirer/checkbox": "^2.5.0",
|
|
80
|
+
"@inquirer/confirm": "^3.2.0",
|
|
81
|
+
"@inquirer/editor": "^2.2.0",
|
|
82
|
+
"@inquirer/expand": "^2.2.0",
|
|
83
|
+
"@inquirer/input": "^2.3.0",
|
|
84
|
+
"@inquirer/number": "^1.1.0",
|
|
85
|
+
"@inquirer/password": "^2.2.0",
|
|
86
|
+
"@inquirer/rawlist": "^2.3.0",
|
|
87
|
+
"@inquirer/search": "^1.1.0",
|
|
88
|
+
"@inquirer/select": "^2.5.0"
|
|
89
89
|
},
|
|
90
90
|
"devDependencies": {
|
|
91
|
-
"@inquirer/type": "^1.5.
|
|
91
|
+
"@inquirer/type": "^1.5.3"
|
|
92
92
|
},
|
|
93
93
|
"homepage": "https://github.com/SBoudrias/Inquirer.js/blob/main/packages/prompts/README.md",
|
|
94
94
|
"sideEffects": false,
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "0c039599ef88fe9eb804fe083ee386ec906a856f"
|
|
96
96
|
}
|