Skip to content

Instantly share code, notes, and snippets.

@mizchi
Last active February 7, 2024 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizchi/7842dd8d4f688aa2f82cf8150e4ba3cd to your computer and use it in GitHub Desktop.
Save mizchi/7842dd8d4f688aa2f82cf8150e4ba3cd to your computer and use it in GitHub Desktop.
// 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