From 3ec1c0a51c28c1137d5b059baa81a022d6229d27 Mon Sep 17 00:00:00 2001 From: Tom Fleet Date: Sat, 22 Nov 2025 08:26:18 +0000 Subject: [PATCH] Fix Color option --- option.go | 6 +++--- snapshot.go | 9 ++------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/option.go b/option.go index 654326f..98ecd73 100644 --- a/option.go +++ b/option.go @@ -4,6 +4,8 @@ import ( "errors" "fmt" "regexp" + + "go.followtheprocess.codes/hue" ) // Option is a functional option for configuring a snapshot test [Runner]. @@ -54,9 +56,7 @@ func Description(description string) Option { // Passing this option will override default detection and set the provided value. func Color(enabled bool) Option { return func(r *Runner) error { - // noColor rather than color so that the default value is false - // which falls back to hue's autodetection - r.noColor = !enabled + hue.Enabled(enabled) return nil } } diff --git a/snapshot.go b/snapshot.go index 2181676..6747f0d 100644 --- a/snapshot.go +++ b/snapshot.go @@ -40,7 +40,6 @@ type Runner struct { filters []filter update bool clean bool - noColor bool } // New initialises a new snapshot test [Runner]. @@ -146,7 +145,7 @@ func (r Runner) Snap(value any) { old = bytes.ReplaceAll(old, []byte("\r\n"), []byte("\n")) if diff := diff.Diff("old", old, "new", content); diff != nil { - r.tb.Fatalf("\nMismatch\n--------\n%s\n", prettyDiff(string(diff), r.noColor)) + r.tb.Fatalf("\nMismatch\n--------\n%s\n", prettyDiff(string(diff))) } } @@ -186,11 +185,7 @@ func fileExists(path string) (bool, error) { // prettyDiff takes a string diff in unified diff format and colourises it for easier viewing. // // if noColor is true, the original diff is returned unchanged. -func prettyDiff(diff string, noColor bool) string { - if noColor { - return diff - } - +func prettyDiff(diff string) string { lines := strings.Split(diff, "\n") for i := range lines { trimmed := strings.TrimSpace(lines[i])