diff options
author | Drew DeVault <sir@cmpwn.com> | 2019-03-21 16:30:23 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-03-21 16:30:23 -0400 |
commit | 8126d82956636a2525263e2d0d985d721fdb8074 (patch) | |
tree | 2c5f5c2e2fb2e5ecfb4c12eb8ef6bc575edc39f8 /commands/account | |
parent | fe79a9a5879936a7f5b16cc6a8be1d93ec1bfae7 (diff) |
Add context-specific commands
Diffstat (limited to 'commands/account')
-rw-r--r-- | commands/account/account.go | 16 | ||||
-rw-r--r-- | commands/account/cf.go | 38 | ||||
-rw-r--r-- | commands/account/delete-message.go | 25 | ||||
-rw-r--r-- | commands/account/next-folder.go | 46 | ||||
-rw-r--r-- | commands/account/next-message.go | 55 | ||||
-rw-r--r-- | commands/account/select-message.go | 34 |
6 files changed, 214 insertions, 0 deletions
diff --git a/commands/account/account.go b/commands/account/account.go new file mode 100644 index 0000000..918d962 --- /dev/null +++ b/commands/account/account.go @@ -0,0 +1,16 @@ +package account + +import ( + "git.sr.ht/~sircmpwn/aerc2/commands" +) + +var ( + AccountCommands *commands.Commands +) + +func register(name string, cmd commands.AercCommand) { + if AccountCommands == nil { + AccountCommands = commands.NewCommands() + } + AccountCommands.Register(name, cmd) +} diff --git a/commands/account/cf.go b/commands/account/cf.go new file mode 100644 index 0000000..3d12b5c --- /dev/null +++ b/commands/account/cf.go @@ -0,0 +1,38 @@ +package account + +import ( + "errors" + + "git.sr.ht/~sircmpwn/aerc2/widgets" +) + +var ( + history map[string]string +) + +func init() { + history = make(map[string]string) + register("cf", ChangeFolder) +} + +func ChangeFolder(aerc *widgets.Aerc, args []string) error { + if len(args) != 2 { + return errors.New("Usage: cf <folder>") + } + acct := aerc.SelectedAccount() + if acct == nil { + return errors.New("No account selected") + } + previous := acct.Directories().Selected() + if args[1] == "-" { + if dir, ok := history[acct.Name()]; ok { + acct.Directories().Select(dir) + } else { + return errors.New("No previous folder to return to") + } + } else { + acct.Directories().Select(args[1]) + } + history[acct.Name()] = previous + return nil +} diff --git a/commands/account/delete-message.go b/commands/account/delete-message.go new file mode 100644 index 0000000..40e3bba --- /dev/null +++ b/commands/account/delete-message.go @@ -0,0 +1,25 @@ +package account + +import ( + "errors" + + "git.sr.ht/~sircmpwn/aerc2/widgets" +) + +func init() { + register("delete-message", DeleteMessage) +} + +func DeleteMessage(aerc *widgets.Aerc, args []string) error { + if len(args) != 1 { + return errors.New("Usage: :delete-message") + } + acct := aerc.SelectedAccount() + if acct == nil { + return errors.New("No account selected") + } + store := acct.Messages().Store() + msg := acct.Messages().Selected() + store.Delete([]uint32{msg.Uid}) + return nil +} diff --git a/commands/account/next-folder.go b/commands/account/next-folder.go new file mode 100644 index 0000000..1b59af1 --- /dev/null +++ b/commands/account/next-folder.go @@ -0,0 +1,46 @@ +package account + +import ( + "errors" + "fmt" + "strconv" + + "git.sr.ht/~sircmpwn/aerc2/widgets" +) + +func init() { + register("next-folder", NextPrevFolder) + register("prev-folder", NextPrevFolder) +} + +func nextPrevFolderUsage(cmd string) error { + return errors.New(fmt.Sprintf("Usage: %s [n]", cmd)) +} + +func NextPrevFolder(aerc *widgets.Aerc, args []string) error { + if len(args) > 2 { + return nextPrevFolderUsage(args[0]) + } + var ( + n int = 1 + err error + ) + if len(args) > 1 { + n, err = strconv.Atoi(args[1]) + if err != nil { + return nextPrevFolderUsage(args[0]) + } + } + acct := aerc.SelectedAccount() + if acct == nil { + return errors.New("No account selected") + } + for ; n > 0; n-- { + if args[0] == "prev-folder" { + acct.Directories().Prev() + } else { + acct.Directories().Next() + } + } + return nil +} diff --git a/commands/account/next-message.go b/commands/account/next-message.go new file mode 100644 index 0000000..d2c006f --- /dev/null +++ b/commands/account/next-message.go @@ -0,0 +1,55 @@ +package account + +import ( + "errors" + "fmt" + "strconv" + "strings" + + "git.sr.ht/~sircmpwn/aerc2/widgets" +) + +func init() { + register("next-message", NextPrevMessage) + register("prev-message", NextPrevMessage) +} + +func nextPrevMessageUsage(cmd string) error { + return errors.New(fmt.Sprintf("Usage: %s [<n>[%%]]", cmd)) +} + +func NextPrevMessage(aerc *widgets.Aerc, args []string) error { + if len(args) > 2 { + return nextPrevMessageUsage(args[0]) + } + var ( + n int = 1 + err error + pct bool + ) + if len(args) > 1 { + if strings.HasSuffix(args[1], "%") { + pct = true + args[1] = args[1][:len(args[1])-1] + } + n, err = strconv.Atoi(args[1]) + if err != nil { + return nextPrevMessageUsage(args[0]) + } + } + acct := aerc.SelectedAccount() + if acct == nil { + return errors.New("No account selected") + } + if pct { + n = int(float64(acct.Messages().Height()) * (float64(n) / 100.0)) + } + for ; n > 0; n-- { + if args[0] == "prev-message" { + acct.Messages().Prev() + } else { + acct.Messages().Next() + } + } + return nil +} diff --git a/commands/account/select-message.go b/commands/account/select-message.go new file mode 100644 index 0000000..54f48f2 --- /dev/null +++ b/commands/account/select-message.go @@ -0,0 +1,34 @@ +package account + +import ( + "errors" + "strconv" + + "git.sr.ht/~sircmpwn/aerc2/widgets" +) + +func init() { + register("select-message", SelectMessage) +} + +func SelectMessage(aerc *widgets.Aerc, args []string) error { + if len(args) != 2 { + return errors.New("Usage: :select-message <n>") + } + var ( + n int = 1 + err error + ) + if len(args) > 1 { + n, err = strconv.Atoi(args[1]) + if err != nil { + return errors.New("Usage: :select-message <n>") + } + } + acct := aerc.SelectedAccount() + if acct == nil { + return errors.New("No account selected") + } + acct.Messages().Select(n) + return nil +} |