summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/node_modules/inquirer/lib/prompts/password.js
diff options
context:
space:
mode:
authorMichaël Zasso <targos@protonmail.com>2017-12-22 16:53:42 +0100
committerMichaël Zasso <targos@protonmail.com>2018-01-11 09:48:05 +0100
commit3dc30632755713179f345f4af024bd904c6162d0 (patch)
treef28c4f6dd6dfc5992edf301449d1a371d229755b /tools/node_modules/eslint/node_modules/inquirer/lib/prompts/password.js
parenta2c7085dd4a8e60d1a47572aca8bb6fcb7a32f88 (diff)
downloadandroid-node-v8-3dc30632755713179f345f4af024bd904c6162d0.tar.gz
android-node-v8-3dc30632755713179f345f4af024bd904c6162d0.tar.bz2
android-node-v8-3dc30632755713179f345f4af024bd904c6162d0.zip
tools: move eslint from tools to tools/node_modules
This is required because we need to add the babel-eslint dependency and it has to be able to resolve "eslint". babel-eslint is required to support future ES features such as async iterators and import.meta. Refs: https://github.com/nodejs/node/pull/17755 PR-URL: https://github.com/nodejs/node/pull/17820 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'tools/node_modules/eslint/node_modules/inquirer/lib/prompts/password.js')
-rw-r--r--tools/node_modules/eslint/node_modules/inquirer/lib/prompts/password.js115
1 files changed, 115 insertions, 0 deletions
diff --git a/tools/node_modules/eslint/node_modules/inquirer/lib/prompts/password.js b/tools/node_modules/eslint/node_modules/inquirer/lib/prompts/password.js
new file mode 100644
index 0000000000..2a9a5e2e6a
--- /dev/null
+++ b/tools/node_modules/eslint/node_modules/inquirer/lib/prompts/password.js
@@ -0,0 +1,115 @@
+/**
+ * `password` type prompt
+ */
+
+var util = require('util');
+var chalk = require('chalk');
+var Base = require('./base');
+var observe = require('../utils/events');
+
+function mask(input, maskChar) {
+ input = String(input);
+ maskChar = typeof maskChar === 'string' ? maskChar : '*';
+ if (input.length === 0) {
+ return '';
+ }
+
+ return new Array(input.length + 1).join(maskChar);
+}
+
+/**
+ * Module exports
+ */
+
+module.exports = Prompt;
+
+/**
+ * Constructor
+ */
+
+function Prompt() {
+ return Base.apply(this, arguments);
+}
+util.inherits(Prompt, Base);
+
+/**
+ * Start the Inquiry session
+ * @param {Function} cb Callback when prompt is done
+ * @return {this}
+ */
+
+Prompt.prototype._run = function (cb) {
+ this.done = cb;
+
+ var events = observe(this.rl);
+
+ // Once user confirm (enter key)
+ var submit = events.line.map(this.filterInput.bind(this));
+
+ var validation = this.handleSubmitEvents(submit);
+ validation.success.forEach(this.onEnd.bind(this));
+ validation.error.forEach(this.onError.bind(this));
+
+ if (this.opt.mask) {
+ events.keypress.takeUntil(validation.success).forEach(this.onKeypress.bind(this));
+ }
+
+ // Init
+ this.render();
+
+ return this;
+};
+
+/**
+ * Render the prompt to screen
+ * @return {Prompt} self
+ */
+
+Prompt.prototype.render = function (error) {
+ var message = this.getQuestion();
+ var bottomContent = '';
+
+ if (this.status === 'answered') {
+ message += this.opt.mask ? chalk.cyan(mask(this.answer, this.opt.mask)) : chalk.italic.dim('[hidden]');
+ } else if (this.opt.mask) {
+ message += mask(this.rl.line || '', this.opt.mask);
+ } else {
+ message += chalk.italic.dim('[input is hidden] ');
+ }
+
+ if (error) {
+ bottomContent = '\n' + chalk.red('>> ') + error;
+ }
+
+ this.screen.render(message, bottomContent);
+};
+
+/**
+ * When user press `enter` key
+ */
+
+Prompt.prototype.filterInput = function (input) {
+ if (!input) {
+ return this.opt.default == null ? '' : this.opt.default;
+ }
+ return input;
+};
+
+Prompt.prototype.onEnd = function (state) {
+ this.status = 'answered';
+ this.answer = state.value;
+
+ // Re-render prompt
+ this.render();
+
+ this.screen.done();
+ this.done(state.value);
+};
+
+Prompt.prototype.onError = function (state) {
+ this.render(state.isValid);
+};
+
+Prompt.prototype.onKeypress = function () {
+ this.render();
+};