Merge pull request #161 from jnordberg/ignore-sigint

Ignore SIGINT when processing stdin
This commit is contained in:
Trent Mick 2014-08-24 23:21:30 -07:00
commit 96b9f35019

View file

@ -99,6 +99,8 @@ var gOptsForUncaughtException;
var pager = null; var pager = null;
var stdout = process.stdout; var stdout = process.stdout;
// Whether we are reading from stdin.
var readingStdin = false;
//---- support functions //---- support functions
@ -1050,6 +1052,7 @@ function drainStdoutAndExit(code) {
* @param callback {Function} `function ()` * @param callback {Function} `function ()`
*/ */
function processStdin(opts, stylize, callback) { function processStdin(opts, stylize, callback) {
readingStdin = true
var leftover = ''; // Left-over partial line from last chunk. var leftover = ''; // Left-over partial line from last chunk.
var stdin = process.stdin; var stdin = process.stdin;
stdin.resume(); stdin.resume();
@ -1349,6 +1352,10 @@ function asyncForEach(arr, iterator, callback) {
*/ */
var cleanedUp = false; var cleanedUp = false;
function cleanupAndExit(code, signal) { function cleanupAndExit(code, signal) {
// Do not exit if reading form stdin and we get a SIGINT (ctrl-c)
if (readingStdin && signal === 'SIGINT') {
return;
}
// Guard one call. // Guard one call.
if (cleanedUp) { if (cleanedUp) {
return; return;