about summary refs log tree commit diff stats
path: root/config/config.go
diff options
context:
space:
mode:
authorKalyan Sriram <coder.kalyan@gmail.com>2020-07-27 01:03:55 -0700
committerReto Brunner <reto@labrat.space>2020-07-30 19:35:59 +0200
commit1ff687ca2b0821c2cacc1fa725abb3302d2af9da (patch)
treeb84df04a645c1fd2ee94d7a08f2f9c717930e9ab /config/config.go
parent1bab1754f095a5c0537fc639d0214f6efbb340a2 (diff)
downloadaerc-1ff687ca2b0821c2cacc1fa725abb3302d2af9da.tar.gz
Implement style configuration.
Introduce the ability to configure stylesets, allowing customization of
aerc's look (color scheme, font weight, etc). Default styleset is
installed to /path/to/aerc/stylesets/default.
Diffstat (limited to 'config/config.go')
-rw-r--r--config/config.go55
1 files changed, 49 insertions, 6 deletions
diff --git a/config/config.go b/config/config.go
index 00a52ce..9e78c86 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)
+}