Last active
February 7, 2024 19:46
-
-
Save mizchi/7842dd8d4f688aa2f82cf8150e4ba3cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// prompt can not catch ctrl-c | |
const ret = prompt('input>'); | |
console.log(ret); // SIGINT interrupt before this line | |
// returns null with ctrl-c if signal handler is registerred. | |
function getInput(message: string): string | null { | |
const handler = () => {}; | |
Deno.addSignalListener('SIGINT', handler); | |
const ret = prompt(message); | |
Deno.removeSignalListener('SIGINT', handler); | |
return ret; | |
} | |
const out = getInput('input>'); | |
console.log(out) // returns null with ctrl-c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment