Skip to content

Commit 16b2c08

Browse files
author
David Wertenteil
authored
start spinner only when fd is terminal (#131)
1 parent 55bc95e commit 16b2c08

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ go 1.14
55
require (
66
github.com/fatih/color v1.7.0
77
github.com/mattn/go-colorable v0.1.2 // indirect
8+
github.com/mattn/go-isatty v0.0.8
89
)

spinner.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"unicode/utf8"
2929

3030
"github.com/fatih/color"
31+
"github.com/mattn/go-isatty"
3132
)
3233

3334
// errInvalidColor is returned when attempting to set an invalid color
@@ -271,7 +272,7 @@ func (s *Spinner) Active() bool {
271272
// Start will start the indicator.
272273
func (s *Spinner) Start() {
273274
s.mu.Lock()
274-
if s.active {
275+
if s.active || !isRunningInTerminal() {
275276
s.mu.Unlock()
276277
return
277278
}
@@ -439,3 +440,8 @@ func GenerateNumberSequence(length int) []string {
439440
}
440441
return numSeq
441442
}
443+
444+
// isRunningInTerminal check if stdout file descriptor is terminal
445+
func isRunningInTerminal() bool {
446+
return isatty.IsTerminal(os.Stdout.Fd())
447+
}

vendor/modules.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ github.com/fatih/color
55
## explicit
66
github.com/mattn/go-colorable
77
# github.com/mattn/go-isatty v0.0.8
8+
## explicit
89
github.com/mattn/go-isatty
910
# golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223
1011
golang.org/x/sys/unix

0 commit comments

Comments
 (0)