aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2019-12-18 06:34:01 +0100
committerDrew DeVault <sir@cmpwn.com>2019-12-21 09:27:50 -0500
commit5da58c669ce516f7ebe2f6db7b9b30d43e31311d (patch)
tree9623b0cf02e3b059135fd8eec6aacc83c65cb1d1
parent881a9081a850f39294ed97c10a1a50f8d852c9a5 (diff)
downloadaerc-5da58c669ce516f7ebe2f6db7b9b30d43e31311d.tar.gz
add mark command
-rw-r--r--commands/msg/mark.go98
1 files changed, 98 insertions, 0 deletions
diff --git a/commands/msg/mark.go b/commands/msg/mark.go
new file mode 100644
index 00000000..6738a5e0
--- /dev/null
+++ b/commands/msg/mark.go
@@ -0,0 +1,98 @@
+package msg
+
+import (
+ "fmt"
+
+ "git.sr.ht/~sircmpwn/aerc/widgets"
+ "git.sr.ht/~sircmpwn/getopt"
+)
+
+type Mark struct{}
+
+func init() {
+ register(Mark{})
+}
+
+func (Mark) Aliases() []string {
+ return []string{"mark", "unmark"}
+}
+
+func (Mark) Complete(aerc *widgets.Aerc, args []string) []string {
+ return nil
+}
+
+func (Mark) Execute(aerc *widgets.Aerc, args []string) error {
+ h := newHelper(aerc)
+ selected, err := h.msgProvider.SelectedMessage()
+ if err != nil {
+ return err
+ }
+ store, err := h.store()
+ if err != nil {
+ return err
+ }
+ opts, _, err := getopt.Getopts(args, "atv")
+ if err != nil {
+ return err
+ }
+ var all bool
+ var toggle bool
+ var visual bool
+ for _, opt := range opts {
+ switch opt.Option {
+ case 'a':
+ all = true
+ case 'v':
+ visual = true
+ case 't':
+ toggle = true
+ }
+ }
+
+ switch args[0] {
+ case "mark":
+ if all && visual {
+ return fmt.Errorf("-a and -v are mutually exclusive")
+ }
+
+ var modFunc func(uint32)
+ if toggle {
+ modFunc = store.ToggleMark
+ } else {
+ modFunc = store.Mark
+ }
+ if all {
+ uids := store.Uids()
+ for _, uid := range uids {
+ modFunc(uid)
+ }
+ return nil
+ } else if visual {
+ store.ToggleVisualMark()
+ return nil
+ } else {
+ modFunc(selected.Uid)
+ return nil
+ }
+
+ case "unmark":
+ if visual {
+ return fmt.Errorf("visual mode not suported for this command")
+ }
+
+ if all && toggle {
+ uids := store.Uids()
+ for _, uid := range uids {
+ store.ToggleMark(uid)
+ }
+ return nil
+ } else if all && !toggle {
+ store.ClearVisualMark()
+ return nil
+ } else {
+ store.Unmark(selected.Uid)
+ return nil
+ }
+ }
+ return nil // never reached
+}