aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-02-01 23:35:42 +0100
committerRobin Jarry <robin@jarry.cc>2023-02-20 14:48:42 +0100
commitaaaa0c184fb43879cc84551983309cad06d665ee (patch)
tree93bb83d32495f679a70dbe5d3913549c29edf675 /widgets
parent420a82a356d53e4b600ba54768f7ed21a43cf85e (diff)
downloadaerc-aaaa0c184fb43879cc84551983309cad06d665ee.tar.gz
triggers: use templates instead of % mini language
Since previous commit, all commands now support expanding text/template markup. Reuse that for the new-email trigger command. Update commands.ExecuteCommand to take optional *AccountConfig and *MessageInfo arguments. If these are nil, fallback to using the currently selected account and message (if any). Pass the proper *AccountConfig and *MessageInfo objects when firing the trigger command so that these are used instead of the currently selected ones. If new-email contains % placeholders, try to convert them to template markup reusing the same conversion added in commit 535300cfdbfc ("config: add columns based index format"). Warn the user that they need to update their configuration file. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'widgets')
-rw-r--r--widgets/account.go10
-rw-r--r--widgets/aerc.go13
2 files changed, 16 insertions, 7 deletions
diff --git a/widgets/account.go b/widgets/account.go
index 3176a2bf..ded71f99 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -293,7 +293,15 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
acct.dirlist.UiConfig(name).ReverseThreadOrder,
acct.dirlist.UiConfig(name).SortThreadSiblings,
func(msg *models.MessageInfo) {
- config.Triggers.ExecNewEmail(acct.acct, msg)
+ if len(config.Triggers.NewEmail) == 0 {
+ return
+ }
+ err := acct.aerc.cmd(
+ config.Triggers.NewEmail,
+ acct.acct, msg)
+ if err != nil {
+ acct.aerc.PushError(err.Error())
+ }
}, func() {
if acct.dirlist.UiConfig(name).NewMessageBell {
acct.host.Beep()
diff --git a/widgets/aerc.go b/widgets/aerc.go
index b946b158..b8be1100 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -20,12 +20,13 @@ import (
"git.sr.ht/~rjarry/aerc/lib/crypto"
"git.sr.ht/~rjarry/aerc/lib/ui"
"git.sr.ht/~rjarry/aerc/log"
+ "git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/types"
)
type Aerc struct {
accounts map[string]*AccountView
- cmd func(cmd []string) error
+ cmd func([]string, *config.AccountConfig, *models.MessageInfo) error
cmdHistory lib.History
complete func(cmd string) []string
focused ui.Interactive
@@ -51,7 +52,8 @@ type Choice struct {
}
func NewAerc(
- crypto crypto.Provider, cmd func(cmd []string) error,
+ crypto crypto.Provider,
+ cmd func([]string, *config.AccountConfig, *models.MessageInfo) error,
complete func(cmd string) []string, cmdHistory lib.History,
deferLoop chan struct{},
) *Aerc {
@@ -86,7 +88,6 @@ func NewAerc(
}
statusline.SetAerc(aerc)
- config.Triggers.ExecuteCommand = cmd
for _, acct := range config.Accounts {
view, err := NewAccountView(aerc, acct, aerc, deferLoop)
@@ -608,7 +609,7 @@ func (aerc *Aerc) BeginExCommand(cmd string) {
if err != nil {
aerc.PushError(err.Error())
}
- err = aerc.cmd(parts)
+ err = aerc.cmd(parts, nil, nil)
if err != nil {
aerc.PushError(err.Error())
}
@@ -634,7 +635,7 @@ func (aerc *Aerc) RegisterPrompt(prompt string, cmd []string) {
if text != "" {
cmd = append(cmd, text)
}
- err := aerc.cmd(cmd)
+ err := aerc.cmd(cmd, nil, nil)
if err != nil {
aerc.PushError(err.Error())
}
@@ -661,7 +662,7 @@ func (aerc *Aerc) RegisterChoices(choices []Choice) {
if !ok {
return
}
- err := aerc.cmd(cmd)
+ err := aerc.cmd(cmd, nil, nil)
if err != nil {
aerc.PushError(err.Error())
}