Browse Source

debugger: Prompt before quitting

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

35
lib/_debugger.js

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

15
lib/readline.js

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

Loading…
Cancel
Save