From 860e7a7a5f423704cecfe3057c3282f32a078dd6 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 13 Jan 2011 16:04:33 -0800 Subject: [PATCH] debugger: don't hang on ^d and ^c --- lib/_debugger.js | 2 +- lib/readline.js | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/_debugger.js b/lib/_debugger.js index 286dc0f60d..08e70573aa 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -595,7 +595,7 @@ function Interface() { self.handleSIGINT(); }); - term.on('close', function() { + term.on('attemptClose', function() { self.tryQuit(); }); diff --git a/lib/readline.js b/lib/readline.js index b52994c3fb..e5feec238c 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -314,6 +314,17 @@ Interface.prototype._historyPrev = function() { } }; + +Interface.prototype._attemptClose = function() { + if (this.listeners('attemptClose').length) { + // User is to call interface.close() manually. + this.emit('attemptClose'); + } else { + this.close(); + } +}; + + // handle a write from the tty Interface.prototype._ttyWrite = function(b) { switch (b[0]) { @@ -324,13 +335,13 @@ Interface.prototype._ttyWrite = function(b) { this.emit('SIGINT'); } else { // default behavior, end the readline - this.close(); + this._attemptClose(); } break; case 4: // control-d, delete right or EOF if (this.cursor === 0 && this.line.length === 0) { - this.close(); + this._attemptClose(); } else if (this.cursor < this.line.length) { this.line = this.line.slice(0, this.cursor) + this.line.slice(this.cursor + 1, this.line.length);