Always color output and fold settled values into constants

This commit is contained in:
flamingcow
2026-07-25 18:20:34 -07:00
parent 29c6ce0b56
commit 3ba68952bb
5 changed files with 29 additions and 79 deletions
+1 -23
View File
@@ -2,7 +2,6 @@ package main
import (
"fmt"
"os"
"strings"
)
@@ -17,29 +16,8 @@ const (
cGrey = "\x1b[90m"
)
var useColor bool
func initColor(mode string) error {
switch mode {
case "always":
useColor = true
case "never":
useColor = false
case "auto":
if os.Getenv("NO_COLOR") != "" || os.Getenv("TERM") == "dumb" {
useColor = false
return nil
}
st, err := os.Stdout.Stat()
useColor = err == nil && st.Mode()&os.ModeCharDevice != 0
default:
return fmt.Errorf("unknown color mode %q (want auto, always, never)", mode)
}
return nil
}
func paint(s, code string) string {
if !useColor || s == "" {
if s == "" {
return s
}
return code + s + cReset