diff options
author | Robin Jarry <robin@jarry.cc> | 2022-11-15 22:50:49 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-11-16 16:12:09 +0100 |
commit | f8e88632c49a4bd70efb503944f642e7daed37d8 (patch) | |
tree | 0424095855417c868b96d44a773fe3e24f3dfbba | |
parent | 3710e459825b78a5adfa7af04128713010e4c9e4 (diff) | |
download | aerc-f8e88632c49a4bd70efb503944f642e7daed37d8.tar.gz |
config: move [statusline] in separate file
The config.go file is getting too big. Move the aerc.conf [statusline]
section parsing logic into a dedicated statusline.go file.
No functional change.
Please ignore the casual "realignment" of fields in the default config
initialization. Thanks gofmt.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Moritz Poldrack <moritz@poldrack.dev>
-rw-r--r-- | config/config.go | 41 | ||||
-rw-r--r-- | config/statusline.go | 33 |
2 files changed, 45 insertions, 29 deletions
diff --git a/config/config.go b/config/config.go index 0c2bf5f3..ef824279 100644 --- a/config/config.go +++ b/config/config.go @@ -16,12 +16,6 @@ import ( "git.sr.ht/~rjarry/aerc/logging" ) -type StatuslineConfig struct { - RenderFormat string `ini:"render-format"` - Separator string - DisplayMode string `ini:"display-mode"` -} - type TriggersConfig struct { NewEmail string `ini:"new-email"` ExecuteCommand func(command []string) error @@ -133,11 +127,6 @@ func (config *AercConfig) LoadConfig(file *ini.File) error { } } } - if statusline, err := file.GetSection("statusline"); err == nil { - if err := statusline.MapTo(&config.Statusline); err != nil { - return err - } - } if triggers, err := file.GetSection("triggers"); err == nil { if err := triggers.MapTo(&config.Triggers); err != nil { @@ -173,24 +162,16 @@ func LoadConfigFromFile(root *string, accts []string) (*AercConfig, error) { } file.NameMapper = mapName config := &AercConfig{ - Bindings: defaultBindsConfig(), - + Bindings: defaultBindsConfig(), ContextualBinds: []BindingConfigContext{}, - - General: defaultGeneralConfig(), - Ui: defaultUiConfig(), - ContextualUis: []UIConfigContext{}, - Viewer: defaultViewerConfig(), - - Statusline: StatuslineConfig{ - RenderFormat: "[%a] %S %>%T", - Separator: " | ", - DisplayMode: "", - }, - - Compose: defaultComposeConfig(), - Templates: defaultTemplatesConfig(), - Openers: make(map[string][]string), + General: defaultGeneralConfig(), + Ui: defaultUiConfig(), + ContextualUis: []UIConfigContext{}, + Viewer: defaultViewerConfig(), + Statusline: defaultStatuslineConfig(), + Compose: defaultComposeConfig(), + Templates: defaultTemplatesConfig(), + Openers: make(map[string][]string), } if err := config.parseFilters(file); err != nil { @@ -202,6 +183,9 @@ func LoadConfigFromFile(root *string, accts []string) (*AercConfig, error) { if err := config.parseViewer(file); err != nil { return nil, err } + if err := config.parseStatusline(file); err != nil { + return nil, err + } if err = config.LoadConfig(file); err != nil { return nil, err } @@ -212,7 +196,6 @@ func LoadConfigFromFile(root *string, accts []string) (*AercConfig, error) { return nil, err } - logging.Debugf("aerc.conf: [statusline] %#v", config.Statusline) logging.Debugf("aerc.conf: [openers] %#v", config.Openers) logging.Debugf("aerc.conf: [triggers] %#v", config.Triggers) diff --git a/config/statusline.go b/config/statusline.go new file mode 100644 index 00000000..a289c84d --- /dev/null +++ b/config/statusline.go @@ -0,0 +1,33 @@ +package config + +import ( + "git.sr.ht/~rjarry/aerc/logging" + "github.com/go-ini/ini" +) + +type StatuslineConfig struct { + RenderFormat string `ini:"render-format"` + Separator string + DisplayMode string `ini:"display-mode"` +} + +func defaultStatuslineConfig() StatuslineConfig { + return StatuslineConfig{ + RenderFormat: "[%a] %S %>%T", + Separator: " | ", + DisplayMode: "", + } +} + +func (config *AercConfig) parseStatusline(file *ini.File) error { + statusline, err := file.GetSection("statusline") + if err != nil { + goto out + } + if err := statusline.MapTo(&config.Statusline); err != nil { + return err + } +out: + logging.Debugf("aerc.conf: [statusline] %#v", config.Statusline) + return nil +} |