turn-off coloring if we have std{err,out} dumb terminals (#19667)

This commit is contained in:
Harshavardhana 2024-05-03 17:17:57 -07:00 committed by GitHub
parent da3e7747ca
commit 8ff70ea5a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 1 deletions

View File

@ -63,6 +63,7 @@ import (
"github.com/minio/pkg/v2/ellipses"
"github.com/minio/pkg/v2/env"
xnet "github.com/minio/pkg/v2/net"
"golang.org/x/term"
)
// serverDebugLog will enable debug printing
@ -73,6 +74,13 @@ var (
)
func init() {
if !term.IsTerminal(int(os.Stdout.Fd())) || !term.IsTerminal(int(os.Stderr.Fd())) {
color.TurnOff()
}
if env.Get("NO_COLOR", "") != "" || env.Get("TERM", "") == "dumb" {
color.TurnOff()
}
if runtime.GOOS == "windows" {
if mousetrap.StartedByExplorer() {
fmt.Printf("Don't double-click %s\n", os.Args[0])

2
go.mod
View File

@ -95,6 +95,7 @@ require (
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f
golang.org/x/oauth2 v0.19.0
golang.org/x/sys v0.19.0
golang.org/x/term v0.19.0
golang.org/x/time v0.5.0
google.golang.org/api v0.172.0
gopkg.in/yaml.v2 v2.4.0
@ -241,7 +242,6 @@ require (
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.20.0 // indirect
google.golang.org/genproto v0.0.0-20240415180920-8c6c420018be // indirect

View File

@ -80,6 +80,7 @@ var (
// EnableQuiet - turns quiet option on.
func EnableQuiet() {
color.TurnOff() // no colored outputs necessary in quiet mode.
quietFlag = true
}