OS signals
i⚠️ The cbreak option requires the
--unstableflag and Deno => 1.6 and works currently only on Linux and macOS!
By default, cliffy will call Deno.exit(0) after the user presses ctrl+c. If
you need to use a custom signal handler, you can enable the cbreak option on
your prompt. This will enable pass-through of os signals to deno, allowing you
to register your own signal handler.
iWhen using prompts like
SelectorTogglewith thecbreakoption enabled, you have to show the cursor and clear the stdout before callingDeno.exit()manually. Maybe this will be improved somehow in the future.
import { tty } from "https://deno.land/x/cliffy@v0.24.2/ansi/tty.ts";
import { Toggle } from "https://deno.land/x/cliffy@v0.24.2/prompt/toggle.ts";
Deno.addSignalListener("SIGINT", () => {
tty.cursorLeft.eraseDown.cursorShow();
console.log("interrupted!");
Deno.exit(1);
});
const confirmed: boolean = await Toggle.prompt({
message: "Please confirm",
cbreak: true,
});
console.log({ confirmed });Copydeno run --unstable https://deno.land/x/cliffy@v0.24.2/examples/prompt/os_signals.tsCopy