-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
46 lines (38 loc) · 1.15 KB
/
index.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 through = require('through');
const inquirer = require('inquirer');
const Observable = require('rxjs').Observable;
module.exports = (questions, done) => {
if (false === (questions instanceof Array)) {
throw new TypeError(`Expected \`questions\` to be of instance of \`array\``);
}
return new Observable(observer => {
let buffer = '';
const outputStream = through(data => {
if (/\u001b\[.*?(D|C)$/.test(data)) {
if (buffer.length > 0) {
observer.next(buffer);
buffer = '';
}
return;
}
buffer += data;
});
const prompt = inquirer.createPromptModule({
output: outputStream
});
prompt(questions)
.then(answers => {
// Clear the output
observer.next();
return done(answers);
})
.then(() => {
observer.complete();
})
.catch(err => {
observer.error(err);
});
return outputStream;
});
};