From d67558d83d85f6f6c9caecbef6b787f754bd58ad Mon Sep 17 00:00:00 2001 From: Timothy Rule <34501912+trulede@users.noreply.github.com> Date: Tue, 16 Dec 2025 21:37:59 +0100 Subject: [PATCH] When --color=false ensure no ANSI codes are printed. --- internal/logger/logger.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/logger/logger.go b/internal/logger/logger.go index 874c197ffb..0655653b32 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -43,6 +43,12 @@ type ( PrintFunc func(io.Writer, string, ...any) ) +func None() PrintFunc { + c := color.New() + c.DisableColor() + return c.FprintfFunc() +} + func Default() PrintFunc { return color.New(attrsReset...).FprintfFunc() } @@ -149,7 +155,7 @@ func (l *Logger) FOutf(w io.Writer, color Color, s string, args ...any) { s, args = "%s", []any{s} } if !l.Color { - color = Default + color = None } print := color() print(w, s, args...) @@ -168,7 +174,7 @@ func (l *Logger) Errf(color Color, s string, args ...any) { s, args = "%s", []any{s} } if !l.Color { - color = Default + color = None } print := color() print(l.Stderr, s, args...)