| 1 |
package color |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"os" |
| 6 |
"strings" |
| 7 |
) |
| 8 |
|
| 9 |
//go:fix inline |
| 10 |
//nolint:unused // Retained as a go:fix inline helper after call sites were rewritten to new(expr). |
| 11 |
func boolPtr(v bool) *bool { |
| 12 |
return new(v) |
| 13 |
} |
| 14 |
|
| 15 |
// noColorIsSet returns true if the NO_COLOR environment variable is set (regardless of value). |
| 16 |
// This follows the NO_COLOR standard (https://no-color.org/) where the presence |
| 17 |
// of the environment variable, with any value including empty, should disable colors. |
| 18 |
func noColorIsSet() bool { |
| 19 |
_, exists := os.LookupEnv("NO_COLOR") |
| 20 |
|
| 21 |
return exists |
| 22 |
} |
| 23 |
|
| 24 |
// sprintln is a helper function to format a string with fmt.Sprintln and trim the trailing newline. |
| 25 |
func sprintln(a ...any) string { |
| 26 |
return strings.TrimSuffix(fmt.Sprintln(a...), "\n") |
| 27 |
} |