This commit is contained in:
oitsjustjose 2017-02-26 17:06:42 -05:00
commit 6b60015c02
9588 changed files with 1149251 additions and 49 deletions

37
node_modules/inquirer/lib/utils/events.js generated vendored Normal file
View file

@ -0,0 +1,37 @@
'use strict';
var rx = require('rx-lite');
function normalizeKeypressEvents(value, key) {
return { value: value, key: key || {} };
}
module.exports = function (rl) {
var keypress = rx.Observable.fromEvent(rl.input, 'keypress', normalizeKeypressEvents)
.filter(function (e) {
// Ignore `enter` key. On the readline, we only care about the `line` event.
return e.key.name !== 'enter' && e.key.name !== 'return';
});
return {
line: rx.Observable.fromEvent(rl, 'line'),
keypress: keypress,
normalizedUpKey: keypress.filter(function (e) {
return e.key.name === 'up' || e.key.name === 'k';
}).share(),
normalizedDownKey: keypress.filter(function (e) {
return e.key.name === 'down' || e.key.name === 'j';
}).share(),
numberKey: keypress.filter(function (e) {
return e.value && '123456789'.indexOf(e.value) >= 0;
}).map(function (e) {
return Number(e.value);
}).share(),
spaceKey: keypress.filter(function (e) {
return e.key && e.key.name === 'space';
}).share()
};
};

38
node_modules/inquirer/lib/utils/paginator.js generated vendored Normal file
View file

@ -0,0 +1,38 @@
'use strict';
var _ = require('lodash');
var chalk = require('chalk');
/**
* The paginator keep trakcs of a pointer index in a list and return
* a subset of the choices if the list is too long.
*/
var Paginator = module.exports = function () {
this.pointer = 0;
this.lastIndex = 0;
};
Paginator.prototype.paginate = function (output, active) {
var pageSize = 7;
var lines = output.split('\n');
// Make sure there's enough lines to paginate
if (lines.length <= pageSize + 2) {
return output;
}
// Move the pointer only when the user go down and limit it to 3
if (this.pointer < 3 && this.lastIndex < active && active - this.lastIndex < 9) {
this.pointer = Math.min(3, this.pointer + active - this.lastIndex);
}
this.lastIndex = active;
// Duplicate the lines so it give an infinite list look
var infinite = _.flatten([lines, lines, lines]);
var topIndex = Math.max(0, active + lines.length - this.pointer);
var section = infinite.splice(topIndex, pageSize).join('\n');
return section + '\n' + chalk.dim('(Move up and down to reveal more choices)');
};

51
node_modules/inquirer/lib/utils/readline.js generated vendored Normal file
View file

@ -0,0 +1,51 @@
'use strict';
var ansiEscapes = require('ansi-escapes');
/**
* Move cursor left by `x`
* @param {Readline} rl - Readline instance
* @param {Number} x - How far to go left (default to 1)
*/
exports.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)
*/
exports.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)
*/
exports.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)
*/
exports.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
*/
exports.clearLine = function (rl, len) {
rl.output.write(ansiEscapes.eraseLines(len));
};

112
node_modules/inquirer/lib/utils/screen-manager.js generated vendored Normal file
View file

@ -0,0 +1,112 @@
'use strict';
var _ = require('lodash');
var util = require('./readline');
var readline = require('readline');
var cliWidth = require('cli-width');
var stripAnsi = require('strip-ansi');
var ScreenManager = module.exports = function (rl) {
// These variables are keeping information to allow correct prompt re-rendering
this.height = 0;
this.extraLinesUnderPrompt = 0;
this.rl = rl;
};
ScreenManager.prototype.render = function (content, opt) {
opt = _.extend({ cursor: 0 }, opt || {});
var cursorPos = this.rl._getCursorPos();
this.rl.output.unmute();
this.clean(this.extraLinesUnderPrompt);
/**
* Write message to screen and setPrompt to control backspace
*/
var lines = content.split(/\n/);
var promptLine = lines[lines.length - 1 - opt.cursor];
var 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.
var prompt = promptLine;
if (this.rl.line.length) {
prompt = prompt.slice(0, -this.rl.line.length);
}
this.rl.setPrompt(prompt);
var rawPrompt = stripAnsi(prompt);
// 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 === cliWidth()) {
lines.splice(lines.length, 0, ' ');
}
this.rl.output.write(lines.join('\n'));
/**
* Re-adjust the cursor at the correct position.
*/
var breakedLines = breakLines(lines);
var actualLines = _.flatten(breakedLines);
var promptLineUpDiff = Math.floor(rawPromptLine.length / cliWidth()) - cursorPos.rows;
if (opt.cursor + promptLineUpDiff > 0) {
util.up(this.rl, opt.cursor + promptLineUpDiff);
}
// Reset cursor at the beginning of the line
util.left(this.rl, stripAnsi(_.last(actualLines)).length);
var rightPos = cursorPos.cols;
if (cursorPos.rows === 0) {
rightPos = Math.max(rightPos, rawPrompt.length);
}
// rightPos should never be further than the total line content size.
// If we changed the prompt and reset the rl.line, we want to reset our
// cursor at the beginning of the prompt.
if (rightPos > rawPromptLine.length && !this.rl.line) {
rightPos = rawPrompt.length;
}
util.right(this.rl, rightPos);
/**
* Set up state for next re-rendering
*/
var bottomSection = breakedLines.slice(breakedLines.length - opt.cursor - promptLineUpDiff);
this.extraLinesUnderPrompt = _.flatten(bottomSection).length;
this.height = actualLines.length;
this.rl.output.mute();
};
ScreenManager.prototype.clean = function (extraLines) {
if (extraLines > 0) {
util.down(this.rl, extraLines);
}
util.clearLine(this.rl, this.height);
};
ScreenManager.prototype.done = function () {
this.rl.setPrompt('');
this.rl.output.unmute();
this.rl.output.write('\n');
};
function breakLines(lines) {
// Break lines who're longuer than the cli width so we can gracefully handle line
// returns.
var regex = new RegExp('.{1,' + cliWidth() + '}', 'g');
return lines.map(function (line) {
return stripAnsi(line).match(regex);
});
}

47
node_modules/inquirer/lib/utils/utils.js generated vendored Normal file
View file

@ -0,0 +1,47 @@
'use strict';
var _ = require('lodash');
var rx = require('rx-lite');
var runAsync = require('run-async');
/**
* Create an oversable returning the result of a function runned in sync or async mode.
* @param {Function} func Function to run
* @return {rx.Observable} Observable emitting when value is known
*/
exports.createObservableFromAsync = function (func) {
return rx.Observable.defer(function () {
return rx.Observable.create(function (obs) {
runAsync(func, function (value) {
obs.onNext(value);
obs.onCompleted();
});
});
});
};
/**
* 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
* @...rest {Mixed} rest - Arguments to pass to `func`
* @return {rx.Obsersable} - Observable emitting once value is known
*/
exports.fetchAsyncQuestionProperty = function (question, prop, answers) {
if (!_.isFunction(question[prop])) {
return rx.Observable.return(question);
}
return exports.createObservableFromAsync(function () {
var done = this.async();
runAsync(question[prop], function (value) {
question[prop] = value;
done(question);
}, answers);
});
};