mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-05 00:54:51 +08:00
fix: TOML colorization now works when NO_COLOR env is set (#2584)
The colorizeToml function intended to force colors by setting color.NoColor = false, but SprintFunc() still respects the NO_COLOR environment variable. This caused TestTomlColourization to fail in CI environments where NO_COLOR=1 is set. Fixed by calling EnableColor() on each color object, which explicitly forces colors regardless of environment settings. Vibe-coded with Cursor (Claude Opus 4)
This commit is contained in:
@@ -546,12 +546,20 @@ func (te *tomlEncoder) colorizeToml(input []byte) []byte {
|
||||
color.NoColor = false
|
||||
|
||||
// Create color functions for different token types
|
||||
commentColor := color.New(color.FgHiBlack).SprintFunc()
|
||||
stringColor := color.New(color.FgGreen).SprintFunc()
|
||||
numberColor := color.New(color.FgHiMagenta).SprintFunc()
|
||||
keyColor := color.New(color.FgCyan).SprintFunc()
|
||||
boolColor := color.New(color.FgHiMagenta).SprintFunc()
|
||||
sectionColor := color.New(color.FgYellow, color.Bold).SprintFunc()
|
||||
// Use EnableColor() to ensure colors work even when NO_COLOR env is set
|
||||
commentColorObj := color.New(color.FgHiBlack); commentColorObj.EnableColor()
|
||||
stringColorObj := color.New(color.FgGreen); stringColorObj.EnableColor()
|
||||
numberColorObj := color.New(color.FgHiMagenta); numberColorObj.EnableColor()
|
||||
keyColorObj := color.New(color.FgCyan); keyColorObj.EnableColor()
|
||||
boolColorObj := color.New(color.FgHiMagenta); boolColorObj.EnableColor()
|
||||
sectionColorObj := color.New(color.FgYellow, color.Bold); sectionColorObj.EnableColor()
|
||||
|
||||
commentColor := commentColorObj.SprintFunc()
|
||||
stringColor := stringColorObj.SprintFunc()
|
||||
numberColor := numberColorObj.SprintFunc()
|
||||
keyColor := keyColorObj.SprintFunc()
|
||||
boolColor := boolColorObj.SprintFunc()
|
||||
sectionColor := sectionColorObj.SprintFunc()
|
||||
|
||||
// Simple tokenization for TOML colouring
|
||||
i := 0
|
||||
|
||||
Reference in New Issue
Block a user