Skip to content
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
6 changes: 5 additions & 1 deletion text/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ func areColorsOnInTheEnv() bool {
if os.Getenv("FORCE_COLOR") == "1" {
return true
}
return os.Getenv("NO_COLOR") == "" || os.Getenv("NO_COLOR") == "0"
if os.Getenv("NO_COLOR") == "" || os.Getenv("NO_COLOR") == "0" {
return os.Getenv("TERM") != "dumb"
}

return false
}

// The logic here is inspired from github.com/fatih/color; the following is
Expand Down
27 changes: 27 additions & 0 deletions text/color_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,45 @@ func TestColor_EnableAndDisable(t *testing.T) {
func TestColor_areColorsOnInTheEnv(t *testing.T) {
_ = os.Setenv("FORCE_COLOR", "0")
_ = os.Setenv("NO_COLOR", "0")
_ = os.Setenv("TERM", "xterm")
assert.True(t, areColorsOnInTheEnv())

_ = os.Setenv("FORCE_COLOR", "0")
_ = os.Setenv("NO_COLOR", "0")
_ = os.Setenv("TERM", "dumb")
assert.False(t, areColorsOnInTheEnv())

// ---
_ = os.Setenv("FORCE_COLOR", "0")
_ = os.Setenv("NO_COLOR", "1")
_ = os.Setenv("TERM", "xterm")
assert.False(t, areColorsOnInTheEnv())

_ = os.Setenv("FORCE_COLOR", "0")
_ = os.Setenv("NO_COLOR", "1")
_ = os.Setenv("TERM", "dumb")
assert.False(t, areColorsOnInTheEnv())

// ---
_ = os.Setenv("FORCE_COLOR", "1")
_ = os.Setenv("NO_COLOR", "0")
_ = os.Setenv("TERM", "xterm")
assert.True(t, areColorsOnInTheEnv())

_ = os.Setenv("FORCE_COLOR", "1")
_ = os.Setenv("NO_COLOR", "0")
_ = os.Setenv("TERM", "dumb")
assert.True(t, areColorsOnInTheEnv())

// ---
_ = os.Setenv("FORCE_COLOR", "1")
_ = os.Setenv("NO_COLOR", "1")
_ = os.Setenv("TERM", "xterm")
assert.True(t, areColorsOnInTheEnv())

_ = os.Setenv("FORCE_COLOR", "1")
_ = os.Setenv("NO_COLOR", "1")
_ = os.Setenv("TERM", "dumb")
assert.True(t, areColorsOnInTheEnv())
}

Expand Down