Comparing version 0.9.0 to 0.10.0
@@ -25,5 +25,5 @@ /** | ||
*/ | ||
inquirer.createPromptModule = function () { | ||
inquirer.createPromptModule = function (opt) { | ||
var promptModule = function (questions, allDone) { | ||
var ui = new inquirer.ui.Prompt(promptModule.prompts); | ||
var ui = new inquirer.ui.Prompt(promptModule.prompts, opt); | ||
ui.run(questions, allDone); | ||
@@ -30,0 +30,0 @@ return ui; |
@@ -8,2 +8,3 @@ /** | ||
var chalk = require("chalk"); | ||
var cliCursor = require("cli-cursor"); | ||
var figures = require("figures"); | ||
@@ -74,3 +75,3 @@ var Base = require("./base"); | ||
// Init the prompt | ||
utils.hideCursor(this.rl); | ||
cliCursor.hide(); | ||
this.render(); | ||
@@ -127,3 +128,3 @@ | ||
this.screen.done(); | ||
utils.showCursor(this.rl); | ||
cliCursor.show(); | ||
this.done( state.value ); | ||
@@ -130,0 +131,0 @@ }; |
@@ -9,2 +9,3 @@ /** | ||
var figures = require("figures"); | ||
var cliCursor = require("cli-cursor"); | ||
var Base = require("./base"); | ||
@@ -73,3 +74,3 @@ var observe = require("../utils/events"); | ||
// Init the prompt | ||
utils.hideCursor(this.rl); | ||
cliCursor.hide(); | ||
this.render(); | ||
@@ -120,3 +121,3 @@ | ||
this.screen.done(); | ||
utils.showCursor(this.rl); | ||
cliCursor.show(); | ||
this.done( choice.value ); | ||
@@ -123,0 +124,0 @@ }; |
@@ -13,3 +13,5 @@ 'use strict'; | ||
// @Note: Don't reassign if already present (allow test to override the Stream) | ||
this.rl || (this.rl = readlineFacade.createInterface()); | ||
if (!this.rl) { | ||
this.rl = readlineFacade.createInterface(opt); | ||
} | ||
this.rl.resume(); | ||
@@ -25,3 +27,3 @@ | ||
// Propagate keypress events directly on the readline | ||
process.stdin.addListener('keypress', this.onKeypress); | ||
this.rl.input.addListener('keypress', this.onKeypress); | ||
}; | ||
@@ -48,3 +50,3 @@ | ||
this.rl.removeListener('SIGINT', this.onForceClose); | ||
process.stdin.removeListener('keypress', this.onKeypress); | ||
this.rl.input.removeListener('keypress', this.onKeypress); | ||
process.removeListener('exit', this.onForceClose); | ||
@@ -54,3 +56,3 @@ | ||
this.rl.output.unmute(); | ||
process.stdout.write('\x1B[?25h'); // show cursor | ||
this.rl.output.write('\x1B[?25h'); // show cursor | ||
@@ -57,0 +59,0 @@ // Close the readline |
@@ -92,3 +92,3 @@ /** | ||
if ( process.stdout.rows === 0 && process.stdout.columns === 0 ) { | ||
if ( this.rl.output.rows === 0 && this.rl.output.columns === 0 ) { | ||
/* When it's a tty through serial port there's no terminal info and the render will malfunction, | ||
@@ -95,0 +95,0 @@ so we need enforce the cursor to locate to the leftmost position for rendering. */ |
@@ -14,4 +14,4 @@ 'use strict'; | ||
var PromptUI = module.exports = function (prompts) { | ||
Base.call(this); | ||
var PromptUI = module.exports = function (prompts, opt) { | ||
Base.call(this, opt); | ||
this.prompts = prompts; | ||
@@ -34,9 +34,10 @@ }; | ||
// be using the exact same object in memory. | ||
var obs = _.isArray(questions) ? rx.Observable.fromArray(questions) : questions; | ||
var obs = _.isArray(questions) ? rx.Observable.from(questions) : questions; | ||
// Start running the questions | ||
this.process = obs.concatMap(this.processQuestion.bind(this)); | ||
this.process = obs | ||
.concatMap(this.processQuestion.bind(this)) | ||
.publish(); // `publish` creates a hot Observable. It prevents duplicating prompts. | ||
this.process.forEach( | ||
function() {}, | ||
this.process.subscribe( | ||
_.noop, | ||
function (err) { throw err; }, | ||
@@ -46,3 +47,3 @@ this.onCompletion.bind(this) | ||
return this.process; | ||
return this.process.connect(); | ||
}; | ||
@@ -49,0 +50,0 @@ |
'use strict'; | ||
var rx = require('rx-lite'); | ||
function normalizeKeypressEvents(args) { | ||
return { value: args[0], key: args[1] }; | ||
function normalizeKeypressEvents(value, key) { | ||
return { value: value, key: key }; | ||
} | ||
module.exports = function (rl) { | ||
var keypress = rx.Observable.fromEvent(rl, 'keypress', normalizeKeypressEvents); | ||
return { | ||
line: rx.Observable.fromEvent(rl, 'line'), | ||
keypress: keypress, | ||
keypress: rx.Observable.fromEvent(rl, 'keypress', normalizeKeypressEvents), | ||
normalizedUpKey: rx.Observable.fromEvent(rl, 'keypress', normalizeKeypressEvents).filter(function (e) { | ||
normalizedUpKey: keypress.filter(function (e) { | ||
return e.key && (e.key.name === 'up' || e.key.name === 'k'); | ||
}).share(), | ||
normalizedDownKey: rx.Observable.fromEvent(rl, 'keypress', normalizeKeypressEvents).filter(function (e) { | ||
normalizedDownKey: keypress.filter(function (e) { | ||
return e.key && (e.key.name === 'down' || e.key.name === 'j'); | ||
}).share(), | ||
numberKey: rx.Observable.fromEvent(rl, 'keypress', normalizeKeypressEvents).filter(function (e) { | ||
numberKey: keypress.filter(function (e) { | ||
return e.value && '123456789'.indexOf(e.value) >= 0; | ||
@@ -28,3 +29,3 @@ }).map(function (e) { | ||
spaceKey: rx.Observable.fromEvent(rl, 'keypress', normalizeKeypressEvents).filter(function (e) { | ||
spaceKey: keypress.filter(function (e) { | ||
return e.key && e.key.name === 'space'; | ||
@@ -31,0 +32,0 @@ }).share(), |
'use strict'; | ||
var _ = require('lodash'); | ||
var cliWidth = require('cli-width'); | ||
var readline = require('readline'); | ||
var ansiEscapes = require('ansi-escapes'); | ||
@@ -13,4 +11,3 @@ /** | ||
exports.left = function(rl, x) { | ||
_.isNumber(x) || (x = 1); | ||
readline.moveCursor(rl.output, -x, 0); | ||
rl.output.write(ansiEscapes.cursorBackward(x)); | ||
}; | ||
@@ -25,4 +22,3 @@ | ||
exports.right = function(rl, x) { | ||
_.isNumber(x) || (x = 1); | ||
readline.moveCursor(rl.output, x, 0); | ||
rl.output.write(ansiEscapes.cursorForward(x)); | ||
}; | ||
@@ -37,4 +33,3 @@ | ||
exports.up = function (rl, x) { | ||
_.isNumber(x) || (x = 1); | ||
readline.moveCursor(rl.output, 0, -x); | ||
rl.output.write(ansiEscapes.cursorUp(x)); | ||
}; | ||
@@ -49,32 +44,12 @@ | ||
exports.down = function (rl, x) { | ||
_.isNumber(x) || (x = 1); | ||
readline.moveCursor(rl.output, 0, x); | ||
rl.output.write(ansiEscapes.cursorDown(x)); | ||
}; | ||
/** | ||
* Hide cursor | ||
* @return {Prompt} self | ||
*/ | ||
exports.hideCursor = function (rl) { | ||
return rl.output.write('\x1B[?25l'); | ||
}; | ||
/** | ||
* Show cursor | ||
* @return {Prompt} self | ||
*/ | ||
exports.showCursor = function (rl) { | ||
return rl.output.write('\x1B[?25h'); | ||
}; | ||
/** | ||
* Clear current line | ||
* @param {Readline} rl - Readline instance | ||
* @param {Readline} rl - Readline instance | ||
* @param {Number} len - number of line to delete | ||
*/ | ||
exports.clearLine = function (rl) { | ||
exports.left(rl, cliWidth()); | ||
readline.clearLine(rl.output, 0); | ||
exports.clearLine = function (rl, len) { | ||
rl.output.write(ansiEscapes.eraseLines(len)); | ||
}; |
@@ -59,3 +59,5 @@ 'use strict'; | ||
var promptLineUpDiff = Math.floor(rawPromptLine.length / cliWidth()) - cursorPos.rows; | ||
util.up(this.rl, opt.cursor + promptLineUpDiff); | ||
if (opt.cursor + promptLineUpDiff > 0) { | ||
util.up(this.rl, opt.cursor + promptLineUpDiff); | ||
} | ||
@@ -92,12 +94,6 @@ // Reset cursor at the beginning of the line | ||
ScreenManager.prototype.clean = function (extraLines) { | ||
util.down(this.rl, extraLines); | ||
var len = this.height; | ||
util.left(this.rl, cliWidth()); | ||
while (len--) { | ||
util.clearLine(this.rl); | ||
if (len > 0) { | ||
util.up(this.rl); | ||
} | ||
if (extraLines > 0) { | ||
util.down(this.rl, extraLines); | ||
} | ||
util.clearLine(this.rl, this.height); | ||
}; | ||
@@ -104,0 +100,0 @@ |
{ | ||
"name": "inquirer", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"description": "A collection of common interactive command line user interfaces.", | ||
@@ -24,10 +24,12 @@ "main": "lib/inquirer.js", | ||
"dependencies": { | ||
"ansi-escapes": "^1.1.0", | ||
"ansi-regex": "^2.0.0", | ||
"chalk": "^1.0.0", | ||
"cli-cursor": "^1.0.1", | ||
"cli-width": "^1.0.1", | ||
"figures": "^1.3.5", | ||
"lodash": "^3.3.1", | ||
"readline2": "^0.1.1", | ||
"readline2": "^1.0.1", | ||
"run-async": "^0.1.0", | ||
"rx-lite": "^2.5.2", | ||
"rx-lite": "^3.1.2", | ||
"strip-ansi": "^3.0.0", | ||
@@ -34,0 +36,0 @@ "through": "^2.3.6" |
@@ -9,11 +9,16 @@ Inquirer.js | ||
## Goal and philosophy | ||
## Goal and Philosophy | ||
<img align="right" alt="Inquirer Logo" src="/assets/inquirer_readme.png" title="Inquirer.js"/> | ||
We strive at providing easily embeddable and beautiful command line interface for Node.js; some hope in becoming the CLI Xanadu. | ||
**`Inquirer.js`** strives to be an easily embeddable and beautiful command line interface for [Node.js](https://nodejs.org/) (and perhaps the "CLI [Xanadu](https://en.wikipedia.org/wiki/Xanadu_(Citizen_Kane))"). | ||
_**Inquirer**_ should ease the process of asking end user **questions**, **parsing**, **validating** answers, managing **hierarchical prompts** and providing **error feedback**. | ||
**`Inquirer.js`** should ease the process of | ||
- providing *error feedback* | ||
- *asking questions* | ||
- *parsing* input | ||
- *validating* answers | ||
- managing *hierarchical prompts* | ||
_**Inquirer**_ provide the user interface, and the inquiry session flow. If you're searching for a full blown command line program utility, then check out [Commander.js](https://github.com/visionmedia/commander.js) (inspired by). | ||
> **Note:** **`Inquirer.js`** provides the user interface, and the inquiry session flow. If you're searching for a full blown command line program utility, then check out [Commander.js](https://github.com/visionmedia/commander.js). | ||
@@ -296,2 +301,2 @@ | ||
Copyright (c) 2012 Simon Boudrias (twitter: @vaxilart) | ||
Licensed under the MIT license. | ||
Licensed under the MIT license. |
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
301
62619
12
1699
+ Addedansi-escapes@^1.1.0
+ Addedcli-cursor@^1.0.1
+ Addedansi-escapes@1.4.0(transitive)
+ Addedcli-cursor@1.0.2(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addedexit-hook@1.1.1(transitive)
+ Addedis-fullwidth-code-point@1.0.0(transitive)
+ Addedmute-stream@0.0.5(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedonetime@1.1.0(transitive)
+ Addedreadline2@1.0.1(transitive)
+ Addedrestore-cursor@1.0.1(transitive)
+ Addedrx-lite@3.1.2(transitive)
- Removedansi-regex@1.1.1(transitive)
- Removedmute-stream@0.0.4(transitive)
- Removedreadline2@0.1.1(transitive)
- Removedrx-lite@2.5.2(transitive)
- Removedstrip-ansi@2.0.1(transitive)
Updatedreadline2@^1.0.1
Updatedrx-lite@^3.1.2