From 455c6f0b774bb5e37906dd3fb8c786892f0b1519 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 19 May 2019 18:23:34 -0400 Subject: Rename :delete-message et al to :delete et al --- commands/account/delete-message.go | 38 ------------------------- commands/account/delete.go | 39 ++++++++++++++++++++++++++ commands/account/next-message.go | 55 ------------------------------------ commands/account/next.go | 57 ++++++++++++++++++++++++++++++++++++++ commands/account/select-message.go | 37 ------------------------- commands/account/select.go | 37 +++++++++++++++++++++++++ commands/account/view-message.go | 29 ------------------- commands/account/view.go | 30 ++++++++++++++++++++ 8 files changed, 163 insertions(+), 159 deletions(-) delete mode 100644 commands/account/delete-message.go create mode 100644 commands/account/delete.go delete mode 100644 commands/account/next-message.go create mode 100644 commands/account/next.go delete mode 100644 commands/account/select-message.go create mode 100644 commands/account/select.go delete mode 100644 commands/account/view-message.go create mode 100644 commands/account/view.go (limited to 'commands') diff --git a/commands/account/delete-message.go b/commands/account/delete-message.go deleted file mode 100644 index d6b669e..0000000 --- a/commands/account/delete-message.go +++ /dev/null @@ -1,38 +0,0 @@ -package account - -import ( - "errors" - "time" - - "github.com/gdamore/tcell" - - "git.sr.ht/~sircmpwn/aerc/widgets" - "git.sr.ht/~sircmpwn/aerc/worker/types" -) - -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() - acct.Messages().Next() - store.Delete([]uint32{msg.Uid}, func(msg types.WorkerMessage) { - switch msg := msg.(type) { - case *types.Done: - aerc.PushStatus("Messages deleted.", 10*time.Second) - case *types.Error: - aerc.PushStatus(" "+msg.Error.Error(), 10*time.Second). - Color(tcell.ColorDefault, tcell.ColorRed) - } - }) - return nil -} diff --git a/commands/account/delete.go b/commands/account/delete.go new file mode 100644 index 0000000..65d6eb9 --- /dev/null +++ b/commands/account/delete.go @@ -0,0 +1,39 @@ +package account + +import ( + "errors" + "time" + + "github.com/gdamore/tcell" + + "git.sr.ht/~sircmpwn/aerc/widgets" + "git.sr.ht/~sircmpwn/aerc/worker/types" +) + +func init() { + register("delete", DeleteMessage) + register("delete-message", DeleteMessage) +} + +func DeleteMessage(aerc *widgets.Aerc, args []string) error { + if len(args) != 1 { + return errors.New("Usage: :delete") + } + acct := aerc.SelectedAccount() + if acct == nil { + return errors.New("No account selected") + } + store := acct.Messages().Store() + msg := acct.Messages().Selected() + acct.Messages().Next() + store.Delete([]uint32{msg.Uid}, func(msg types.WorkerMessage) { + switch msg := msg.(type) { + case *types.Done: + aerc.PushStatus("Messages deleted.", 10*time.Second) + case *types.Error: + aerc.PushStatus(" "+msg.Error.Error(), 10*time.Second). + Color(tcell.ColorDefault, tcell.ColorRed) + } + }) + return nil +} diff --git a/commands/account/next-message.go b/commands/account/next-message.go deleted file mode 100644 index f13ea5a..0000000 --- a/commands/account/next-message.go +++ /dev/null @@ -1,55 +0,0 @@ -package account - -import ( - "errors" - "fmt" - "strconv" - "strings" - - "git.sr.ht/~sircmpwn/aerc/widgets" -) - -func init() { - register("next-message", NextPrevMessage) - register("prev-message", NextPrevMessage) -} - -func nextPrevMessageUsage(cmd string) error { - return errors.New(fmt.Sprintf("Usage: %s [[%%]]", 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/next.go b/commands/account/next.go new file mode 100644 index 0000000..7e8541f --- /dev/null +++ b/commands/account/next.go @@ -0,0 +1,57 @@ +package account + +import ( + "errors" + "fmt" + "strconv" + "strings" + + "git.sr.ht/~sircmpwn/aerc/widgets" +) + +func init() { + register("next", NextPrevMessage) + register("next-message", NextPrevMessage) + register("prev", NextPrevMessage) + register("prev-message", NextPrevMessage) +} + +func nextPrevMessageUsage(cmd string) error { + return errors.New(fmt.Sprintf("Usage: %s [[%%]]", 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" || args[0] == "prev" { + acct.Messages().Prev() + } else { + acct.Messages().Next() + } + } + return nil +} diff --git a/commands/account/select-message.go b/commands/account/select-message.go deleted file mode 100644 index bd44c1b..0000000 --- a/commands/account/select-message.go +++ /dev/null @@ -1,37 +0,0 @@ -package account - -import ( - "errors" - "strconv" - - "git.sr.ht/~sircmpwn/aerc/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 ") - } - 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 ") - } - } - acct := aerc.SelectedAccount() - if acct == nil { - return errors.New("No account selected") - } - if acct.Messages().Empty() { - return nil - } - acct.Messages().Select(n) - return nil -} diff --git a/commands/account/select.go b/commands/account/select.go new file mode 100644 index 0000000..bd44c1b --- /dev/null +++ b/commands/account/select.go @@ -0,0 +1,37 @@ +package account + +import ( + "errors" + "strconv" + + "git.sr.ht/~sircmpwn/aerc/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 ") + } + 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 ") + } + } + acct := aerc.SelectedAccount() + if acct == nil { + return errors.New("No account selected") + } + if acct.Messages().Empty() { + return nil + } + acct.Messages().Select(n) + return nil +} diff --git a/commands/account/view-message.go b/commands/account/view-message.go deleted file mode 100644 index 4db5c95..0000000 --- a/commands/account/view-message.go +++ /dev/null @@ -1,29 +0,0 @@ -package account - -import ( - "errors" - - "git.sr.ht/~sircmpwn/aerc/widgets" -) - -func init() { - register("view-message", ViewMessage) -} - -func ViewMessage(aerc *widgets.Aerc, args []string) error { - if len(args) != 1 { - return errors.New("Usage: view-message") - } - acct := aerc.SelectedAccount() - if acct.Messages().Empty() { - return nil - } - store := acct.Messages().Store() - msg := acct.Messages().Selected() - if msg == nil { - return nil - } - viewer := widgets.NewMessageViewer(aerc.Config(), store, msg) - aerc.NewTab(viewer, msg.Envelope.Subject) - return nil -} diff --git a/commands/account/view.go b/commands/account/view.go new file mode 100644 index 0000000..40abec3 --- /dev/null +++ b/commands/account/view.go @@ -0,0 +1,30 @@ +package account + +import ( + "errors" + + "git.sr.ht/~sircmpwn/aerc/widgets" +) + +func init() { + register("view", ViewMessage) + register("view-message", ViewMessage) +} + +func ViewMessage(aerc *widgets.Aerc, args []string) error { + if len(args) != 1 { + return errors.New("Usage: view-message") + } + acct := aerc.SelectedAccount() + if acct.Messages().Empty() { + return nil + } + store := acct.Messages().Store() + msg := acct.Messages().Selected() + if msg == nil { + return nil + } + viewer := widgets.NewMessageViewer(aerc.Config(), store, msg) + aerc.NewTab(viewer, msg.Envelope.Subject) + return nil +} -- cgit v1.2.3