Always color output and fold settled values into constants
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user