aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--commands/commands.go17
-rw-r--r--commands/next-folder.go34
-rw-r--r--commands/prev-folder.go15
-rw-r--r--go.mod1
-rw-r--r--go.sum2
-rw-r--r--widgets/account.go2
6 files changed, 48 insertions, 23 deletions
diff --git a/commands/commands.go b/commands/commands.go
index 71dabe4c..49a8b46e 100644
--- a/commands/commands.go
+++ b/commands/commands.go
@@ -3,10 +3,12 @@ package commands
import (
"errors"
+ "github.com/google/shlex"
+
"git.sr.ht/~sircmpwn/aerc2/widgets"
)
-type AercCommand func(aerc *widgets.Aerc, cmd string) error
+type AercCommand func(aerc *widgets.Aerc, args []string) error
var (
commands map[string]AercCommand
@@ -21,8 +23,15 @@ func Register(name string, cmd AercCommand) {
}
func ExecuteCommand(aerc *widgets.Aerc, cmd string) error {
- if fn, ok := commands[cmd]; ok {
- return fn(aerc, cmd)
+ args, err := shlex.Split(cmd)
+ if err != nil {
+ return err
+ }
+ if len(args) == 0 {
+ return errors.New("Expected a command.")
+ }
+ if fn, ok := commands[args[0]]; ok {
+ return fn(aerc, args)
}
- return errors.New("Unknown command " + cmd)
+ return errors.New("Unknown command " + args[0])
}
diff --git a/commands/next-folder.go b/commands/next-folder.go
index 02975e10..ed116153 100644
--- a/commands/next-folder.go
+++ b/commands/next-folder.go
@@ -1,15 +1,43 @@
package commands
import (
+ "errors"
+ "fmt"
+ "strconv"
+
"git.sr.ht/~sircmpwn/aerc2/widgets"
)
func init() {
- Register("next-folder", NextFolder)
+ Register("next-folder", NextPrevFolder)
+ Register("prev-folder", NextPrevFolder)
+}
+
+func usage(cmd string) error {
+ return errors.New(fmt.Sprintf("Usage: %s [n]", cmd))
}
-func NextFolder(aerc *widgets.Aerc, cmd string) error {
+func NextPrevFolder(aerc *widgets.Aerc, args []string) error {
+ if len(args) > 2 {
+ return usage(args[0])
+ }
+ var (
+ n int = 1
+ err error
+ )
+ if len(args) > 1 {
+ n, err = strconv.Atoi(args[1])
+ if err != nil {
+ return usage(args[0])
+ }
+ }
acct := aerc.SelectedAccount()
- acct.Directories().Next()
+ for ; n > 0; n-- {
+ if args[0] == "prev-folder" {
+ acct.Directories().Prev()
+ } else {
+ acct.Directories().Next()
+ }
+ }
return nil
}
diff --git a/commands/prev-folder.go b/commands/prev-folder.go
deleted file mode 100644
index a38214fc..00000000
--- a/commands/prev-folder.go
+++ /dev/null
@@ -1,15 +0,0 @@
-package commands
-
-import (
- "git.sr.ht/~sircmpwn/aerc2/widgets"
-)
-
-func init() {
- Register("prev-folder", PrevFolder)
-}
-
-func PrevFolder(aerc *widgets.Aerc, cmd string) error {
- acct := aerc.SelectedAccount()
- acct.Directories().Prev()
- return nil
-}
diff --git a/go.mod b/go.mod
index f70969c9..05f08806 100644
--- a/go.mod
+++ b/go.mod
@@ -7,6 +7,7 @@ require (
github.com/gdamore/encoding v0.0.0-20151215212835-b23993cbb635
github.com/gdamore/tcell v1.0.0
github.com/go-ini/ini v1.32.0
+ github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf
github.com/kyoh86/xdg v0.0.0-20171127140545-8db68a8ea76a
github.com/lucasb-eyer/go-colorful v0.0.0-20180531031333-d9cec903b20c
github.com/mattn/go-isatty v0.0.3
diff --git a/go.sum b/go.sum
index c6e943f7..be1bff13 100644
--- a/go.sum
+++ b/go.sum
@@ -10,6 +10,8 @@ github.com/gdamore/tcell v1.0.0 h1:oaly4AkxvDT5ffKHV/n4L8iy6FxG2QkAVl0M6cjryuE=
github.com/gdamore/tcell v1.0.0/go.mod h1:tqyG50u7+Ctv1w5VX67kLzKcj9YXR/JSBZQq/+mLl1A=
github.com/go-ini/ini v1.32.0 h1:/MArBHSS0TFR28yPPDK1vPIjt4wUnPBfb81i6iiyKvA=
github.com/go-ini/ini v1.32.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
+github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf h1:7+FW5aGwISbqUtkfmIpZJGRgNFg2ioYPvFaUxdqpDsg=
+github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf/go.mod h1:RpwtwJQFrIEPstU94h88MWPXP2ektJZ8cZ0YntAmXiE=
github.com/kyoh86/xdg v0.0.0-20171127140545-8db68a8ea76a h1:vLFQnHOnCnmlySdpHAKF+mH7MhsthJgpBbfexVhHwxY=
github.com/kyoh86/xdg v0.0.0-20171127140545-8db68a8ea76a/go.mod h1:Z5mDqe0fxyxn3W2yTxsBAOQqIrXADQIh02wrTnaRM38=
github.com/lucasb-eyer/go-colorful v0.0.0-20180531031333-d9cec903b20c h1:b11Y3yxg40v2/9KUz76a4mSC1DMlgnPGAt+4pJSgmyU=
diff --git a/widgets/account.go b/widgets/account.go
index dc339cbb..be1e068a 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -115,7 +115,7 @@ func (acct *AccountView) Event(event tcell.Event) bool {
err := acct.runCmd(command)
if err != nil {
acct.statusline.Push(
- fmt.Sprintf("Error: %v", err), 3*time.Second).
+ fmt.Sprintf("Error: %v", err), 10*time.Second).
Color(tcell.ColorRed, tcell.ColorDefault)
}
acct.statusbar.Pop()