-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
76 lines (64 loc) · 1.32 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*!
* prompt-sort <https://github.com/enquirer/prompt-sort>
*
* Copyright (c) 2015-2017, Brian Woodward.
* Released under the MIT License.
*/
'use strict';
var debug = require('debug')('prompt-sort');
var List = require('prompt-list');
var cyan = require('ansi-cyan');
/**
* Create a new prompt:
*
* ```js
* var Prompt = require('prompt-sort');
* var prompt = new Prompt({
* name: 'colors',
* message: 'Sort colors from most to least favorite',
* choices: [
* 'green',
* 'red',
* 'yellow'
* ]
* });
*
* prompt.run()
* .then(function(answer) {
* console.log(answer);
* })
* ```
*/
function Prompt() {
debug('initializing from <%s>', __filename);
List.apply(this, arguments);
// disable "expand" behavior on up/down keypresses
this.options.expandChoices = false;
this.choices.check();
this.action('space', function(pos) {
return pos;
});
this.action('number', function(pos) {
return pos;
});
}
/**
* Inherit `List`
*/
List.extend(Prompt);
/**
* Override built-in `.renderAnswer` method
*/
Prompt.prototype.renderAnswer = function() {
return cyan(this.choices.checked.join(', '));
};
/**
* Override built-in `.getAnswer` method
*/
Prompt.prototype.getAnswer = function() {
return this.choices.checked;
};
/**
* Expose `Prompt`
*/
module.exports = Prompt;