Updated the files.
This commit is contained in:
parent
1553e6b971
commit
753967d4f5
23418 changed files with 3784666 additions and 0 deletions
52
my-app/node_modules/inquirer/lib/utils/events.js
generated
vendored
Executable file
52
my-app/node_modules/inquirer/lib/utils/events.js
generated
vendored
Executable file
|
@ -0,0 +1,52 @@
|
|||
import { fromEvent, filter, map, share, takeUntil } from 'rxjs';
|
||||
|
||||
function normalizeKeypressEvents(value, key) {
|
||||
return { value, key: key || {} };
|
||||
}
|
||||
|
||||
export default function (rl) {
|
||||
const keypress = fromEvent(rl.input, 'keypress', normalizeKeypressEvents)
|
||||
.pipe(takeUntil(fromEvent(rl, 'close')))
|
||||
// Ignore `enter` key. On the readline, we only care about the `line` event.
|
||||
.pipe(filter(({ key }) => key.name !== 'enter' && key.name !== 'return'));
|
||||
|
||||
return {
|
||||
line: fromEvent(rl, 'line'),
|
||||
keypress,
|
||||
|
||||
normalizedUpKey: keypress.pipe(
|
||||
filter(
|
||||
({ key }) =>
|
||||
key.name === 'up' || key.name === 'k' || (key.name === 'p' && key.ctrl),
|
||||
),
|
||||
share(),
|
||||
),
|
||||
|
||||
normalizedDownKey: keypress.pipe(
|
||||
filter(
|
||||
({ key }) =>
|
||||
key.name === 'down' || key.name === 'j' || (key.name === 'n' && key.ctrl),
|
||||
),
|
||||
share(),
|
||||
),
|
||||
|
||||
numberKey: keypress.pipe(
|
||||
filter((e) => e.value && '123456789'.indexOf(e.value) >= 0),
|
||||
map((e) => Number(e.value)),
|
||||
share(),
|
||||
),
|
||||
|
||||
spaceKey: keypress.pipe(
|
||||
filter(({ key }) => key && key.name === 'space'),
|
||||
share(),
|
||||
),
|
||||
aKey: keypress.pipe(
|
||||
filter(({ key }) => key && key.name === 'a'),
|
||||
share(),
|
||||
),
|
||||
iKey: keypress.pipe(
|
||||
filter(({ key }) => key && key.name === 'i'),
|
||||
share(),
|
||||
),
|
||||
};
|
||||
}
|
17
my-app/node_modules/inquirer/lib/utils/incrementListIndex.js
generated
vendored
Executable file
17
my-app/node_modules/inquirer/lib/utils/incrementListIndex.js
generated
vendored
Executable file
|
@ -0,0 +1,17 @@
|
|||
export default function incrementListIndex(current, dir, opt) {
|
||||
const len = opt.choices.realLength;
|
||||
const shouldLoop = 'loop' in opt ? Boolean(opt.loop) : true;
|
||||
if (dir === 'up') {
|
||||
if (current > 0) {
|
||||
return current - 1;
|
||||
}
|
||||
return shouldLoop ? len - 1 : current;
|
||||
}
|
||||
if (dir === 'down') {
|
||||
if (current < len - 1) {
|
||||
return current + 1;
|
||||
}
|
||||
return shouldLoop ? 0 : current;
|
||||
}
|
||||
throw new Error('dir must be up or down');
|
||||
}
|
77
my-app/node_modules/inquirer/lib/utils/paginator.js
generated
vendored
Executable file
77
my-app/node_modules/inquirer/lib/utils/paginator.js
generated
vendored
Executable file
|
@ -0,0 +1,77 @@
|
|||
import chalk from 'chalk';
|
||||
|
||||
/**
|
||||
* The paginator returns a subset of the choices if the list is too long.
|
||||
*/
|
||||
|
||||
export default class Paginator {
|
||||
/**
|
||||
* @param {import("./screen-manager")} [screen]
|
||||
* @param {{isInfinite?: boolean}} [options]
|
||||
*/
|
||||
constructor(screen, options = {}) {
|
||||
const { isInfinite = true } = options;
|
||||
this.lastIndex = 0;
|
||||
this.screen = screen;
|
||||
this.isInfinite = isInfinite;
|
||||
}
|
||||
|
||||
paginate(output, active, pageSize) {
|
||||
pageSize = pageSize || 7;
|
||||
let lines = output.split('\n');
|
||||
|
||||
if (this.screen) {
|
||||
lines = this.screen.breakLines(lines);
|
||||
active = lines
|
||||
.map((lineParts) => lineParts.length)
|
||||
.splice(0, active)
|
||||
.reduce((a, b) => a + b, 0);
|
||||
lines = lines.flat();
|
||||
}
|
||||
|
||||
// Make sure there's enough lines to paginate
|
||||
if (lines.length <= pageSize) {
|
||||
return output;
|
||||
}
|
||||
const visibleLines = this.isInfinite
|
||||
? this.getInfiniteLines(lines, active, pageSize)
|
||||
: this.getFiniteLines(lines, active, pageSize);
|
||||
this.lastIndex = active;
|
||||
return (
|
||||
visibleLines.join('\n') +
|
||||
'\n' +
|
||||
chalk.dim('(Move up and down to reveal more choices)')
|
||||
);
|
||||
}
|
||||
|
||||
getInfiniteLines(lines, active, pageSize) {
|
||||
if (this.pointer === undefined) {
|
||||
this.pointer = 0;
|
||||
}
|
||||
const middleOfList = Math.floor(pageSize / 2);
|
||||
// Move the pointer only when the user go down and limit it to the middle of the list
|
||||
if (
|
||||
this.pointer < middleOfList &&
|
||||
this.lastIndex < active &&
|
||||
active - this.lastIndex < pageSize
|
||||
) {
|
||||
this.pointer = Math.min(middleOfList, this.pointer + active - this.lastIndex);
|
||||
}
|
||||
|
||||
// Duplicate the lines so it give an infinite list look
|
||||
const infinite = [lines, lines, lines].flat();
|
||||
const topIndex = Math.max(0, active + lines.length - this.pointer);
|
||||
|
||||
return infinite.splice(topIndex, pageSize);
|
||||
}
|
||||
|
||||
getFiniteLines(lines, active, pageSize) {
|
||||
let topIndex = active - pageSize / 2;
|
||||
if (topIndex < 0) {
|
||||
topIndex = 0;
|
||||
} else if (topIndex + pageSize > lines.length) {
|
||||
topIndex = lines.length - pageSize;
|
||||
}
|
||||
return lines.splice(topIndex, pageSize);
|
||||
}
|
||||
}
|
50
my-app/node_modules/inquirer/lib/utils/readline.js
generated
vendored
Executable file
50
my-app/node_modules/inquirer/lib/utils/readline.js
generated
vendored
Executable file
|
@ -0,0 +1,50 @@
|
|||
import ansiEscapes from 'ansi-escapes';
|
||||
|
||||
/**
|
||||
* Move cursor left by `x`
|
||||
* @param {Readline} rl - Readline instance
|
||||
* @param {Number} x - How far to go left (default to 1)
|
||||
*/
|
||||
|
||||
export const left = function (rl, x) {
|
||||
rl.output.write(ansiEscapes.cursorBackward(x));
|
||||
};
|
||||
|
||||
/**
|
||||
* Move cursor right by `x`
|
||||
* @param {Readline} rl - Readline instance
|
||||
* @param {Number} x - How far to go left (default to 1)
|
||||
*/
|
||||
|
||||
export const right = function (rl, x) {
|
||||
rl.output.write(ansiEscapes.cursorForward(x));
|
||||
};
|
||||
|
||||
/**
|
||||
* Move cursor up by `x`
|
||||
* @param {Readline} rl - Readline instance
|
||||
* @param {Number} x - How far to go up (default to 1)
|
||||
*/
|
||||
|
||||
export const up = function (rl, x) {
|
||||
rl.output.write(ansiEscapes.cursorUp(x));
|
||||
};
|
||||
|
||||
/**
|
||||
* Move cursor down by `x`
|
||||
* @param {Readline} rl - Readline instance
|
||||
* @param {Number} x - How far to go down (default to 1)
|
||||
*/
|
||||
|
||||
export const down = function (rl, x) {
|
||||
rl.output.write(ansiEscapes.cursorDown(x));
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear current line
|
||||
* @param {Readline} rl - Readline instance
|
||||
* @param {Number} len - number of line to delete
|
||||
*/
|
||||
export const clearLine = function (rl, len) {
|
||||
rl.output.write(ansiEscapes.eraseLines(len));
|
||||
};
|
173
my-app/node_modules/inquirer/lib/utils/screen-manager.js
generated
vendored
Executable file
173
my-app/node_modules/inquirer/lib/utils/screen-manager.js
generated
vendored
Executable file
|
@ -0,0 +1,173 @@
|
|||
import cliWidth from 'cli-width';
|
||||
import wrapAnsi from 'wrap-ansi';
|
||||
import stripAnsi from 'strip-ansi';
|
||||
import stringWidth from 'string-width';
|
||||
import ora from 'ora';
|
||||
import * as util from './readline.js';
|
||||
|
||||
function height(content) {
|
||||
return content.split('\n').length;
|
||||
}
|
||||
|
||||
/** @param {string} content */
|
||||
function lastLine(content) {
|
||||
return content.split('\n').pop();
|
||||
}
|
||||
|
||||
export default class ScreenManager {
|
||||
constructor(rl) {
|
||||
// These variables are keeping information to allow correct prompt re-rendering
|
||||
this.height = 0;
|
||||
this.extraLinesUnderPrompt = 0;
|
||||
|
||||
this.rl = rl;
|
||||
}
|
||||
|
||||
renderWithSpinner(content, bottomContent) {
|
||||
if (this.spinnerId) {
|
||||
clearInterval(this.spinnerId);
|
||||
}
|
||||
|
||||
let spinner;
|
||||
let contentFunc;
|
||||
let bottomContentFunc;
|
||||
|
||||
if (bottomContent) {
|
||||
spinner = ora(bottomContent);
|
||||
contentFunc = () => content;
|
||||
bottomContentFunc = () => spinner.frame();
|
||||
} else {
|
||||
spinner = ora(content);
|
||||
contentFunc = () => spinner.frame();
|
||||
bottomContentFunc = () => '';
|
||||
}
|
||||
|
||||
this.spinnerId = setInterval(
|
||||
() => this.render(contentFunc(), bottomContentFunc(), true),
|
||||
spinner.interval,
|
||||
);
|
||||
}
|
||||
|
||||
render(content, bottomContent, spinning = false) {
|
||||
if (this.spinnerId && !spinning) {
|
||||
clearInterval(this.spinnerId);
|
||||
}
|
||||
|
||||
this.rl.output.unmute();
|
||||
this.clean(this.extraLinesUnderPrompt);
|
||||
|
||||
/**
|
||||
* Write message to screen and setPrompt to control backspace
|
||||
*/
|
||||
|
||||
const promptLine = lastLine(content);
|
||||
const rawPromptLine = stripAnsi(promptLine);
|
||||
|
||||
// Remove the rl.line from our prompt. We can't rely on the content of
|
||||
// rl.line (mainly because of the password prompt), so just rely on it's
|
||||
// length.
|
||||
let prompt = rawPromptLine;
|
||||
if (this.rl.line.length) {
|
||||
prompt = prompt.slice(0, -this.rl.line.length);
|
||||
}
|
||||
|
||||
this.rl.setPrompt(prompt);
|
||||
|
||||
// SetPrompt will change cursor position, now we can get correct value
|
||||
const cursorPos = this.rl._getCursorPos();
|
||||
const width = this.normalizedCliWidth();
|
||||
|
||||
content = this.forceLineReturn(content, width);
|
||||
if (bottomContent) {
|
||||
bottomContent = this.forceLineReturn(bottomContent, width);
|
||||
}
|
||||
|
||||
// Manually insert an extra line if we're at the end of the line.
|
||||
// This prevent the cursor from appearing at the beginning of the
|
||||
// current line.
|
||||
if (rawPromptLine.length % width === 0) {
|
||||
content += '\n';
|
||||
}
|
||||
|
||||
const fullContent = content + (bottomContent ? '\n' + bottomContent : '');
|
||||
this.rl.output.write(fullContent);
|
||||
|
||||
/**
|
||||
* Re-adjust the cursor at the correct position.
|
||||
*/
|
||||
|
||||
// We need to consider parts of the prompt under the cursor as part of the bottom
|
||||
// content in order to correctly cleanup and re-render.
|
||||
const promptLineUpDiff = Math.floor(rawPromptLine.length / width) - cursorPos.rows;
|
||||
const bottomContentHeight =
|
||||
promptLineUpDiff + (bottomContent ? height(bottomContent) : 0);
|
||||
if (bottomContentHeight > 0) {
|
||||
util.up(this.rl, bottomContentHeight);
|
||||
}
|
||||
|
||||
// Reset cursor at the beginning of the line
|
||||
util.left(this.rl, stringWidth(lastLine(fullContent)));
|
||||
|
||||
// Adjust cursor on the right
|
||||
if (cursorPos.cols > 0) {
|
||||
util.right(this.rl, cursorPos.cols);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up state for next re-rendering
|
||||
*/
|
||||
this.extraLinesUnderPrompt = bottomContentHeight;
|
||||
this.height = height(fullContent);
|
||||
|
||||
this.rl.output.mute();
|
||||
}
|
||||
|
||||
clean(extraLines) {
|
||||
if (extraLines > 0) {
|
||||
util.down(this.rl, extraLines);
|
||||
}
|
||||
|
||||
util.clearLine(this.rl, this.height);
|
||||
}
|
||||
|
||||
done() {
|
||||
this.rl.setPrompt('');
|
||||
this.rl.output.unmute();
|
||||
this.rl.output.write('\n');
|
||||
}
|
||||
|
||||
releaseCursor() {
|
||||
if (this.extraLinesUnderPrompt > 0) {
|
||||
util.down(this.rl, this.extraLinesUnderPrompt);
|
||||
}
|
||||
}
|
||||
|
||||
normalizedCliWidth() {
|
||||
const width = cliWidth({
|
||||
defaultWidth: 80,
|
||||
output: this.rl.output,
|
||||
});
|
||||
return width;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string[]} lines
|
||||
*/
|
||||
breakLines(lines, width = this.normalizedCliWidth()) {
|
||||
// Break lines who're longer than the cli width so we can normalize the natural line
|
||||
// returns behavior across terminals.
|
||||
// re: trim: false; by default, `wrap-ansi` trims whitespace, which
|
||||
// is not what we want.
|
||||
// re: hard: true; by default', `wrap-ansi` does soft wrapping
|
||||
return lines.map((line) =>
|
||||
wrapAnsi(line, width, { trim: false, hard: true }).split('\n'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} content
|
||||
*/
|
||||
forceLineReturn(content, width = this.normalizedCliWidth()) {
|
||||
return this.breakLines(content.split('\n'), width).flat().join('\n');
|
||||
}
|
||||
}
|
24
my-app/node_modules/inquirer/lib/utils/utils.js
generated
vendored
Executable file
24
my-app/node_modules/inquirer/lib/utils/utils.js
generated
vendored
Executable file
|
@ -0,0 +1,24 @@
|
|||
import { from, of } from 'rxjs';
|
||||
import runAsync from 'run-async';
|
||||
|
||||
/**
|
||||
* Resolve a question property value if it is passed as a function.
|
||||
* This method will overwrite the property on the question object with the received value.
|
||||
* @param {Object} question - Question object
|
||||
* @param {String} prop - Property to fetch name
|
||||
* @param {Object} answers - Answers object
|
||||
* @return {Rx.Observable} - Observable emitting once value is known
|
||||
*/
|
||||
|
||||
export const fetchAsyncQuestionProperty = function (question, prop, answers) {
|
||||
if (typeof question[prop] !== 'function') {
|
||||
return of(question);
|
||||
}
|
||||
|
||||
return from(
|
||||
runAsync(question[prop])(answers).then((value) => {
|
||||
question[prop] = value;
|
||||
return question;
|
||||
}),
|
||||
);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue