aboutsummaryrefslogtreecommitdiffstats
path: root/config/config.go
diff options
context:
space:
mode:
authorSrivathsan Murali <sri@vathsan.com>2019-11-03 13:51:14 +0100
committerDrew DeVault <sir@cmpwn.com>2019-11-10 10:15:49 -0500
commit3ba69edab5f0c787424dac9649e43a7743da13ca (patch)
treebccbdd4e1844cc89f011839f0d6557012a14d1d0 /config/config.go
parentad68a9e4e471eb708893ad16601ab14a4672a2da (diff)
downloadaerc-3ba69edab5f0c787424dac9649e43a7743da13ca.tar.gz
Add Templates with Parsing
+ Changes NewComposer to return error. + Add lib to handle templates using "text/template". + Add -T option to following commands - compose. - reply - forward + Quoted replies using templates. + Forwards as body using templates + Default templates are installed similar to filters. + Templates Config in aerc.conf. - Required templates are parsed while loading config. + Add aerc-templates.7 manual for using template data.
Diffstat (limited to 'config/config.go')
-rw-r--r--config/config.go44
1 files changed, 35 insertions, 9 deletions
diff --git a/config/config.go b/config/config.go
index 133a7f4e..f46af09c 100644
--- a/config/config.go
+++ b/config/config.go
@@ -16,6 +16,8 @@ import (
"github.com/gdamore/tcell"
"github.com/go-ini/ini"
"github.com/kyoh86/xdg"
+
+ "git.sr.ht/~sircmpwn/aerc/lib/templates"
)
type GeneralConfig struct {
@@ -98,16 +100,23 @@ type TriggersConfig struct {
ExecuteCommand func(command []string) error
}
+type TemplateConfig struct {
+ TemplateDirs []string
+ QuotedReply string `ini:"quoted-reply"`
+ Forwards string `ini:"forwards"`
+}
+
type AercConfig struct {
- Bindings BindingConfig
- Compose ComposeConfig
- Ini *ini.File `ini:"-"`
- Accounts []AccountConfig `ini:"-"`
- Filters []FilterConfig `ini:"-"`
- Viewer ViewerConfig `ini:"-"`
- Triggers TriggersConfig `ini:"-"`
- Ui UIConfig
- General GeneralConfig
+ Bindings BindingConfig
+ Compose ComposeConfig
+ Ini *ini.File `ini:"-"`
+ Accounts []AccountConfig `ini:"-"`
+ Filters []FilterConfig `ini:"-"`
+ Viewer ViewerConfig `ini:"-"`
+ Triggers TriggersConfig `ini:"-"`
+ Ui UIConfig
+ General GeneralConfig
+ Templates TemplateConfig
}
// Input: TimestampFormat
@@ -305,6 +314,23 @@ func (config *AercConfig) LoadConfig(file *ini.File) error {
return err
}
}
+ if templatesSec, err := file.GetSection("templates"); err == nil {
+ if err := templatesSec.MapTo(&config.Templates); err != nil {
+ return err
+ }
+ templateDirs := templatesSec.Key("template-dirs").String()
+ config.Templates.TemplateDirs = strings.Split(templateDirs, ":")
+ for key, val := range templatesSec.KeysHash() {
+ if key == "template-dirs" {
+ continue
+ }
+ _, err := templates.ParseTemplateFromFile(
+ val, config.Templates.TemplateDirs, templates.TestTemplateData())
+ if err != nil {
+ return err
+ }
+ }
+ }
return nil
}