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
8 changes: 5 additions & 3 deletions internal/colors/colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"io"
"os"
"strings"

"github.com/gkampitakis/ciinfo"
)

const (
Expand All @@ -31,9 +33,9 @@ var NOCOLOR = isNoColor()
func isNoColor() bool {
// https://no-color.org (with any value)
_, noColor := os.LookupEnv("NO_COLOR")
// hacky way but should be good enough to support diff on vscode output panel
term := strings.ToLower(os.Getenv("_"))
return noColor || strings.Contains(term, "visual") || strings.Contains(term, "code")
termenv, isTerm := os.LookupEnv("TERM")

return noColor || (!isTerm && !ciinfo.IsCI) || termenv == "dumb"
}

func Sprint(color, s string) string {
Expand Down
2 changes: 2 additions & 0 deletions snaps/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ func TestDiff(t *testing.T) {
})

t.Run("with color", func(t *testing.T) {
colors.NOCOLOR = false

t.Run("should apply highlights on single line diff", func(t *testing.T) {
a := strings.Repeat("abcd", 20)
b := strings.Repeat("abcf", 20)
Expand Down
Loading