diff options
author | Reto Brunner <reto@labrat.space> | 2019-12-18 06:34:00 +0100 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-12-21 09:27:50 -0500 |
commit | 881a9081a850f39294ed97c10a1a50f8d852c9a5 (patch) | |
tree | 1eeffb2dea2d4dadfa80c92e3e76f8df42dbda71 /commands/util.go | |
parent | cf43066d5b8bbe991bef8280bbbeeb13059585b6 (diff) | |
download | aerc-881a9081a850f39294ed97c10a1a50f8d852c9a5.tar.gz |
add command helpers
Diffstat (limited to 'commands/util.go')
-rw-r--r-- | commands/util.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/commands/util.go b/commands/util.go index a5c30af2..5529edb0 100644 --- a/commands/util.go +++ b/commands/util.go @@ -10,6 +10,7 @@ import ( "strings" "time" + "git.sr.ht/~sircmpwn/aerc/models" "git.sr.ht/~sircmpwn/aerc/widgets" "github.com/gdamore/tcell" "github.com/mitchellh/go-homedir" @@ -148,3 +149,32 @@ func listDir(path string, hidden bool) []string { return filtered } + +// MarkedOrSelected returns either all marked messages if any are marked or the +// selected message instead +func MarkedOrSelected(pm widgets.ProvidesMessages) ([]*models.MessageInfo, error) { + // marked has priority over the selected message + marked, err := pm.MarkedMessages() + if err != nil { + return nil, err + } + if len(marked) > 0 { + return marked, nil + } + msg, err := pm.SelectedMessage() + if err != nil { + return nil, err + } + return []*models.MessageInfo{msg}, nil +} + +// UidsFromMessageInfos extracts a uid slice from a slice of MessageInfos +func UidsFromMessageInfos(msgs []*models.MessageInfo) []uint32 { + uids := make([]uint32, len(msgs)) + i := 0 + for _, msg := range msgs { + uids[i] = msg.Uid + i++ + } + return uids +} |