Comparing version 2.0.0 to 2.0.1
'use strict'; | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
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); }); }; } | ||
const color = require('kleur'); | ||
const Prompt = require('./prompt'); | ||
var _require = require('sisteransi'); | ||
const _require = require('sisteransi'), | ||
cursor = _require.cursor; | ||
const cursor = _require.cursor; | ||
var _require2 = require('../util'); | ||
const style = _require2.style, | ||
const _require2 = require('../util'), | ||
style = _require2.style, | ||
clear = _require2.clear, | ||
@@ -19,6 +20,5 @@ figures = _require2.figures, | ||
const getVal = (arr, i) => arr[i] && (arr[i].value || arr[i].title || arr[i]); | ||
const getVal = (arr, i) => arr[i] && (arr[i].value || arr[i].title || arr[i]); | ||
const getTitle = (arr, i) => arr[i] && (arr[i].title || arr[i].value || arr[i]); | ||
/** | ||
@@ -39,2 +39,4 @@ * TextPrompt Base Element | ||
*/ | ||
class AutocompletePrompt extends Prompt { | ||
@@ -73,11 +75,12 @@ constructor(opts = {}) { | ||
const p = _this.completing = _this.suggest(_this.input, _this.choices); | ||
const suggestions = yield p; | ||
if (_this.completing !== p) return; | ||
_this.suggestions = suggestions.slice(0, _this.limit).map(function (s, i, arr) { | ||
return { title: getTitle(arr, i), value: getVal(arr, i) }; | ||
}); | ||
_this.suggestions = suggestions.slice(0, _this.limit).map((s, i, arr) => ({ | ||
title: getTitle(arr, i), | ||
value: getVal(arr, i) | ||
})); | ||
_this.completing = false; | ||
const l = Math.max(suggestions.length - 1, 0); | ||
const l = Math.max(suggestions.length - 1, 0); | ||
_this.moveSelect(Math.min(l, _this.select)); | ||
@@ -186,3 +189,2 @@ | ||
if (this.lineCount) this.out.write(cursor.down(this.lineCount)); | ||
let prompt = `${style.symbol(this.done, this.aborted)} ${this.msg} ${style.delimiter(this.completing)} `; | ||
@@ -202,2 +204,3 @@ let length = strip(prompt).length; | ||
let suggestions = this.suggestions.reduce((acc, item, i) => acc + `\n${i === this.select ? color.cyan(item.title) : item.title}`, ''); | ||
if (suggestions) { | ||
@@ -221,4 +224,5 @@ prompt += suggestions; | ||
} | ||
} | ||
module.exports = AutocompletePrompt; |
@@ -1,15 +0,13 @@ | ||
'use strict'; | ||
"use strict"; | ||
const color = require('kleur'); | ||
const Prompt = require('./prompt'); | ||
var _require = require('../util'); | ||
const _require = require('../util'), | ||
style = _require.style; | ||
const style = _require.style; | ||
var _require2 = require('sisteransi'); | ||
const erase = _require2.erase, | ||
const _require2 = require('sisteransi'), | ||
erase = _require2.erase, | ||
cursor = _require2.cursor; | ||
/** | ||
@@ -28,2 +26,3 @@ * ConfirmPrompt Base Element | ||
class ConfirmPrompt extends Prompt { | ||
@@ -71,2 +70,3 @@ constructor(opts = {}) { | ||
} | ||
if (c.toLowerCase() === 'n') { | ||
@@ -76,2 +76,3 @@ this.value = false; | ||
} | ||
return this.bell(); | ||
@@ -84,7 +85,7 @@ } | ||
super.render(); | ||
this.out.write(erase.line + cursor.to(0) + [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(' ')); | ||
} | ||
} | ||
module.exports = ConfirmPrompt; |
'use strict'; | ||
const color = require('kleur'); | ||
const Prompt = require('./prompt'); | ||
var _require = require('sisteransi'); | ||
const _require = require('sisteransi'), | ||
cursor = _require.cursor; | ||
const cursor = _require.cursor; | ||
var _require2 = require('../util'); | ||
const clear = _require2.clear, | ||
const _require2 = require('../util'), | ||
clear = _require2.clear, | ||
figures = _require2.figures, | ||
style = _require2.style; | ||
/** | ||
@@ -28,2 +26,3 @@ * MultiselectPrompt Base Element | ||
class MultiselectPrompt extends Prompt { | ||
@@ -88,2 +87,3 @@ constructor(opts = {}) { | ||
} | ||
next() { | ||
@@ -135,9 +135,7 @@ this.cursor = (this.cursor + 1) % this.value.length; | ||
if (this.first) this.out.write(cursor.hide); | ||
super.render(); | ||
super.render(); // print prompt | ||
// print prompt | ||
const selected = this.value.filter(e => e.selected).map(v => v.title).join(', '); | ||
let prompt = [style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(false), this.done ? selected : this.value[this.cursor].disabled ? color.yellow(this.warn) : color.gray(this.hint)].join(' '); | ||
let prompt = [style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(false), this.done ? selected : this.value[this.cursor].disabled ? color.yellow(this.warn) : color.gray(this.hint)].join(' '); // print choices | ||
// print choices | ||
if (!this.done) { | ||
@@ -155,4 +153,5 @@ const c = this.cursor; | ||
} | ||
} | ||
module.exports = MultiselectPrompt; |
@@ -1,16 +0,17 @@ | ||
'use strict'; | ||
"use strict"; | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
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); }); }; } | ||
const color = require('kleur'); | ||
const Prompt = require('./prompt'); | ||
var _require = require('sisteransi'); | ||
const cursor = _require.cursor, | ||
const _require = require('sisteransi'), | ||
cursor = _require.cursor, | ||
erase = _require.erase; | ||
var _require2 = require('../util'); | ||
const style = _require2.style, | ||
const _require2 = require('../util'), | ||
style = _require2.style, | ||
clear = _require2.clear, | ||
@@ -20,6 +21,7 @@ figures = _require2.figures, | ||
const isNumber = /[0-9]/; | ||
const isValidChar = /\.|-/; | ||
const isDef = any => any !== undefined; | ||
const round = (number, precision) => { | ||
@@ -29,3 +31,2 @@ let factor = Math.pow(10, precision); | ||
}; | ||
/** | ||
@@ -47,2 +48,4 @@ * NumberPrompt Base Element | ||
*/ | ||
class NumberPrompt extends Prompt { | ||
@@ -60,3 +63,5 @@ constructor(opts = {}) { | ||
this.errorMsg = opts.error || `Please Enter A Valid Value`; | ||
this.validator = opts.validate || (() => true); | ||
this.color = `cyan`; | ||
@@ -79,2 +84,3 @@ this.value = ``; | ||
} | ||
this.fire(); | ||
@@ -118,2 +124,3 @@ } | ||
let valid = yield _this.validator(_this.value); | ||
if (typeof valid === `string`) { | ||
@@ -123,2 +130,3 @@ _this.errorMsg = valid; | ||
} | ||
_this.error = !valid; | ||
@@ -133,8 +141,13 @@ })(); | ||
yield _this2.validate(); | ||
if (_this2.error) { | ||
_this2.color = `red`; | ||
_this2.fire(); | ||
_this2.render(); | ||
return; | ||
} | ||
let x = _this2.value; | ||
@@ -145,5 +158,9 @@ _this2.value = x !== `` ? x : _this2.initial; | ||
_this2.error = false; | ||
_this2.fire(); | ||
_this2.render(); | ||
_this2.out.write(`\n`); | ||
_this2.close(); | ||
@@ -188,11 +205,9 @@ })(); | ||
if (!this.valid(c)) return this.bell(); | ||
const now = Date.now(); | ||
if (now - this.lastHit > 1000) this.typed = ``; // 1s elapsed | ||
this.typed += c; | ||
this.lastHit = now; | ||
this.color = `cyan`; | ||
if (c === `.`) return this.fire(); | ||
this.value = Math.min(this.parse(this.typed), this.max); | ||
@@ -210,4 +225,4 @@ if (this.value > this.max) this.value = this.max; | ||
this.lines = 0; | ||
let error = ``; | ||
let error = ``; | ||
if (this.error) { | ||
@@ -221,4 +236,4 @@ let lines = this.errorMsg.split(`\n`); | ||
let prompt = [style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(this.done), underline ? color[this.color]().underline(this.rendered) : this.rendered].join(` `); | ||
let position = ``; | ||
let position = ``; | ||
if (this.lines) { | ||
@@ -231,4 +246,5 @@ position += cursor.up(this.lines); | ||
} | ||
} | ||
module.exports = NumberPrompt; |
@@ -5,15 +5,12 @@ 'use strict'; | ||
var _require = require('../util'); | ||
const _require = require('../util'), | ||
action = _require.action; | ||
const action = _require.action; | ||
const EventEmitter = require('events'); | ||
var _require2 = require('sisteransi'); | ||
const beep = _require2.beep, | ||
const _require2 = require('sisteransi'), | ||
beep = _require2.beep, | ||
cursor = _require2.cursor; | ||
const color = require('kleur'); | ||
/** | ||
@@ -24,9 +21,11 @@ * Base prompt skeleton | ||
*/ | ||
class Prompt extends EventEmitter { | ||
constructor(opts = {}) { | ||
super(); | ||
this.first = true; | ||
this.firstRender = true; | ||
this.in = opts.in || process.stdin; | ||
this.out = opts.out || process.stdout; | ||
this.onRender = (opts.onRender || (() => void 0)).bind(this); | ||
@@ -36,3 +35,2 @@ | ||
readline.emitKeypressEvents(this.in, rl); | ||
if (this.in.isTTY) this.in.setRawMode(true); | ||
@@ -42,2 +40,3 @@ | ||
let a = action(key); | ||
if (a === false) { | ||
@@ -60,4 +59,4 @@ this._ && this._(str, key); | ||
}; | ||
this.close = close; | ||
this.in.on('keypress', keypress); | ||
@@ -79,6 +78,7 @@ } | ||
this.onRender(color); | ||
if (this.first) this.first = false; | ||
if (this.firstRender) this.firstRender = false; | ||
} | ||
} | ||
module.exports = Prompt; |
'use strict'; | ||
const color = require('kleur'); | ||
const Prompt = require('./prompt'); | ||
var _require = require('../util'); | ||
const style = _require.style, | ||
const _require = require('../util'), | ||
style = _require.style, | ||
clear = _require.clear, | ||
figures = _require.figures; | ||
var _require2 = require('sisteransi'); | ||
const erase = _require2.erase, | ||
const _require2 = require('sisteransi'), | ||
erase = _require2.erase, | ||
cursor = _require2.cursor; | ||
/** | ||
@@ -28,2 +26,3 @@ * SelectPrompt Base Element | ||
class SelectPrompt extends Prompt { | ||
@@ -115,12 +114,11 @@ constructor(opts = {}) { | ||
if (this.closed) return; | ||
if (this.first) this.out.write(cursor.hide);else this.out.write(erase.lines(this.values.length + 1)); | ||
super.render(); | ||
if (this.firstRender) this.out.write(cursor.hide);else this.out.write(erase.lines(this.values.length + 1)); | ||
super.render(); // Print prompt | ||
// Print prompt | ||
this.out.write([style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(false), this.done ? this.selection.title : this.selection.disabled ? color.yellow(this.warn) : color.gray(this.hint)].join(' ')); | ||
this.out.write([style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(false), this.done ? this.selection.title : this.selection.disabled ? color.yellow(this.warn) : color.gray(this.hint)].join(' ')); // Print choices | ||
// Print choices | ||
if (!this.done) { | ||
this.out.write('\n' + this.values.map((v, i) => { | ||
let title, prefix; | ||
if (v.disabled) { | ||
@@ -133,2 +131,3 @@ title = this.cursor === i ? color.gray().underline(v.title) : color.strikethrough().gray(v.title); | ||
} | ||
return `${prefix} ${title}`; | ||
@@ -138,4 +137,5 @@ }).join('\n')); | ||
} | ||
} | ||
module.exports = SelectPrompt; |
@@ -1,19 +0,19 @@ | ||
'use strict'; | ||
"use strict"; | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
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); }); }; } | ||
const color = require('kleur'); | ||
const Prompt = require('./prompt'); | ||
var _require = require('sisteransi'); | ||
const _require = require('sisteransi'), | ||
cursor = _require.cursor; | ||
const cursor = _require.cursor; | ||
var _require2 = require('../util'); | ||
const style = _require2.style, | ||
const _require2 = require('../util'), | ||
style = _require2.style, | ||
clear = _require2.clear, | ||
strip = _require2.strip, | ||
figures = _require2.figures; | ||
/** | ||
@@ -31,2 +31,3 @@ * TextPrompt Base Element | ||
class TextPrompt extends Prompt { | ||
@@ -39,3 +40,5 @@ constructor(opts = {}) { | ||
this.initial = opts.initial || ``; | ||
this.validator = opts.validate || (() => true); | ||
this.value = ``; | ||
@@ -56,2 +59,3 @@ this.errorMsg = opts.error || `Please Enter A Valid Value`; | ||
} | ||
this._value = v; | ||
@@ -88,2 +92,3 @@ this.fire(); | ||
let valid = yield _this.validator(_this.value); | ||
if (typeof valid === `string`) { | ||
@@ -93,2 +98,3 @@ _this.errorMsg = valid; | ||
} | ||
_this.error = !valid; | ||
@@ -104,13 +110,22 @@ })(); | ||
yield _this2.validate(); | ||
if (_this2.error) { | ||
_this2.red = true; | ||
_this2.fire(); | ||
_this2.render(); | ||
return; | ||
} | ||
_this2.done = true; | ||
_this2.aborted = false; | ||
_this2.fire(); | ||
_this2.render(); | ||
_this2.out.write('\n'); | ||
_this2.close(); | ||
@@ -188,6 +203,5 @@ })(); | ||
this.lines = 0; | ||
let prompt = [style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(this.done), this.red ? color.red(this.rendered) : this.rendered].join(` `); | ||
let error = ``; | ||
let error = ``; | ||
if (this.error) { | ||
@@ -200,2 +214,3 @@ let lines = this.errorMsg.split(`\n`); | ||
let position = ``; | ||
if (this.lines) { | ||
@@ -205,9 +220,10 @@ position += cursor.up(this.lines); | ||
} | ||
position += cursor.move(this.placeholder ? -this.initial.length * this.scale : -this.rendered.length + this.cursor * this.scale); | ||
this.out.write(erase + prompt + error + position); | ||
this.clear = clear(prompt + error); | ||
} | ||
} | ||
module.exports = TextPrompt; |
@@ -1,16 +0,14 @@ | ||
'use strict'; | ||
"use strict"; | ||
const color = require('kleur'); | ||
const Prompt = require('./prompt'); | ||
var _require = require('../util'); | ||
const style = _require.style, | ||
const _require = require('../util'), | ||
style = _require.style, | ||
clear = _require.clear; | ||
var _require2 = require('sisteransi'); | ||
const cursor = _require2.cursor, | ||
const _require2 = require('sisteransi'), | ||
cursor = _require2.cursor, | ||
erase = _require2.erase; | ||
/** | ||
@@ -27,2 +25,3 @@ * TogglePrompt Base Element | ||
class TogglePrompt extends Prompt { | ||
@@ -77,11 +76,15 @@ constructor(opts = {}) { | ||
} | ||
left() { | ||
this.deactivate(); | ||
} | ||
right() { | ||
this.activate(); | ||
} | ||
down() { | ||
this.deactivate(); | ||
} | ||
up() { | ||
@@ -105,2 +108,3 @@ this.activate(); | ||
} else return this.bell(); | ||
this.render(); | ||
@@ -113,7 +117,7 @@ } | ||
super.render(); | ||
this.out.write(erase.lines(this.first ? 1 : this.msg.split(/\n/g).length) + cursor.to(0) + [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(' ')); | ||
} | ||
} | ||
module.exports = TogglePrompt; |
'use strict'; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, 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 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); }); }; } | ||
const prompts = require('./prompts'); | ||
const passOn = ['suggest', 'format', 'onState', 'validate', 'onRender']; | ||
const noop = () => {}; | ||
/** | ||
@@ -10,8 +21,16 @@ * Prompt for a series of questions | ||
*/ | ||
let prompt = (() => { | ||
var _ref = _asyncToGenerator(function* (questions = [], { onSubmit = noop, onCancel = noop } = {}) { | ||
function prompt() { | ||
return _prompt.apply(this, arguments); | ||
} | ||
function _prompt() { | ||
_prompt = _asyncToGenerator(function* (questions = [], { | ||
onSubmit = noop, | ||
onCancel = noop | ||
} = {}) { | ||
const answers = {}; | ||
questions = [].concat(questions); | ||
let answer, question, quit, name, type; | ||
var _iteratorNormalCompletion = true; | ||
@@ -24,12 +43,11 @@ var _didIteratorError = false; | ||
question = _step.value; | ||
// if property is a function, invoke it unless it's a special function | ||
var _question = question; | ||
name = _question.name; | ||
type = _question.type; | ||
// if property is a function, invoke it unless it's a special function | ||
for (let key in question) { | ||
if (passOn.includes(key)) continue; | ||
let value = question[key]; | ||
question[key] = typeof value === 'function' ? yield value(answer, _extends({}, answers), question) : value; | ||
question[key] = typeof value === 'function' ? yield value(answer, _objectSpread({}, answers), question) : value; | ||
} | ||
@@ -39,11 +57,9 @@ | ||
throw new Error('prompt message is required'); | ||
} | ||
} // update vars in case they changed | ||
// update vars in case they changed | ||
// skip if type is a falsy value | ||
var _question2 = question; | ||
name = _question2.name; | ||
type = _question2.type; | ||
// skip if type is a falsy value | ||
if (!type) continue; | ||
@@ -71,3 +87,3 @@ | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
@@ -84,17 +100,8 @@ } | ||
}); | ||
return _prompt.apply(this, arguments); | ||
} | ||
return function prompt() { | ||
return _ref.apply(this, arguments); | ||
}; | ||
})(); | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
const prompts = require('./prompts'); | ||
const passOn = ['suggest', 'format', 'onState', 'validate', 'onRender']; | ||
const noop = () => {}; | ||
function getInjectedAnswer(injected) { | ||
const answer = injected.shift(); | ||
if (answer instanceof Error) { | ||
@@ -111,2 +118,6 @@ throw answer; | ||
module.exports = Object.assign(prompt, { prompt, prompts, inject }); | ||
module.exports = Object.assign(prompt, { | ||
prompt, | ||
prompts, | ||
inject | ||
}); |
'use strict'; | ||
const $ = exports; | ||
const el = require('./elements'); | ||
const noop = v => v; | ||
@@ -17,3 +19,2 @@ | ||
} | ||
/** | ||
@@ -30,4 +31,5 @@ * Text prompt | ||
*/ | ||
$.text = args => toPrompt('TextPrompt', args); | ||
/** | ||
@@ -43,2 +45,4 @@ * Password prompt with masked input | ||
*/ | ||
$.password = args => { | ||
@@ -48,3 +52,2 @@ args.style = 'password'; | ||
}; | ||
/** | ||
@@ -60,2 +63,4 @@ * Prompt where input is invisible, like sudo | ||
*/ | ||
$.invisible = args => { | ||
@@ -65,3 +70,2 @@ args.style = 'invisible'; | ||
}; | ||
/** | ||
@@ -83,4 +87,5 @@ * Number prompt | ||
*/ | ||
$.number = args => toPrompt('NumberPrompt', args); | ||
/** | ||
@@ -95,4 +100,5 @@ * Classic yes/no prompt | ||
*/ | ||
$.confirm = args => toPrompt('ConfirmPrompt', args); | ||
/** | ||
@@ -109,2 +115,4 @@ * List prompt, split intput string by `seperator` | ||
*/ | ||
$.list = args => { | ||
@@ -116,3 +124,2 @@ const sep = args.separator || ','; | ||
}; | ||
/** | ||
@@ -129,4 +136,5 @@ * Toggle/switch prompt | ||
*/ | ||
$.toggle = args => toPrompt('TogglePrompt', args); | ||
/** | ||
@@ -143,4 +151,5 @@ * Interactive select prompt | ||
*/ | ||
$.select = args => toPrompt('SelectPrompt', args); | ||
/** | ||
@@ -158,5 +167,9 @@ * Interactive multi-select prompt | ||
*/ | ||
$.multiselect = args => { | ||
args.choices = [].concat(args.choices || []); | ||
const toSelected = items => items.filter(item => item.selected).map(item => item.value); | ||
return toPrompt('MultiselectPrompt', args, { | ||
@@ -169,3 +182,2 @@ onAbort: toSelected, | ||
const byTitle = (input, choices) => Promise.resolve(choices.filter(item => item.title.slice(0, input.length).toLowerCase() === input.toLowerCase())); | ||
/** | ||
@@ -185,2 +197,4 @@ * Interactive auto-complete prompt | ||
*/ | ||
$.autocomplete = args => { | ||
@@ -187,0 +201,0 @@ args.suggest = args.suggest || byTitle; |
@@ -11,4 +11,6 @@ 'use strict'; | ||
} | ||
if (key.name === 'return') return 'submit'; | ||
if (key.name === 'enter') return 'submit'; // ctrl + J | ||
if (key.name === 'backspace') return 'delete'; | ||
@@ -19,3 +21,2 @@ if (key.name === 'delete') return 'deleteForward'; | ||
if (key.name === 'tab') return 'next'; | ||
if (key.name === 'up') return 'up'; | ||
@@ -25,4 +26,3 @@ if (key.name === 'down') return 'down'; | ||
if (key.name === 'left') return 'left'; | ||
return false; | ||
}; |
@@ -5,8 +5,6 @@ 'use strict'; | ||
var _require = require('sisteransi'); | ||
const erase = _require.erase, | ||
const _require = require('sisteransi'), | ||
erase = _require.erase, | ||
cursor = _require.cursor; | ||
const width = str => [...strip(str)].length; | ||
@@ -16,3 +14,2 @@ | ||
if (!perLine) return erase.line + cursor.to(0); | ||
let rows = 0; | ||
@@ -27,3 +24,2 @@ const lines = prompt.split(/\r?\n/); | ||
let line = _step.value; | ||
rows += 1 + Math.floor(Math.max(width(line) - 1, 0) / perLine); | ||
@@ -36,3 +32,3 @@ } | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
@@ -39,0 +35,0 @@ } |
@@ -20,3 +20,2 @@ 'use strict'; | ||
const figures = process.platform === 'win32' ? win : main; | ||
module.exports = figures; |
@@ -5,5 +5,4 @@ 'use strict'; | ||
const pattern = ['[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)', '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))'].join('|'); | ||
const RGX = new RegExp(pattern, 'g'); | ||
return typeof str === 'string' ? str.replace(RGX, '') : str; | ||
}; |
'use strict'; | ||
const c = require('kleur'); | ||
const figures = require('./figures'); | ||
// rendering user input. | ||
const figures = require('./figures'); // rendering user input. | ||
const styles = Object.freeze({ | ||
password: { scale: 1, render: input => '*'.repeat(input.length) }, | ||
emoji: { scale: 2, render: input => '😃'.repeat(input.length) }, | ||
invisible: { scale: 0, render: input => '' }, | ||
default: { scale: 1, render: input => `${input}` } | ||
password: { | ||
scale: 1, | ||
render: input => '*'.repeat(input.length) | ||
}, | ||
emoji: { | ||
scale: 2, | ||
render: input => '😃'.repeat(input.length) | ||
}, | ||
invisible: { | ||
scale: 0, | ||
render: input => '' | ||
}, | ||
default: { | ||
scale: 1, | ||
render: input => `${input}` | ||
} | ||
}); | ||
const render = type => styles[type] || styles.default; | ||
// icon to signalize a prompt. | ||
const render = type => styles[type] || styles.default; // icon to signalize a prompt. | ||
const symbols = Object.freeze({ | ||
@@ -22,5 +36,5 @@ aborted: c.red(figures.cross), | ||
const symbol = (done, aborted) => aborted ? symbols.aborted : done ? symbols.done : symbols.default; | ||
const symbol = (done, aborted) => aborted ? symbols.aborted : done ? symbols.done : symbols.default; // between the question and the user's input. | ||
// between the question and the user's input. | ||
const delimiter = completing => c.gray(completing ? figures.ellipsis : figures.pointerSmall); | ||
@@ -27,0 +41,0 @@ |
@@ -18,3 +18,3 @@ 'use strict'; | ||
this.first = true; | ||
this.firstRender = true; | ||
this.in = opts.in || process.stdin; | ||
@@ -66,3 +66,3 @@ this.out = opts.out || process.stdout; | ||
this.onRender(color); | ||
if (this.first) this.first = false; | ||
if (this.firstRender) this.firstRender = false; | ||
} | ||
@@ -69,0 +69,0 @@ } |
@@ -105,3 +105,3 @@ 'use strict'; | ||
if (this.closed) return; | ||
if (this.first) this.out.write(cursor.hide); | ||
if (this.firstRender) this.out.write(cursor.hide); | ||
else this.out.write(erase.lines(this.values.length + 1)); | ||
@@ -108,0 +108,0 @@ super.render(); |
{ | ||
"name": "prompts", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Lightweight, beautiful and user-friendly prompts", | ||
@@ -43,5 +43,6 @@ "license": "MIT", | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-plugin-transform-object-rest-spread": "^6.26.0", | ||
"babel-preset-env": "^1.7.0", | ||
"@babel/cli": "^7.1.5", | ||
"@babel/core": "^7.1.6", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.0.0", | ||
"@babel/preset-env": "^7.1.6", | ||
"tap-spec": "^5.0.0", | ||
@@ -48,0 +49,0 @@ "tape": "^4.9.1" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
117826
2759
6