aboutsummaryrefslogtreecommitdiff
path: root/widgets/aerc.go
diff options
context:
space:
mode:
authorJeffas <dev@jeffas.io>2019-07-21 21:01:51 +0100
committerDrew DeVault <sir@cmpwn.com>2019-07-26 14:00:24 -0400
commitdc4c36adbfbffd34319ddc007bad437ef802ee72 (patch)
tree1742b507d27a9564c3f51623c01266cca8f9a267 /widgets/aerc.go
parent0950e39f538610172858a5e3b7582a7f5cb1fd64 (diff)
Add new-email trigger
This patch sets up the trigger config section of aerc.conf. Each trigger has its own function which is called from the place where it is triggered. Currently only the new-email trigger is implemented. The triggers make use of format strings. For instance, in the new-email trigger this allows the user to select the trigger command and also the information extracted from the command and placed into their command. To actually execute the trigger commands the keypresses are simulated. Further triggers can be implemented in the future. Formatting of the command is moved to a new package.
Diffstat (limited to 'widgets/aerc.go')
-rw-r--r--widgets/aerc.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/widgets/aerc.go b/widgets/aerc.go
index 079d442..3cf1f64 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -8,6 +8,7 @@ import (
"time"
"github.com/gdamore/tcell"
+ "github.com/google/shlex"
"git.sr.ht/~sircmpwn/aerc/config"
"git.sr.ht/~sircmpwn/aerc/lib/ui"
@@ -16,7 +17,7 @@ import (
type Aerc struct {
accounts map[string]*AccountView
- cmd func(cmd string) error
+ cmd func(cmd []string) error
complete func(cmd string) []string
conf *config.AercConfig
focused libui.Interactive
@@ -30,7 +31,7 @@ type Aerc struct {
}
func NewAerc(conf *config.AercConfig, logger *log.Logger,
- cmd func(cmd string) error, complete func(cmd string) []string) *Aerc {
+ cmd func(cmd []string) error, complete func(cmd string) []string) *Aerc {
tabs := libui.NewTabs()
@@ -62,6 +63,7 @@ func NewAerc(conf *config.AercConfig, logger *log.Logger,
}
statusline.SetAerc(aerc)
+ conf.Triggers.ExecuteCommand = cmd
for i, acct := range conf.Accounts {
view := NewAccountView(conf, &conf.Accounts[i], logger, aerc)
@@ -311,7 +313,12 @@ func (aerc *Aerc) focus(item libui.Interactive) {
func (aerc *Aerc) BeginExCommand() {
previous := aerc.focused
exline := NewExLine(func(cmd string) {
- err := aerc.cmd(cmd)
+ parts, err := shlex.Split(cmd)
+ if err != nil {
+ aerc.PushStatus(" "+err.Error(), 10*time.Second).
+ Color(tcell.ColorDefault, tcell.ColorRed)
+ }
+ err = aerc.cmd(parts)
if err != nil {
aerc.PushStatus(" "+err.Error(), 10*time.Second).
Color(tcell.ColorDefault, tcell.ColorRed)