MCPcopy
hub / github.com/go-task/task / envColor

Function envColor

internal/logger/logger.go:103–128  ·  view source on GitHub ↗
(name string, defaultColor color.Attribute)

Source from the content-addressed store, hash-verified

101}
102
103func envColor(name string, defaultColor color.Attribute) []color.Attribute {
104 // Fetch the environment variable
105 override := env.GetTaskEnv(name)
106
107 // First, try splitting the string by commas (RGB shortcut syntax) and if it
108 // matches, then prepend the 256-color foreground escape sequence.
109 // Otherwise, split by semicolons (ANSI color codes) and use them as is.
110 attributeStrs := strings.Split(override, ",")
111 if len(attributeStrs) == 3 {
112 attributeStrs = slices.Concat([]string{"38", "2"}, attributeStrs)
113 } else {
114 attributeStrs = strings.Split(override, ";")
115 }
116
117 // Loop over the attributes and convert them to integers
118 attributes := make([]color.Attribute, len(attributeStrs))
119 for i, attributeStr := range attributeStrs {
120 attribute, err := strconv.Atoi(attributeStr)
121 if err != nil {
122 return []color.Attribute{defaultColor}
123 }
124 attributes[i] = color.Attribute(attribute)
125 }
126
127 return attributes
128}
129
130// Logger is just a wrapper that prints stuff to STDOUT or STDERR,
131// with optional color.

Callers 1

logger.goFile · 0.85

Calls 1

GetTaskEnvFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…