Skip to content

Commit

Permalink
tty: detect tty without depending on the color package
Browse files Browse the repository at this point in the history
This fixes the issue when coloring is disabled with `NO_COLOR` enviroment variable. This would set `color.NoColor` to true and hence in an enviroment where `NO_COLOR` is set, commands like `pscale auth login` would fail:

```
$ pscale auth login
Error: The 'login' command requires an interactive shell
```

Now, if the user sets the `NO_COLOR` environment variable, it still continues to work, but only the color's are disabled.
  • Loading branch information
fatih committed May 24, 2021
1 parent a79e30b commit 03d976c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/hashicorp/go-version v1.3.0
github.com/kataras/tablewriter v0.0.0-20180708051242-e063d29b7c23 // indirect
github.com/lensesio/tableprinter v0.0.0-20201125135848-89e81fc956e7
github.com/mattn/go-isatty v0.0.12
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mattn/go-shellwords v1.0.11
github.com/mitchellh/go-homedir v1.1.0
Expand Down
3 changes: 2 additions & 1 deletion internal/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import (
"github.com/fatih/color"
"github.com/gocarina/gocsv"
"github.com/lensesio/tableprinter"
"github.com/mattn/go-isatty"
)

var IsTTY = !color.NoColor
var IsTTY = isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd())

// Format defines the option output format of a resource.
type Format int
Expand Down

0 comments on commit 03d976c

Please sign in to comment.