@inquirer/demo 0.4.0 → 0.4.2

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/demos/input.mjs CHANGED
@@ -37,14 +37,6 @@ const demo = async () => {
37
37
  }),
38
38
  });
39
39
  console.log('Answer:', answer);
40
-
41
- answer = await input({
42
- message: () =>
43
- new Promise((resolve) => {
44
- setTimeout(() => resolve('(Slow message) Input any value:'), 3000);
45
- }),
46
- });
47
- console.log('Answer:', answer);
48
40
  };
49
41
 
50
42
  if (import.meta.url.startsWith('file:')) {
@@ -0,0 +1,34 @@
1
+ import * as url from 'node:url';
2
+ import { setTimeout } from 'node:timers/promises';
3
+ import { input } from '@inquirer/prompts';
4
+
5
+ async function demo() {
6
+ const ac = new AbortController();
7
+ const prompt = input({
8
+ message: 'Enter a value (timing out in 5 seconds)',
9
+ });
10
+
11
+ prompt
12
+ .finally(() => {
13
+ ac.abort();
14
+ })
15
+ // Silencing the cancellation error.
16
+ .catch(() => {});
17
+
18
+ const defaultValue = setTimeout(5000, 'timeout', { signal: ac.signal }).then(() => {
19
+ prompt.cancel();
20
+ return 'Timed out!';
21
+ });
22
+
23
+ const answer = await Promise.race([defaultValue, prompt]);
24
+ console.log('Answer:', answer);
25
+ }
26
+
27
+ if (import.meta.url.startsWith('file:')) {
28
+ const modulePath = url.fileURLToPath(import.meta.url);
29
+ if (process.argv[1] === modulePath) {
30
+ demo();
31
+ }
32
+ }
33
+
34
+ export default demo;
package/index.mjs CHANGED
@@ -10,6 +10,7 @@ import inputDemo from './demos/input.mjs';
10
10
  import passwordDemo from './demos/password.mjs';
11
11
  import rawlistDemo from './demos/rawlist.mjs';
12
12
  import selectDemo from './demos/select.mjs';
13
+ import timeoutDemo from './demos/timeout.mjs';
13
14
 
14
15
  const demos = {
15
16
  checkbox: checkboxDemo,
@@ -20,10 +21,11 @@ const demos = {
20
21
  password: passwordDemo,
21
22
  rawlist: rawlistDemo,
22
23
  select: selectDemo,
24
+ timeout: timeoutDemo,
23
25
  };
24
26
 
25
- function askNextDemo() {
26
- return select({
27
+ async function askNextDemo() {
28
+ let selectedDemo = await select({
27
29
  message: 'Which prompt demo do you want to run?',
28
30
  choices: [
29
31
  { name: 'Input', value: 'input' },
@@ -34,9 +36,26 @@ function askNextDemo() {
34
36
  { name: 'Expand', value: 'expand' },
35
37
  { name: 'Rawlist', value: 'rawlist' },
36
38
  { name: 'Editor', value: 'editor' },
39
+ { name: 'Advanced demos', value: 'advanced' },
37
40
  { name: "Exit (I'm done)", value: 'exit' },
38
41
  ],
39
42
  });
43
+
44
+ if (selectedDemo === 'advanced') {
45
+ selectedDemo = await select({
46
+ message: 'Which demo do you want to run?',
47
+ choices: [
48
+ { name: 'Default value after timeout', value: 'timeout' },
49
+ { name: 'Go back', value: 'back' },
50
+ ],
51
+ });
52
+ }
53
+
54
+ if (selectedDemo === 'back') {
55
+ return askNextDemo();
56
+ }
57
+
58
+ return selectedDemo;
40
59
  }
41
60
 
42
61
  (async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/demo",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "engines": {
5
5
  "node": ">=18"
6
6
  },
@@ -61,11 +61,11 @@
61
61
  "license": "MIT",
62
62
  "homepage": "https://github.com/SBoudrias/Inquirer.js",
63
63
  "dependencies": {
64
- "@inquirer/prompts": "^4.3.0",
64
+ "@inquirer/prompts": "^4.3.2",
65
65
  "chalk": "^4.1.2"
66
66
  },
67
67
  "publishConfig": {
68
68
  "access": "public"
69
69
  },
70
- "gitHead": "2de191afab92c1a214dfe268c80109014803f11b"
70
+ "gitHead": "e5300568c6b043f325a1107e38e99d931593510e"
71
71
  }