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

@@ -38,6 +38,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
@@ -56,6 +57,7 @@ class AutocompletePrompt extends Prompt {
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;
@@ -64,7 +66,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();
}
@@ -120,8 +122,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');
@@ -130,7 +146,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');
@@ -176,14 +192,22 @@ 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();
}
@@ -239,14 +263,14 @@ class AutocompletePrompt extends Prompt {
render() {
if (this.closed) return;
if (this.firstRender) this.out.write(cursor.hide);else this.out.write(clear(this.outputText));
if (this.firstRender) this.out.write(cursor.hide);else this.out.write(clear(this.outputText, this.out.columns));
super.render();
let _entriesToDisplay = entriesToDisplay(this.select, this.choices.length, this.limit),
startIndex = _entriesToDisplay.startIndex,
endIndex = _entriesToDisplay.endIndex;
this.outputText = [color.bold(style.symbol(this.done, this.aborted)), color.bold(this.msg), style.delimiter(this.completing), this.done && this.suggestions[this.select] ? this.suggestions[this.select].title : this.rendered = this.transform.render(this.input)].join(' ');
this.outputText = [style.symbol(this.done, this.aborted, this.exited), color.bold(this.msg), style.delimiter(this.completing), this.done && this.suggestions[this.select] ? this.suggestions[this.select].title : this.rendered = this.transform.render(this.input)].join(' ');
if (!this.done) {
const suggestions = this.suggestions.slice(startIndex, endIndex).map((item, i) => this.renderOption(item, this.select === i + startIndex, i === 0 && startIndex > 0, i + startIndex === endIndex - 1 && endIndex < this.choices.length)).join('\n');

View File

@@ -30,7 +30,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();
}
@@ -193,7 +193,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

@@ -44,6 +44,10 @@ class ConfirmPrompt extends Prompt {
this.render();
}
exit() {
this.abort();
}
abort() {
this.done = this.aborted = true;
this.fire();
@@ -78,7 +82,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));
if (this.firstRender) this.out.write(cursor.hide);else this.out.write(clear(this.outputText, this.out.columns));
super.render();
this.outputText = [style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(this.done), this.done ? this.value ? this.yesMsg : this.noMsg : color.gray(this.initialValue ? this.yesOption : this.noOption)].join(' ');
this.out.write(erase.line + cursor.to(0) + this.outputText);

View File

@@ -55,20 +55,19 @@ const dfltLocales = {
monthsShort: 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'.split(','),
weekdays: 'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday'.split(','),
weekdaysShort: 'Sun,Mon,Tue,Wed,Thu,Fri,Sat'.split(',')
/**
* DatePrompt Base Element
* @param {Object} opts Options
* @param {String} opts.message Message
* @param {Number} [opts.initial] Index of default value
* @param {String} [opts.mask] The format mask
* @param {object} [opts.locales] The date locales
* @param {String} [opts.error] The error message shown on invalid value
* @param {Function} [opts.validate] Function to validate the submitted value
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
*/
};
/**
* DatePrompt Base Element
* @param {Object} opts Options
* @param {String} opts.message Message
* @param {Number} [opts.initial] Index of default value
* @param {String} [opts.mask] The format mask
* @param {object} [opts.locales] The date locales
* @param {String} [opts.error] The error message shown on invalid value
* @param {Function} [opts.validate] Function to validate the submitted value
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
*/
class DatePrompt extends Prompt {
constructor(opts = {}) {
@@ -83,7 +82,7 @@ class DatePrompt extends Prompt {
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();
}
@@ -135,6 +134,10 @@ class DatePrompt extends Prompt {
this.render();
}
exit() {
this.abort();
}
abort() {
this.done = this.aborted = true;
this.error = false;
@@ -230,7 +233,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));
if (this.firstRender) this.out.write(cursor.hide);else this.out.write(clear(this.outputText, this.out.columns));
super.render(); // Print prompt
this.outputText = [style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(false), this.parts.reduce((arr, p, idx) => arr.concat(idx === this.cursor && !this.done ? color.cyan().underline(p.toString()) : p), []).join('')].join(' '); // Print error

View File

@@ -54,7 +54,7 @@ class MultiselectPrompt extends Prompt {
disabled: ch && ch.disabled
};
});
this.clear = clear('');
this.clear = clear('', this.out.columns);
if (!opts.overrideRender) {
this.render();
@@ -72,6 +72,10 @@ class MultiselectPrompt extends Prompt {
return this.value.filter(v => v.selected);
}
exit() {
this.abort();
}
abort() {
this.done = this.aborted = true;
this.fire();
@@ -277,7 +281,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

@@ -99,6 +99,10 @@ class NumberPrompt extends Prompt {
this.render();
}
exit() {
this.abort();
}
abort() {
let x = this.value;
this.value = x !== `` ? x : this.initial;
@@ -225,8 +229,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));
if (this.outputError) 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();

View File

@@ -28,7 +28,10 @@ class Prompt extends EventEmitter {
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);
const isSelect = ['SelectPrompt', 'MultiselectPrompt'].indexOf(this.constructor.name) > -1;
@@ -50,7 +53,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;
};
@@ -60,7 +63,8 @@ class Prompt extends EventEmitter {
fire() {
this.emit('state', {
value: this.value,
aborted: !!this.aborted
aborted: !!this.aborted,
exited: !!this.exited
});
}

View File

@@ -48,7 +48,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();
}
@@ -64,6 +64,10 @@ class SelectPrompt extends Prompt {
this.render();
}
exit() {
this.abort();
}
abort() {
this.done = this.aborted = true;
this.fire();
@@ -94,14 +98,22 @@ 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();
}
@@ -120,7 +132,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));
if (this.firstRender) this.out.write(cursor.hide);else this.out.write(clear(this.outputText, this.out.columns));
super.render();
let _entriesToDisplay = entriesToDisplay(this.cursor, this.choices.length, this.optionsPerPage),

