summary refs log tree commit diff stats
path: root/config/config.go
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-03-31 14:24:53 -0400
committerDrew DeVault <sir@cmpwn.com>2019-03-31 14:24:53 -0400
commitbbdf9df75e8597e38cf1d90145f22aab9bd95178 (patch)
treee721502779327758956694edffbd6e01762801e9 /config/config.go
parent711d22891bd50646d1cf925fbf0b8a760c638fd0 (diff)
downloadaerc-bbdf9df75e8597e38cf1d90145f22aab9bd95178.tar.gz
Add basic filter implementation
Diffstat (limited to 'config/config.go')
-rw-r--r--config/config.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/config/config.go b/config/config.go
index e5e332e..8d460ca 100644
--- a/config/config.go
+++ b/config/config.go
@@ -22,6 +22,12 @@ type UIConfig struct {
 	EmptyMessage      string   `ini:"empty-message"`
 }
 
+const (
+	FILTER_MIMETYPE = iota
+	FILTER_HEADER
+	FILTER_HEADER_REGEX
+)
+
 type AccountConfig struct {
 	Default string
 	Name    string
@@ -38,10 +44,23 @@ type BindingConfig struct {
 	Terminal    *KeyBindings
 }
 
+type FilterConfig struct {
+	FilterType int
+	Filter     string
+	Command    string
+}
+
+type ViewerConfig struct {
+	Pager        string
+	Alternatives []string
+}
+
 type AercConfig struct {
 	Bindings BindingConfig
 	Ini      *ini.File       `ini:"-"`
 	Accounts []AccountConfig `ini:"-"`
+	Filters  []FilterConfig  `ini:"-"`
+	Viewer   ViewerConfig    `ini:"-"`
 	Ui       UIConfig
 }
 
@@ -135,6 +154,34 @@ func LoadConfig(root *string) (*AercConfig, error) {
 			EmptyMessage:      "(no messages)",
 		},
 	}
+	if filters, err := file.GetSection("filters"); err == nil {
+		// TODO: Parse the filter more finely, e.g. parse the regex
+		for match, cmd := range filters.KeysHash() {
+			filter := FilterConfig{
+				Command: cmd,
+				Filter:  match,
+			}
+			if strings.Contains(match, "~:") {
+				filter.FilterType = FILTER_HEADER_REGEX
+			} else if strings.ContainsRune(match, ':') {
+				filter.FilterType = FILTER_HEADER
+			} else {
+				filter.FilterType = FILTER_MIMETYPE
+			}
+			config.Filters = append(config.Filters, filter)
+		}
+	}
+	if viewer, err := file.GetSection("viewer"); err == nil {
+		if err := viewer.MapTo(&config.Viewer); err != nil {
+			return nil, err
+		}
+		for key, val := range viewer.KeysHash() {
+			switch key {
+			case "alternatives":
+				config.Viewer.Alternatives = strings.Split(val, ",")
+			}
+		}
+	}
 	if ui, err := file.GetSection("ui"); err == nil {
 		if err := ui.MapTo(&config.Ui); err != nil {
 			return nil, err