repl: better SIGINT handling behavior

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
pull/24503/head
Nathan Rajlich 2012-03-12 18:05:16 -07:00 committed by Bert Belder
parent 6b5a34cdf3
commit f214758dd1
1 changed files with 11 additions and 9 deletions

View File

@ -140,20 +140,22 @@ function REPLServer(prompt, stream, eval, useGlobal, ignoreUndefined) {
rli.on('SIGINT', function() {
rli.output.write('\n');
if (!(self.bufferedCommand && self.bufferedCommand.length > 0) &&
rli.line.length === 0) {
if (sawSIGINT) {
rli.pause();
self.emit('exit');
sawSIGINT = false;
return;
}
rli.line = '';
if (!(self.bufferedCommand && self.bufferedCommand.length > 0)) {
rli.output.write('(^C again to quit)\n');
sawSIGINT = true;
} else {
sawSIGINT = false;
}
rli.line = '';
self.bufferedCommand = '';
self.displayPrompt();
});