When using readline, the process.on('SIGINT', ...) is never triggered.
Is that planned, or perhaps a bug?
I searched and did not find other issues about it.
Hi @felipenmoura. Thanks for the report. Could you possibly give us a reduced test case with no external dependencies that shows this behavior so we can reproduce? Thanks!
@felipenmoura If you are trying to trigger by ctrl+C, that won't work, because readline catches the keys?
Yep.
That's what is happening.
It's being discussed in Inquirer.js, here: https://github.com/SBoudrias/Inquirer.js/issues/293#issuecomment-172282009
Inquirer uses realine internally, therefore, who uses it cannot catch the SIGINT!
By the way, a test case:
process.on('SIGINT', function(){
console.log('oh, you triggered it!');
});
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('What do you think of Node.js? ', (answer) => {
console.log('Thank you for your valuable feedback, which was:\n', answer);
rl.close();
});
So, readline is actually handles it, but only if it thinks it's input is a TTY: https://github.com/nodejs/node/blob/master/lib/readline.js#L693-L701
Adding the SIGINT listener on the readline instance itself instead of process should work?
This looks to have been solved for some time now so I'll go ahead and close the issue. Holler if it should be reopened.
Most helpful comment
Adding the
SIGINTlistener on the readline instance itself instead ofprocessshould work?