Updating NPM dependencies

This commit is contained in:
Drew Heavner
2020-11-11 13:30:52 +00:00
committed by GitHub
parent 7a6fb66c63
commit bd487ef324
9068 changed files with 1400893 additions and 587661 deletions

View File

@@ -23,6 +23,7 @@ const getIndex = (arr, valOrTitle) => {
* @param {String} [opts.style='default'] Render style
* @param {String} [opts.fallback] Fallback message - initial to default value
* @param {String} [opts.initial] Index of the default value
* @param {Boolean} [opts.clearFirst] The first ESCAPE keypress will clear the input
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
* @param {String} [opts.noMatches] The no matches found label
@@ -39,6 +40,7 @@ class AutocompletePrompt extends Prompt {
this.select = this.initial || opts.cursor || 0;
this.i18n = { noMatches: opts.noMatches || 'no matches found' };
this.fallback = opts.fallback || this.initial;
this.clearFirst = opts.clearFirst || false;
this.suggestions = [];
this.input = '';
this.limit = opts.limit || 10;
@@ -47,7 +49,7 @@ class AutocompletePrompt extends Prompt {
this.scale = this.transform.scale;
this.render = this.render.bind(this);
this.complete = this.complete.bind(this);
this.clear = clear('');
this.clear = clear('', this.out.columns);
this.complete(this.render);
this.render();
}
@@ -96,8 +98,22 @@ class AutocompletePrompt extends Prompt {
this.render();
}
exit() {
if (this.clearFirst && this.input.length > 0) {
this.reset();
} else {
this.done = this.exited = true;
this.aborted = false;
this.fire();
this.render();
this.out.write('\n');
this.close();
}
}
abort() {
this.done = this.aborted = true;
this.exited = false;
this.fire();
this.render();
this.out.write('\n');
@@ -106,7 +122,7 @@ class AutocompletePrompt extends Prompt {
submit() {
this.done = true;
this.aborted = false;
this.aborted = this.exited = false;
this.fire();
this.render();
this.out.write('\n');
@@ -152,14 +168,20 @@ class AutocompletePrompt extends Prompt {
}
up() {
if (this.select <= 0) return this.bell();
this.moveSelect(this.select - 1);
if (this.select === 0) {
this.moveSelect(this.suggestions.length - 1);
} else {
this.moveSelect(this.select - 1);
}
this.render();
}
down() {
if (this.select >= this.suggestions.length - 1) return this.bell();
this.moveSelect(this.select + 1);
if (this.select === this.suggestions.length - 1) {
this.moveSelect(0);
} else {
this.moveSelect(this.select + 1);
}
this.render();
}
@@ -210,13 +232,13 @@ class AutocompletePrompt extends Prompt {
render() {
if (this.closed) return;
if (this.firstRender) this.out.write(cursor.hide);
else this.out.write(clear(this.outputText));
else this.out.write(clear(this.outputText, this.out.columns));
super.render();
let { startIndex, endIndex } = entriesToDisplay(this.select, this.choices.length, this.limit);
this.outputText = [
color.bold(style.symbol(this.done, this.aborted)),
style.symbol(this.done, this.aborted, this.exited),
color.bold(this.msg),
style.delimiter(this.completing),
this.done && this.suggestions[this.select]

View File

@@ -21,7 +21,7 @@ class AutocompleteMultiselectPrompt extends MultiselectPrompt {
opts.overrideRender = true;
super(opts);
this.inputValue = '';
this.clear = clear('');
this.clear = clear('', this.out.columns);
this.filteredOptions = this.value;
this.render();
}
@@ -187,7 +187,7 @@ Filtered results for: ${this.inputValue ? this.inputValue : color.gray('Enter so
prompt += this.renderOptions(this.filteredOptions);
this.out.write(this.clear + prompt);
this.clear = clear(prompt);
this.clear = clear(prompt, this.out.columns);
}
}

View File

@@ -34,6 +34,10 @@ class ConfirmPrompt extends Prompt {
this.render();
}
exit() {
this.abort();
}
abort() {
this.done = this.aborted = true;
this.fire();
@@ -67,7 +71,7 @@ class ConfirmPrompt extends Prompt {
render() {
if (this.closed) return;
if (this.firstRender) this.out.write(cursor.hide);
else this.out.write(clear(this.outputText));
else this.out.write(clear(this.outputText, this.out.columns));
super.render();
this.outputText = [

View File

@@ -50,7 +50,7 @@ class DatePrompt extends Prompt {
this.errorMsg = opts.error || 'Please Enter A Valid Value';
this.validator = opts.validate || (() => true);
this.mask = opts.mask || 'YYYY-MM-DD HH:mm:ss';
this.clear = clear('');
this.clear = clear('', this.out.columns);
this.render();
}
@@ -101,6 +101,10 @@ class DatePrompt extends Prompt {
this.render();
}
exit() {
this.abort();
}
abort() {
this.done = this.aborted = true;
this.error = false;
@@ -180,7 +184,7 @@ class DatePrompt extends Prompt {
render() {
if (this.closed) return;
if (this.firstRender) this.out.write(cursor.hide);
else this.out.write(clear(this.outputText));
else this.out.write(clear(this.outputText, this.out.columns));
super.render();
// Print prompt

View File

@@ -42,7 +42,7 @@ class MultiselectPrompt extends Prompt {
disabled: ch && ch.disabled
};
});
this.clear = clear('');
this.clear = clear('', this.out.columns);
if (!opts.overrideRender) {
this.render();
}
@@ -59,6 +59,10 @@ class MultiselectPrompt extends Prompt {
return this.value.filter(v => v.selected);
}
exit() {
this.abort();
}
abort() {
this.done = this.aborted = true;
this.fire();
@@ -260,7 +264,7 @@ class MultiselectPrompt extends Prompt {
prompt += this.renderOptions(this.value);
this.out.write(this.clear + prompt);
this.clear = clear(prompt);
this.clear = clear(prompt, this.out.columns);
}
}

View File

@@ -78,6 +78,10 @@ class NumberPrompt extends Prompt {
this.render();
}
exit() {
this.abort();
}
abort() {
let x = this.value;
this.value = x !== `` ? x : this.initial;
@@ -181,8 +185,8 @@ class NumberPrompt extends Prompt {
if (this.closed) return;
if (!this.firstRender) {
if (this.outputError)
this.out.write(cursor.down(lines(this.outputError) - 1) + clear(this.outputError));
this.out.write(clear(this.outputText));
this.out.write(cursor.down(lines(this.outputError, this.out.columns) - 1) + clear(this.outputError, this.out.columns));
this.out.write(clear(this.outputText, this.out.columns));
}
super.render();
this.outputError = '';

View File

@@ -19,7 +19,7 @@ class Prompt extends EventEmitter {
this.in = opts.stdin || process.stdin;
this.out = opts.stdout || process.stdout;
this.onRender = (opts.onRender || (() => void 0)).bind(this);
const rl = readline.createInterface(this.in);
const rl = readline.createInterface({ input:this.in, escapeCodeTimeout:50 });
readline.emitKeypressEvents(this.in, rl);
if (this.in.isTTY) this.in.setRawMode(true);
@@ -40,7 +40,7 @@ class Prompt extends EventEmitter {
this.in.removeListener('keypress', keypress);
if (this.in.isTTY) this.in.setRawMode(false);
rl.close();
this.emit(this.aborted ? 'abort' : 'submit', this.value);
this.emit(this.aborted ? 'abort' : this.exited ? 'exit' : 'submit', this.value);
this.closed = true;
};
@@ -50,7 +50,8 @@ class Prompt extends EventEmitter {
fire() {
this.emit('state', {
value: this.value,
aborted: !!this.aborted
aborted: !!this.aborted,
exited: !!this.exited
});
}

View File

@@ -36,7 +36,7 @@ class SelectPrompt extends Prompt {
});
this.optionsPerPage = opts.optionsPerPage || 10;
this.value = (this.choices[this.cursor] || {}).value;
this.clear = clear('');
this.clear = clear('', this.out.columns);
this.render();
}
@@ -52,6 +52,10 @@ class SelectPrompt extends Prompt {
this.render();
}
exit() {
this.abort();
}
abort() {
this.done = this.aborted = true;
this.fire();
@@ -83,14 +87,20 @@ class SelectPrompt extends Prompt {
}
up() {
if (this.cursor === 0) return this.bell();
this.moveCursor(this.cursor - 1);
if (this.cursor === 0) {
this.moveCursor(this.choices.length - 1);
} else {
this.moveCursor(this.cursor - 1);
}
this.render();
}
down() {
if (this.cursor === this.choices.length - 1) return this.bell();
this.moveCursor(this.cursor + 1);
if (this.cursor === this.choices.length - 1) {
this.moveCursor(0);
} else {
this.moveCursor(this.cursor + 1);
}
this.render();
}
@@ -110,7 +120,7 @@ class SelectPrompt extends Prompt {
render() {
if (this.closed) return;
if (this.firstRender) this.out.write(cursor.hide);
else this.out.write(clear(this.outputText));
else this.out.write(clear(this.outputText, this.out.columns));
super.render();
let { startIndex, endIndex } = entriesToDisplay(this.cursor, this.choices.length, this.optionsPerPage);

View File

@@ -25,7 +25,7 @@ class TextPrompt extends Prompt {
this.value = ``;
this.errorMsg = opts.error || `Please Enter A Valid Value`;
this.cursor = Number(!!this.initial);
this.clear = clear(``);
this.clear = clear(``, this.out.columns);
this.render();
}
@@ -52,6 +52,10 @@ class TextPrompt extends Prompt {
this.render();
}
exit() {
this.abort();
}
abort() {
this.value = this.value || this.initial;
this.done = this.aborted = true;
@@ -156,8 +160,8 @@ class TextPrompt extends Prompt {
if (this.closed) return;
if (!this.firstRender) {
if (this.outputError)
this.out.write(cursor.down(lines(this.outputError) - 1) + clear(this.outputError));
this.out.write(clear(this.outputText));
this.out.write(cursor.down(lines(this.outputError, this.out.columns) - 1) + clear(this.outputError, this.out.columns));
this.out.write(clear(this.outputText, this.out.columns));
}
super.render();
this.outputError = '';

View File

@@ -30,6 +30,10 @@ class TogglePrompt extends Prompt {
this.render();
}
exit() {
this.abort();
}
abort() {
this.done = this.aborted = true;
this.fire();
@@ -95,7 +99,7 @@ class TogglePrompt extends Prompt {
render() {
if (this.closed) return;
if (this.firstRender) this.out.write(cursor.hide);
else this.out.write(clear(this.outputText));
else this.out.write(clear(this.outputText, this.out.columns));
super.render();
this.outputText = [

6
node_modules/prompts/lib/index.js generated vendored
View File

@@ -65,7 +65,7 @@ async function prompt(questions=[], { onSubmit=noop, onCancel=noop }={}) {
try {
// Get the injected answer if there is one or prompt the user
answer = prompt._injected ? getInjectedAnswer(prompt._injected) : await prompts[type](question);
answer = prompt._injected ? getInjectedAnswer(prompt._injected, question.initial) : await prompts[type](question);
answers[name] = answer = await getFormattedAnswer(question, answer, true);
quit = await onSubmit(question, answer, answers);
} catch (err) {
@@ -78,13 +78,13 @@ async function prompt(questions=[], { onSubmit=noop, onCancel=noop }={}) {
return answers;
}
function getInjectedAnswer(injected) {
function getInjectedAnswer(injected, deafultValue) {
const answer = injected.shift();
if (answer instanceof Error) {
throw answer;
}
return answer;
return (answer === undefined) ? deafultValue : answer;
}
function inject(answers) {

View File

@@ -8,8 +8,10 @@ function toPrompt(type, args, opts={}) {
const p = new el[type](args);
const onAbort = opts.onAbort || noop;
const onSubmit = opts.onSubmit || noop;
const onExit = opts.onExit || noop;
p.on('state', args.onState || noop);
p.on('submit', x => res(onSubmit(x)));
p.on('exit', x => res(onExit(x)));
p.on('abort', x => rej(onAbort(x)));
});
}
@@ -190,6 +192,7 @@ const byTitle = (input, choices) => Promise.resolve(
* @param {number} [args.limit=10] Max number of results to show
* @param {string} [args.style="default"] Render style ('default', 'password', 'invisible')
* @param {String} [args.initial] Index of the default value
* @param {boolean} [opts.clearFirst] The first ESCAPE keypress will clear the input
* @param {String} [args.fallback] Fallback message - defaults to initial value
* @param {function} [args.onState] On state change callback
* @param {Stream} [args.stdin] The Readable stream to listen to

View File

@@ -1,7 +1,7 @@
'use strict';
module.exports = (key, isSelect) => {
if (key.meta) return;
if (key.meta && key.name !== 'escape') return;
if (key.ctrl) {
if (key.name === 'a') return 'first';
@@ -21,10 +21,14 @@ module.exports = (key, isSelect) => {
if (key.name === 'backspace') return 'delete';
if (key.name === 'delete') return 'deleteForward';
if (key.name === 'abort') return 'abort';
if (key.name === 'escape') return 'abort';
if (key.name === 'escape') return 'exit';
if (key.name === 'tab') return 'next';
if (key.name === 'pagedown') return 'nextPage';
if (key.name === 'pageup') return 'prevPage';
// TODO create home() in prompt types (e.g. TextPrompt)
if (key.name === 'home') return 'home';
// TODO create end() in prompt types (e.g. TextPrompt)
if (key.name === 'end') return 'end';
if (key.name === 'up') return 'up';
if (key.name === 'down') return 'down';

View File

@@ -5,7 +5,11 @@ const { erase, cursor } = require('sisteransi');
const width = str => [...strip(str)].length;
module.exports = function(prompt, perLine = process.stdout.columns) {
/**
* @param {string} prompt
* @param {number} perLine
*/
module.exports = function(prompt, perLine) {
if (!perLine) return erase.line + cursor.to(0);
let rows = 0;
@@ -14,5 +18,5 @@ module.exports = function(prompt, perLine = process.stdout.columns) {
rows += 1 + Math.floor(Math.max(width(line) - 1, 0) / perLine);
}
return (erase.line + cursor.prevLine()).repeat(rows - 1) + erase.line + cursor.to(0);
return erase.lines(rows);
};

View File

@@ -2,7 +2,11 @@
const strip = require('./strip');
module.exports = function (msg, perLine = process.stdout.columns) {
/**
* @param {string} msg
* @param {number} perLine
*/
module.exports = function (msg, perLine) {
let lines = String(strip(msg) || '').split(/\r?\n/);
if (!perLine) return lines.length;

View File

@@ -16,11 +16,12 @@ const render = type => styles[type] || styles.default;
const symbols = Object.freeze({
aborted: c.red(figures.cross),
done: c.green(figures.tick),
exited: c.yellow(figures.cross),
default: c.cyan('?')
});
const symbol = (done, aborted) =>
aborted ? symbols.aborted : done ? symbols.done : symbols.default;
const symbol = (done, aborted, exited) =>
aborted ? symbols.aborted : exited ? symbols.exited : done ? symbols.done : symbols.default;
// between the question and the user's input.
const delimiter = completing =>

View File

@@ -2,16 +2,16 @@
/**
* @param {string} msg The message to wrap
* @param {object} [opts]
* @param {object} opts
* @param {number|string} [opts.margin] Left margin
* @param {number} [opts.width] Maximum characters per line including the margin
* @param {number} opts.width Maximum characters per line including the margin
*/
module.exports = (msg, opts = {}) => {
const tab = Number.isSafeInteger(parseInt(opts.margin))
? new Array(parseInt(opts.margin)).fill(' ').join('')
: (opts.margin || '');
const width = opts.width || process.stdout.columns;
const width = opts.width;
return (msg || '').split(/\r?\n/g)
.map(line => line