From 66ce277832bd8c2baca4d6de2600786be8a18e99 Mon Sep 17 00:00:00 2001 From: Jeremiah Senkpiel Date: Tue, 17 May 2016 18:46:03 -0400 Subject: [PATCH] feat: add an isTTY check (#3) BREAKING CHANGE: stdio/stderr will not be set to blocking if isTTY === false --- index.js | 2 +- test/fixtures/yargs-497-stderr.js | 4 ++++ test/fixtures/yargs-497-stdout.js | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 0da3a56..6f78774 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ module.exports = function (blocking) { [process.stdout, process.stderr].forEach(function (stream) { - if (stream._handle && typeof stream._handle.setBlocking === 'function') { + if (stream._handle && stream.isTTY && typeof stream._handle.setBlocking === 'function') { stream._handle.setBlocking(blocking) } }) diff --git a/test/fixtures/yargs-497-stderr.js b/test/fixtures/yargs-497-stderr.js index 9b498af..1362d61 100755 --- a/test/fixtures/yargs-497-stderr.js +++ b/test/fixtures/yargs-497-stderr.js @@ -1,5 +1,9 @@ #!/usr/bin/env node +// pretend we are a TTY +process.stdout.isTTY = true +process.stderr.isTTY = true + // see: https://github.com/yargs/yargs/issues/497 var buffer = '' for (var i = 0; i < 3000; i++) { diff --git a/test/fixtures/yargs-497-stdout.js b/test/fixtures/yargs-497-stdout.js index fdc792a..ae29976 100755 --- a/test/fixtures/yargs-497-stdout.js +++ b/test/fixtures/yargs-497-stdout.js @@ -1,5 +1,9 @@ #!/usr/bin/env node +// pretend we are a TTY +process.stdout.isTTY = true +process.stderr.isTTY = true + // see: https://github.com/yargs/yargs/issues/497 var buffer = '' for (var i = 0; i < 3000; i++) {