enquirer: esc is fine, but after first prompt SIGINT will be ignore; onRawSIGINT keeps process running -> switch to inquirer

This commit is contained in:
Ralf Vogler 2025-05-14 00:30:39 +02:00
parent 97ef14f514
commit 6aea18836d
3 changed files with 35 additions and 8 deletions

View file

@ -0,0 +1,21 @@
// open issue: prevents handleSIGINT() to work if prompt is cancelled with Ctrl-C instead of Escape: https://github.com/enquirer/enquirer/issues/372
function onRawSIGINT(fn) {
const { stdin, stdout } = process;
stdin.setRawMode(true);
stdin.resume();
stdin.on('data', data => {
const key = data.toString('utf-8');
if (key === '\u0003') { // ctrl + c
fn();
} else {
stdout.write(key);
}
});
}
console.log(1)
onRawSIGINT(() => {
console.log('raw'); process.exit(1);
});
console.log(2)
// onRawSIGINT workaround for enquirer keeps the process from exiting here...