Prevent SIGINT on Ctrl+C
This function will prevent sending of SIGINT
signal when Ctrl+C
is pressed. Instead, the specified (or default) callback will be invoked.
Preventing SIGINT
in projects that are (for example) using file system watchers on Windows will suppress the annoying Terminate batch job (Y/N)?
prompt after Ctrl+C
. This gives your watcher consistent behavior across all platforms.
$ npm install --save-dev monitorctrlc
# or yarn
$ yarn add --dev monitorctrlc
import { monitorCtrlC } from "monitorctrlc";
const monitor = monitorCtrlC();
// ... execute your program
monitor.dispose(); // detaches event handlers and pauses STDIN
Assuming:
import { monitorCtrlC, defaultCtrlCHandler } from "monitorctrlc";
This function will prevent sending of SIGINT
signal when Ctrl+C
is pressed. Instead, the specified (or default) callback will be invoked.
NOTE: This should only be used by programs that do not normally read from STDIN, as this puts the stream into "raw" mode.
If your program has a normal termination path, you should invoke the dispose
method on the object returned by monitorCtrlC
to ensure the process can terminate normally. E.g.,
const monitor = monitorCtrlC();
// ... processing
monitor.dispose(); // detaches event handlers and pauses STDIN
Type: Function
Default: default handler
optional function that will be called when Ctrl+C
is pressed; if not specified, default handler that prints a message and exits the current process will be used.
The function that handles Ctrl+C
by default (if no callback is specified for monitorCtrlC
).
-
Clone git repository
-
npm install
(will install dev dependencies needed by the next step) -
npm start
(will start a file system watcher that will re-lint JavaScript and JSON files + re-run all tests when change is detected) -
Make changes, don't forget to add tests, submit a pull request.
In terminal of your choice:
cd ~/work/node-monitorctrlc
yarn clobber
yarn version # updates version in "./package.json", requires yarn 0.20+
yarn install
yarn dist
cd dist
yarn publish # for beta releases: yarn publish --tag beta
MIT © Pandell Technology