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
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SimpleColor int = iota
|
SimpleColor int = iota
|
||||||
EightBitColor
|
EightBitColor
|
||||||
|
@ -29,27 +34,44 @@ var colors = map[int]map[string]string{
|
||||||
"Input": "\033[30;107m", // black on bright white
|
"Input": "\033[30;107m", // black on bright white
|
||||||
},
|
},
|
||||||
EightBitColor: map[string]string{
|
EightBitColor: map[string]string{
|
||||||
"Header": "\033[48;5;254m\033[38;5;21\033[1m",
|
"Header": "\033[38;5;24m\033[48;5;230m\033[1m",
|
||||||
"Message": "\033[48;5;35m\033[38;5;231m",
|
"Message": "\033[38;5;253m\033[48;5;24m",
|
||||||
"MessageErr": "\033[48;5;124m\033[38;5;231m",
|
"MessageErr": "\033[38;5;253m\033[48;5;124m",
|
||||||
"Lane": "\033[48;5;63m\033[38;5;235m",
|
"Lane": "\033[38;5;234m\033[48;5;109m",
|
||||||
"Input": "\033[48;5;231m\033[38;5;235",
|
"LaneSelected": "\033[38;5;234m\033[48;5;214m",
|
||||||
|
"Input": "\033[38;5;234m\033[48;5;230m",
|
||||||
},
|
},
|
||||||
TrueColor: map[string]string{
|
TrueColor: map[string]string{
|
||||||
"Header": "",
|
"Header": "\033[38;2;14;152;160m\033[48;2;253;244;220m",
|
||||||
"Message": "",
|
"Message": "\033[38;2;220;220;220m\033[48;2;14;152;160m",
|
||||||
"MessageErr": "",
|
"MessageErr": "\033[38;2;220;220;220m\033[48;2;169;3;3m",
|
||||||
"Lane": "",
|
"Lane": "\033[38;2;25;25;25m\033[48;2;133;170;156m",
|
||||||
"Input": "",
|
"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) {
|
func (s *Styles) SetColorMode(kind int) {
|
||||||
if mode == TrueColor || mode == EightBitColor {
|
switch kind {
|
||||||
s.Mode = mode
|
case SimpleColor, EightBitColor, TrueColor:
|
||||||
} else {
|
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
|
s.Mode = SimpleColor
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Styles) Init(kind int) {
|
||||||
|
s.SetColorMode(kind)
|
||||||
s.Header = colors[s.Mode]["Header"]
|
s.Header = colors[s.Mode]["Header"]
|
||||||
s.Message = colors[s.Mode]["Message"]
|
s.Message = colors[s.Mode]["Message"]
|
||||||
s.MessageErr = colors[s.Mode]["MessageErr"]
|
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() {
|
func main() {
|
||||||
|
colors := flag.String("color", "", "Color mode: 8, 256, or TRUE" )
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
args := flag.Args()
|
args := flag.Args()
|
||||||
style.Init(SimpleColor)
|
style.Init(SetColorFromFlag(*colors))
|
||||||
cols, rows := termios.GetWindowSize()
|
cols, rows := termios.GetWindowSize()
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
LoadFile(args[0], cols, rows)
|
LoadFile(args[0], cols, rows)
|
||||||
|
|
Loading…
Reference in New Issue