v/GTT
1
0
mirror of https://github.com/eeeXun/GTT.git synced 2025-05-29 05:50:17 -07:00

refactor: Change theme name to lowercase

This commit is contained in:
eeeXun 2023-04-27 01:05:51 +08:00
parent 7788d82c4f
commit a76807d254
2 changed files with 11 additions and 5 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/eeeXun/gtt/internal/style"
"github.com/eeeXun/gtt/internal/translate" "github.com/eeeXun/gtt/internal/translate"
config "github.com/spf13/viper" config "github.com/spf13/viper"
) )
@ -15,7 +16,7 @@ func configInit() {
defaultConfig = map[string]interface{}{ defaultConfig = map[string]interface{}{
"hide_below": false, "hide_below": false,
"transparent": false, "transparent": false,
"theme": "Gruvbox", "theme": "gruvbox",
"source.border_color": "red", "source.border_color": "red",
"destination.border_color": "blue", "destination.border_color": "blue",
"source.language.apertiumtranslate": "English", "source.language.apertiumtranslate": "English",
@ -42,7 +43,7 @@ func configInit() {
} }
config.AddConfigPath("$HOME/.config/gtt") config.AddConfigPath("$HOME/.config/gtt")
// Create config file if not exists // Create config file if it does not exist
// Otherwise check if config value is missing // Otherwise check if config value is missing
if err := config.ReadInConfig(); err != nil { if err := config.ReadInConfig(); err != nil {
for key, value := range defaultConfig { for key, value := range defaultConfig {
@ -60,6 +61,11 @@ func configInit() {
missing = true missing = true
} }
} }
// Set to default theme if theme in config does not exist
if IndexOf(config.GetString("theme"), style.AllTheme) < 0 {
config.Set("theme", defaultConfig["theme"])
missing = true
}
if missing { if missing {
config.WriteConfig() config.WriteConfig()
} }

View File

@ -5,10 +5,10 @@ import (
) )
var ( var (
AllTheme = []string{"Gruvbox", "Nord"} AllTheme = []string{"gruvbox", "nord"}
Palette = []string{"red", "green", "yellow", "blue", "purple", "cyan", "orange"} Palette = []string{"red", "green", "yellow", "blue", "purple", "cyan", "orange"}
themes = map[string]map[string]tcell.Color{ themes = map[string]map[string]tcell.Color{
"Gruvbox": { "gruvbox": {
"bg": tcell.NewHexColor(0x282828), "bg": tcell.NewHexColor(0x282828),
"fg": tcell.NewHexColor(0xebdbb2), "fg": tcell.NewHexColor(0xebdbb2),
"gray": tcell.NewHexColor(0x665c54), "gray": tcell.NewHexColor(0x665c54),
@ -20,7 +20,7 @@ var (
"cyan": tcell.NewHexColor(0x8ec07c), "cyan": tcell.NewHexColor(0x8ec07c),
"orange": tcell.NewHexColor(0xfe8019), "orange": tcell.NewHexColor(0xfe8019),
}, },
"Nord": { "nord": {
"bg": tcell.NewHexColor(0x3b4252), "bg": tcell.NewHexColor(0x3b4252),
"fg": tcell.NewHexColor(0xeceff4), "fg": tcell.NewHexColor(0xeceff4),
"gray": tcell.NewHexColor(0x4c566a), "gray": tcell.NewHexColor(0x4c566a),