feat(config): add theme customization (#81)
Added theme customization via config.toml #17 ``` [theme] border = "#665C54" accent = "#FABD2F" muted = "#928374" text = "#EBDBB2" text_sel = "#FBF1C7" match = "#FE8019" desc = "#A89984" desc_sel = "#EBDBB2" sel_bg = "#504945" scroll_info = "#83A598" ghost_text = "#7C6F64" hist= "#fe8019" hist_sel = "#d65d0e" sys = "#fb4934" sys_sel = "#cc241d" alias = "#b8bb26" alias_sel = "#98971a" ``` --------- Co-authored-by: verse91 <versedev.store@proton.me> Co-authored-by: VERSE <sunnyone0901@gmail.com>
This commit is contained in:
+36
-15
@@ -144,30 +144,47 @@ func Init(cfg *Config) {
|
||||
}
|
||||
|
||||
func AutoDetectConfigChange(onReload func(cfg *Config)) {
|
||||
path, err := ConfigPath()
|
||||
cfgPath, err := ConfigPath()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
themePath, _ := ThemePath()
|
||||
|
||||
go func() {
|
||||
var lastMod time.Time
|
||||
if info, err := os.Stat(path); err == nil {
|
||||
lastMod = info.ModTime()
|
||||
statMod := func(p string) time.Time {
|
||||
if info, err := os.Stat(p); err == nil {
|
||||
return info.ModTime()
|
||||
}
|
||||
return time.Time{}
|
||||
}
|
||||
cfgLast := statMod(cfgPath)
|
||||
themeLast := statMod(themePath)
|
||||
ticker := time.NewTicker(1 * time.Second)
|
||||
defer ticker.Stop()
|
||||
for range ticker.C {
|
||||
info, err := os.Stat(path)
|
||||
if err == nil {
|
||||
if !lastMod.IsZero() && info.ModTime().After(lastMod) {
|
||||
lastMod = info.ModTime()
|
||||
if newCfg, err := Load(); err == nil {
|
||||
Init(newCfg)
|
||||
if onReload != nil {
|
||||
onReload(newCfg)
|
||||
}
|
||||
changed := false
|
||||
cfgMod := statMod(cfgPath)
|
||||
if !cfgLast.IsZero() && cfgMod.After(cfgLast) {
|
||||
cfgLast = cfgMod
|
||||
changed = true
|
||||
} else if cfgLast.IsZero() {
|
||||
cfgLast = cfgMod
|
||||
}
|
||||
if themePath != "" {
|
||||
themeMod := statMod(themePath)
|
||||
if !themeLast.IsZero() && (themeMod.After(themeLast) || themeMod.IsZero()) {
|
||||
themeLast = themeMod
|
||||
changed = true
|
||||
} else if themeLast.IsZero() {
|
||||
themeLast = themeMod
|
||||
}
|
||||
}
|
||||
if changed {
|
||||
if newCfg, err := Load(); err == nil {
|
||||
Init(newCfg)
|
||||
if onReload != nil {
|
||||
onReload(newCfg)
|
||||
}
|
||||
} else if lastMod.IsZero() {
|
||||
lastMod = info.ModTime()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -190,6 +207,10 @@ func Load() (*Config, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if themePath, err := ThemePath(); err == nil {
|
||||
LoadTheme(themePath)
|
||||
}
|
||||
|
||||
applyEnv(cfg)
|
||||
|
||||
// fallback for empty keybindings
|
||||
|
||||
Reference in New Issue
Block a user