aboutsummaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2024-08-07 20:52:29 +0200
committerRobin Jarry <robin@jarry.cc>2024-08-20 12:26:46 +0200
commit50647d589544abab35bcfb3d120bd2b6f907525e (patch)
tree77efbe0814e9ba2d6ee2e8ec55396894f1714b79 /config
parent401bcee258713b911cd67aa6dc832e4eff25deb4 (diff)
downloadaerc-50647d589544abab35bcfb3d120bd2b6f907525e.tar.gz
config: add reload helper functions
Add reload helper function to reload config files. Store the initially used config files for the reloading. Signed-off-by: Koni Marti <koni.marti@gmail.com> Tested-by: Inwit <inwit@sindominio.net> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'config')
-rw-r--r--config/binds.go2
-rw-r--r--config/config.go1
-rw-r--r--config/reload.go68
-rw-r--r--config/ui.go10
4 files changed, 77 insertions, 4 deletions
diff --git a/config/binds.go b/config/binds.go
index 1d391af7..3305fd3a 100644
--- a/config/binds.go
+++ b/config/binds.go
@@ -163,7 +163,7 @@ func parseBinds(root string, filename string) error {
}
}
}
-
+ SetBindsFilename(filename)
if err := parseBindsFromFile(root, filename); err != nil {
return fmt.Errorf("%s: %w", filename, err)
}
diff --git a/config/config.go b/config/config.go
index 61ac041e..6bab5fc8 100644
--- a/config/config.go
+++ b/config/config.go
@@ -134,6 +134,7 @@ func LoadConfigFromFile(
}
}
}
+ SetConfFilename(filename)
if err := parseConf(filename); err != nil {
return fmt.Errorf("%s: %w", filename, err)
}
diff --git a/config/reload.go b/config/reload.go
new file mode 100644
index 00000000..f572cea1
--- /dev/null
+++ b/config/reload.go
@@ -0,0 +1,68 @@
+package config
+
+import (
+ "errors"
+ "os"
+ "path/filepath"
+
+ "git.sr.ht/~rjarry/aerc/lib/log"
+)
+
+type reloadStore struct {
+ binds string
+ conf string
+}
+
+var rlst reloadStore
+
+func SetBindsFilename(fn string) {
+ log.Debugf("reloader: set binds file: %s", fn)
+ rlst.binds = fn
+}
+
+func SetConfFilename(fn string) {
+ log.Debugf("reloader: set conf file: %s", fn)
+ rlst.conf = fn
+}
+
+func ReloadBinds() (string, error) {
+ f := rlst.binds
+ if !exists(f) {
+ return f, os.ErrNotExist
+ }
+ log.Debugf("reload binds file: %s", f)
+ Binds = defaultBindsConfig()
+ return f, parseBindsFromFile(filepath.Dir(f), f)
+}
+
+func ReloadConf() (string, error) {
+ f := rlst.conf
+ if !exists(f) {
+ return f, os.ErrNotExist
+ }
+ log.Debugf("reload conf file: %s", f)
+
+ General = new(GeneralConfig)
+ Filters = nil
+ Compose = new(ComposeConfig)
+ Converters = make(map[string]string)
+ Viewer = new(ViewerConfig)
+ Statusline = new(StatuslineConfig)
+ Openers = nil
+ Hooks = HooksConfig{}
+ Ui = defaultUIConfig()
+ Templates = new(TemplateConfig)
+
+ return f, parseConf(f)
+}
+
+func ReloadAccounts() error {
+ return errors.New("not implemented")
+}
+
+func exists(fn string) bool {
+ if _, err := os.Stat(fn); errors.Is(err, os.ErrNotExist) {
+ return false
+ }
+ return true
+}
diff --git a/config/ui.go b/config/ui.go
index 9839db9b..578ad294 100644
--- a/config/ui.go
+++ b/config/ui.go
@@ -134,9 +134,13 @@ type uiContextKey struct {
value string
}
-var Ui = &UIConfig{
- contextualCounts: make(map[uiContextType]int),
- contextualCache: make(map[uiContextKey]*UIConfig),
+var Ui = defaultUIConfig()
+
+func defaultUIConfig() *UIConfig {
+ return &UIConfig{
+ contextualCounts: make(map[uiContextType]int),
+ contextualCache: make(map[uiContextKey]*UIConfig),
+ }
}
var uiContextualSectionRe = regexp.MustCompile(`^ui:(account|folder|subject)([~=])(.+)$`)