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 /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 'aerc.go')
-rw-r--r-- | aerc.go | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -27,6 +27,7 @@ import ( "git.sr.ht/~rjarry/aerc/lib/templates" libui "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/log" + "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/widgets" "git.sr.ht/~rjarry/aerc/worker/types" ) @@ -60,10 +61,13 @@ func getCommands(selected libui.Drawable) []*commands.Commands { } } -func execCommand(aerc *widgets.Aerc, ui *libui.UI, cmd []string) error { +func execCommand( + aerc *widgets.Aerc, ui *libui.UI, cmd []string, + acct *config.AccountConfig, msg *models.MessageInfo, +) error { cmds := getCommands(aerc.SelectedTabContent()) for i, set := range cmds { - err := set.ExecuteCommand(aerc, cmd) + err := set.ExecuteCommand(aerc, cmd, acct, msg) if err != nil { if errors.As(err, new(commands.NoSuchCommand)) { if i == len(cmds)-1 { @@ -189,8 +193,11 @@ func main() { } defer c.Close() - aerc = widgets.NewAerc(c, func(cmd []string) error { - return execCommand(aerc, ui, cmd) + aerc = widgets.NewAerc(c, func( + cmd []string, acct *config.AccountConfig, + msg *models.MessageInfo, + ) error { + return execCommand(aerc, ui, cmd, acct, msg) }, func(cmd string) []string { return getCompletions(aerc, cmd) }, &commands.CmdHistory, deferLoop) |