diff --git a/lib/readline.js b/lib/readline.js index de484d3f323..724c27b5d87 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -126,6 +126,7 @@ Interface.prototype.setPrompt = function(prompt, length) { Interface.prototype.prompt = function(preserveCursor) { + if (this._closed) this.resume(); if (this.enabled) { if (!preserveCursor) this.cursor = 0; this._refreshLine(); @@ -136,7 +137,7 @@ Interface.prototype.prompt = function(preserveCursor) { Interface.prototype.question = function(query, cb) { - if (cb) { + if (typeof cb === 'function') { this.resume(); if (this._questionCallback) { this.output.write('\n'); @@ -153,6 +154,7 @@ Interface.prototype.question = function(query, cb) { Interface.prototype._onLine = function(line) { + if (this._closed) return; if (this._questionCallback) { var cb = this._questionCallback; this._questionCallback = null; @@ -165,6 +167,7 @@ Interface.prototype._onLine = function(line) { Interface.prototype._addHistory = function() { + if (this._closed) return; if (this.line.length === 0) return ''; this.history.unshift(this.line); @@ -204,8 +207,8 @@ Interface.prototype.close = function(d) { if (this.enabled) { tty.setRawMode(false); } - this.emit('close'); this._closed = true; + this.emit('close'); }; @@ -220,6 +223,8 @@ Interface.prototype.resume = function() { if (this.enabled) { tty.setRawMode(true); } + this._closing = false; + this._closed = false; }; @@ -466,6 +471,8 @@ Interface.prototype._attemptClose = function() { // handle a write from the tty Interface.prototype._ttyWrite = function(s, key) { + if (this._closed) return; + var next_word, next_non_word, previous_word, previous_non_word; key = key || {};