gomu/colors.go

69 lines
1.5 KiB
Go
Raw Normal View History

2020-08-22 14:41:03 +08:00
package main
import (
2021-01-21 01:30:16 +08:00
"github.com/gdamore/tcell/v2"
2020-08-22 14:41:03 +08:00
)
type Colors struct {
accent tcell.Color
foreground tcell.Color
background tcell.Color
// title refers to now_playing_title in config file
title tcell.Color
popup tcell.Color
playlist tcell.Color
}
func newColor() *Colors {
defaultColors := map[string]string{
2021-02-18 10:23:15 +08:00
"Color.accent": "#008B8B",
"Color.foreground": "#FFFFFF",
"Color.background": "none",
"Color.popup": "#0A0F14",
"Color.now_playing_title": "#017702",
"Color.playlist": "#008B8B",
2020-08-22 14:41:03 +08:00
}
2021-02-14 13:45:43 +08:00
anko := gomu.anko
2020-08-22 14:41:03 +08:00
// Validate hex color
for k, v := range defaultColors {
// color from the config file
2021-02-14 14:35:36 +08:00
cfgColor := anko.GetString(k)
2020-08-22 14:41:03 +08:00
if validHexColor(cfgColor) {
continue
}
// use default value if invalid hex color was given
2021-02-14 14:35:36 +08:00
anko.Set(k, v)
2020-08-22 14:41:03 +08:00
}
// handle none background color
var bgColor tcell.Color
2021-02-18 10:23:15 +08:00
bg := anko.GetString("Color.background")
2020-08-22 14:41:03 +08:00
if bg == "none" {
bgColor = tcell.ColorDefault
} else {
bgColor = tcell.GetColor(bg)
}
2021-02-18 10:23:15 +08:00
accent := anko.GetString("Color.accent")
foreground := anko.GetString("Color.foreground")
popup := anko.GetString("Color.popup")
title := anko.GetString("Color.now_playing_title")
playlist := anko.GetString("Color.playlist")
2020-08-22 14:41:03 +08:00
color := &Colors{
accent: tcell.GetColor(accent),
foreground: tcell.GetColor(foreground),
2020-08-22 14:41:03 +08:00
background: bgColor,
popup: tcell.GetColor(popup),
title: tcell.GetColor(title),
playlist: tcell.GetColor(playlist),
2020-08-22 14:41:03 +08:00
}
return color
}