diff options
Diffstat (limited to 'config/config.go')
-rw-r--r-- | config/config.go | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/config/config.go b/config/config.go index 00a52ce7..9e78c86c 100644 --- a/config/config.go +++ b/config/config.go @@ -45,6 +45,9 @@ type UIConfig struct { NextMessageOnDelete bool `ini:"next-message-on-delete"` CompletionDelay time.Duration `ini:"completion-delay"` CompletionPopovers bool `ini:"completion-popovers"` + StyleSetDirs []string `ini:"stylesets-dirs" delim:":"` + StyleSetName string `ini:"styleset-name"` + style StyleSet } type ContextType int @@ -411,6 +414,19 @@ func (config *AercConfig) LoadConfig(file *ini.File) error { } } } + + if err := config.Ui.loadStyleSet( + config.Ui.StyleSetDirs); err != nil { + return err + } + + for idx, _ := range config.ContextualUis { + if err := config.ContextualUis[idx].UiConfig.loadStyleSet( + config.Ui.StyleSetDirs); err != nil { + return err + } + } + return nil } @@ -471,6 +487,8 @@ func LoadConfigFromFile(root *string, sharedir string) (*AercConfig, error) { NextMessageOnDelete: true, CompletionDelay: 250 * time.Millisecond, CompletionPopovers: true, + StyleSetDirs: []string{path.Join(sharedir, "stylesets")}, + StyleSetName: "default", }, ContextualUis: []UIConfigContext{}, @@ -500,6 +518,7 @@ func LoadConfigFromFile(root *string, sharedir string) (*AercConfig, error) { Forwards: "forward_as_body", }, } + // These bindings are not configurable config.Bindings.AccountWizard.ExKey = KeyStroke{ Key: tcell.KeyCtrlE, @@ -510,6 +529,7 @@ func LoadConfigFromFile(root *string, sharedir string) (*AercConfig, error) { if err = config.LoadConfig(file); err != nil { return nil, err } + if ui, err := file.GetSection("general"); err == nil { if err := ui.MapTo(&config.General); err != nil { return nil, err @@ -617,8 +637,18 @@ func parseLayout(layout string) [][]string { return l } -func (config *AercConfig) mergeContextualUi(baseUi *UIConfig, - contextType ContextType, s string) { +func (ui *UIConfig) loadStyleSet(styleSetDirs []string) error { + ui.style = NewStyleSet() + err := ui.style.LoadStyleSet(ui.StyleSetName, styleSetDirs) + if err != nil { + return fmt.Errorf("Unable to load default styleset: %s", err) + } + + return nil +} + +func (config AercConfig) mergeContextualUi(baseUi UIConfig, + contextType ContextType, s string) UIConfig { for _, contextualUi := range config.ContextualUis { if contextualUi.ContextType != contextType { continue @@ -628,17 +658,30 @@ func (config *AercConfig) mergeContextualUi(baseUi *UIConfig, continue } - mergo.MergeWithOverwrite(baseUi, contextualUi.UiConfig) - return + mergo.Merge(&baseUi, contextualUi.UiConfig, mergo.WithOverride) + if contextualUi.UiConfig.StyleSetName != "" { + baseUi.style = contextualUi.UiConfig.style + } + return baseUi } + + return baseUi } -func (config *AercConfig) GetUiConfig(params map[ContextType]string) UIConfig { +func (config AercConfig) GetUiConfig(params map[ContextType]string) UIConfig { baseUi := config.Ui for k, v := range params { - config.mergeContextualUi(&baseUi, k, v) + baseUi = config.mergeContextualUi(baseUi, k, v) } return baseUi } + +func (uiConfig UIConfig) GetStyle(so StyleObject) tcell.Style { + return uiConfig.style.Get(so) +} + +func (uiConfig UIConfig) GetStyleSelected(so StyleObject) tcell.Style { + return uiConfig.style.Selected(so) +} |