sigint
Cleaner process interrupt handling.
Last updated 5 years ago by bluejeansandrain .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install sigint 
SYNC missed versions from official npm registry.

sigint

Cleaner process interrupt signal handling.

Hooks standard input in raw mode to enable interupts in Windows as well as to hide the "^C" echoed to the terminal.

Installation

npm install sigint --save

Example

var sigint = require('sigint').create();

sigint.on('signal', function(source, count) {
	if (source === 'keyboard' && count === 1) {
		console.log('press Ctrl+C again to quit');
	} else {
		process.exit();
	}
});

You can bind to only keyboard or kill interrupts.

var sigint = require('sigint').create();

sigint.on('keyboard', function(count) {
	if (count === 1) {
		console.log('press Ctrl+C again to quit');
	} else {
		process.exit();
	}
});

sigint.on('kill', function(count) {
	process.exit();
});

You can also use the process "SIGINT" event directly.

var sigint = require('sigint').create();

process.on('sigint', function() {
	if (sigint.source() === 'keyboard' && sigint.count() === 1) {
		console.log('press Ctrl+C again to quit');
	} else {
		process.exit();
	}
});

Current Tags

  • 1.0.0                                ...           latest (5 years ago)

1 Versions

  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (0)
None

Copyright 2014 - 2016 © taobao.org |