diff --git a/README.md b/README.md index caea4b1..171e337 100644 --- a/README.md +++ b/README.md @@ -90,9 +90,9 @@ optional: as **stream**. This is used for detecting the width of the terminal and resizes. The width used is `tty.columns - 1`. If no tty is available then a width of `79` is assumed. -* **enabled**: Defaults to true. If true the gauge starts enabled. If - disabled then all update commands are ignored and no gauge will be printed - until you call `.enable()`. +* **enabled**: Defaults to true if `tty` is a TTY, false otherwise. If true + the gauge starts enabled. If disabled then all update commands are + ignored and no gauge will be printed until you call `.enable()`. * **Plumbing**: The class to use to actually generate the gauge for printing. This defaults to `require('gauge/plumbing')` and ordinarly you shouldn't need to override this. diff --git a/index.js b/index.js index 762434c..090a1bd 100644 --- a/index.js +++ b/index.js @@ -66,7 +66,7 @@ function Gauge (arg1, arg2) { onExit(callWith(this, this.disable)) } - if (options.enabled || options.enabled == null) { + if (options.enabled || (options.enabled == null && this._tty && this._tty.isTTY)) { this.enable() } else { this.disable() diff --git a/test/index.js b/test/index.js index 7cc2da9..2ade787 100644 --- a/test/index.js +++ b/test/index.js @@ -35,7 +35,7 @@ function RecordCall (name) { test('defaults', function (t) { var gauge = new Gauge(process.stdout) - t.is(gauge._disabled, false, 'disabled') + t.is(gauge._disabled, !process.stdout.isTTY, 'disabled') t.is(gauge._updateInterval, 50, 'updateInterval') if (process.stdout.isTTY) { t.is(gauge._tty, process.stdout, 'tty')