debugger: don't hang on ^d and ^c

This commit is contained in:
Ryan Dahl 2011-01-13 16:04:33 -08:00
parent 4fa712c48f
commit 860e7a7a5f
2 changed files with 14 additions and 3 deletions

View File

@ -595,7 +595,7 @@ function Interface() {
self.handleSIGINT(); self.handleSIGINT();
}); });
term.on('close', function() { term.on('attemptClose', function() {
self.tryQuit(); self.tryQuit();
}); });

View File

@ -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 // handle a write from the tty
Interface.prototype._ttyWrite = function(b) { Interface.prototype._ttyWrite = function(b) {
switch (b[0]) { switch (b[0]) {
@ -324,13 +335,13 @@ Interface.prototype._ttyWrite = function(b) {
this.emit('SIGINT'); this.emit('SIGINT');
} else { } else {
// default behavior, end the readline // default behavior, end the readline
this.close(); this._attemptClose();
} }
break; break;
case 4: // control-d, delete right or EOF case 4: // control-d, delete right or EOF
if (this.cursor === 0 && this.line.length === 0) { if (this.cursor === 0 && this.line.length === 0) {
this.close(); this._attemptClose();
} else if (this.cursor < this.line.length) { } else if (this.cursor < this.line.length) {
this.line = this.line.slice(0, this.cursor) + this.line = this.line.slice(0, this.cursor) +
this.line.slice(this.cursor + 1, this.line.length); this.line.slice(this.cursor + 1, this.line.length);