Skip to content

Commit

Permalink
Consolidate the dependencies for the IsTerminal() API (#156)
Browse files Browse the repository at this point in the history
* Consolidate the dependencies for the IsTerminal() API

The code was already using golang.org/x/term for the IsTerminal() API.
It seems better to stick to packages from the golang.org domain, because
they are likely to be more widely used than github.com/mattn/go-isatty,
and one less dependency is always a good thing.

This can reduce the number of dependencies for consumers of
github.com/briandowns/spinner, who may already have golang.org/x/term in
their dependency chain.
  • Loading branch information
debarshiray authored Jan 21, 2024
1 parent 12e6c29 commit 8f269dd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
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

0 comments on commit 8f269dd

Please sign in to comment.