Skip to content

Commit

Permalink
Fix bug when multiple inquirer process where fired (module required a…
Browse files Browse the repository at this point in the history
…t multiple place by different submodules - inception)

Conflicts:
	lib/inquirer.js
  • Loading branch information
SBoudrias committed Jul 6, 2013
1 parent 20db0a2 commit ac41b34
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
18 changes: 18 additions & 0 deletions examples/nestedCall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Nested Inquirer call
*/

"use strict";
var inquirer = require("../lib/inquirer");

inquirer.prompt({
type: "input",
name: "candy",
message: "What's your favorite candy?"
}, function( answers ) {
inquirer.prompt({
type: "input",
name: "liquor",
message: "And your favorite liquor?"
});
});
8 changes: 7 additions & 1 deletion lib/inquirer.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ cli.prompt = function( questions, allDone ) {
process.stdin.removeListener( "keypress", this.onKeypress );

// Close the readline
this.rl.pause();
this.rl.close();
this.rl = null;

if ( _.isFunction(allDone) ) {
allDone(this.answers);
Expand Down Expand Up @@ -121,6 +122,11 @@ cli.onKeypress = function( s, key ) {
*/

cli.onForceClose = function() {
this.rl.output.unmute();

// close the readline
this.rl.close();
this.rl = null;

console.log("\n"); // Line return
}.bind(cli);
6 changes: 4 additions & 2 deletions test/specs/inquirer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ describe("inquirer.prompt", function() {
message: "message"
}, function( answers ) {
expect(rl.resume.called).to.be.true;
expect(rl.pause.called).to.be.true;
expect(rl.close.called).to.be.true;
expect(inquirer.rl).to.be.null;

rl = inquirer.rl = new ReadlineStub();
inquirer.prompt({
Expand All @@ -33,7 +34,8 @@ describe("inquirer.prompt", function() {
message: "message"
}, function( answers ) {
expect(rl.resume.called).to.be.true;
expect(rl.pause.called).to.be.true;
expect(rl.close.called).to.be.true;
expect(inquirer.rl).to.be.null;
done();
});

Expand Down

0 comments on commit ac41b34

Please sign in to comment.