forked from enquirer/enquirer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
record.js
44 lines (39 loc) · 908 Bytes
/
record.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
'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 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'
]
});
let prev = Date.now();
let steps = [];
prompt.on('submit', () => store.set(prompt.name, steps));
prompt.on('keypress', (ch, key) => {
let now = Date.now();
steps.push({ keypress: [ch, key], interval: now - prev });
prev = now;
});
prompt.run()
.then(answer => console.log('Answer:', answer))
.catch(console.error);