-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (34 loc) · 900 Bytes
/
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
'use strict';
var utils = require('readline-utils');
module.exports = function emit(prompt, val) {
prompt.once('ask', function() {
setImmediate(function() {
if (Array.isArray(val)) {
for (var i = 0; i < val.length; i++) {
utils.emitKey(prompt.ui.input, String(val[i]));
}
} else if (typeof val === 'number') {
utils.emitKey(prompt.ui.input, String(val));
} else if (typeof val !== 'string') {
throw new TypeError('expected answer value to be a string or number');
} else {
prompt.rl.write(val.replace(/\n+$/, ''));
}
prompt.rl.write('\n');
});
});
};
/**
* Get the `.up`, `.down`, `.left` and `.right` values to use
* on an answer.
*
* @name .keys
* @return {Object}
* @api public
*/
module.exports.keys = {
up: '\u001b[A',
down: '\u001b[B',
left: '\u001b[D',
right: '\u001b[C'
};