View File

@@ -43,7 +43,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();
}
@@ -71,6 +71,10 @@ class TextPrompt extends Prompt {
this.render();
}
exit() {
this.abort();
}
abort() {
this.value = this.value || this.initial;
this.done = this.aborted = true;
@@ -194,8 +198,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));
if (this.outputError) 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();

View File

@@ -40,6 +40,10 @@ class TogglePrompt extends Prompt {
this.render();
}
exit() {
this.abort();
}
abort() {
this.done = this.aborted = true;
this.fire();
@@ -109,7 +113,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));
if (this.firstRender) this.out.write(cursor.hide);else this.out.write(clear(this.outputText, this.out.columns));
super.render();
this.outputText = [style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(this.done), this.value ? this.inactive : color.cyan().underline(this.inactive), color.gray('/'), this.value ? color.cyan().underline(this.active) : this.active].join(' ');
this.out.write(erase.line + cursor.to(0) + this.outputText);

38
node_modules/prompts/dist/index.js generated vendored
View File

@@ -2,10 +2,16 @@
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
@@ -38,9 +44,7 @@ function _prompt() {
questions = [].concat(questions);
let answer, question, quit, name, type, lastPrompt;
const getFormattedAnswer =
/*#__PURE__*/
function () {
const getFormattedAnswer = /*#__PURE__*/function () {
var _ref = _asyncToGenerator(function* (question, answer, skipValidation = false) {
if (!skipValidation && question.validate && question.validate(answer) !== true) {
return;
@@ -54,12 +58,11 @@ function _prompt() {
};
}();
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
var _iterator = _createForOfIteratorHelper(questions),
_step;
try {
for (var _iterator = questions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
question = _step.value;
var _question = question;
name = _question.name;
@@ -105,7 +108,7 @@ function _prompt() {
try {
// Get the injected answer if there is one or prompt the user
answer = prompt._injected ? getInjectedAnswer(prompt._injected) : yield prompts[type](question);
answer = prompt._injected ? getInjectedAnswer(prompt._injected, question.initial) : yield prompts[type](question);
answers[name] = answer = yield getFormattedAnswer(question, answer, true);
quit = yield onSubmit(question, answer, answers);
} catch (err) {
@@ -115,18 +118,9 @@ function _prompt() {
if (quit) return answers;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
_iterator.e(err);
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
_iterator.f();
}
return answers;
@@ -134,14 +128,14 @@ function _prompt() {
return _prompt.apply(this, arguments);
}
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

@@ -11,8 +11,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)));
});
}
@@ -204,6 +206,7 @@ const byTitle = (input, choices) => Promise.resolve(choices.filter(item => item.
* @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';
@@ -22,10 +22,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';
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';
if (key.name === 'right') return 'right';

View File

@@ -1,5 +1,11 @@
'use strict';
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
const strip = require('./strip');
const _require = require('sisteransi'),
@@ -7,34 +13,30 @@ const _require = require('sisteransi'),
cursor = _require.cursor;
const width = str => [...strip(str)].length;
/**
* @param {string} prompt
* @param {number} perLine
*/
module.exports = function (prompt, perLine = process.stdout.columns) {
module.exports = function (prompt, perLine) {
if (!perLine) return erase.line + cursor.to(0);
let rows = 0;
const lines = prompt.split(/\r?\n/);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
var _iterator = _createForOfIteratorHelper(lines),
_step;
try {
for (var _iterator = lines[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
let line = _step.value;
rows += 1 + Math.floor(Math.max(width(line) - 1, 0) / perLine);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
_iterator.e(err);
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
_iterator.f();
}
return (erase.line + cursor.prevLine()).repeat(rows - 1) + erase.line + cursor.to(0);
return erase.lines(rows);
};

View File

@@ -1,8 +1,13 @@
'use strict';
const strip = require('./strip');
/**
* @param {string} msg
* @param {number} perLine
*/
module.exports = function (msg, perLine = process.stdout.columns) {
module.exports = function (msg, perLine) {
let lines = String(strip(msg) || '').split(/\r?\n/);
if (!perLine) return lines.length;
return lines.map(l => Math.ceil(l.length / perLine)).reduce((a, b) => a + b);

View File

@@ -30,10 +30,11 @@ const render = type => styles[type] || styles.default; // icon to signalize a pr
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; // between the question and the user's input.
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 => c.gray(completing ? figures.ellipsis : figures.pointerSmall);

View File

@@ -1,14 +1,14 @@
'use strict';
/**
* @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.split(/\s+/g).reduce((arr, w) => {
if (w.length + tab.length >= width || arr[arr.length - 1].length + w.length + 1 < width) arr[arr.length - 1] += ` ${w}`;else arr.push(`${tab}${w}`);
return arr;

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

24
node_modules/prompts/package.json generated vendored
View File

@@ -1,8 +1,8 @@
{
"_from": "prompts@^2.0.1",
"_id": "prompts@2.3.0",
"_id": "prompts@2.4.0",
"_inBundle": false,
"_integrity": "sha512-NfbbPPg/74fT7wk2XYQ7hAIp9zJyZp5Fu19iRbORqqy1BhtrkZ0fPafBU+7bmn8ie69DpT0R6QpJIN2oisYjJg==",
"_integrity": "sha512-awZAKrk3vN6CroQukBL+R9051a4R3zCZBlJm/HBfrSZ8iTpYix3VX1vU4mveiLpiwmOJT4wokTF9m6HUk4KqWQ==",
"_location": "/prompts",
"_phantomChildren": {},
"_requested": {
@@ -18,10 +18,10 @@
"_requiredBy": [
"/jest/jest-cli"
],
"_resolved": "https://registry.npmjs.org/prompts/-/prompts-2.3.0.tgz",
"_shasum": "a444e968fa4cc7e86689a74050685ac8006c4cc4",
"_resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.0.tgz",
"_shasum": "4aa5de0723a231d1ee9121c40fdf663df73f61d7",
"_spec": "prompts@^2.0.1",
"_where": "/Users/drew.heavner/Documents/Github/upload-google-play/node_modules/jest/node_modules/jest-cli",
"_where": "/home/codespace/workspace/upload-google-play/node_modules/jest/node_modules/jest-cli",
"author": {
"name": "Terkel Gjervig",
"email": "terkel@terkel.com",
@@ -33,17 +33,17 @@
"bundleDependencies": false,
"dependencies": {
"kleur": "^3.0.3",
"sisteransi": "^1.0.3"
"sisteransi": "^1.0.5"
},
"deprecated": false,
"description": "Lightweight, beautiful and user-friendly prompts",
"devDependencies": {
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-object-rest-spread": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"@babel/plugin-proposal-object-rest-spread": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"tap-spec": "^5.0.0",
"tape": "^4.11.0"
"tape": "^4.13.3"
},
"engines": {
"node": ">= 6"
@@ -81,5 +81,5 @@
"start": "node lib/index.js",
"test": "tape test/*.js | tap-spec"
},
"version": "2.3.0"
"version": "2.4.0"
}

16
node_modules/prompts/readme.md generated vendored
View File

@@ -22,8 +22,8 @@
</p>
<p align="center">
<b>Lightweight, beautiful and user-friendly interactive prompts</b></br>
<sub>>_ Easy to use CLI prompts to enquire users for information▌<sub>
<b>Lightweight, beautiful and user-friendly interactive prompts</b><br />
<sub>>_ Easy to use CLI prompts to enquire users for information▌</sub>
</p>
<br />
@@ -316,6 +316,8 @@ Almost all prompt objects have the following properties:
format: Function | Async Function,
onRender: Function
onState: Function
stdin: Readable
stdout: Writeable
}
```
@@ -417,6 +419,13 @@ Callback for when the state of the current prompt changes.
The function signature is `(state)` where `state` is an object with a snapshot of the current state.
The state object has two properties `value` and `aborted`. E.g `{ value: 'This is ', aborted: false }`
### stdin and stdout
Type: `Stream`
By default, prompts uses `process.stdin` for receiving input and `process.stdout` for writing output.
If you need to use different streams, for instance `process.stderr`, you can set these with the `stdin` and `stdout` properties.
![split](https://github.com/terkelg/prompts/raw/master/media/split.png)
@@ -790,9 +799,10 @@ You can overwrite how choices are being filtered by passing your own suggest fun
| limit | `number` | Max number of results to show. Defaults to `10` |
| style | `string` | Render style (`default`, `password`, `invisible`, `emoji`). Defaults to `'default'` |
| initial | `string \| number` | Default initial value |
| clearFirst | `boolean` | The first ESCAPE keypress will clear the input |
| fallback | `string` | Fallback message when no match is found. Defaults to `initial` value if provided |
| onRender | `function` | On render callback. Keyword `this` refers to the current prompt |
| onState | `function` | On state change callback. Function signature is an `object` with two properties: `value` and `aborted` |
| onState | `function` | On state change callback. Function signature is an `object` with three properties: `value`, `aborted` and `exited` |
Example on what a `suggest` function might look like:
```js