# monitorctrlc

> Prevent SIGINT on Ctrl+C

Latest version **2.0.1** (published 2017-02-08) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install monitorctrlc
pnpm add monitorctrlc
yarn add monitorctrlc
bun add monitorctrlc
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2017-02-08 |
| First published | 2014-06-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Pandell Technology |
| Maintainers | pandell, milang |
| Keywords | key, keydown, tty, stdin, sigint, ctrl+c, ctrlc |

## Links

- npm: https://www.npmjs.com/package/monitorctrlc
- Repository: https://github.com/pandell/node-monitorctrlc
- Issues: https://github.com/pandell/node-monitorctrlc/issues
- npm.io page: https://npm.io/package/monitorctrlc

## Dependencies (1)

- [chalk](https://npm.io/package/chalk.md) ^1.1.3

## Recent versions

- 2.0.1 (latest) — 2017-02-08
- 2.0.0-beta.2 (beta) — 2017-02-03
- 2.0.0 — 2017-02-08
- 2.0.0-beta.1 — 2017-02-03
- 1.0.1 — 2015-05-28
- 1.0.0 — 2014-09-09
- 1.0.0-pre1 — 2014-09-09
- 0.0.5 — 2014-07-22
- 0.0.4 — 2014-07-08
- 0.0.3 — 2014-06-16
- 0.0.2 — 2014-06-11
- 0.0.1 — 2014-06-11

## README

# monitorctrlc

[![Build status](https://travis-ci.org/pandell/node-monitorctrlc.svg?branch=master)](https://travis-ci.org/pandell/node-monitorctrlc) [!["dependencies" status](https://david-dm.org/pandell/node-monitorctrlc.svg)](https://david-dm.org/pandell/node-monitorctrlc) [!["devDependencies" status](https://david-dm.org/pandell/node-monitorctrlc/dev-status.svg)](https://david-dm.org/pandell/node-monitorctrlc#info=devDependencies)

> Prevent SIGINT on Ctrl+C

[Git repository](https://github.com/pandell/node-monitorctrlc)

[Changelog](https://github.com/pandell/node-monitorctrlc/releases)

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.

## Install

```sh
$ npm install --save-dev monitorctrlc
# or yarn
$ yarn add --dev monitorctrlc
```


## Usage

```js
import { monitorCtrlC } from "monitorctrlc";
const monitor = monitorCtrlC();

// ... execute your program

monitor.dispose(); // detaches event handlers and pauses STDIN
```


## API

Assuming:

```js
import { monitorCtrlC, defaultCtrlCHandler } from "monitorctrlc";
```

### `monitorCtrlC([onCtrlC]): Disposable`

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.,

```js
const monitor = monitorCtrlC();

// ... processing

monitor.dispose(); // detaches event handlers and pauses STDIN
```

#### onCtrlC

_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.


### `defaultCtrlCHandler()`

The function that handles `Ctrl+C` by default (if no callback is specified for `monitorCtrlC`).


## Contributing

1. Clone git repository

2. `npm install` (will install dev dependencies needed by the next step)

3. `npm start` (will start a file system watcher that will re-lint JavaScript and JSON files + re-run all tests when change is detected)

4. Make changes, don't forget to add tests, submit a pull request.

## How to publish

In terminal of your choice:


```sh
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
```


## License

MIT © [Pandell Technology](http://pandell.com/)

---
_Source: https://npm.io/package/monitorctrlc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
