(name string, defaultColor color.Attribute)
| 101 | } |
| 102 | |
| 103 | func 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. |
no test coverage detected
searching dependent graphs…