OS signals
!WARNING
The cbreak option works currently only on Linux and macOS and is not supported with Bun!
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.
iNOTE
When 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 "@cliffy/ansi/tty";
import { Toggle } from "@cliffy/prompt/toggle";
Deno.addSignalListener("SIGINT", () => {
tty.cursorLeft.eraseDown.cursorShow();
console.log("interrupted!");
Deno.exit(1);
});
const confirmed = await Toggle.prompt({
message: "Please confirm",
cbreak: true,
});
console.log({ confirmed });
$ deno run http://cliffy.io/examples/v1.0.0/prompt/os_signals.ts