// SPDX-FileCopyrightText: (C) Copyright 2026 Pim van Pelt // SPDX-License-Identifier: Apache-2.0 package cli // Bright (high-intensity) ANSI color codes, plus the reset sequence. These are // the palette consumed by Paint and Label; status words pop while unremarkable // "normal" states can stay uncolored. const ( Reset = "\x1b[0m" Red = "\x1b[91m" // bright red Green = "\x1b[92m" // bright green Blue = "\x1b[94m" // bright blue Yellow = "\x1b[93m" // bright yellow Cyan = "\x1b[96m" // bright cyan ) // colorEnabled is process-global, toggled once at startup via SetColor. It // defaults to false so output is script-safe unless a program opts in. var colorEnabled bool // SetColor turns colorized output on or off for Paint and Label. Call it once // at startup (e.g. from a -color flag): color is useful in an interactive shell // but noise when piping one-shot output into scripts. func SetColor(on bool) { colorEnabled = on } // ColorEnabled reports whether colorization is currently on. func ColorEnabled() bool { return colorEnabled } // Paint wraps s in an ANSI color when color is enabled; otherwise it returns s // unchanged, so the word still reads in scripts and on no-color terminals. func Paint(s, code string) string { if !colorEnabled { return s } return code + s + Reset } // Label wraps s in blue when color is enabled. Use it for static field labels — // the "key=" half of a "key=value" pair — so the value stands out in normal font. func Label(s string) string { return Paint(s, Blue) }