Auto-color detection and shortcut for description edit
This commit is contained in:
parent
0ad6cfbde4
commit
1a235c3ecd
50
colors.go
50
colors.go
|
@ -1,5 +1,10 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
SimpleColor int = iota
|
||||
EightBitColor
|
||||
|
@ -29,27 +34,44 @@ var colors = map[int]map[string]string{
|
|||
"Input": "\033[30;107m", // black on bright white
|
||||
},
|
||||
EightBitColor: map[string]string{
|
||||
"Header": "\033[48;5;254m\033[38;5;21\033[1m",
|
||||
"Message": "\033[48;5;35m\033[38;5;231m",
|
||||
"MessageErr": "\033[48;5;124m\033[38;5;231m",
|
||||
"Lane": "\033[48;5;63m\033[38;5;235m",
|
||||
"Input": "\033[48;5;231m\033[38;5;235",
|
||||
"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": "",
|
||||
"Message": "",
|
||||
"MessageErr": "",
|
||||
"Lane": "",
|
||||
"Input": "",
|
||||
"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",
|
||||
},
|
||||
}
|
||||
|
||||
func (s *Styles) Init(mode int) {
|
||||
if mode == TrueColor || mode == EightBitColor {
|
||||
s.Mode = mode
|
||||
} else {
|
||||
func (s *Styles) SetColorMode(kind int) {
|
||||
switch kind {
|
||||
case SimpleColor, EightBitColor, TrueColor:
|
||||
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"]
|
||||
|
|
17
main.go
17
main.go
|
@ -207,10 +207,25 @@ func DefaultBoard(cols, rows int) Board {
|
|||
|
||||
}
|
||||
|
||||
func SetColorFromFlag(f string) int {
|
||||
f = strings.ToUpper(f)
|
||||
switch f {
|
||||
case "8":
|
||||
return SimpleColor
|
||||
case "256":
|
||||
return EightBitColor
|
||||
case "TRUE":
|
||||
return TrueColor
|
||||
default:
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
colors := flag.String("color", "", "Color mode: 8, 256, or TRUE" )
|
||||
flag.Parse()
|
||||
args := flag.Args()
|
||||
style.Init(SimpleColor)
|
||||
style.Init(SetColorFromFlag(*colors))
|
||||
cols, rows := termios.GetWindowSize()
|
||||
if len(args) > 0 {
|
||||
LoadFile(args[0], cols, rows)
|
||||
|
|
Loading…
Reference in New Issue