diff --git a/test/sigint-enquirer-raw-keeps-running.js b/test/sigint-enquirer-raw-keeps-running.js new file mode 100644 index 0000000..23d9983 --- /dev/null +++ b/test/sigint-enquirer-raw-keeps-running.js @@ -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... diff --git a/test/sigint-enquirer-raw.js b/test/sigint-enquirer-raw.js index 0a95892..e6b538d 100644 --- a/test/sigint-enquirer-raw.js +++ b/test/sigint-enquirer-raw.js @@ -1,10 +1,10 @@ // https://github.com/enquirer/enquirer/issues/372 -import { prompt } from '../src/util.js'; +import { prompt, handleSIGINT } from '../src/util.js'; -const handleSIGINT = () => process.on('SIGINT', () => { // e.g. when killed by Ctrl-C - console.log('\nInterrupted by SIGINT. Exit!'); - process.exitCode = 130; -}); +// const handleSIGINT = () => process.on('SIGINT', () => { // e.g. when killed by Ctrl-C +// console.log('\nInterrupted by SIGINT. Exit!'); +// process.exitCode = 130; +// }); handleSIGINT(); function onRawSIGINT(fn) { @@ -20,15 +20,16 @@ function onRawSIGINT(fn) { } }); } -onRawSIGINT(() => { - console.log('raw'); process.exit(1); -}); +// onRawSIGINT(() => { +// console.log('raw'); process.exit(1); +// }); console.log('hello'); console.error('hello error'); try { let i = 'foo'; i = await prompt(); // SIGINT no longer handled if this is executed + i = await prompt(); // SIGINT no longer handled if this is executed // handleSIGINT(); console.log('value:', i); setTimeout(() => console.log('timeout 3s'), 3000); diff --git a/test/sigint-enquirer-simple.js b/test/sigint-enquirer-simple.js index 13e7d02..25f13ee 100644 --- a/test/sigint-enquirer-simple.js +++ b/test/sigint-enquirer-simple.js @@ -13,3 +13,8 @@ await enquirer.prompt({ name: 'username', message: 'What is your username?', }); +await enquirer.prompt({ + type: 'input', + name: 'username', + message: 'What is your username 2?', +});