enquirer: esc is fine, but after first prompt SIGINT will be ignore; onRawSIGINT keeps process running -> switch to inquirer
This commit is contained in:
parent
97ef14f514
commit
6aea18836d
3 changed files with 35 additions and 8 deletions
21
test/sigint-enquirer-raw-keeps-running.js
Normal file
21
test/sigint-enquirer-raw-keeps-running.js
Normal 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...
|
||||
Loading…
Add table
Add a link
Reference in a new issue