Skip to content

Commit

Permalink
Default enabled to true only of the tty is a TTY
Browse files Browse the repository at this point in the history
  • Loading branch information
iarna committed Jun 16, 2016
1 parent 58b5f1d commit a7fffc3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit a7fffc3

Please sign in to comment.