aboutsummaryrefslogtreecommitdiffstats
path: root/config/viewer.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-12-12 15:03:30 +0100
committerRobin Jarry <robin@jarry.cc>2022-12-14 11:22:58 +0100
commitc05c2ffe0424b048b10e7dd1aca59ae9cf631f12 (patch)
tree13a3a84eb74fdea77996161f01bec5596f67f39f /config/viewer.go
parent9d0297e9d913a92b2d7ae02692e83f0f4093a766 (diff)
downloadaerc-c05c2ffe0424b048b10e7dd1aca59ae9cf631f12.tar.gz
config: make various sections accessible via global vars
There is only one instance of AercConfig which is associated to the Aerc widget. Everywhere we need to access configuration options, we need somehow to get a reference either to the Aerc widget or to a pointer to the AercConfig instance. This makes the code cluttered. Remove the AercConfig structure and every place where it is referenced. Instead, declare global variables for every configuration section and access them directly from the `config` module. Since bindings and ui sections can be "contextual" (i.e. per account, per folder or per subject), leave most local references intact. Replacing them with config.{Ui,Binds}.For{Account,Folder,Subject} would make this patch even more unreadable. This is something that may be addressed in the future. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'config/viewer.go')
-rw-r--r--config/viewer.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/config/viewer.go b/config/viewer.go
index 3f7c6934..d5e32ac8 100644
--- a/config/viewer.go
+++ b/config/viewer.go
@@ -18,8 +18,8 @@ type ViewerConfig struct {
CloseOnReply bool `ini:"close-on-reply"`
}
-func defaultViewerConfig() ViewerConfig {
- return ViewerConfig{
+func defaultViewerConfig() *ViewerConfig {
+ return &ViewerConfig{
Pager: "less -R",
Alternatives: []string{"text/plain", "text/html"},
ShowHeaders: false,
@@ -34,23 +34,25 @@ func defaultViewerConfig() ViewerConfig {
}
}
-func (config *AercConfig) parseViewer(file *ini.File) error {
+var Viewer = defaultViewerConfig()
+
+func parseViewer(file *ini.File) error {
viewer, err := file.GetSection("viewer")
if err != nil {
goto out
}
- if err := viewer.MapTo(&config.Viewer); err != nil {
+ if err := viewer.MapTo(&Viewer); err != nil {
return err
}
for key, val := range viewer.KeysHash() {
switch key {
case "alternatives":
- config.Viewer.Alternatives = strings.Split(val, ",")
+ Viewer.Alternatives = strings.Split(val, ",")
case "header-layout":
- config.Viewer.HeaderLayout = parseLayout(val)
+ Viewer.HeaderLayout = parseLayout(val)
}
}
out:
- log.Debugf("aerc.conf: [viewer] %#v", config.Viewer)
+ log.Debugf("aerc.conf: [viewer] %#v", Viewer)
return nil
}