diff options
author | mjarkk <mkopenga@gmail.com> | 2019-10-18 09:48:37 +0200 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-10-20 12:32:57 +1100 |
commit | 02fef3136f27a0a93352ee62f47d4924e54389dd (patch) | |
tree | 1be96988ffda2cc6f29c1d06ebf60d8677c5121c /pkg/theme | |
parent | 8fe0e00cd9484c231c79c77ad3bc3dd601f0451a (diff) |
Added light theme option to the settings
Diffstat (limited to 'pkg/theme')
-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 +} |