summary refs log tree commit diff stats
path: root/widgets
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
parent0950e39f538610172858a5e3b7582a7f5cb1fd64 (diff)
downloadaerc-dc4c36adbfbffd34319ddc007bad437ef802ee72.tar.gz
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')
-rw-r--r--widgets/account.go6
-rw-r--r--widgets/aerc.go13
-rw-r--r--widgets/msglist.go5
3 files changed, 19 insertions, 5 deletions
diff --git a/widgets/account.go b/widgets/account.go
index f070df1..92e7a56 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -203,7 +203,11 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
 		if store, ok := acct.msgStores[msg.Info.Name]; ok {
 			store.Update(msg)
 		} else {
-			store = lib.NewMessageStore(acct.worker, msg.Info)
+			store = lib.NewMessageStore(acct.worker, msg.Info,
+				func(msg *models.MessageInfo) {
+					acct.conf.Triggers.ExecNewEmail(acct.acct,
+						acct.conf, msg)
+				})
 			acct.msgStores[msg.Info.Name] = store
 			store.OnUpdate(func(_ *lib.MessageStore) {
 				store.OnUpdate(nil)
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)
diff --git a/widgets/msglist.go b/widgets/msglist.go
index e8ba8c1..abf6921 100644
--- a/widgets/msglist.go
+++ b/widgets/msglist.go
@@ -9,6 +9,7 @@ import (
 
 	"git.sr.ht/~sircmpwn/aerc/config"
 	"git.sr.ht/~sircmpwn/aerc/lib"
+	"git.sr.ht/~sircmpwn/aerc/lib/format"
 	"git.sr.ht/~sircmpwn/aerc/lib/ui"
 	"git.sr.ht/~sircmpwn/aerc/models"
 )
@@ -95,7 +96,9 @@ func (ml *MessageList) Draw(ctx *ui.Context) {
 		}
 
 		ctx.Fill(0, row, ctx.Width(), 1, ' ', style)
-		fmtStr, args, err := lib.ParseIndexFormat(ml.conf, i, msg)
+		fmtStr, args, err := format.ParseMessageFormat(
+			ml.conf.Ui.IndexFormat,
+			ml.conf.Ui.TimestampFormat, "", i, msg)
 		if err != nil {
 			ctx.Printf(0, row, style, "%v", err)
 		} else {