diff options
author | Robin Jarry <robin@jarry.cc> | 2023-02-01 23:35:42 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-02-20 14:48:42 +0100 |
commit | aaaa0c184fb43879cc84551983309cad06d665ee (patch) | |
tree | 93bb83d32495f679a70dbe5d3913549c29edf675 /widgets/aerc.go | |
parent | 420a82a356d53e4b600ba54768f7ed21a43cf85e (diff) | |
download | aerc-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/aerc.go')
-rw-r--r-- | widgets/aerc.go | 13 |
1 files changed, 7 insertions, 6 deletions
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()) } |