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

Consolidate the dependencies for the IsTerminal() API #156

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ go 1.17

require (
github.com/fatih/color v1.7.0
github.com/mattn/go-isatty v0.0.8
golang.org/x/term v0.1.0
)

require (
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.8 // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
)
4 changes: 2 additions & 2 deletions spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"unicode/utf8"

"github.com/fatih/color"
"github.com/mattn/go-isatty"
"golang.org/x/term"
)

Expand Down Expand Up @@ -502,7 +501,8 @@ func GenerateNumberSequence(length int) []string {

// isRunningInTerminal check if the writer file descriptor is a terminal
func isRunningInTerminal(s *Spinner) bool {
return isatty.IsTerminal(s.WriterFile.Fd())
fd := s.WriterFile.Fd()
return term.IsTerminal(int(fd))
}

func computeNumberOfLinesNeededToPrintString(linePrinted string) int {
Expand Down
8 changes: 4 additions & 4 deletions spinner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"testing"
"time"

"github.com/mattn/go-isatty"
"golang.org/x/term"
)

const baseWait = 3
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestStart(t *testing.T) {

// TestActive will verify we can tell when a spinner is running
func TestActive(t *testing.T) {
if !isatty.IsTerminal(os.Stdout.Fd()) {
if fd := os.Stdout.Fd(); !term.IsTerminal(int(fd)) {
t.Log("not running in a terminal")
return
}
Expand Down Expand Up @@ -157,8 +157,8 @@ func TestDisable(t *testing.T) {

// TestHookFunctions will verify that hook functions works as expected
func TestHookFunctions(t *testing.T) {
if !isatty.IsTerminal(os.Stdout.Fd()) {
t.Log("not running in a termian")
if fd := os.Stdout.Fd(); !term.IsTerminal(int(fd)) {
t.Log("not running in a terminal")
return
}
s := New(CharSets[4], 50*time.Millisecond)
Expand Down