From f214758dd1ef74b7f9746ec7a859a9dc73887aa3 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Mon, 12 Mar 2012 18:05:16 -0700 Subject: [PATCH] repl: better SIGINT handling behavior MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before: ☮ ~ (master) ⚡ node > asdf (^C again to quit) > sdcasd☮ ~ (master) ⚡ Now: ☮ ~/node (repl) ⚡ ./node > asfs > sda > (^C again to quit) > scdsdc > sdcsdc > (^C again to quit) > sdc > (^C again to quit) > ☮ ~/node (repl) ⚡ ^ note that each new line above is a ctrl+c sequence --- lib/repl.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/repl.js b/lib/repl.js index d6a5425380a..4ce849a35c8 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -140,20 +140,22 @@ function REPLServer(prompt, stream, eval, useGlobal, ignoreUndefined) { rli.on('SIGINT', function() { rli.output.write('\n'); - if (sawSIGINT) { - rli.pause(); - self.emit('exit'); + if (!(self.bufferedCommand && self.bufferedCommand.length > 0) && + rli.line.length === 0) { + if (sawSIGINT) { + rli.pause(); + self.emit('exit'); + sawSIGINT = false; + return; + } + rli.output.write('(^C again to quit)\n'); + sawSIGINT = true; + } else { sawSIGINT = false; - return; } rli.line = ''; - if (!(self.bufferedCommand && self.bufferedCommand.length > 0)) { - rli.output.write('(^C again to quit)\n'); - sawSIGINT = true; - } - self.bufferedCommand = ''; self.displayPrompt(); });