v/GTT
1
0
mirror of https://github.com/eeeXun/GTT.git synced 2025-05-16 07:40:44 -07:00

feat: allow user to import their own themes (#17)

* feat: allow user to import their own themes

* refactor: use make to create map

* add catppuccin example

* fix: theme importing should before reading config file

* docs: add create theme in README

* docs: style
This commit is contained in:
Xun 2023-05-12 21:57:40 +08:00 committed by GitHub
parent 8dcf8c449d
commit 4aa96ec3de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 0 deletions

View File

@ -48,6 +48,20 @@ go install github.com/eeeXun/gtt@latest
docker run -it eeexun/gtt
```
## Create a theme
You can create a theme with theme name. And you must provide the color of `bg`, `fg`, `gray`, `red`, `green`, `yellow`, `blue`, `purple`, `cyan`, `orange`.
And note that:
- `bg` is for background color
- `fg` is for foreground color
- `gray` is for selected color
- `yellow` is for label color
- `orange` is for KeyMap menu color
See the example in [theme.yaml](example/theme.yaml) file. This file should located under `$XDG_CONFIG_HOME/gtt/theme.yaml` or `$HOME/.config/gtt/theme.yaml`
## Language in argument
You can pass `-src` and `-dst` in argument to set source and destination language.

View File

@ -13,6 +13,7 @@ import (
func configInit() {
var (
defaultConfigPath string
themeConfig = config.New()
defaultConfig = map[string]interface{}{
"hide_below": false,
"transparent": false,
@ -37,14 +38,31 @@ func configInit() {
config.SetConfigName("gtt")
config.SetConfigType("yaml")
themeConfig.SetConfigName("theme")
themeConfig.SetConfigType("yaml")
if len(os.Getenv("XDG_CONFIG_HOME")) > 0 {
defaultConfigPath = os.Getenv("XDG_CONFIG_HOME") + "/gtt"
config.AddConfigPath(defaultConfigPath)
themeConfig.AddConfigPath(defaultConfigPath)
} else {
defaultConfigPath = os.Getenv("HOME") + "/.config/gtt"
}
config.AddConfigPath("$HOME/.config/gtt")
themeConfig.AddConfigPath("$HOME/.config/gtt")
// import theme if file exists
if err := themeConfig.ReadInConfig(); err == nil {
var (
palate = make(map[string]int32)
colors = []string{"bg", "fg", "gray", "red", "green", "yellow", "blue", "purple", "cyan", "orange"}
)
for name := range themeConfig.AllSettings() {
for _, color := range colors {
palate[color] = themeConfig.GetInt32(fmt.Sprintf("%s.%s", name, color))
}
style.NewTheme(name, palate)
}
}
// Create config file if it does not exist
// Otherwise check if config value is missing
if err := config.ReadInConfig(); err != nil {

30
example/theme.yaml Normal file
View File

@ -0,0 +1,30 @@
# This file should located under $XDG_CONFIG_HOME/gtt/theme.yaml or $HOME/.config/gtt/theme.yaml
# You have to provide theme name. e.g. tokyonight
# And colors: bg, fg, gray, red, green, yellow, blue, purple, cyan, orange
# bg is for background color
# fg is for foreground color
# gray is for selected color
# yellow is for label color
# orange is for KeyMap menu color
tokyonight:
bg: 0x1a1b26
fg: 0xc0caf5
gray: 0x414868
red: 0xf7768e
green: 0x9ece6a
yellow: 0xe0af68
blue: 0x7aa2f7
purple: 0xbb9af7
cyan: 0x7dcfff
orange: 0xff9e64
catppuccin:
bg: 0x24273A
fg: 0xCAD3F5
gray: 0x5B6078
red: 0xED8796
green: 0xA6DA95
yellow: 0xEED49F
blue: 0x8AADF4
purple: 0xF5BDE6
cyan: 0x8BD5CA
orange: 0xF5A97F

View File

@ -34,3 +34,11 @@ var (
},
}
)
func NewTheme(name string, palette map[string]int32) {
AllTheme = append(AllTheme, name)
themes[name] = make(map[string]tcell.Color)
for color, rgb := range palette {
themes[name][color] = tcell.NewHexColor(rgb)
}
}