forked from enquirer/enquirer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
play.js
46 lines (41 loc) · 978 Bytes
/
play.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
'use strict';
const path = require('path');
const Store = require('data-store');
const store = new Store({ path: path.join(__dirname, 'recordings.json') });
const { AutoComplete } = require('enquirer');
const timeout = (fn, ms = 0) => {
return new Promise((resolve, reject) => {
setTimeout(() => fn().then(resolve).catch(reject), ms);
});
};
const prompt = new AutoComplete({
name: 'flavor',
message: 'Pick your favorite flavor',
choices: [
'almond',
'apple',
'banana',
'cherry',
'chocolate',
'cinnamon',
'coconut',
'cotton candy',
'grape',
'nougat',
'orange',
'pear',
'pineapple',
'strawberry',
'vanilla',
'watermelon',
'wintergreen'
]
});
prompt.once('run', async() => {
for (let step of store.get(prompt.name)) {
await timeout(() => prompt.keypress(...step.keypress), step.interval);
}
});
prompt.run()
.then(answer => console.log('Answer:', answer))
.catch(console.error);