2
1
Fork 0
swim/colors.go

91 lines
2.2 KiB
Go

package main
import (
"os"
"strings"
)
const (
SimpleColor int = iota
EightBitColor
TrueColor
Term // more or less no color added
)
type Styles struct {
Mode int
Header string
Message string
MessageErr string
Lane string
LaneSelected string
Input string
}
var style Styles
var colors = map[int]map[string]string{
SimpleColor: map[string]string{
"Header": "\033[34;107;1m", // bold blue on bright white
"Message": "\033[97;44m", // bright white on blue
"MessageErr": "\033[97;41m", // bright white on red
"Lane": "\033[30;104m", // black on bright blue
"LaneSelected": "\033[30;103m", // black on bright yellow
"Input": "\033[30;107m", // black on bright white
},
EightBitColor: map[string]string{
"Header": "\033[38;5;24m\033[48;5;230m\033[1m",
"Message": "\033[38;5;253m\033[48;5;24m",
"MessageErr": "\033[38;5;253m\033[48;5;124m",
"Lane": "\033[38;5;234m\033[48;5;109m",
"LaneSelected": "\033[38;5;234m\033[48;5;214m",
"Input": "\033[38;5;234m\033[48;5;230m",
},
TrueColor: map[string]string{
"Header": "\033[38;2;14;152;160m\033[48;2;253;244;220m",
"Message": "\033[38;2;220;220;220m\033[48;2;14;152;160m",
"MessageErr": "\033[38;2;220;220;220m\033[48;2;169;3;3m",
"Lane": "\033[38;2;25;25;25m\033[48;2;133;170;156m",
"LaneSelected": "\033[38;2;25;25;25m\033[48;2;255;184;16m",
"Input": "\033[38;2;25;25;25m\033[48;2;253;244;220m",
},
Term: map[string]string{
"Header": "",
"Message": "",
"MessageErr": "",
"Lane": "",
"LaneSelected": "",
"Input": "",
},
}
func (s *Styles) SetColorMode(kind int) {
switch kind {
case SimpleColor, EightBitColor, TrueColor, Term:
s.Mode = kind
default:
ct := os.Getenv("COLORTERM")
ct = strings.ToLower(ct)
if ct == "truecolor" || ct == "24bit" {
s.Mode = TrueColor
break
}
if strings.Contains(os.Getenv("TERM"), "256") {
s.Mode = EightBitColor
break
}
s.Mode = SimpleColor
}
}
func (s *Styles) Init(kind int) {
s.SetColorMode(kind)
s.Header = colors[s.Mode]["Header"]
s.Message = colors[s.Mode]["Message"]
s.MessageErr = colors[s.Mode]["MessageErr"]
s.Lane = colors[s.Mode]["Lane"]
s.LaneSelected = colors[s.Mode]["LaneSelected"]
s.Input = colors[s.Mode]["Input"]
}