Skip to content

Commit 8f269dd

Browse files
authored
Consolidate the dependencies for the IsTerminal() API (#156)
* 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.
1 parent 12e6c29 commit 8f269dd

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ go 1.17
44

55
require (
66
github.com/fatih/color v1.7.0
7-
github.com/mattn/go-isatty v0.0.8
87
golang.org/x/term v0.1.0
98
)
109

1110
require (
1211
github.com/mattn/go-colorable v0.1.2 // indirect
12+
github.com/mattn/go-isatty v0.0.8 // indirect
1313
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
1414
)

spinner.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"unicode/utf8"
3030

3131
"github.com/fatih/color"
32-
"github.com/mattn/go-isatty"
3332
"golang.org/x/term"
3433
)
3534

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

503502
// isRunningInTerminal check if the writer file descriptor is a terminal
504503
func isRunningInTerminal(s *Spinner) bool {
505-
return isatty.IsTerminal(s.WriterFile.Fd())
504+
fd := s.WriterFile.Fd()
505+
return term.IsTerminal(int(fd))
506506
}
507507

508508
func computeNumberOfLinesNeededToPrintString(linePrinted string) int {

spinner_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"testing"
2626
"time"
2727

28-
"github.com/mattn/go-isatty"
28+
"golang.org/x/term"
2929
)
3030

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

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

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

0 commit comments

Comments
 (0)