Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start spinner only when the stdout file descriptor is a terminal #131

Merged
merged 1 commit into from Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -5,4 +5,5 @@ go 1.14
require (
github.com/fatih/color v1.7.0
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.8
)
8 changes: 7 additions & 1 deletion spinner.go
Expand Up @@ -28,6 +28,7 @@ import (
"unicode/utf8"

"github.com/fatih/color"
"github.com/mattn/go-isatty"
)

// errInvalidColor is returned when attempting to set an invalid color
Expand Down Expand Up @@ -271,7 +272,7 @@ func (s *Spinner) Active() bool {
// Start will start the indicator.
func (s *Spinner) Start() {
s.mu.Lock()
if s.active {
if s.active || !isRunningInTerminal() {
s.mu.Unlock()
return
}
Expand Down Expand Up @@ -439,3 +440,8 @@ func GenerateNumberSequence(length int) []string {
}
return numSeq
}

// isRunningInTerminal check if stdout file descriptor is terminal
func isRunningInTerminal() bool {
return isatty.IsTerminal(os.Stdout.Fd())
}
1 change: 1 addition & 0 deletions vendor/modules.txt
Expand Up @@ -5,6 +5,7 @@ github.com/fatih/color
## explicit
github.com/mattn/go-colorable
# github.com/mattn/go-isatty v0.0.8
## explicit
github.com/mattn/go-isatty
# golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223
golang.org/x/sys/unix