@inquirer/core
Advanced tools
Comparing version 0.0.17-alpha.0 to 0.0.18-alpha.0
16
index.js
@@ -1,5 +0,1 @@ | ||
const _ = { | ||
isFunction: require('lodash/isFunction'), | ||
noop: require('lodash/noop'), | ||
}; | ||
const readline = require('readline'); | ||
@@ -53,3 +49,3 @@ const chalk = require('chalk'); | ||
let config = configFactory; | ||
if (_.isFunction(configFactory)) { | ||
if (typeof configFactory === 'function') { | ||
config = configFactory(this.rl); | ||
@@ -74,3 +70,3 @@ } | ||
const showLoader = setTimeout(this.startLoading, 500); | ||
if (_.isFunction(message)) { | ||
if (typeof message === 'function') { | ||
message = await runAsync(message)(); | ||
@@ -90,3 +86,3 @@ } | ||
onKeypress(value, key) { | ||
const { onKeypress = _.noop } = this.config; | ||
const { onKeypress } = this.config; | ||
// Ignore enter keypress. The "line" event is handling those. | ||
@@ -98,3 +94,5 @@ if (key.name === 'enter' || key.name === 'return') { | ||
this.setState({ value: this.rl.line, error: null }); | ||
onKeypress(this.rl.line, key, this.getState(), this.setState); | ||
if (onKeypress) { | ||
onKeypress(this.rl.line, key, this.getState(), this.setState); | ||
} | ||
} | ||
@@ -202,3 +200,3 @@ | ||
// Only pass message down if it's a string. Otherwise we're still in init state | ||
message: _.isFunction(message) ? 'Loading...' : message, | ||
message: typeof message === 'function' ? 'Loading...' : message, | ||
value: transformer(value, { isFinal: status === 'done' }), | ||
@@ -205,0 +203,0 @@ validate: undefined, |
'use strict'; | ||
const _ = { | ||
flatten: require('lodash/flatten'), | ||
}; | ||
const chalk = require('chalk'); | ||
@@ -48,3 +45,3 @@ const cliWidth = require('cli-width'); | ||
// Duplicate the lines so it give an infinite list look | ||
const infinite = _.flatten([lines, lines, lines]); | ||
const infinite = [lines, lines, lines].flat(); | ||
const topIndex = Math.max(0, active + lines.length - this.pointer); | ||
@@ -51,0 +48,0 @@ |
@@ -1,4 +0,1 @@ | ||
const _ = { | ||
last: require('lodash/last'), | ||
}; | ||
const cliWidth = require('cli-width'); | ||
@@ -12,3 +9,3 @@ const stripAnsi = require('strip-ansi'); | ||
const height = (content) => content.split('\n').length; | ||
const lastLine = (content) => _.last(content.split('\n')); | ||
const lastLine = (content) => content.split('\n').pop(); | ||
@@ -15,0 +12,0 @@ module.exports = class ScreenManager { |
@@ -1,9 +0,5 @@ | ||
const _ = { | ||
flatten: require('lodash/flatten'), | ||
}; | ||
/** | ||
* Force line returns at specific width. This function is ANSI code friendly and it'll | ||
* ignore invisible codes during width calculation. | ||
* @param {string} lines | ||
* @param {string} content | ||
* @param {number} width | ||
@@ -14,4 +10,5 @@ * @return {string} | ||
const regex = new RegExp('(?:(?:\\033[[0-9;]*m)*.?){1,' + width + '}', 'g'); | ||
return _.flatten( | ||
content.split('\n').map((line) => { | ||
return content | ||
.split('\n') | ||
.flatMap((line) => { | ||
const chunk = line.match(regex); | ||
@@ -22,3 +19,3 @@ // Remove the last match as it's always empty | ||
}) | ||
).join('\n'); | ||
.join('\n'); | ||
}; |
{ | ||
"name": "@inquirer/core", | ||
"version": "0.0.17-alpha.0", | ||
"version": "0.0.18-alpha.0", | ||
"description": "Core Inquirer prompt API", | ||
@@ -18,3 +18,3 @@ "main": "index.js", | ||
"chalk": "^4.1.1", | ||
"cli-spinners": "^2.6.0", | ||
"cli-spinners": "^2.6.1", | ||
"cli-width": "^3.0.0", | ||
@@ -30,3 +30,3 @@ "lodash": "^4.17.21", | ||
}, | ||
"gitHead": "8e0b3d4c76bcf5c970936fec2561d3cc7964abb5" | ||
"gitHead": "e71313db1a6e26f501b58d75a9d3acf53dab5da7" | ||
} |
26443
739
Updatedcli-spinners@^2.6.1