From 31866a578890ab8a8c6a2bfe8994d692cc02c904 Mon Sep 17 00:00:00 2001 From: keitosuwahara Date: Thu, 24 Jul 2025 08:46:46 +0900 Subject: [PATCH] Eliminate magic number in init functions Signed-off-by: keitosuwahara --- cmd/formatter/colors.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/formatter/colors.go b/cmd/formatter/colors.go index cc13bc209d1..446de032aa2 100644 --- a/cmd/formatter/colors.go +++ b/cmd/formatter/colors.go @@ -58,6 +58,9 @@ const ( Auto = "auto" ) +// ansiColorOffset is the offset for basic foreground colors in ANSI escape codes. +const ansiColorOffset = 30 + // SetANSIMode configure formatter for colored output on ANSI-compliant console func SetANSIMode(streams command.Streams, ansi string) { if !useAnsi(streams, ansi) { @@ -122,8 +125,8 @@ func rainbowColor() colorFunc { func init() { colors := map[string]colorFunc{} for i, name := range names { - colors[name] = makeColorFunc(strconv.Itoa(30 + i)) - colors["intense_"+name] = makeColorFunc(strconv.Itoa(30+i) + ";1") + colors[name] = makeColorFunc(strconv.Itoa(ansiColorOffset + i)) + colors["intense_"+name] = makeColorFunc(strconv.Itoa(ansiColorOffset+i) + ";1") } rainbow = []colorFunc{ colors["cyan"],