joyent/node — Issue #2725: Readline bug when overriding SIGINT
Author: Southern
Created: 2012-02-09 11:27:51+00:00
State: open

Script:
~~~
// Create readline interface
var rl = require('readline').createInterface(process.stdin, process.stdout);

// Keep STDIN from exiting
process.stdin.resume();

// Override SIGINT
process.on('SIGINT', function() {

});

// Set readline prompt
rl.setPrompt('Anything> ');

// Send prompt
rl.prompt();

// Read line
rl.on('line', function(line) {
// Add exit since SIGINT won't exit
if (line.match(/^exit$/i)) process.exit();

// Echo line if not exit
console.log('LINE: ' + line);

// Try to reprompt
rl.prompt();
});
~~~

Output:
~~~
Anything> test
LINE: test
Anything> blah
LINE: blah
Anything> ^C^C

LINE:
test
test
LINE: test
blah
blah
LINE: blah
exit
exit
~~~