forked from enquirer/enquirer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
everything.js
54 lines (50 loc) · 1.64 KB
/
everything.js
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
'use strict';
const yosay = require('yosay');
const colors = require('ansi-colors');
const { MultiSelect } = require('enquirer');
/**
* Example that shows all of the prompt elements displayed at once.
*/
const prompt = new MultiSelect({
type: 'multiselect',
name: 'colors',
message: 'Pick your favorite colors',
hint: '(Use <space> to select, <return> to submit)',
limit: 6,
header: yosay('Welcome to my awesome generator!'),
format() {
return prompt.input + ' ' + prompt.styles.muted(prompt.state.hint);
},
pointer(state, choice, i) {
return (state.index === i ? state.symbols.pointer : ' ') + ' ';
},
footer(state) {
if (state.limit < state.choices.length) {
return colors.dim('(Scroll up and down to reveal more choices)');
}
},
result(names) {
return this.map(names);
},
choices: [
{ name: 'aqua', value: '#00ffff' },
{ name: 'black', value: '#000000' },
{ name: 'blue', value: '#0000ff', hint: '(this is a choice hint)' },
{ name: 'fuchsia', value: '#ff00ff' },
{ name: 'gray', value: '#808080' },
{ name: 'green', value: '#008000' },
{ name: 'lime', value: '#00ff00' },
{ name: 'maroon', value: '#800000' },
{ name: 'navy', value: '#000080' },
{ name: 'olive', value: '#808000' },
{ name: 'purple', value: '#800080', hint: colors.red('(this is a colored choice hint)') },
{ name: 'red', value: '#ff0000' },
{ name: 'silver', value: '#c0c0c0' },
{ name: 'teal', value: '#008080' },
{ name: 'white', value: '#ffffff' },
{ name: 'yellow', value: '#ffff00' }
]
});
prompt.run()
.then(names => console.log('Answer:', names))
.catch(console.error);