diff --git a/lib/_debugger.js b/lib/_debugger.js index 8b5a65a244..bc1d810056 100644 --- a/lib/_debugger.js +++ b/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) { diff --git a/lib/readline.js b/lib/readline.js index 474e227e5d..6d588fd5b8 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -89,10 +89,17 @@ Interface.prototype.prompt = function() { Interface.prototype.question = function(query, cb) { if (cb) { - this._oldPrompt = this._prompt; - this.setPrompt(query); - this._questionCallback = cb; - this.prompt(); + 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(); + } } };