Browse Source

debugger: Prompt before quitting

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
af6662d5e5
  1. 35
      lib/_debugger.js
  2. 7
      lib/readline.js

35
lib/_debugger.js

@ -350,7 +350,7 @@ function Interface() {
term.setPrompt('debug> ');
term.prompt();
this.quitTried = false;
this.quitting = false;
process.on('SIGINT', function () {
self.handleSIGINT();
@ -387,15 +387,32 @@ Interface.prototype.handleSIGINT = function() {
};
Interface.prototype.tryQuit = function() {
if (this.quitTried) return;
this.quitTried = true;
Interface.prototype.quit = function() {
if (this.quitting) return;
this.quitting = true;
this.killChild();
this.term.close();
process.exit(0);
};
Interface.prototype.tryQuit = function() {
var self = this;
if (self.child) {
self.quitQuestion(function (yes) {
if (yes) {
self.quit();
} else {
self.term.prompt();
}
});
} else {
self.quit();
}
};
Interface.prototype.pause = function() {
this.paused = true;
this.stdin.pause();
@ -454,6 +471,7 @@ Interface.prototype.handleCommand = function(cmd) {
var term = this.term;
if (cmd == 'quit' || cmd == 'q' || cmd == 'exit') {
self._lastCommand = null;
self.tryQuit();
} else if (/^r(un)?/.test(cmd)) {
@ -610,6 +628,7 @@ Interface.prototype.handleCommand = function(cmd) {
Interface.prototype.yesNoQuestion = function(prompt, cb) {
var self = this;
self.resume();
this.term.question(prompt, function (answer) {
if (/^y(es)?$/i.test(answer)) {
cb(true);
@ -634,6 +653,12 @@ Interface.prototype.killQuestion = function(cb) {
};
Interface.prototype.quitQuestion = function(cb) {
this.yesNoQuestion("A debugging session is active. Quit anyway? (y or n) ",
cb);
};
Interface.prototype.killChild = function() {
if (this.child) {
this.child.kill();
@ -678,7 +703,7 @@ Interface.prototype.trySpawn = function(cb) {
console.log("\nprogram terminated");
self.client = null;
self.killChild();
self.term.prompt();
if (!self.quitting) self.term.prompt();
});
client.on('unhandledResponse', function (res) {

7
lib/readline.js

@ -89,11 +89,18 @@ Interface.prototype.prompt = function() {
Interface.prototype.question = function(query, cb) {
if (cb) {
this.resume();
if (this._questionCallback) {
this.output.write('\n');
this.prompt();
} else {
this._oldPrompt = this._prompt;
this.setPrompt(query);
this._questionCallback = cb;
this.output.write('\n');
this.prompt();
}
}
};

Loading…
Cancel
Save