diff options
Diffstat (limited to 'pkg/theme/theme.go')
-rw-r--r-- | pkg/theme/theme.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/pkg/theme/theme.go b/pkg/theme/theme.go new file mode 100644 index 000000000..4b2c0e9b2 --- /dev/null +++ b/pkg/theme/theme.go @@ -0,0 +1,68 @@ +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 + + // 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 + GocuiDefaultTextColor = gocui.ColorBlack + } else { + DefaultTextColor = color.FgWhite + 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 +} |