|
1 |
| -'use strict'; |
2 |
| - |
3 |
| -const { prompt } = require('./'); |
| 1 | +import { prompt } from './index.js'; |
4 | 2 |
|
5 | 3 | let interval;
|
6 | 4 |
|
7 |
| -(async function(){ |
8 |
| - const questions = [ |
9 |
| - { |
10 |
| - type: 'text', |
11 |
| - name: 'twitter', |
12 |
| - message: `What's your twitter handle?`, |
13 |
| - initial: `terkelg`, |
14 |
| - format: v => `@${v}` |
15 |
| - }, |
16 |
| - { |
17 |
| - type: 'number', |
18 |
| - name: 'age', |
19 |
| - message: 'How old are you?', |
20 |
| - validate: value => value < 18 ? `Sorry, you have to be 18` : true |
21 |
| - }, |
22 |
| - { |
23 |
| - type: 'password', |
24 |
| - name: 'secret', |
25 |
| - message: 'Tell me a secret' |
26 |
| - }, |
27 |
| - { |
28 |
| - type: 'confirm', |
29 |
| - name: 'confirmed', |
30 |
| - message: 'Can you confirm?' |
31 |
| - }, |
32 |
| - { |
33 |
| - type: prev => prev && 'toggle', |
34 |
| - name: 'confirmtoggle', |
35 |
| - message: 'Can you confirm again?', |
36 |
| - active: 'yes', |
37 |
| - inactive: 'no' |
38 |
| - }, |
39 |
| - { |
40 |
| - type: 'list', |
41 |
| - name: 'keywords', |
42 |
| - message: 'Enter keywords' |
43 |
| - }, |
44 |
| - { |
45 |
| - type: 'select', |
46 |
| - name: 'color', |
47 |
| - message: 'Pick a color', |
48 |
| - choices: [ |
49 |
| - { title: 'Red', description: 'This option has a description.', value: '#ff0000' }, |
50 |
| - { title: 'Green', value: '#00ff00' }, |
51 |
| - { title: 'Yellow', value: '#ffff00', disabled: true }, |
52 |
| - { title: 'Blue', value: '#0000ff' } |
53 |
| - ] |
54 |
| - }, |
55 |
| - { |
56 |
| - type: 'multiselect', |
57 |
| - name: 'multicolor', |
58 |
| - message: 'Pick colors', |
59 |
| - hint: false, |
60 |
| - choices: [ |
61 |
| - { title: 'Red', description: 'This option has a description.', value: '#ff0000' }, |
62 |
| - { title: 'Green', value: '#00ff00' }, |
63 |
| - { title: 'Yellow', value: '#ffff00', disabled: true }, |
64 |
| - { title: 'Blue', value: '#0000ff' } |
65 |
| - ] |
66 |
| - }, |
67 |
| - { |
68 |
| - type: 'autocomplete', |
69 |
| - name: 'actor', |
70 |
| - message: 'Pick your favorite actor', |
71 |
| - initial: 1, |
72 |
| - limit: 3, |
73 |
| - suggest: (input, choices) => choices.filter(i => i.title.toLowerCase().includes(input.toLowerCase())), |
74 |
| - choices: [ |
75 |
| - { title: 'Cage' }, |
76 |
| - { title: 'Clooney', value: 'silver-fox' }, |
77 |
| - { title: 'Gyllenhaal' }, |
78 |
| - { title: 'Gibson' }, |
79 |
| - { title: 'Grant', description: 'This option has a description.' }, |
80 |
| - { title: 'Hanks' }, |
81 |
| - { title: 'Downey Jr.' } |
82 |
| - ], |
83 |
| - fallback: { |
84 |
| - title: `This is the fallback. Its value is 'fallback'`, |
85 |
| - value: 'fallback' |
86 |
| - } |
87 |
| - }, |
88 |
| - { |
89 |
| - type: 'date', |
90 |
| - name: 'birthday', |
91 |
| - message: `What's your birthday?`, |
92 |
| - validate: date => date > Date.now() ? `Your birth day can't be in the future` : true |
93 |
| - }, |
94 |
| - { |
95 |
| - type: 'number', |
96 |
| - name: 'prompt', |
97 |
| - message: 'This will be overridden', |
98 |
| - onRender(color) { |
99 |
| - this.no = (this.no || 1); |
100 |
| - this.msg = `Enter a number (e.g. ${color.cyan(this.no)})`; |
101 |
| - if (!interval) interval = setInterval(() => { |
102 |
| - this.no += 1; |
103 |
| - this.render(); |
104 |
| - }, 1000); |
105 |
| - } |
| 5 | +const questions = [ |
| 6 | + { |
| 7 | + type: 'text', |
| 8 | + name: 'twitter', |
| 9 | + message: `What's your twitter handle?`, |
| 10 | + initial: `terkelg`, |
| 11 | + format: v => `@${v}` |
| 12 | + }, |
| 13 | + { |
| 14 | + type: 'number', |
| 15 | + name: 'age', |
| 16 | + message: 'How old are you?', |
| 17 | + validate: value => value < 18 ? `Sorry, you have to be 18` : true |
| 18 | + }, |
| 19 | + { |
| 20 | + type: 'password', |
| 21 | + name: 'secret', |
| 22 | + message: 'Tell me a secret' |
| 23 | + }, |
| 24 | + { |
| 25 | + type: 'confirm', |
| 26 | + name: 'confirmed', |
| 27 | + message: 'Can you confirm?' |
| 28 | + }, |
| 29 | + { |
| 30 | + type: prev => prev && 'toggle', |
| 31 | + name: 'confirmtoggle', |
| 32 | + message: 'Can you confirm again?', |
| 33 | + active: 'yes', |
| 34 | + inactive: 'no' |
| 35 | + }, |
| 36 | + { |
| 37 | + type: 'list', |
| 38 | + name: 'keywords', |
| 39 | + message: 'Enter keywords' |
| 40 | + }, |
| 41 | + { |
| 42 | + type: 'select', |
| 43 | + name: 'color', |
| 44 | + message: 'Pick a color', |
| 45 | + choices: [ |
| 46 | + { title: 'Red', description: 'This option has a description.', value: '#ff0000' }, |
| 47 | + { title: 'Green', value: '#00ff00' }, |
| 48 | + { title: 'Yellow', value: '#ffff00', disabled: true }, |
| 49 | + { title: 'Blue', value: '#0000ff' } |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + type: 'multiselect', |
| 54 | + name: 'multicolor', |
| 55 | + message: 'Pick colors', |
| 56 | + hint: false, |
| 57 | + choices: [ |
| 58 | + { title: 'Red', description: 'This option has a description.', value: '#ff0000' }, |
| 59 | + { title: 'Green', value: '#00ff00' }, |
| 60 | + { title: 'Yellow', value: '#ffff00', disabled: true }, |
| 61 | + { title: 'Blue', value: '#0000ff' } |
| 62 | + ] |
| 63 | + }, |
| 64 | + { |
| 65 | + type: 'autocomplete', |
| 66 | + name: 'actor', |
| 67 | + message: 'Pick your favorite actor', |
| 68 | + initial: 1, |
| 69 | + limit: 3, |
| 70 | + suggest: (input, choices) => choices.filter(i => i.title.toLowerCase().includes(input.toLowerCase())), |
| 71 | + choices: [ |
| 72 | + { title: 'Cage' }, |
| 73 | + { title: 'Clooney', value: 'silver-fox' }, |
| 74 | + { title: 'Gyllenhaal' }, |
| 75 | + { title: 'Gibson' }, |
| 76 | + { title: 'Grant', description: 'This option has a description.' }, |
| 77 | + { title: 'Hanks' }, |
| 78 | + { title: 'Downey Jr.' } |
| 79 | + ], |
| 80 | + fallback: { |
| 81 | + title: `This is the fallback. Its value is 'fallback'`, |
| 82 | + value: 'fallback' |
| 83 | + } |
| 84 | + }, |
| 85 | + { |
| 86 | + type: 'date', |
| 87 | + name: 'birthday', |
| 88 | + message: `What's your birthday?`, |
| 89 | + validate: date => date > Date.now() ? `Your birth day can't be in the future` : true |
| 90 | + }, |
| 91 | + { |
| 92 | + type: 'number', |
| 93 | + name: 'prompt', |
| 94 | + message: 'This will be overridden', |
| 95 | + onRender(color) { |
| 96 | + this.no = (this.no || 1); |
| 97 | + this.msg = `Enter a number (e.g. ${color.cyan(this.no)})`; |
| 98 | + if (!interval) interval = setInterval(() => { |
| 99 | + this.no += 1; |
| 100 | + this.render(); |
| 101 | + }, 1000); |
106 | 102 | }
|
107 |
| - ]; |
| 103 | + } |
| 104 | +]; |
108 | 105 |
|
109 |
| - const answers = await prompt(questions, {onCancel:cleanup, onSubmit:cleanup}); |
110 |
| - console.log(answers); |
111 |
| -})(); |
| 106 | +const answers = await prompt(questions, {onCancel:cleanup, onSubmit:cleanup}); |
| 107 | +console.log(answers); |
112 | 108 |
|
113 | 109 | function cleanup() {
|
114 | 110 | clearInterval(interval);
|
|
0 commit comments