spyne-cli 0.6.8 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +80 -30
- package/index.js +123 -21
- package/package.json +24 -6
- package/src/cli/args.js +197 -0
- package/src/cli/render.js +184 -0
- package/src/core/create-app.js +232 -0
- package/src/core/generate-module.js +146 -0
- package/src/registry.js +174 -0
- package/src/spyne-file-prompt.js +77 -30
- package/src/templates/generate-prompt-input-fields.js +1 -1
- package/src/ui.js +5 -1
- package/lib/ansi.js +0 -116
- package/lib/combos.js +0 -75
- package/lib/completer.js +0 -52
- package/lib/interpolate.js +0 -266
- package/lib/keypress.js +0 -243
- package/lib/placeholder.js +0 -63
- package/lib/prompt.js +0 -485
- package/lib/prompts/autocomplete.js +0 -113
- package/lib/prompts/basicauth.js +0 -41
- package/lib/prompts/confirm.js +0 -13
- package/lib/prompts/editable.js +0 -136
- package/lib/prompts/form.js +0 -196
- package/lib/prompts/index.js +0 -28
- package/lib/prompts/input.js +0 -55
- package/lib/prompts/invisible.js +0 -11
- package/lib/prompts/list.js +0 -36
- package/lib/prompts/multiselect.js +0 -11
- package/lib/prompts/numeral.js +0 -1
- package/lib/prompts/password.js +0 -18
- package/lib/prompts/quiz.js +0 -37
- package/lib/prompts/scale.js +0 -237
- package/lib/prompts/select.js +0 -139
- package/lib/prompts/snippet.js +0 -185
- package/lib/prompts/sort.js +0 -37
- package/lib/prompts/survey.js +0 -163
- package/lib/prompts/text.js +0 -1
- package/lib/prompts/toggle.js +0 -109
- package/lib/render.js +0 -33
- package/lib/roles.js +0 -46
- package/lib/state.js +0 -69
- package/lib/styles.js +0 -144
- package/lib/symbols.js +0 -66
- package/lib/theme.js +0 -11
- package/lib/timer.js +0 -38
- package/lib/types/array.js +0 -658
- package/lib/types/auth.js +0 -29
- package/lib/types/boolean.js +0 -88
- package/lib/types/index.js +0 -7
- package/lib/types/number.js +0 -86
- package/lib/types/string.js +0 -185
- package/lib/utils.js +0 -268
- package/mocha.conf.cjs +0 -16
- package/src/app/channels/.gitkeep +0 -0
- package/src/app/channels/channel-custom.js +0 -1
- package/src/app/components/.gitkeep +0 -0
- package/src/app/traits/.gitkeep +0 -0
- package/src/hello-world-app-source/README.md +0 -15
- package/src/hello-world-app-source/apache-htaccess +0 -20
- package/src/hello-world-app-source/karma.conf.js +0 -75
- package/src/hello-world-app-source/package.json +0 -50
- package/src/hello-world-app-source/src/app/app-view.js +0 -38
- package/src/hello-world-app-source/src/app/channels/.gitkeep +0 -0
- package/src/hello-world-app-source/src/app/components/.gitkeep +0 -0
- package/src/hello-world-app-source/src/app/traits/.gitkeep +0 -0
- package/src/hello-world-app-source/src/index.js +0 -16
- package/src/hello-world-app-source/src/index.tmpl.html +0 -12
- package/src/hello-world-app-source/src/scss/01-vendors/normalize.css +0 -349
- package/src/hello-world-app-source/src/scss/02-variables/mixins.scss +0 -0
- package/src/hello-world-app-source/src/scss/03-components/.gitkeep +0 -0
- package/src/hello-world-app-source/src/scss/main.scss +0 -15
- package/src/hello-world-app-source/src/static/data/.gitkeep +0 -0
- package/src/hello-world-app-source/src/static/fonts/.gitkeep +0 -0
- package/src/hello-world-app-source/src/static/imgs/.gitkeep +0 -0
- package/src/hello-world-app-source/src/tests/unit-tests/index.test.js +0 -10
- package/src/hello-world-app-source/webpack.config.js +0 -178
- package/src/spyne-app-create.js +0 -209
- package/src/spyne-app-creator.js +0 -119
- package/src/spyne-starter-app-create.js +0 -147
- package/tests/create-spyne-app.test.js +0 -63
- package/tests/generate-file-prompt.test.js +0 -45
- package/tests/generate-file-string.test.js +0 -66
- package/tests/generate-prompt-input-fields-methods.test.js +0 -177
- package/tests/generate-prompt-input-fields.test.js +0 -179
- package/tests/generate-prompt-input-object.test.js +0 -39
- package/tests/generate-prompt-output.test.js +0 -58
- package/tests/index.test.js +0 -11
- package/tests/mocks/answers.js +0 -33
- package/tests/mocks/answers.json +0 -33
- package/tests/mocks/enquirer-data.js +0 -411
- package/tests/mocks/enquirer-data.json +0 -409
- package/tests/utils/file-utils.test.js +0 -84
package/lib/prompts/survey.js
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const ArrayPrompt = require('../types/array');
|
|
4
|
-
|
|
5
|
-
class Survey extends ArrayPrompt {
|
|
6
|
-
constructor(options = {}) {
|
|
7
|
-
super(options);
|
|
8
|
-
this.emptyError = options.emptyError || 'No items were selected';
|
|
9
|
-
this.term = process.env.TERM_PROGRAM;
|
|
10
|
-
|
|
11
|
-
if (!this.options.header) {
|
|
12
|
-
let header = ['', '4 - Strongly Agree', '3 - Agree', '2 - Neutral', '1 - Disagree', '0 - Strongly Disagree', ''];
|
|
13
|
-
header = header.map(ele => this.styles.muted(ele));
|
|
14
|
-
this.state.header = header.join('\n ');
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async toChoices(...args) {
|
|
19
|
-
if (this.createdScales) return false;
|
|
20
|
-
this.createdScales = true;
|
|
21
|
-
let choices = await super.toChoices(...args);
|
|
22
|
-
for (let choice of choices) {
|
|
23
|
-
choice.scale = createScale(5, this.options);
|
|
24
|
-
choice.scaleIdx = 2;
|
|
25
|
-
}
|
|
26
|
-
return choices;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
dispatch() {
|
|
30
|
-
this.alert();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
space() {
|
|
34
|
-
let choice = this.focused;
|
|
35
|
-
let ele = choice.scale[choice.scaleIdx];
|
|
36
|
-
let selected = ele.selected;
|
|
37
|
-
choice.scale.forEach(e => (e.selected = false));
|
|
38
|
-
ele.selected = !selected;
|
|
39
|
-
return this.render();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
indicator() {
|
|
43
|
-
return '';
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
pointer() {
|
|
47
|
-
return '';
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
separator() {
|
|
51
|
-
return this.styles.muted(this.symbols.ellipsis);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
right() {
|
|
55
|
-
let choice = this.focused;
|
|
56
|
-
if (choice.scaleIdx >= choice.scale.length - 1) return this.alert();
|
|
57
|
-
choice.scaleIdx++;
|
|
58
|
-
return this.render();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
left() {
|
|
62
|
-
let choice = this.focused;
|
|
63
|
-
if (choice.scaleIdx <= 0) return this.alert();
|
|
64
|
-
choice.scaleIdx--;
|
|
65
|
-
return this.render();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
indent() {
|
|
69
|
-
return ' ';
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async renderChoice(item, i) {
|
|
73
|
-
await this.onChoice(item, i);
|
|
74
|
-
let focused = this.index === i;
|
|
75
|
-
let isHyper = this.term === 'Hyper';
|
|
76
|
-
let n = !isHyper ? 8 : 9;
|
|
77
|
-
let s = !isHyper ? ' ' : '';
|
|
78
|
-
let ln = this.symbols.line.repeat(n);
|
|
79
|
-
let sp = ' '.repeat(n + (isHyper ? 0 : 1));
|
|
80
|
-
let dot = enabled => (enabled ? this.styles.success('◉') : '◯') + s;
|
|
81
|
-
|
|
82
|
-
let num = i + 1 + '.';
|
|
83
|
-
let color = focused ? this.styles.heading : this.styles.noop;
|
|
84
|
-
let msg = await this.resolve(item.message, this.state, item, i);
|
|
85
|
-
let indent = this.indent(item);
|
|
86
|
-
let scale = indent + item.scale.map((e, i) => dot(i === item.scaleIdx)).join(ln);
|
|
87
|
-
let val = i => i === item.scaleIdx ? color(i) : i;
|
|
88
|
-
let next = indent + item.scale.map((e, i) => val(i)).join(sp);
|
|
89
|
-
|
|
90
|
-
let line = () => [num, msg].filter(Boolean).join(' ');
|
|
91
|
-
let lines = () => [line(), scale, next, ' '].filter(Boolean).join('\n');
|
|
92
|
-
|
|
93
|
-
if (focused) {
|
|
94
|
-
scale = this.styles.cyan(scale);
|
|
95
|
-
next = this.styles.cyan(next);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return lines();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async renderChoices() {
|
|
102
|
-
if (this.state.submitted) return '';
|
|
103
|
-
let choices = this.visible.map(async(ch, i) => await this.renderChoice(ch, i));
|
|
104
|
-
let visible = await Promise.all(choices);
|
|
105
|
-
if (!visible.length) visible.push(this.styles.danger('No matching choices'));
|
|
106
|
-
return visible.join('\n');
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
format() {
|
|
110
|
-
if (this.state.submitted) {
|
|
111
|
-
let values = this.choices.map(ch => this.styles.info(ch.scaleIdx));
|
|
112
|
-
return values.join(', ');
|
|
113
|
-
}
|
|
114
|
-
return '';
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
async render() {
|
|
118
|
-
let { submitted, size } = this.state;
|
|
119
|
-
|
|
120
|
-
let prefix = await this.prefix();
|
|
121
|
-
let separator = await this.separator();
|
|
122
|
-
let message = await this.message();
|
|
123
|
-
|
|
124
|
-
let prompt = [prefix, message, separator].filter(Boolean).join(' ');
|
|
125
|
-
this.state.prompt = prompt;
|
|
126
|
-
|
|
127
|
-
let header = await this.header();
|
|
128
|
-
let output = await this.format();
|
|
129
|
-
let help = await this.error() || await this.hint();
|
|
130
|
-
let body = await this.renderChoices();
|
|
131
|
-
let footer = await this.footer();
|
|
132
|
-
|
|
133
|
-
if (output || !help) prompt += ' ' + output;
|
|
134
|
-
if (help && !prompt.includes(help)) prompt += ' ' + help;
|
|
135
|
-
|
|
136
|
-
if (submitted && !output && !body && this.multiple && this.type !== 'form') {
|
|
137
|
-
prompt += this.styles.danger(this.emptyError);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
this.clear(size);
|
|
141
|
-
this.write([prompt, header, body, footer].filter(Boolean).join('\n'));
|
|
142
|
-
this.restore();
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
submit() {
|
|
146
|
-
this.value = {};
|
|
147
|
-
for (let choice of this.choices) {
|
|
148
|
-
this.value[choice.name] = choice.scaleIdx;
|
|
149
|
-
}
|
|
150
|
-
return this.base.submit.call(this);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function createScale(n, options = {}) {
|
|
155
|
-
if (Array.isArray(options.scale)) {
|
|
156
|
-
return options.scale.map(ele => ({ ...ele }));
|
|
157
|
-
}
|
|
158
|
-
let scale = [];
|
|
159
|
-
for (let i = 1; i < n + 1; i++) scale.push({ i, selected: false });
|
|
160
|
-
return scale;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
module.exports = Survey;
|
package/lib/prompts/text.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('./input');
|
package/lib/prompts/toggle.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const BooleanPrompt = require('../types/boolean');
|
|
4
|
-
|
|
5
|
-
class TogglePrompt extends BooleanPrompt {
|
|
6
|
-
async initialize() {
|
|
7
|
-
await super.initialize();
|
|
8
|
-
this.value = this.initial = !!this.options.initial;
|
|
9
|
-
this.disabled = this.options.disabled || 'no';
|
|
10
|
-
this.enabled = this.options.enabled || 'yes';
|
|
11
|
-
await this.render();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
reset() {
|
|
15
|
-
this.value = this.initial;
|
|
16
|
-
this.render();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
delete() {
|
|
20
|
-
this.alert();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
toggle() {
|
|
24
|
-
this.value = !this.value;
|
|
25
|
-
this.render();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
enable() {
|
|
29
|
-
if (this.value === true) return this.alert();
|
|
30
|
-
this.value = true;
|
|
31
|
-
this.render();
|
|
32
|
-
}
|
|
33
|
-
disable() {
|
|
34
|
-
if (this.value === false) return this.alert();
|
|
35
|
-
this.value = false;
|
|
36
|
-
this.render();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
up() {
|
|
40
|
-
this.toggle();
|
|
41
|
-
}
|
|
42
|
-
down() {
|
|
43
|
-
this.toggle();
|
|
44
|
-
}
|
|
45
|
-
right() {
|
|
46
|
-
this.toggle();
|
|
47
|
-
}
|
|
48
|
-
left() {
|
|
49
|
-
this.toggle();
|
|
50
|
-
}
|
|
51
|
-
next() {
|
|
52
|
-
this.toggle();
|
|
53
|
-
}
|
|
54
|
-
prev() {
|
|
55
|
-
this.toggle();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
dispatch(ch = '', key) {
|
|
59
|
-
switch (ch.toLowerCase()) {
|
|
60
|
-
case ' ':
|
|
61
|
-
return this.toggle();
|
|
62
|
-
case '1':
|
|
63
|
-
case 'y':
|
|
64
|
-
case 't':
|
|
65
|
-
return this.enable();
|
|
66
|
-
case '0':
|
|
67
|
-
case 'n':
|
|
68
|
-
case 'f':
|
|
69
|
-
return this.disable();
|
|
70
|
-
default: {
|
|
71
|
-
return this.alert();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
format() {
|
|
77
|
-
let active = str => this.styles.primary.underline(str);
|
|
78
|
-
let value = [
|
|
79
|
-
this.value ? this.disabled : active(this.disabled),
|
|
80
|
-
this.value ? active(this.enabled) : this.enabled
|
|
81
|
-
];
|
|
82
|
-
return value.join(this.styles.muted(' / '));
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async render() {
|
|
86
|
-
let { size } = this.state;
|
|
87
|
-
|
|
88
|
-
let header = await this.header();
|
|
89
|
-
let prefix = await this.prefix();
|
|
90
|
-
let separator = await this.separator();
|
|
91
|
-
let message = await this.message();
|
|
92
|
-
|
|
93
|
-
let output = await this.format();
|
|
94
|
-
let help = (await this.error()) || (await this.hint());
|
|
95
|
-
let footer = await this.footer();
|
|
96
|
-
|
|
97
|
-
let prompt = [prefix, message, separator, output].join(' ');
|
|
98
|
-
this.state.prompt = prompt;
|
|
99
|
-
|
|
100
|
-
if (help && !prompt.includes(help)) prompt += ' ' + help;
|
|
101
|
-
|
|
102
|
-
this.clear(size);
|
|
103
|
-
this.write([header, prompt, footer].filter(Boolean).join('\n'));
|
|
104
|
-
this.write(this.margin[2]);
|
|
105
|
-
this.restore();
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
module.exports = TogglePrompt;
|
package/lib/render.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = async(value, prompt, context = {}) => {
|
|
4
|
-
let { choices, multiple } = prompt.options;
|
|
5
|
-
let { size, submitted } = prompt.state;
|
|
6
|
-
|
|
7
|
-
let prefix = context.prefix || await prompt.prefix();
|
|
8
|
-
let separator = context.separator || await prompt.separator();
|
|
9
|
-
let message = context.message || await prompt.message();
|
|
10
|
-
|
|
11
|
-
// ? Select your favorite colors >
|
|
12
|
-
// ^ ^ ^
|
|
13
|
-
// prefix message separator
|
|
14
|
-
let promptLine = [prefix, message, separator].filter(Boolean).join(' ');
|
|
15
|
-
prompt.state.prompt = promptLine;
|
|
16
|
-
|
|
17
|
-
let header = context.header || await prompt.header();
|
|
18
|
-
let output = context.format || await prompt.format(value);
|
|
19
|
-
let help = context.help || await prompt.error() || await prompt.hint();
|
|
20
|
-
let body = context.body || await prompt.body();
|
|
21
|
-
let footer = context.footer || await prompt.footer();
|
|
22
|
-
|
|
23
|
-
if (output || !help) promptLine += ' ' + output;
|
|
24
|
-
if (help && !promptLine.includes(help)) promptLine += ' ' + help;
|
|
25
|
-
|
|
26
|
-
if (submitted && choices && multiple && !output && !body) {
|
|
27
|
-
promptLine += prompt.styles.danger('No items were selected');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
prompt.clear(size);
|
|
31
|
-
prompt.write([header, promptLine, body, footer].filter(Boolean).join('\n'));
|
|
32
|
-
prompt.restore();
|
|
33
|
-
};
|
package/lib/roles.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const utils = require('./utils');
|
|
4
|
-
const roles = {
|
|
5
|
-
default(prompt, choice) {
|
|
6
|
-
return choice;
|
|
7
|
-
},
|
|
8
|
-
checkbox(prompt, choice) {
|
|
9
|
-
throw new Error('checkbox role is not implemented yet');
|
|
10
|
-
},
|
|
11
|
-
editable(prompt, choice) {
|
|
12
|
-
throw new Error('editable role is not implemented yet');
|
|
13
|
-
},
|
|
14
|
-
expandable(prompt, choice) {
|
|
15
|
-
throw new Error('expandable role is not implemented yet');
|
|
16
|
-
},
|
|
17
|
-
heading(prompt, choice) {
|
|
18
|
-
choice.disabled = '';
|
|
19
|
-
choice.indicator = [choice.indicator, ' '].find(v => v != null);
|
|
20
|
-
choice.message = choice.message || '';
|
|
21
|
-
return choice;
|
|
22
|
-
},
|
|
23
|
-
input(prompt, choice) {
|
|
24
|
-
throw new Error('input role is not implemented yet');
|
|
25
|
-
},
|
|
26
|
-
option(prompt, choice) {
|
|
27
|
-
return roles.default(prompt, choice);
|
|
28
|
-
},
|
|
29
|
-
radio(prompt, choice) {
|
|
30
|
-
throw new Error('radio role is not implemented yet');
|
|
31
|
-
},
|
|
32
|
-
separator(prompt, choice) {
|
|
33
|
-
choice.disabled = '';
|
|
34
|
-
choice.indicator = [choice.indicator, ' '].find(v => v != null);
|
|
35
|
-
choice.message = choice.message || prompt.symbols.line.repeat(5);
|
|
36
|
-
return choice;
|
|
37
|
-
},
|
|
38
|
-
spacer(prompt, choice) {
|
|
39
|
-
return choice;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
module.exports = (name, options = {}) => {
|
|
44
|
-
let role = utils.merge({}, roles, options.roles);
|
|
45
|
-
return role[name] || role.default;
|
|
46
|
-
};
|
package/lib/state.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { define, width } = require('./utils');
|
|
4
|
-
|
|
5
|
-
class State {
|
|
6
|
-
constructor(prompt) {
|
|
7
|
-
let options = prompt.options;
|
|
8
|
-
define(this, '_prompt', prompt);
|
|
9
|
-
this.type = prompt.type;
|
|
10
|
-
this.name = prompt.name;
|
|
11
|
-
this.message = '';
|
|
12
|
-
this.header = '';
|
|
13
|
-
this.footer = '';
|
|
14
|
-
this.error = '';
|
|
15
|
-
this.hint = '';
|
|
16
|
-
this.input = '';
|
|
17
|
-
this.cursor = 0;
|
|
18
|
-
this.index = 0;
|
|
19
|
-
this.lines = 0;
|
|
20
|
-
this.tick = 0;
|
|
21
|
-
this.prompt = '';
|
|
22
|
-
this.buffer = '';
|
|
23
|
-
this.width = width(options.stdout || process.stdout);
|
|
24
|
-
Object.assign(this, options);
|
|
25
|
-
this.name = this.name || this.message;
|
|
26
|
-
this.message = this.message || this.name;
|
|
27
|
-
this.symbols = prompt.symbols;
|
|
28
|
-
this.styles = prompt.styles;
|
|
29
|
-
this.required = new Set();
|
|
30
|
-
this.cancelled = false;
|
|
31
|
-
this.submitted = false;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
clone() {
|
|
35
|
-
let state = { ...this };
|
|
36
|
-
state.status = this.status;
|
|
37
|
-
state.buffer = Buffer.from(state.buffer);
|
|
38
|
-
delete state.clone;
|
|
39
|
-
return state;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
set color(val) {
|
|
43
|
-
this._color = val;
|
|
44
|
-
}
|
|
45
|
-
get color() {
|
|
46
|
-
let styles = this.prompt.styles;
|
|
47
|
-
if (this.cancelled) return styles.cancelled;
|
|
48
|
-
if (this.submitted) return styles.submitted;
|
|
49
|
-
let color = this._color || styles[this.status];
|
|
50
|
-
return typeof color === 'function' ? color : styles.pending;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
set loading(value) {
|
|
54
|
-
this._loading = value;
|
|
55
|
-
}
|
|
56
|
-
get loading() {
|
|
57
|
-
if (typeof this._loading === 'boolean') return this._loading;
|
|
58
|
-
if (this.loadingChoices) return 'choices';
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
get status() {
|
|
63
|
-
if (this.cancelled) return 'cancelled';
|
|
64
|
-
if (this.submitted) return 'submitted';
|
|
65
|
-
return 'pending';
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
module.exports = State;
|
package/lib/styles.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const utils = require('./utils');
|
|
4
|
-
const colors = require('ansi-colors');
|
|
5
|
-
|
|
6
|
-
const styles = {
|
|
7
|
-
default: colors.noop,
|
|
8
|
-
noop: colors.noop,
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Modifiers
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
set inverse(custom) {
|
|
15
|
-
this._inverse = custom;
|
|
16
|
-
},
|
|
17
|
-
get inverse() {
|
|
18
|
-
return this._inverse || utils.inverse(this.primary);
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
set complement(custom) {
|
|
22
|
-
this._complement = custom;
|
|
23
|
-
},
|
|
24
|
-
get complement() {
|
|
25
|
-
return this._complement || utils.complement(this.primary);
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Main color
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
primary: colors.cyan,
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Main palette
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
success: colors.green,
|
|
39
|
-
danger: colors.magenta,
|
|
40
|
-
strong: colors.bold,
|
|
41
|
-
warning: colors.yellow,
|
|
42
|
-
muted: colors.dim,
|
|
43
|
-
disabled: colors.gray,
|
|
44
|
-
dark: colors.dim.gray,
|
|
45
|
-
underline: colors.underline,
|
|
46
|
-
|
|
47
|
-
set info(custom) {
|
|
48
|
-
this._info = custom;
|
|
49
|
-
},
|
|
50
|
-
get info() {
|
|
51
|
-
return this._info || this.primary;
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
set em(custom) {
|
|
55
|
-
this._em = custom;
|
|
56
|
-
},
|
|
57
|
-
get em() {
|
|
58
|
-
return this._em || this.primary.underline;
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
set heading(custom) {
|
|
62
|
-
this._heading = custom;
|
|
63
|
-
},
|
|
64
|
-
get heading() {
|
|
65
|
-
return this._heading || this.muted.underline;
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Statuses
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
set pending(custom) {
|
|
73
|
-
this._pending = custom;
|
|
74
|
-
},
|
|
75
|
-
get pending() {
|
|
76
|
-
return this._pending || this.primary;
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
set submitted(custom) {
|
|
80
|
-
this._submitted = custom;
|
|
81
|
-
},
|
|
82
|
-
get submitted() {
|
|
83
|
-
return this._submitted || this.success;
|
|
84
|
-
},
|
|
85
|
-
|
|
86
|
-
set cancelled(custom) {
|
|
87
|
-
this._cancelled = custom;
|
|
88
|
-
},
|
|
89
|
-
get cancelled() {
|
|
90
|
-
return this._cancelled || this.danger;
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Special styling
|
|
95
|
-
*/
|
|
96
|
-
|
|
97
|
-
set typing(custom) {
|
|
98
|
-
this._typing = custom;
|
|
99
|
-
},
|
|
100
|
-
get typing() {
|
|
101
|
-
return this._typing || this.dim;
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
set placeholder(custom) {
|
|
105
|
-
this._placeholder = custom;
|
|
106
|
-
},
|
|
107
|
-
get placeholder() {
|
|
108
|
-
return this._placeholder || this.primary.dim;
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
set highlight(custom) {
|
|
112
|
-
this._highlight = custom;
|
|
113
|
-
},
|
|
114
|
-
get highlight() {
|
|
115
|
-
return this._highlight || this.inverse;
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
styles.merge = (options = {}) => {
|
|
120
|
-
if (options.styles && typeof options.styles.enabled === 'boolean') {
|
|
121
|
-
colors.enabled = options.styles.enabled;
|
|
122
|
-
}
|
|
123
|
-
if (options.styles && typeof options.styles.visible === 'boolean') {
|
|
124
|
-
colors.visible = options.styles.visible;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
let result = utils.merge({}, styles, options.styles);
|
|
128
|
-
delete result.merge;
|
|
129
|
-
|
|
130
|
-
for (let key of Object.keys(colors)) {
|
|
131
|
-
if (!result.hasOwnProperty(key)) {
|
|
132
|
-
Reflect.defineProperty(result, key, { get: () => colors[key] });
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
for (let key of Object.keys(colors.styles)) {
|
|
137
|
-
if (!result.hasOwnProperty(key)) {
|
|
138
|
-
Reflect.defineProperty(result, key, { get: () => colors[key] });
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return result;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
module.exports = styles;
|
package/lib/symbols.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const isWindows = process.platform === 'win32';
|
|
4
|
-
const colors = require('ansi-colors');
|
|
5
|
-
const utils = require('./utils');
|
|
6
|
-
|
|
7
|
-
const symbols = {
|
|
8
|
-
...colors.symbols,
|
|
9
|
-
upDownDoubleArrow: '⇕',
|
|
10
|
-
upDownDoubleArrow2: '⬍',
|
|
11
|
-
upDownArrow: '↕',
|
|
12
|
-
asterisk: '*',
|
|
13
|
-
asterism: '⁂',
|
|
14
|
-
bulletWhite: '◦',
|
|
15
|
-
electricArrow: '⌁',
|
|
16
|
-
ellipsisLarge: '⋯',
|
|
17
|
-
ellipsisSmall: '…',
|
|
18
|
-
fullBlock: '█',
|
|
19
|
-
identicalTo: '≡',
|
|
20
|
-
indicator: colors.symbols.check,
|
|
21
|
-
leftAngle: '‹',
|
|
22
|
-
mark: '※',
|
|
23
|
-
minus: '−',
|
|
24
|
-
multiplication: '×',
|
|
25
|
-
obelus: '÷',
|
|
26
|
-
percent: '%',
|
|
27
|
-
pilcrow: '¶',
|
|
28
|
-
pilcrow2: '❡',
|
|
29
|
-
pencilUpRight: '✐',
|
|
30
|
-
pencilDownRight: '✎',
|
|
31
|
-
pencilRight: '✏',
|
|
32
|
-
plus: '+',
|
|
33
|
-
plusMinus: '±',
|
|
34
|
-
pointRight: '☞',
|
|
35
|
-
rightAngle: '›',
|
|
36
|
-
section: '§',
|
|
37
|
-
hexagon: { off: '⬡', on: '⬢', disabled: '⬢' },
|
|
38
|
-
ballot: { on: '☑', off: '☐', disabled: '☒' },
|
|
39
|
-
stars: { on: '★', off: '☆', disabled: '☆' },
|
|
40
|
-
folder: { on: '▼', off: '▶', disabled: '▶' },
|
|
41
|
-
prefix: {
|
|
42
|
-
pending: colors.symbols.question,
|
|
43
|
-
submitted: colors.symbols.check,
|
|
44
|
-
cancelled: colors.symbols.cross
|
|
45
|
-
},
|
|
46
|
-
separator: {
|
|
47
|
-
pending: colors.symbols.pointerSmall,
|
|
48
|
-
submitted: colors.symbols.middot,
|
|
49
|
-
cancelled: colors.symbols.middot
|
|
50
|
-
},
|
|
51
|
-
radio: {
|
|
52
|
-
off: isWindows ? '( )' : '◯',
|
|
53
|
-
on: isWindows ? '(*)' : '◉',
|
|
54
|
-
disabled: isWindows ? '(|)' : 'Ⓘ'
|
|
55
|
-
},
|
|
56
|
-
numbers: ['⓪', '①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨', '⑩', '⑪', '⑫', '⑬', '⑭', '⑮', '⑯', '⑰', '⑱', '⑲', '⑳', '㉑', '㉒', '㉓', '㉔', '㉕', '㉖', '㉗', '㉘', '㉙', '㉚', '㉛', '㉜', '㉝', '㉞', '㉟', '㊱', '㊲', '㊳', '㊴', '㊵', '㊶', '㊷', '㊸', '㊹', '㊺', '㊻', '㊼', '㊽', '㊾', '㊿']
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
symbols.merge = options => {
|
|
60
|
-
let result = utils.merge({}, colors.symbols, symbols, options.symbols);
|
|
61
|
-
delete result.merge;
|
|
62
|
-
return result;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
module.exports = symbols;
|
|
66
|
-
|
package/lib/theme.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const styles = require('./styles');
|
|
4
|
-
const symbols = require('./symbols');
|
|
5
|
-
const utils = require('./utils');
|
|
6
|
-
|
|
7
|
-
module.exports = prompt => {
|
|
8
|
-
prompt.options = utils.merge({}, prompt.options.theme, prompt.options);
|
|
9
|
-
prompt.symbols = symbols.merge(prompt.options);
|
|
10
|
-
prompt.styles = styles.merge(prompt.options);
|
|
11
|
-
};
|
package/lib/timer.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = prompt => {
|
|
4
|
-
prompt.timers = prompt.timers || {};
|
|
5
|
-
|
|
6
|
-
let timers = prompt.options.timers;
|
|
7
|
-
if (!timers) return;
|
|
8
|
-
|
|
9
|
-
for (let key of Object.keys(timers)) {
|
|
10
|
-
let opts = timers[key];
|
|
11
|
-
if (typeof opts === 'number') {
|
|
12
|
-
opts = { interval: opts };
|
|
13
|
-
}
|
|
14
|
-
create(prompt, key, opts);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
function create(prompt, name, options = {}) {
|
|
19
|
-
let timer = prompt.timers[name] = { name, start: Date.now(), ms: 0, tick: 0 };
|
|
20
|
-
let ms = options.interval || 120;
|
|
21
|
-
timer.frames = options.frames || [];
|
|
22
|
-
timer.loading = true;
|
|
23
|
-
|
|
24
|
-
let interval = setInterval(() => {
|
|
25
|
-
timer.ms = Date.now() - timer.start;
|
|
26
|
-
timer.tick++;
|
|
27
|
-
prompt.render();
|
|
28
|
-
}, ms);
|
|
29
|
-
|
|
30
|
-
timer.stop = () => {
|
|
31
|
-
timer.loading = false;
|
|
32
|
-
clearInterval(interval);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
Reflect.defineProperty(timer, 'interval', { value: interval });
|
|
36
|
-
prompt.once('close', () => timer.stop());
|
|
37
|
-
return timer.stop;
|
|
38
|
-
}
|