diff options
author | Robin Jarry <robin@jarry.cc> | 2022-12-12 15:03:30 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-12-14 11:22:58 +0100 |
commit | c05c2ffe0424b048b10e7dd1aca59ae9cf631f12 (patch) | |
tree | 13a3a84eb74fdea77996161f01bec5596f67f39f /config/config.go | |
parent | 9d0297e9d913a92b2d7ae02692e83f0f4093a766 (diff) | |
download | aerc-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/config.go')
-rw-r--r-- | config/config.go | 82 |
1 files changed, 28 insertions, 54 deletions
diff --git a/config/config.go b/config/config.go index 90951985..09fb5efc 100644 --- a/config/config.go +++ b/config/config.go @@ -14,21 +14,6 @@ import ( "github.com/mitchellh/go-homedir" ) -type AercConfig struct { - Bindings BindingConfig - Compose ComposeConfig - Converters map[string]string - Accounts []AccountConfig `ini:"-"` - Filters []FilterConfig `ini:"-"` - Viewer ViewerConfig `ini:"-"` - Statusline StatuslineConfig `ini:"-"` - Triggers TriggersConfig `ini:"-"` - Ui UIConfig - General GeneralConfig - Templates TemplateConfig - Openers map[string][]string -} - // Input: TimestampFormat // Output: timestamp-format func mapName(raw string) string { @@ -108,7 +93,7 @@ func installTemplate(root, name string) error { return nil } -func LoadConfigFromFile(root *string, accts []string) (*AercConfig, error) { +func LoadConfigFromFile(root *string, accts []string) error { if root == nil { _root := path.Join(xdg.ConfigHome(), "aerc") root = &_root @@ -119,7 +104,7 @@ func LoadConfigFromFile(root *string, accts []string) (*AercConfig, error) { if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) { fmt.Printf("%s not found, installing the system default", filename) if err := installTemplate(*root, "aerc.conf"); err != nil { - return nil, err + return err } } @@ -127,59 +112,48 @@ func LoadConfigFromFile(root *string, accts []string) (*AercConfig, error) { KeyValueDelimiters: "=", }, filename) if err != nil { - return nil, err + return err } file.NameMapper = mapName - config := &AercConfig{ - Bindings: defaultBindsConfig(), - General: defaultGeneralConfig(), - Ui: defaultUiConfig(), - Viewer: defaultViewerConfig(), - Statusline: defaultStatuslineConfig(), - Compose: defaultComposeConfig(), - Converters: make(map[string]string), - Templates: defaultTemplatesConfig(), - Openers: make(map[string][]string), - } - if err := config.parseGeneral(file); err != nil { - return nil, err + if err := parseGeneral(file); err != nil { + return err } - if err := config.parseFilters(file); err != nil { - return nil, err + if err := parseFilters(file); err != nil { + return err } - if err := config.parseCompose(file); err != nil { - return nil, err + if err := parseCompose(file); err != nil { + return err } - if err := config.parseConverters(file); err != nil { - return nil, err + if err := parseConverters(file); err != nil { + return err } - if err := config.parseViewer(file); err != nil { - return nil, err + if err := parseViewer(file); err != nil { + return err } - if err := config.parseStatusline(file); err != nil { - return nil, err + if err := parseStatusline(file); err != nil { + return err } - if err := config.parseOpeners(file); err != nil { - return nil, err + if err := parseOpeners(file); err != nil { + return err } - if err := config.parseTriggers(file); err != nil { - return nil, err + if err := parseTriggers(file); err != nil { + return err } - if err := config.parseUi(file); err != nil { - return nil, err + if err := parseUi(file); err != nil { + return err } - if err := config.parseTemplates(file); err != nil { - return nil, err + if err := parseTemplates(file); err != nil { + return err } - if err := config.parseAccounts(*root, accts); err != nil { - return nil, err + if err := parseAccounts(*root, accts); err != nil { + return err } - if err := config.parseBinds(*root); err != nil { - return nil, err + if err := parseBinds(*root); err != nil { + return err } - return config, nil + return nil } func parseLayout(layout string) [][]string { |