2019-10-18 09:48:37 +02:00
|
|
|
package theme
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/fatih/color"
|
|
|
|
"github.com/jesseduffield/gocui"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// DefaultTextColor is the default text color
|
|
|
|
DefaultTextColor = color.FgWhite
|
2019-10-30 11:23:25 +02:00
|
|
|
// DefaultHiTextColor is the default highlighted text color
|
|
|
|
DefaultHiTextColor = color.FgHiWhite
|
2019-10-18 09:48:37 +02:00
|
|
|
|
|
|
|
// GocuiDefaultTextColor does the same as DefaultTextColor but this one only colors gocui default text colors
|
|
|
|
GocuiDefaultTextColor gocui.Attribute
|
|
|
|
|
|
|
|
// ActiveBorderColor is the border color of the active frame
|
|
|
|
ActiveBorderColor gocui.Attribute
|
|
|
|
|
|
|
|
// InactiveBorderColor is the border color of the inactive active frames
|
|
|
|
InactiveBorderColor gocui.Attribute
|
|
|
|
)
|
|
|
|
|
|
|
|
// UpdateTheme updates all theme variables
|
|
|
|
func UpdateTheme(userConfig *viper.Viper) {
|
|
|
|
ActiveBorderColor = getColor(userConfig.GetStringSlice("gui.theme.activeBorderColor"))
|
|
|
|
InactiveBorderColor = getColor(userConfig.GetStringSlice("gui.theme.inactiveBorderColor"))
|
|
|
|
|
|
|
|
isLightTheme := userConfig.GetBool("gui.theme.lightTheme")
|
|
|
|
if isLightTheme {
|
|
|
|
DefaultTextColor = color.FgBlack
|
2019-10-30 11:23:25 +02:00
|
|
|
DefaultHiTextColor = color.FgHiBlack
|
2019-10-18 09:48:37 +02:00
|
|
|
GocuiDefaultTextColor = gocui.ColorBlack
|
|
|
|
} else {
|
|
|
|
DefaultTextColor = color.FgWhite
|
2019-10-30 11:23:25 +02:00
|
|
|
DefaultHiTextColor = color.FgHiWhite
|
2019-10-18 09:48:37 +02:00
|
|
|
GocuiDefaultTextColor = gocui.ColorWhite
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// getAttribute gets the gocui color attribute from the string
|
|
|
|
func getAttribute(key string) gocui.Attribute {
|
|
|
|
colorMap := map[string]gocui.Attribute{
|
|
|
|
"default": gocui.ColorDefault,
|
|
|
|
"black": gocui.ColorBlack,
|
|
|
|
"red": gocui.ColorRed,
|
|
|
|
"green": gocui.ColorGreen,
|
|
|
|
"yellow": gocui.ColorYellow,
|
|
|
|
"blue": gocui.ColorBlue,
|
|
|
|
"magenta": gocui.ColorMagenta,
|
|
|
|
"cyan": gocui.ColorCyan,
|
|
|
|
"white": gocui.ColorWhite,
|
|
|
|
"bold": gocui.AttrBold,
|
|
|
|
"reverse": gocui.AttrReverse,
|
|
|
|
"underline": gocui.AttrUnderline,
|
|
|
|
}
|
|
|
|
value, present := colorMap[key]
|
|
|
|
if present {
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
return gocui.ColorWhite
|
|
|
|
}
|
|
|
|
|
|
|
|
// getColor bitwise OR's a list of attributes obtained via the given keys
|
|
|
|
func getColor(keys []string) gocui.Attribute {
|
|
|
|
var attribute gocui.Attribute
|
|
|
|
for _, key := range keys {
|
|
|
|
attribute |= getAttribute(key)
|
|
|
|
}
|
|
|
|
return attribute
|
|
|
|
}
|
2019-10-19 11:39:18 +02:00
|
|
|
|
|
|
|
// GetAttribute gets the gocui color attribute from the string
|
|
|
|
func GetAttribute(key string) gocui.Attribute {
|
|
|
|
colorMap := map[string]gocui.Attribute{
|
|
|
|
"default": gocui.ColorDefault,
|
|
|
|
"black": gocui.ColorBlack,
|
|
|
|
"red": gocui.ColorRed,
|
|
|
|
"green": gocui.ColorGreen,
|
|
|
|
"yellow": gocui.ColorYellow,
|
|
|
|
"blue": gocui.ColorBlue,
|
|
|
|
"magenta": gocui.ColorMagenta,
|
|
|
|
"cyan": gocui.ColorCyan,
|
|
|
|
"white": gocui.ColorWhite,
|
|
|
|
"bold": gocui.AttrBold,
|
|
|
|
"reverse": gocui.AttrReverse,
|
|
|
|
"underline": gocui.AttrUnderline,
|
|
|
|
}
|
|
|
|
value, present := colorMap[key]
|
|
|
|
if present {
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
return gocui.ColorWhite
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetColor bitwise OR's a list of attributes obtained via the given keys
|
|
|
|
func GetColor(keys []string) gocui.Attribute {
|
|
|
|
var attribute gocui.Attribute
|
|
|
|
for _, key := range keys {
|
|
|
|
attribute |= GetAttribute(key)
|
|
|
|
}
|
|
|
|
return attribute
|
|
|
|
}
|