first commit
This commit is contained in:
118
app_vue/node_modules/enquirer/lib/prompts/autocomplete.js
generated
vendored
Normal file
118
app_vue/node_modules/enquirer/lib/prompts/autocomplete.js
generated
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
'use strict';
|
||||
|
||||
const Select = require('./select');
|
||||
|
||||
const highlight = (input, color) => {
|
||||
const regex = input ? new RegExp(input, 'ig') : /$^/;
|
||||
|
||||
return str => {
|
||||
return input ? str.replace(regex, match => color(match)) : str;
|
||||
};
|
||||
};
|
||||
|
||||
class AutoComplete extends Select {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this.cursorShow();
|
||||
}
|
||||
|
||||
moveCursor(n) {
|
||||
this.state.cursor += n;
|
||||
}
|
||||
|
||||
dispatch(ch) {
|
||||
return this.append(ch);
|
||||
}
|
||||
|
||||
space(ch) {
|
||||
return this.options.multiple ? super.space(ch) : this.append(ch);
|
||||
}
|
||||
|
||||
append(ch) {
|
||||
let { cursor, input } = this.state;
|
||||
this.input = input.slice(0, cursor) + ch + input.slice(cursor);
|
||||
this.moveCursor(1);
|
||||
return this.complete();
|
||||
}
|
||||
|
||||
delete() {
|
||||
let { cursor, input } = this.state;
|
||||
if (!input) return this.alert();
|
||||
this.input = input.slice(0, cursor - 1) + input.slice(cursor);
|
||||
this.moveCursor(-1);
|
||||
return this.complete();
|
||||
}
|
||||
|
||||
deleteForward() {
|
||||
let { cursor, input } = this.state;
|
||||
if (input[cursor] === void 0) return this.alert();
|
||||
this.input = `${input}`.slice(0, cursor) + `${input}`.slice(cursor + 1);
|
||||
return this.complete();
|
||||
}
|
||||
|
||||
number(ch) {
|
||||
return this.append(ch);
|
||||
}
|
||||
|
||||
async complete() {
|
||||
this.completing = true;
|
||||
this.choices = await this.suggest(this.input, this.state._choices);
|
||||
this.state.limit = void 0; // allow getter/setter to reset limit
|
||||
this.index = Math.min(Math.max(this.visible.length - 1, 0), this.index);
|
||||
await this.render();
|
||||
this.completing = false;
|
||||
}
|
||||
|
||||
suggest(input = this.input, choices = this.state._choices) {
|
||||
if (typeof this.options.suggest === 'function') {
|
||||
return this.options.suggest.call(this, input, choices);
|
||||
}
|
||||
let str = input.toLowerCase();
|
||||
return choices.filter(ch => ch.message.toLowerCase().includes(str));
|
||||
}
|
||||
|
||||
pointer() {
|
||||
return '';
|
||||
}
|
||||
|
||||
format() {
|
||||
if (!this.focused) return this.input;
|
||||
|
||||
if (this.options.multiple && this.state.submitted) {
|
||||
return this.selected.map(ch => this.styles.primary(ch.message)).join(', ');
|
||||
}
|
||||
|
||||
if (this.state.submitted) {
|
||||
let value = this.value = this.input = this.focused.value;
|
||||
return this.styles.primary(value);
|
||||
}
|
||||
|
||||
return this.input;
|
||||
}
|
||||
|
||||
async render() {
|
||||
if (this.state.status !== 'pending') return super.render();
|
||||
const hl = this.options.highlight || this.styles.complement;
|
||||
|
||||
const style = (input, color) => {
|
||||
if (!input) return input;
|
||||
if (hl.stack) return hl(input);
|
||||
return hl.call(this, input);
|
||||
};
|
||||
|
||||
const color = highlight(this.input, style);
|
||||
const choices = this.choices;
|
||||
this.choices = choices.map(ch => ({ ...ch, message: color(ch.message) }));
|
||||
await super.render();
|
||||
this.choices = choices;
|
||||
}
|
||||
|
||||
submit() {
|
||||
if (this.options.multiple) {
|
||||
this.value = this.selected.map(ch => ch.name);
|
||||
}
|
||||
return super.submit();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AutoComplete;
|
41
app_vue/node_modules/enquirer/lib/prompts/basicauth.js
generated
vendored
Normal file
41
app_vue/node_modules/enquirer/lib/prompts/basicauth.js
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
|
||||
const AuthPrompt = require('../types/auth');
|
||||
|
||||
function defaultAuthenticate(value, state) {
|
||||
if (value.username === this.options.username && value.password === this.options.password) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const factory = (authenticate = defaultAuthenticate) => {
|
||||
const choices = [
|
||||
{ name: 'username', message: 'username' },
|
||||
{
|
||||
name: 'password',
|
||||
message: 'password',
|
||||
format(input) {
|
||||
if (this.options.showPassword) {
|
||||
return input;
|
||||
}
|
||||
let color = this.state.submitted ? this.styles.primary : this.styles.muted;
|
||||
return color(this.symbols.asterisk.repeat(input.length));
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
class BasicAuthPrompt extends AuthPrompt.create(authenticate) {
|
||||
constructor(options) {
|
||||
super({ ...options, choices });
|
||||
}
|
||||
|
||||
static create(authenticate) {
|
||||
return factory(authenticate);
|
||||
}
|
||||
}
|
||||
|
||||
return BasicAuthPrompt;
|
||||
};
|
||||
|
||||
module.exports = factory();
|
13
app_vue/node_modules/enquirer/lib/prompts/confirm.js
generated
vendored
Normal file
13
app_vue/node_modules/enquirer/lib/prompts/confirm.js
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const BooleanPrompt = require('../types/boolean');
|
||||
|
||||
class ConfirmPrompt extends BooleanPrompt {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this.default = this.options.default || (this.initial ? '(Y/n)' : '(y/N)');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ConfirmPrompt;
|
||||
|
136
app_vue/node_modules/enquirer/lib/prompts/editable.js
generated
vendored
Normal file
136
app_vue/node_modules/enquirer/lib/prompts/editable.js
generated
vendored
Normal file
@ -0,0 +1,136 @@
|
||||
'use strict';
|
||||
|
||||
const Select = require('./select');
|
||||
const Form = require('./form');
|
||||
const form = Form.prototype;
|
||||
|
||||
class Editable extends Select {
|
||||
constructor(options) {
|
||||
super({ ...options, multiple: true });
|
||||
this.align = [this.options.align, 'left'].find(v => v != null);
|
||||
this.emptyError = '';
|
||||
this.values = {};
|
||||
}
|
||||
|
||||
dispatch(char, key) {
|
||||
let choice = this.focused;
|
||||
let parent = choice.parent || {};
|
||||
if (!choice.editable && !parent.editable) {
|
||||
if (char === 'a' || char === 'i') return super[char]();
|
||||
}
|
||||
return form.dispatch.call(this, char, key);
|
||||
}
|
||||
|
||||
append(char, key) {
|
||||
return form.append.call(this, char, key);
|
||||
}
|
||||
|
||||
delete(char, key) {
|
||||
return form.delete.call(this, char, key);
|
||||
}
|
||||
|
||||
space(char) {
|
||||
return this.focused.editable ? this.append(char) : super.space();
|
||||
}
|
||||
|
||||
number(char) {
|
||||
return this.focused.editable ? this.append(char) : super.number(char);
|
||||
}
|
||||
|
||||
next() {
|
||||
return this.focused.editable ? form.next.call(this) : super.next();
|
||||
}
|
||||
|
||||
prev() {
|
||||
return this.focused.editable ? form.prev.call(this) : super.prev();
|
||||
}
|
||||
|
||||
async indicator(choice, i) {
|
||||
let symbol = choice.indicator || '';
|
||||
let value = choice.editable ? symbol : super.indicator(choice, i);
|
||||
return await this.resolve(value, this.state, choice, i) || '';
|
||||
}
|
||||
|
||||
indent(choice) {
|
||||
return choice.role === 'heading' ? '' : (choice.editable ? ' ' : ' ');
|
||||
}
|
||||
|
||||
async renderChoice(choice, i) {
|
||||
choice.indent = '';
|
||||
if (choice.editable) return form.renderChoice.call(this, choice, i);
|
||||
return super.renderChoice(choice, i);
|
||||
}
|
||||
|
||||
error() {
|
||||
return '';
|
||||
}
|
||||
|
||||
footer() {
|
||||
return this.state.error;
|
||||
}
|
||||
|
||||
async validate() {
|
||||
let result = true;
|
||||
|
||||
for (let choice of this.choices) {
|
||||
if (typeof choice.validate !== 'function') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (choice.role === 'heading') {
|
||||
continue;
|
||||
}
|
||||
|
||||
let val = choice.parent ? this.value[choice.parent.name] : this.value;
|
||||
|
||||
if (choice.editable) {
|
||||
val = choice.value === choice.name ? choice.initial || '' : choice.value;
|
||||
} else if (!this.isDisabled(choice)) {
|
||||
val = choice.enabled === true;
|
||||
}
|
||||
|
||||
result = await choice.validate(val, this.state);
|
||||
|
||||
if (result !== true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (result !== true) {
|
||||
this.state.error = typeof result === 'string' ? result : 'Invalid Input';
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
submit() {
|
||||
if (this.focused.newChoice === true) return super.submit();
|
||||
if (this.choices.some(ch => ch.newChoice)) {
|
||||
return this.alert();
|
||||
}
|
||||
|
||||
this.value = {};
|
||||
|
||||
for (let choice of this.choices) {
|
||||
let val = choice.parent ? this.value[choice.parent.name] : this.value;
|
||||
|
||||
if (choice.role === 'heading') {
|
||||
this.value[choice.name] = {};
|
||||
continue;
|
||||
}
|
||||
|
||||
if (choice.editable) {
|
||||
val[choice.name] = choice.value === choice.name
|
||||
? (choice.initial || '')
|
||||
: choice.value;
|
||||
|
||||
} else if (!this.isDisabled(choice)) {
|
||||
val[choice.name] = choice.enabled === true;
|
||||
}
|
||||
}
|
||||
|
||||
return this.base.submit.call(this);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Editable;
|
195
app_vue/node_modules/enquirer/lib/prompts/form.js
generated
vendored
Normal file
195
app_vue/node_modules/enquirer/lib/prompts/form.js
generated
vendored
Normal file
@ -0,0 +1,195 @@
|
||||
'use strict';
|
||||
|
||||
const stripAnsi = require('strip-ansi');
|
||||
const SelectPrompt = require('./select');
|
||||
const placeholder = require('../placeholder');
|
||||
|
||||
class FormPrompt extends SelectPrompt {
|
||||
constructor(options) {
|
||||
super({ ...options, multiple: true });
|
||||
this.type = 'form';
|
||||
this.initial = this.options.initial;
|
||||
this.align = [this.options.align, 'right'].find(v => v != null);
|
||||
this.emptyError = '';
|
||||
this.values = {};
|
||||
}
|
||||
|
||||
async reset(first) {
|
||||
await super.reset();
|
||||
if (first === true) this._index = this.index;
|
||||
this.index = this._index;
|
||||
this.values = {};
|
||||
this.choices.forEach(choice => choice.reset && choice.reset());
|
||||
return this.render();
|
||||
}
|
||||
|
||||
dispatch(char) {
|
||||
return !!char && this.append(char);
|
||||
}
|
||||
|
||||
append(char) {
|
||||
let choice = this.focused;
|
||||
if (!choice) return this.alert();
|
||||
let { cursor, input } = choice;
|
||||
choice.value = choice.input = input.slice(0, cursor) + char + input.slice(cursor);
|
||||
choice.cursor++;
|
||||
return this.render();
|
||||
}
|
||||
|
||||
delete() {
|
||||
let choice = this.focused;
|
||||
if (!choice || choice.cursor <= 0) return this.alert();
|
||||
let { cursor, input } = choice;
|
||||
choice.value = choice.input = input.slice(0, cursor - 1) + input.slice(cursor);
|
||||
choice.cursor--;
|
||||
return this.render();
|
||||
}
|
||||
|
||||
deleteForward() {
|
||||
let choice = this.focused;
|
||||
if (!choice) return this.alert();
|
||||
let { cursor, input } = choice;
|
||||
if (input[cursor] === void 0) return this.alert();
|
||||
let str = `${input}`.slice(0, cursor) + `${input}`.slice(cursor + 1);
|
||||
choice.value = choice.input = str;
|
||||
return this.render();
|
||||
}
|
||||
|
||||
right() {
|
||||
let choice = this.focused;
|
||||
if (!choice) return this.alert();
|
||||
if (choice.cursor >= choice.input.length) return this.alert();
|
||||
choice.cursor++;
|
||||
return this.render();
|
||||
}
|
||||
|
||||
left() {
|
||||
let choice = this.focused;
|
||||
if (!choice) return this.alert();
|
||||
if (choice.cursor <= 0) return this.alert();
|
||||
choice.cursor--;
|
||||
return this.render();
|
||||
}
|
||||
|
||||
space(ch, key) {
|
||||
return this.dispatch(ch, key);
|
||||
}
|
||||
|
||||
number(ch, key) {
|
||||
return this.dispatch(ch, key);
|
||||
}
|
||||
|
||||
next() {
|
||||
let ch = this.focused;
|
||||
if (!ch) return this.alert();
|
||||
let { initial, input } = ch;
|
||||
if (initial && initial.startsWith(input) && input !== initial) {
|
||||
ch.value = ch.input = initial;
|
||||
ch.cursor = ch.value.length;
|
||||
return this.render();
|
||||
}
|
||||
return super.next();
|
||||
}
|
||||
|
||||
prev() {
|
||||
let ch = this.focused;
|
||||
if (!ch) return this.alert();
|
||||
if (ch.cursor === 0) return super.prev();
|
||||
ch.value = ch.input = '';
|
||||
ch.cursor = 0;
|
||||
return this.render();
|
||||
}
|
||||
|
||||
separator() {
|
||||
return '';
|
||||
}
|
||||
|
||||
format(value) {
|
||||
return !this.state.submitted ? super.format(value) : '';
|
||||
}
|
||||
|
||||
pointer() {
|
||||
return '';
|
||||
}
|
||||
|
||||
indicator(choice) {
|
||||
return choice.input ? '⦿' : '⊙';
|
||||
}
|
||||
|
||||
async choiceSeparator(choice, i) {
|
||||
let sep = await this.resolve(choice.separator, this.state, choice, i) || ':';
|
||||
return sep ? ' ' + this.styles.disabled(sep) : '';
|
||||
}
|
||||
|
||||
async renderChoice(choice, i) {
|
||||
await this.onChoice(choice, i);
|
||||
|
||||
let { state, styles } = this;
|
||||
let { cursor, initial = '', name, input = '' } = choice;
|
||||
let { muted, submitted, primary, danger } = styles;
|
||||
|
||||
let focused = this.index === i;
|
||||
let validate = choice.validate || (() => true);
|
||||
let sep = await this.choiceSeparator(choice, i);
|
||||
let msg = choice.message;
|
||||
|
||||
if (this.align === 'right') msg = msg.padStart(this.longest + 1, ' ');
|
||||
if (this.align === 'left') msg = msg.padEnd(this.longest + 1, ' ');
|
||||
|
||||
// re-populate the form values (answers) object
|
||||
let value = this.values[name] = (input || initial);
|
||||
let color = input ? 'success' : 'dark';
|
||||
|
||||
if ((await validate.call(choice, value, this.state)) !== true) {
|
||||
color = 'danger';
|
||||
}
|
||||
|
||||
let style = styles[color];
|
||||
let indicator = style(await this.indicator(choice, i)) + (choice.pad || '');
|
||||
|
||||
let indent = this.indent(choice);
|
||||
let line = () => [indent, indicator, msg + sep, input ].filter(Boolean).join(' ');
|
||||
|
||||
if (state.submitted) {
|
||||
msg = stripAnsi(msg);
|
||||
input = submitted(input);
|
||||
|
||||
return line();
|
||||
}
|
||||
|
||||
if (choice.format) {
|
||||
input = await choice.format.call(this, input, choice, i);
|
||||
} else {
|
||||
let color = this.styles.muted;
|
||||
let options = { input, initial, pos: cursor, showCursor: focused, color };
|
||||
input = placeholder(this, options);
|
||||
}
|
||||
|
||||
if (!this.isValue(input)) {
|
||||
input = this.styles.muted(this.symbols.ellipsis);
|
||||
}
|
||||
|
||||
if (choice.result) {
|
||||
this.values[name] = await choice.result.call(this, value, choice, i);
|
||||
}
|
||||
|
||||
if (focused) {
|
||||
msg = primary(msg);
|
||||
}
|
||||
|
||||
if (choice.error) {
|
||||
input += (input ? ' ' : '') + danger(choice.error.trim());
|
||||
} else if (choice.hint) {
|
||||
input += (input ? ' ' : '') + muted(choice.hint.trim());
|
||||
}
|
||||
|
||||
return line();
|
||||
}
|
||||
|
||||
async submit() {
|
||||
this.value = this.values;
|
||||
return super.base.submit.call(this);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FormPrompt;
|
28
app_vue/node_modules/enquirer/lib/prompts/index.js
generated
vendored
Normal file
28
app_vue/node_modules/enquirer/lib/prompts/index.js
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
const utils = require('../utils');
|
||||
|
||||
const define = (key, fn) => {
|
||||
utils.defineExport(exports, key, fn);
|
||||
utils.defineExport(exports, key.toLowerCase(), fn);
|
||||
};
|
||||
|
||||
define('AutoComplete', () => require('./autocomplete'));
|
||||
define('BasicAuth', () => require('./basicauth'));
|
||||
define('Confirm', () => require('./confirm'));
|
||||
define('Editable', () => require('./editable'));
|
||||
define('Form', () => require('./form'));
|
||||
define('Input', () => require('./input'));
|
||||
define('Invisible', () => require('./invisible'));
|
||||
define('List', () => require('./list'));
|
||||
define('MultiSelect', () => require('./multiselect'));
|
||||
define('Numeral', () => require('./numeral'));
|
||||
define('Password', () => require('./password'));
|
||||
define('Scale', () => require('./scale'));
|
||||
define('Select', () => require('./select'));
|
||||
define('Snippet', () => require('./snippet'));
|
||||
define('Sort', () => require('./sort'));
|
||||
define('Survey', () => require('./survey'));
|
||||
define('Text', () => require('./text'));
|
||||
define('Toggle', () => require('./toggle'));
|
||||
define('Quiz', () => require('./quiz'));
|
55
app_vue/node_modules/enquirer/lib/prompts/input.js
generated
vendored
Normal file
55
app_vue/node_modules/enquirer/lib/prompts/input.js
generated
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
'use strict';
|
||||
|
||||
const Prompt = require('../types/string');
|
||||
const completer = require('../completer');
|
||||
|
||||
class Input extends Prompt {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
let history = this.options.history;
|
||||
if (history && history.store) {
|
||||
let initial = history.values || this.initial;
|
||||
this.autosave = !!history.autosave;
|
||||
this.store = history.store;
|
||||
this.data = this.store.get('values') || { past: [], present: initial };
|
||||
this.initial = this.data.present || this.data.past[this.data.past.length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
completion(action) {
|
||||
if (!this.store) return this.alert();
|
||||
this.data = completer(action, this.data, this.input);
|
||||
if (!this.data.present) return this.alert();
|
||||
this.input = this.data.present;
|
||||
this.cursor = this.input.length;
|
||||
return this.render();
|
||||
}
|
||||
|
||||
altUp() {
|
||||
return this.completion('prev');
|
||||
}
|
||||
|
||||
altDown() {
|
||||
return this.completion('next');
|
||||
}
|
||||
|
||||
prev() {
|
||||
this.save();
|
||||
return super.prev();
|
||||
}
|
||||
|
||||
save() {
|
||||
if (!this.store) return;
|
||||
this.data = completer('save', this.data, this.input);
|
||||
this.store.set('values', this.data);
|
||||
}
|
||||
|
||||
submit() {
|
||||
if (this.store && this.autosave === true) {
|
||||
this.save();
|
||||
}
|
||||
return super.submit();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Input;
|
11
app_vue/node_modules/enquirer/lib/prompts/invisible.js
generated
vendored
Normal file
11
app_vue/node_modules/enquirer/lib/prompts/invisible.js
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
const StringPrompt = require('../types/string');
|
||||
|
||||
class InvisiblePrompt extends StringPrompt {
|
||||
format() {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InvisiblePrompt;
|
36
app_vue/node_modules/enquirer/lib/prompts/list.js
generated
vendored
Normal file
36
app_vue/node_modules/enquirer/lib/prompts/list.js
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
const StringPrompt = require('../types/string');
|
||||
|
||||
class ListPrompt extends StringPrompt {
|
||||
constructor(options = {}) {
|
||||
super(options);
|
||||
this.sep = this.options.separator || /, */;
|
||||
this.initial = options.initial || '';
|
||||
}
|
||||
|
||||
split(input = this.value) {
|
||||
return input ? String(input).split(this.sep) : [];
|
||||
}
|
||||
|
||||
format() {
|
||||
let style = this.state.submitted ? this.styles.primary : val => val;
|
||||
return this.list.map(style).join(', ');
|
||||
}
|
||||
|
||||
async submit(value) {
|
||||
let result = this.state.error || await this.validate(this.list, this.state);
|
||||
if (result !== true) {
|
||||
this.state.error = result;
|
||||
return super.submit();
|
||||
}
|
||||
this.value = this.list;
|
||||
return super.submit();
|
||||
}
|
||||
|
||||
get list() {
|
||||
return this.split();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ListPrompt;
|
11
app_vue/node_modules/enquirer/lib/prompts/multiselect.js
generated
vendored
Normal file
11
app_vue/node_modules/enquirer/lib/prompts/multiselect.js
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
const Select = require('./select');
|
||||
|
||||
class MultiSelect extends Select {
|
||||
constructor(options) {
|
||||
super({ ...options, multiple: true });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MultiSelect;
|
1
app_vue/node_modules/enquirer/lib/prompts/numeral.js
generated
vendored
Normal file
1
app_vue/node_modules/enquirer/lib/prompts/numeral.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require('../types/number');
|
18
app_vue/node_modules/enquirer/lib/prompts/password.js
generated
vendored
Normal file
18
app_vue/node_modules/enquirer/lib/prompts/password.js
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
const StringPrompt = require('../types/string');
|
||||
|
||||
class PasswordPrompt extends StringPrompt {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this.cursorShow();
|
||||
}
|
||||
|
||||
format(input = this.input) {
|
||||
if (!this.keypressed) return '';
|
||||
let color = this.state.submitted ? this.styles.primary : this.styles.muted;
|
||||
return color(this.symbols.asterisk.repeat(input.length));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PasswordPrompt;
|
37
app_vue/node_modules/enquirer/lib/prompts/quiz.js
generated
vendored
Normal file
37
app_vue/node_modules/enquirer/lib/prompts/quiz.js
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
|
||||
const SelectPrompt = require('./select');
|
||||
|
||||
class Quiz extends SelectPrompt {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
if (typeof this.options.correctChoice !== 'number' || this.options.correctChoice < 0) {
|
||||
throw new Error('Please specify the index of the correct answer from the list of choices');
|
||||
}
|
||||
}
|
||||
|
||||
async toChoices(value, parent) {
|
||||
let choices = await super.toChoices(value, parent);
|
||||
if (choices.length < 2) {
|
||||
throw new Error('Please give at least two choices to the user');
|
||||
}
|
||||
if (this.options.correctChoice > choices.length) {
|
||||
throw new Error('Please specify the index of the correct answer from the list of choices');
|
||||
}
|
||||
return choices;
|
||||
}
|
||||
|
||||
check(state) {
|
||||
return state.index === this.options.correctChoice;
|
||||
}
|
||||
|
||||
async result(selected) {
|
||||
return {
|
||||
selectedAnswer: selected,
|
||||
correctAnswer: this.options.choices[this.options.correctChoice].value,
|
||||
correct: await this.check(this.state)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Quiz;
|
237
app_vue/node_modules/enquirer/lib/prompts/scale.js
generated
vendored
Normal file
237
app_vue/node_modules/enquirer/lib/prompts/scale.js
generated
vendored
Normal file
@ -0,0 +1,237 @@
|
||||
'use strict';
|
||||
|
||||
const stripAnsi = require('strip-ansi');
|
||||
const ArrayPrompt = require('../types/array');
|
||||
const utils = require('../utils');
|
||||
|
||||
class LikertScale extends ArrayPrompt {
|
||||
constructor(options = {}) {
|
||||
super(options);
|
||||
this.widths = [].concat(options.messageWidth || 50);
|
||||
this.align = [].concat(options.align || 'left');
|
||||
this.linebreak = options.linebreak || false;
|
||||
this.edgeLength = options.edgeLength || 3;
|
||||
this.newline = options.newline || '\n ';
|
||||
let start = options.startNumber || 1;
|
||||
if (typeof this.scale === 'number') {
|
||||
this.scaleKey = false;
|
||||
this.scale = Array(this.scale).fill(0).map((v, i) => ({ name: i + start }));
|
||||
}
|
||||
}
|
||||
|
||||
async reset() {
|
||||
this.tableized = false;
|
||||
await super.reset();
|
||||
return this.render();
|
||||
}
|
||||
|
||||
tableize() {
|
||||
if (this.tableized === true) return;
|
||||
this.tableized = true;
|
||||
let longest = 0;
|
||||
|
||||
for (let ch of this.choices) {
|
||||
longest = Math.max(longest, ch.message.length);
|
||||
ch.scaleIndex = ch.initial || 2;
|
||||
ch.scale = [];
|
||||
|
||||
for (let i = 0; i < this.scale.length; i++) {
|
||||
ch.scale.push({ index: i });
|
||||
}
|
||||
}
|
||||
this.widths[0] = Math.min(this.widths[0], longest + 3);
|
||||
}
|
||||
|
||||
async dispatch(s, key) {
|
||||
if (this.multiple) {
|
||||
return this[key.name] ? await this[key.name](s, key) : await super.dispatch(s, key);
|
||||
}
|
||||
this.alert();
|
||||
}
|
||||
|
||||
heading(msg, item, i) {
|
||||
return this.styles.strong(msg);
|
||||
}
|
||||
|
||||
separator() {
|
||||
return this.styles.muted(this.symbols.ellipsis);
|
||||
}
|
||||
|
||||
right() {
|
||||
let choice = this.focused;
|
||||
if (choice.scaleIndex >= this.scale.length - 1) return this.alert();
|
||||
choice.scaleIndex++;
|
||||
return this.render();
|
||||
}
|
||||
|
||||
left() {
|
||||
let choice = this.focused;
|
||||
if (choice.scaleIndex <= 0) return this.alert();
|
||||
choice.scaleIndex--;
|
||||
return this.render();
|
||||
}
|
||||
|
||||
indent() {
|
||||
return '';
|
||||
}
|
||||
|
||||
format() {
|
||||
if (this.state.submitted) {
|
||||
let values = this.choices.map(ch => this.styles.info(ch.index));
|
||||
return values.join(', ');
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
pointer() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the scale "Key". Something like:
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
renderScaleKey() {
|
||||
if (this.scaleKey === false) return '';
|
||||
if (this.state.submitted) return '';
|
||||
let scale = this.scale.map(item => ` ${item.name} - ${item.message}`);
|
||||
let key = ['', ...scale].map(item => this.styles.muted(item));
|
||||
return key.join('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the heading row for the scale.
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
renderScaleHeading(max) {
|
||||
let keys = this.scale.map(ele => ele.name);
|
||||
if (typeof this.options.renderScaleHeading === 'function') {
|
||||
keys = this.options.renderScaleHeading.call(this, max);
|
||||
}
|
||||
let diff = this.scaleLength - keys.join('').length;
|
||||
let spacing = Math.round(diff / (keys.length - 1));
|
||||
let names = keys.map(key => this.styles.strong(key));
|
||||
let headings = names.join(' '.repeat(spacing));
|
||||
let padding = ' '.repeat(this.widths[0]);
|
||||
return this.margin[3] + padding + this.margin[1] + headings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a scale indicator => ◯ or ◉ by default
|
||||
*/
|
||||
|
||||
scaleIndicator(choice, item, i) {
|
||||
if (typeof this.options.scaleIndicator === 'function') {
|
||||
return this.options.scaleIndicator.call(this, choice, item, i);
|
||||
}
|
||||
let enabled = choice.scaleIndex === item.index;
|
||||
if (item.disabled) return this.styles.hint(this.symbols.radio.disabled);
|
||||
if (enabled) return this.styles.success(this.symbols.radio.on);
|
||||
return this.symbols.radio.off;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the actual scale => ◯────◯────◉────◯────◯
|
||||
*/
|
||||
|
||||
renderScale(choice, i) {
|
||||
let scale = choice.scale.map(item => this.scaleIndicator(choice, item, i));
|
||||
let padding = this.term === 'Hyper' ? '' : ' ';
|
||||
return scale.join(padding + this.symbols.line.repeat(this.edgeLength));
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a choice, including scale =>
|
||||
* "The website is easy to navigate. ◯───◯───◉───◯───◯"
|
||||
*/
|
||||
|
||||
async renderChoice(choice, i) {
|
||||
await this.onChoice(choice, i);
|
||||
|
||||
let focused = this.index === i;
|
||||
let pointer = await this.pointer(choice, i);
|
||||
let hint = await choice.hint;
|
||||
|
||||
if (hint && !utils.hasColor(hint)) {
|
||||
hint = this.styles.muted(hint);
|
||||
}
|
||||
|
||||
let pad = str => this.margin[3] + str.replace(/\s+$/, '').padEnd(this.widths[0], ' ');
|
||||
let newline = this.newline;
|
||||
let ind = this.indent(choice);
|
||||
let message = await this.resolve(choice.message, this.state, choice, i);
|
||||
let scale = await this.renderScale(choice, i);
|
||||
let margin = this.margin[1] + this.margin[3];
|
||||
this.scaleLength = stripAnsi(scale).length;
|
||||
this.widths[0] = Math.min(this.widths[0], this.width - this.scaleLength - margin.length);
|
||||
let msg = utils.wordWrap(message, { width: this.widths[0], newline });
|
||||
let lines = msg.split('\n').map(line => pad(line) + this.margin[1]);
|
||||
|
||||
if (focused) {
|
||||
scale = this.styles.info(scale);
|
||||
lines = lines.map(line => this.styles.info(line));
|
||||
}
|
||||
|
||||
lines[0] += scale;
|
||||
|
||||
if (this.linebreak) lines.push('');
|
||||
return [ind + pointer, lines.join('\n')].filter(Boolean);
|
||||
}
|
||||
|
||||
async renderChoices() {
|
||||
if (this.state.submitted) return '';
|
||||
this.tableize();
|
||||
let choices = this.visible.map(async(ch, i) => await this.renderChoice(ch, i));
|
||||
let visible = await Promise.all(choices);
|
||||
let heading = await this.renderScaleHeading();
|
||||
return this.margin[0] + [heading, ...visible.map(v => v.join(' '))].join('\n');
|
||||
}
|
||||
|
||||
async render() {
|
||||
let { submitted, size } = this.state;
|
||||
|
||||
let prefix = await this.prefix();
|
||||
let separator = await this.separator();
|
||||
let message = await this.message();
|
||||
|
||||
let prompt = '';
|
||||
if (this.options.promptLine !== false) {
|
||||
prompt = [prefix, message, separator, ''].join(' ');
|
||||
this.state.prompt = prompt;
|
||||
}
|
||||
|
||||
let header = await this.header();
|
||||
let output = await this.format();
|
||||
let key = await this.renderScaleKey();
|
||||
let help = await this.error() || await this.hint();
|
||||
let body = await this.renderChoices();
|
||||
let footer = await this.footer();
|
||||
let err = this.emptyError;
|
||||
|
||||
if (output) prompt += output;
|
||||
if (help && !prompt.includes(help)) prompt += ' ' + help;
|
||||
|
||||
if (submitted && !output && !body.trim() && this.multiple && err != null) {
|
||||
prompt += this.styles.danger(err);
|
||||
}
|
||||
|
||||
this.clear(size);
|
||||
this.write([header, prompt, key, body, footer].filter(Boolean).join('\n'));
|
||||
if (!this.state.submitted) {
|
||||
this.write(this.margin[2]);
|
||||
}
|
||||
this.restore();
|
||||
}
|
||||
|
||||
submit() {
|
||||
this.value = {};
|
||||
for (let choice of this.choices) {
|
||||
this.value[choice.name] = choice.scaleIndex;
|
||||
}
|
||||
return this.base.submit.call(this);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LikertScale;
|
139
app_vue/node_modules/enquirer/lib/prompts/select.js
generated
vendored
Normal file
139
app_vue/node_modules/enquirer/lib/prompts/select.js
generated
vendored
Normal file
@ -0,0 +1,139 @@
|
||||
'use strict';
|
||||
|
||||
const ArrayPrompt = require('../types/array');
|
||||
const utils = require('../utils');
|
||||
|
||||
class SelectPrompt extends ArrayPrompt {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this.emptyError = this.options.emptyError || 'No items were selected';
|
||||
}
|
||||
|
||||
async dispatch(s, key) {
|
||||
if (this.multiple) {
|
||||
return this[key.name] ? await this[key.name](s, key) : await super.dispatch(s, key);
|
||||
}
|
||||
this.alert();
|
||||
}
|
||||
|
||||
separator() {
|
||||
if (this.options.separator) return super.separator();
|
||||
let sep = this.styles.muted(this.symbols.ellipsis);
|
||||
return this.state.submitted ? super.separator() : sep;
|
||||
}
|
||||
|
||||
pointer(choice, i) {
|
||||
return (!this.multiple || this.options.pointer) ? super.pointer(choice, i) : '';
|
||||
}
|
||||
|
||||
indicator(choice, i) {
|
||||
return this.multiple ? super.indicator(choice, i) : '';
|
||||
}
|
||||
|
||||
choiceMessage(choice, i) {
|
||||
let message = this.resolve(choice.message, this.state, choice, i);
|
||||
if (choice.role === 'heading' && !utils.hasColor(message)) {
|
||||
message = this.styles.strong(message);
|
||||
}
|
||||
return this.resolve(message, this.state, choice, i);
|
||||
}
|
||||
|
||||
choiceSeparator() {
|
||||
return ':';
|
||||
}
|
||||
|
||||
async renderChoice(choice, i) {
|
||||
await this.onChoice(choice, i);
|
||||
|
||||
let focused = this.index === i;
|
||||
let pointer = await this.pointer(choice, i);
|
||||
let check = await this.indicator(choice, i) + (choice.pad || '');
|
||||
let hint = await this.resolve(choice.hint, this.state, choice, i);
|
||||
|
||||
if (hint && !utils.hasColor(hint)) {
|
||||
hint = this.styles.muted(hint);
|
||||
}
|
||||
|
||||
let ind = this.indent(choice);
|
||||
let msg = await this.choiceMessage(choice, i);
|
||||
let line = () => [this.margin[3], ind + pointer + check, msg, this.margin[1], hint].filter(Boolean).join(' ');
|
||||
|
||||
if (choice.role === 'heading') {
|
||||
return line();
|
||||
}
|
||||
|
||||
if (choice.disabled) {
|
||||
if (!utils.hasColor(msg)) {
|
||||
msg = this.styles.disabled(msg);
|
||||
}
|
||||
return line();
|
||||
}
|
||||
|
||||
if (focused) {
|
||||
msg = this.styles.em(msg);
|
||||
}
|
||||
|
||||
return line();
|
||||
}
|
||||
|
||||
async renderChoices() {
|
||||
if (this.state.loading === 'choices') {
|
||||
return this.styles.warning('Loading choices');
|
||||
}
|
||||
|
||||
if (this.state.submitted) return '';
|
||||
let choices = this.visible.map(async(ch, i) => await this.renderChoice(ch, i));
|
||||
let visible = await Promise.all(choices);
|
||||
if (!visible.length) visible.push(this.styles.danger('No matching choices'));
|
||||
let result = this.margin[0] + visible.join('\n');
|
||||
let header;
|
||||
|
||||
if (this.options.choicesHeader) {
|
||||
header = await this.resolve(this.options.choicesHeader, this.state);
|
||||
}
|
||||
|
||||
return [header, result].filter(Boolean).join('\n');
|
||||
}
|
||||
|
||||
format() {
|
||||
if (!this.state.submitted || this.state.cancelled) return '';
|
||||
if (Array.isArray(this.selected)) {
|
||||
return this.selected.map(choice => this.styles.primary(choice.name)).join(', ');
|
||||
}
|
||||
return this.styles.primary(this.selected.name);
|
||||
}
|
||||
|
||||
async render() {
|
||||
let { submitted, size } = this.state;
|
||||
|
||||
let prompt = '';
|
||||
let header = await this.header();
|
||||
let prefix = await this.prefix();
|
||||
let separator = await this.separator();
|
||||
let message = await this.message();
|
||||
|
||||
if (this.options.promptLine !== false) {
|
||||
prompt = [prefix, message, separator, ''].join(' ');
|
||||
this.state.prompt = prompt;
|
||||
}
|
||||
|
||||
let output = await this.format();
|
||||
let help = (await this.error()) || (await this.hint());
|
||||
let body = await this.renderChoices();
|
||||
let footer = await this.footer();
|
||||
|
||||
if (output) prompt += output;
|
||||
if (help && !prompt.includes(help)) prompt += ' ' + help;
|
||||
|
||||
if (submitted && !output && !body.trim() && this.multiple && this.emptyError != null) {
|
||||
prompt += this.styles.danger(this.emptyError);
|
||||
}
|
||||
|
||||
this.clear(size);
|
||||
this.write([header, prompt, body, footer].filter(Boolean).join('\n'));
|
||||
this.write(this.margin[2]);
|
||||
this.restore();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SelectPrompt;
|
185
app_vue/node_modules/enquirer/lib/prompts/snippet.js
generated
vendored
Normal file
185
app_vue/node_modules/enquirer/lib/prompts/snippet.js
generated
vendored
Normal file
@ -0,0 +1,185 @@
|
||||
'use strict';
|
||||
|
||||
const stripAnsi = require('strip-ansi');
|
||||
const interpolate = require('../interpolate');
|
||||
const Prompt = require('../prompt');
|
||||
|
||||
class SnippetPrompt extends Prompt {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this.cursorHide();
|
||||
this.reset(true);
|
||||
}
|
||||
|
||||
async initialize() {
|
||||
this.interpolate = await interpolate(this);
|
||||
await super.initialize();
|
||||
}
|
||||
|
||||
async reset(first) {
|
||||
this.state.keys = [];
|
||||
this.state.invalid = new Map();
|
||||
this.state.missing = new Set();
|
||||
this.state.completed = 0;
|
||||
this.state.values = {};
|
||||
|
||||
if (first !== true) {
|
||||
await this.initialize();
|
||||
await this.render();
|
||||
}
|
||||
}
|
||||
|
||||
moveCursor(n) {
|
||||
let item = this.getItem();
|
||||
this.cursor += n;
|
||||
item.cursor += n;
|
||||
}
|
||||
|
||||
dispatch(ch, key) {
|
||||
if (!key.code && !key.ctrl && ch != null && this.getItem()) {
|
||||
this.append(ch, key);
|
||||
return;
|
||||
}
|
||||
this.alert();
|
||||
}
|
||||
|
||||
append(ch, key) {
|
||||
let item = this.getItem();
|
||||
let prefix = item.input.slice(0, this.cursor);
|
||||
let suffix = item.input.slice(this.cursor);
|
||||
this.input = item.input = `${prefix}${ch}${suffix}`;
|
||||
this.moveCursor(1);
|
||||
this.render();
|
||||
}
|
||||
|
||||
delete() {
|
||||
let item = this.getItem();
|
||||
if (this.cursor <= 0 || !item.input) return this.alert();
|
||||
let suffix = item.input.slice(this.cursor);
|
||||
let prefix = item.input.slice(0, this.cursor - 1);
|
||||
this.input = item.input = `${prefix}${suffix}`;
|
||||
this.moveCursor(-1);
|
||||
this.render();
|
||||
}
|
||||
|
||||
increment(i) {
|
||||
return i >= this.state.keys.length - 1 ? 0 : i + 1;
|
||||
}
|
||||
|
||||
decrement(i) {
|
||||
return i <= 0 ? this.state.keys.length - 1 : i - 1;
|
||||
}
|
||||
|
||||
first() {
|
||||
this.state.index = 0;
|
||||
this.render();
|
||||
}
|
||||
|
||||
last() {
|
||||
this.state.index = this.state.keys.length - 1;
|
||||
this.render();
|
||||
}
|
||||
|
||||
right() {
|
||||
if (this.cursor >= this.input.length) return this.alert();
|
||||
this.moveCursor(1);
|
||||
this.render();
|
||||
}
|
||||
|
||||
left() {
|
||||
if (this.cursor <= 0) return this.alert();
|
||||
this.moveCursor(-1);
|
||||
this.render();
|
||||
}
|
||||
|
||||
prev() {
|
||||
this.state.index = this.decrement(this.state.index);
|
||||
this.getItem();
|
||||
this.render();
|
||||
}
|
||||
|
||||
next() {
|
||||
this.state.index = this.increment(this.state.index);
|
||||
this.getItem();
|
||||
this.render();
|
||||
}
|
||||
|
||||
up() {
|
||||
this.prev();
|
||||
}
|
||||
|
||||
down() {
|
||||
this.next();
|
||||
}
|
||||
|
||||
format(value) {
|
||||
let color = this.state.completed < 100 ? this.styles.warning : this.styles.success;
|
||||
if (this.state.submitted === true && this.state.completed !== 100) {
|
||||
color = this.styles.danger;
|
||||
}
|
||||
return color(`${this.state.completed}% completed`);
|
||||
}
|
||||
|
||||
async render() {
|
||||
let { index, keys = [], submitted, size } = this.state;
|
||||
|
||||
let newline = [this.options.newline, '\n'].find(v => v != null);
|
||||
let prefix = await this.prefix();
|
||||
let separator = await this.separator();
|
||||
let message = await this.message();
|
||||
|
||||
let prompt = [prefix, message, separator].filter(Boolean).join(' ');
|
||||
this.state.prompt = prompt;
|
||||
|
||||
let header = await this.header();
|
||||
let error = (await this.error()) || '';
|
||||
let hint = (await this.hint()) || '';
|
||||
let body = submitted ? '' : await this.interpolate(this.state);
|
||||
|
||||
let key = this.state.key = keys[index] || '';
|
||||
let input = await this.format(key);
|
||||
let footer = await this.footer();
|
||||
if (input) prompt += ' ' + input;
|
||||
if (hint && !input && this.state.completed === 0) prompt += ' ' + hint;
|
||||
|
||||
this.clear(size);
|
||||
let lines = [header, prompt, body, footer, error.trim()];
|
||||
this.write(lines.filter(Boolean).join(newline));
|
||||
this.restore();
|
||||
}
|
||||
|
||||
getItem(name) {
|
||||
let { items, keys, index } = this.state;
|
||||
let item = items.find(ch => ch.name === keys[index]);
|
||||
if (item && item.input != null) {
|
||||
this.input = item.input;
|
||||
this.cursor = item.cursor;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
async submit() {
|
||||
if (typeof this.interpolate !== 'function') await this.initialize();
|
||||
await this.interpolate(this.state, true);
|
||||
|
||||
let { invalid, missing, output, values } = this.state;
|
||||
if (invalid.size) {
|
||||
let err = '';
|
||||
for (let [key, value] of invalid) err += `Invalid ${key}: ${value}\n`;
|
||||
this.state.error = err;
|
||||
return super.submit();
|
||||
}
|
||||
|
||||
if (missing.size) {
|
||||
this.state.error = 'Required: ' + [...missing.keys()].join(', ');
|
||||
return super.submit();
|
||||
}
|
||||
|
||||
let lines = stripAnsi(output).split('\n');
|
||||
let result = lines.map(v => v.slice(1)).join('\n');
|
||||
this.value = { values, result };
|
||||
return super.submit();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SnippetPrompt;
|
37
app_vue/node_modules/enquirer/lib/prompts/sort.js
generated
vendored
Normal file
37
app_vue/node_modules/enquirer/lib/prompts/sort.js
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
|
||||
const hint = '(Use <shift>+<up/down> to sort)';
|
||||
const Prompt = require('./select');
|
||||
|
||||
class Sort extends Prompt {
|
||||
constructor(options) {
|
||||
super({ ...options, reorder: false, sort: true, multiple: true });
|
||||
this.state.hint = [this.options.hint, hint].find(this.isValue.bind(this));
|
||||
}
|
||||
|
||||
indicator() {
|
||||
return '';
|
||||
}
|
||||
|
||||
async renderChoice(choice, i) {
|
||||
let str = await super.renderChoice(choice, i);
|
||||
let sym = this.symbols.identicalTo + ' ';
|
||||
let pre = (this.index === i && this.sorting) ? this.styles.muted(sym) : ' ';
|
||||
if (this.options.drag === false) pre = '';
|
||||
if (this.options.numbered === true) {
|
||||
return pre + `${i + 1} - ` + str;
|
||||
}
|
||||
return pre + str;
|
||||
}
|
||||
|
||||
get selected() {
|
||||
return this.choices;
|
||||
}
|
||||
|
||||
submit() {
|
||||
this.value = this.choices.map(choice => choice.value);
|
||||
return super.submit();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Sort;
|
163
app_vue/node_modules/enquirer/lib/prompts/survey.js
generated
vendored
Normal file
163
app_vue/node_modules/enquirer/lib/prompts/survey.js
generated
vendored
Normal file
@ -0,0 +1,163 @@
|
||||
'use strict';
|
||||
|
||||
const ArrayPrompt = require('../types/array');
|
||||
|
||||
class Survey extends ArrayPrompt {
|
||||
constructor(options = {}) {
|
||||
super(options);
|
||||
this.emptyError = options.emptyError || 'No items were selected';
|
||||
this.term = process.env.TERM_PROGRAM;
|
||||
|
||||
if (!this.options.header) {
|
||||
let header = ['', '4 - Strongly Agree', '3 - Agree', '2 - Neutral', '1 - Disagree', '0 - Strongly Disagree', ''];
|
||||
header = header.map(ele => this.styles.muted(ele));
|
||||
this.state.header = header.join('\n ');
|
||||
}
|
||||
}
|
||||
|
||||
async toChoices(...args) {
|
||||
if (this.createdScales) return false;
|
||||
this.createdScales = true;
|
||||
let choices = await super.toChoices(...args);
|
||||
for (let choice of choices) {
|
||||
choice.scale = createScale(5, this.options);
|
||||
choice.scaleIdx = 2;
|
||||
}
|
||||
return choices;
|
||||
}
|
||||
|
||||
dispatch() {
|
||||
this.alert();
|
||||
}
|
||||
|
||||
space() {
|
||||
let choice = this.focused;
|
||||
let ele = choice.scale[choice.scaleIdx];
|
||||
let selected = ele.selected;
|
||||
choice.scale.forEach(e => (e.selected = false));
|
||||
ele.selected = !selected;
|
||||
return this.render();
|
||||
}
|
||||
|
||||
indicator() {
|
||||
return '';
|
||||
}
|
||||
|
||||
pointer() {
|
||||
return '';
|
||||
}
|
||||
|
||||
separator() {
|
||||
return this.styles.muted(this.symbols.ellipsis);
|
||||
}
|
||||
|
||||
right() {
|
||||
let choice = this.focused;
|
||||
if (choice.scaleIdx >= choice.scale.length - 1) return this.alert();
|
||||
choice.scaleIdx++;
|
||||
return this.render();
|
||||
}
|
||||
|
||||
left() {
|
||||
let choice = this.focused;
|
||||
if (choice.scaleIdx <= 0) return this.alert();
|
||||
choice.scaleIdx--;
|
||||
return this.render();
|
||||
}
|
||||
|
||||
indent() {
|
||||
return ' ';
|
||||
}
|
||||
|
||||
async renderChoice(item, i) {
|
||||
await this.onChoice(item, i);
|
||||
let focused = this.index === i;
|
||||
let isHyper = this.term === 'Hyper';
|
||||
let n = !isHyper ? 8 : 9;
|
||||
let s = !isHyper ? ' ' : '';
|
||||
let ln = this.symbols.line.repeat(n);
|
||||
let sp = ' '.repeat(n + (isHyper ? 0 : 1));
|
||||
let dot = enabled => (enabled ? this.styles.success('◉') : '◯') + s;
|
||||
|
||||
let num = i + 1 + '.';
|
||||
let color = focused ? this.styles.heading : this.styles.noop;
|
||||
let msg = await this.resolve(item.message, this.state, item, i);
|
||||
let indent = this.indent(item);
|
||||
let scale = indent + item.scale.map((e, i) => dot(i === item.scaleIdx)).join(ln);
|
||||
let val = i => i === item.scaleIdx ? color(i) : i;
|
||||
let next = indent + item.scale.map((e, i) => val(i)).join(sp);
|
||||
|
||||
let line = () => [num, msg].filter(Boolean).join(' ');
|
||||
let lines = () => [line(), scale, next, ' '].filter(Boolean).join('\n');
|
||||
|
||||
if (focused) {
|
||||
scale = this.styles.cyan(scale);
|
||||
next = this.styles.cyan(next);
|
||||
}
|
||||
|
||||
return lines();
|
||||
}
|
||||
|
||||
async renderChoices() {
|
||||
if (this.state.submitted) return '';
|
||||
let choices = this.visible.map(async(ch, i) => await this.renderChoice(ch, i));
|
||||
let visible = await Promise.all(choices);
|
||||
if (!visible.length) visible.push(this.styles.danger('No matching choices'));
|
||||
return visible.join('\n');
|
||||
}
|
||||
|
||||
format() {
|
||||
if (this.state.submitted) {
|
||||
let values = this.choices.map(ch => this.styles.info(ch.scaleIdx));
|
||||
return values.join(', ');
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
async render() {
|
||||
let { submitted, size } = this.state;
|
||||
|
||||
let prefix = await this.prefix();
|
||||
let separator = await this.separator();
|
||||
let message = await this.message();
|
||||
|
||||
let prompt = [prefix, message, separator].filter(Boolean).join(' ');
|
||||
this.state.prompt = prompt;
|
||||
|
||||
let header = await this.header();
|
||||
let output = await this.format();
|
||||
let help = await this.error() || await this.hint();
|
||||
let body = await this.renderChoices();
|
||||
let footer = await this.footer();
|
||||
|
||||
if (output || !help) prompt += ' ' + output;
|
||||
if (help && !prompt.includes(help)) prompt += ' ' + help;
|
||||
|
||||
if (submitted && !output && !body && this.multiple && this.type !== 'form') {
|
||||
prompt += this.styles.danger(this.emptyError);
|
||||
}
|
||||
|
||||
this.clear(size);
|
||||
this.write([prompt, header, body, footer].filter(Boolean).join('\n'));
|
||||
this.restore();
|
||||
}
|
||||
|
||||
submit() {
|
||||
this.value = {};
|
||||
for (let choice of this.choices) {
|
||||
this.value[choice.name] = choice.scaleIdx;
|
||||
}
|
||||
return this.base.submit.call(this);
|
||||
}
|
||||
}
|
||||
|
||||
function createScale(n, options = {}) {
|
||||
if (Array.isArray(options.scale)) {
|
||||
return options.scale.map(ele => ({ ...ele }));
|
||||
}
|
||||
let scale = [];
|
||||
for (let i = 1; i < n + 1; i++) scale.push({ i, selected: false });
|
||||
return scale;
|
||||
}
|
||||
|
||||
module.exports = Survey;
|
1
app_vue/node_modules/enquirer/lib/prompts/text.js
generated
vendored
Normal file
1
app_vue/node_modules/enquirer/lib/prompts/text.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require('./input');
|
109
app_vue/node_modules/enquirer/lib/prompts/toggle.js
generated
vendored
Normal file
109
app_vue/node_modules/enquirer/lib/prompts/toggle.js
generated
vendored
Normal file
@ -0,0 +1,109 @@
|
||||
'use strict';
|
||||
|
||||
const BooleanPrompt = require('../types/boolean');
|
||||
|
||||
class TogglePrompt extends BooleanPrompt {
|
||||
async initialize() {
|
||||
await super.initialize();
|
||||
this.value = this.initial = this.resolve(this.options.initial);
|
||||
this.disabled = this.options.disabled || 'no';
|
||||
this.enabled = this.options.enabled || 'yes';
|
||||
await this.render();
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.value = this.initial;
|
||||
this.render();
|
||||
}
|
||||
|
||||
delete() {
|
||||
this.alert();
|
||||
}
|
||||
|
||||
toggle() {
|
||||
this.value = !this.value;
|
||||
this.render();
|
||||
}
|
||||
|
||||
enable() {
|
||||
if (this.value === true) return this.alert();
|
||||
this.value = true;
|
||||
this.render();
|
||||
}
|
||||
disable() {
|
||||
if (this.value === false) return this.alert();
|
||||
this.value = false;
|
||||
this.render();
|
||||
}
|
||||
|
||||
up() {
|
||||
this.toggle();
|
||||
}
|
||||
down() {
|
||||
this.toggle();
|
||||
}
|
||||
right() {
|
||||
this.toggle();
|
||||
}
|
||||
left() {
|
||||
this.toggle();
|
||||
}
|
||||
next() {
|
||||
this.toggle();
|
||||
}
|
||||
prev() {
|
||||
this.toggle();
|
||||
}
|
||||
|
||||
dispatch(ch = '', key) {
|
||||
switch (ch.toLowerCase()) {
|
||||
case ' ':
|
||||
return this.toggle();
|
||||
case '1':
|
||||
case 'y':
|
||||
case 't':
|
||||
return this.enable();
|
||||
case '0':
|
||||
case 'n':
|
||||
case 'f':
|
||||
return this.disable();
|
||||
default: {
|
||||
return this.alert();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
format() {
|
||||
let active = str => this.styles.primary.underline(str);
|
||||
let value = [
|
||||
this.value ? this.disabled : active(this.disabled),
|
||||
this.value ? active(this.enabled) : this.enabled
|
||||
];
|
||||
return value.join(this.styles.muted(' / '));
|
||||
}
|
||||
|
||||
async render() {
|
||||
let { size } = this.state;
|
||||
|
||||
let header = await this.header();
|
||||
let prefix = await this.prefix();
|
||||
let separator = await this.separator();
|
||||
let message = await this.message();
|
||||
|
||||
let output = await this.format();
|
||||
let help = (await this.error()) || (await this.hint());
|
||||
let footer = await this.footer();
|
||||
|
||||
let prompt = [prefix, message, separator, output].join(' ');
|
||||
this.state.prompt = prompt;
|
||||
|
||||
if (help && !prompt.includes(help)) prompt += ' ' + help;
|
||||
|
||||
this.clear(size);
|
||||
this.write([header, prompt, footer].filter(Boolean).join('\n'));
|
||||
this.write(this.margin[2]);
|
||||
this.restore();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TogglePrompt;
|
Reference in New Issue
Block a user