diff --git a/doc/api/repl.markdown b/doc/api/repl.markdown index 1bdb4f2fcb..fe2c8b7c82 100644 --- a/doc/api/repl.markdown +++ b/doc/api/repl.markdown @@ -77,9 +77,9 @@ The special variable `_` (underscore) contains the result of the last expression > _ += 1 4 -The REPL provides access to any variables in the global scope. You can expose a variable -to the REPL explicitly by assigning it to the `context` object associated with each -`REPLServer`. For example: +The REPL provides access to any variables in the global scope. You can expose +a variable to the REPL explicitly by assigning it to the `context` object +associated with each `REPLServer`. For example: // repl_test.js var repl = require("repl"), @@ -97,7 +97,14 @@ There are a few special REPL commands: - `.break` - While inputting a multi-line expression, sometimes you get lost or just don't care about completing it. `.break` will start over. - - `.clear` - Resets the `context` object to an empty object and clears any multi-line expression. + - `.clear` - Resets the `context` object to an empty object and clears any + multi-line expression. - `.exit` - Close the I/O stream, which will cause the REPL to exit. - `.help` - Show this list of special commands. +The following key combinations in the REPL have these special effects: + + - `C` - Similar to the `.break` keyword. Terminates the current + command. Press twice on a blank line to forcibly exit. + - `D` - Similar to the `.exit` keyword. + diff --git a/lib/repl.js b/lib/repl.js index 9fea582614..c36cee328f 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -101,17 +101,27 @@ function REPLServer(prompt, stream) { rli.setPrompt(self.prompt); + var sawSIGINT = false; rli.on('SIGINT', function() { - if (self.bufferedCommand && self.bufferedCommand.length > 0) { - rli.write('\n'); - self.bufferedCommand = ''; - self.displayPrompt(); - } else { - rli.close(); + if (sawSIGINT) { + rli.close(); + process.exit(); } + var bareInt = false; + if (!(self.bufferedCommand && self.bufferedCommand.length > 0) && + rli.line.length === 0) { + rli.write('\n(^C again to quit)'); + bareInt = true; + } + rli.line = ''; + rli.write('\n'); + self.bufferedCommand = ''; + self.displayPrompt(); + sawSIGINT = bareInt; }); rli.addListener('line', function(cmd) { + sawSIGINT = false; var skipCatchall = false; cmd = trimWhitespace(cmd);