klog/color.go

94 lines
1.8 KiB
Go
Raw Normal View History

2021-11-01 14:38:30 +00:00
package log
2021-11-01 14:41:11 +00:00
import "text/template"
2021-11-01 14:38:30 +00:00
type Attribute int
// Base attributes
const (
Reset Attribute = iota
Bold
Faint
Italic
Underline
BlinkSlow
BlinkRapid
ReverseVideo
Concealed
CrossedOut
)
// Foreground text colors
const (
FgBlack Attribute = iota + 30
FgRed
FgGreen
FgYellow
FgBlue
FgMagenta
FgCyan
FgWhite
)
// Foreground Hi-Intensity text colors
const (
FgHiBlack Attribute = iota + 90
FgHiRed
FgHiGreen
FgHiYellow
FgHiBlue
FgHiMagenta
FgHiCyan
FgHiWhite
)
// Background text colors
const (
BgBlack Attribute = iota + 40
BgRed
BgGreen
BgYellow
BgBlue
BgMagenta
BgCyan
BgWhite
)
// Background Hi-Intensity text colors
const (
BgHiBlack Attribute = iota + 100
BgHiRed
BgHiGreen
BgHiYellow
BgHiBlue
BgHiMagenta
BgHiCyan
BgHiWhite
)
2021-11-01 14:41:11 +00:00
func setColorMap(funcMap template.FuncMap, color bool) {
if color {
funcMap["red"] = func() string { return "\033[91m" }
funcMap["redl"] = func() string { return "\033[31m" }
funcMap["green"] = func() string { return "\033[92m" }
funcMap["yellow"] = func() string { return "\033[93m" }
funcMap["blue"] = func() string { return "\033[94m" }
funcMap["magenta"] = func() string { return "\033[95m" }
funcMap["cyan"] = func() string { return "\033[96m" }
funcMap["white"] = func() string { return "\033[97m" }
funcMap["reset"] = func() string { return "\033[0m" }
return
}
funcMap["red"] = func() string { return "" }
funcMap["redl"] = func() string { return "" }
funcMap["green"] = func() string { return "" }
funcMap["yellow"] = func() string { return "" }
funcMap["blue"] = func() string { return "" }
funcMap["magenta"] = func() string { return "" }
funcMap["cyan"] = func() string { return "" }
funcMap["white"] = func() string { return "" }
funcMap["reset"] = func() string { return "" }
}
// func