-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
50 lines (39 loc) · 995 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
41
42
43
44
45
46
47
48
49
50
'use strict';
var debug = require('debug')('prompt-checkbox');
var Prompt = require('prompt-base');
var cyan = require('ansi-cyan');
/**
* Checkbox prompt
*/
function Checkbox() {
debug('initializing from <%s>', __filename);
Prompt.apply(this, arguments);
this.errorMessage = null;
this.infoMessage = this.options.infoMessage || '(Press '
+ cyan('<space>')
+ ' to toggle)';
}
/**
* Inherit prompt-base
*/
Prompt.extend(Checkbox);
/**
* Render all prompt choices to the terminal
*/
Checkbox.prototype.renderOutput = function() {
this.choices.options.filterList = true;
return this.choices.render(this.position, this.question.options);
};
/**
* Render only the selected choices to the terminal
*/
Checkbox.prototype.renderAnswer = function() {
var keys = this.choices.checked.map(function(choice) {
return typeof choice === 'string' ? choice : choice.value;
});
return cyan(keys.join(', '));
};
/**
* Module exports
*/
module.exports = Checkbox;