diff options
author | Jeffas <dev@jeffas.io> | 2019-09-19 23:37:44 +0100 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-09-20 14:56:02 -0400 |
commit | 90d26da58a4af2d34328f5916adf3781222966c6 (patch) | |
tree | 58a60e0d42b183f94d12b35e19ed1b046d03d5cd /lib/sort | |
parent | 43435ba06cd0820a83f14630881981b338473cb8 (diff) | |
download | aerc-90d26da58a4af2d34328f5916adf3781222966c6.tar.gz |
Add sorting functionality
There is a command and config option. The criteria are a list of the
sort criterion and each can be individually reversed.
This only includes support for sorting in the maildir backend currently.
The other backends are not supported in this patch.
Diffstat (limited to 'lib/sort')
-rw-r--r-- | lib/sort/sort.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/sort/sort.go b/lib/sort/sort.go new file mode 100644 index 00000000..89c36a90 --- /dev/null +++ b/lib/sort/sort.go @@ -0,0 +1,56 @@ +package sort + +import ( + "errors" + "fmt" + "strings" + + "git.sr.ht/~sircmpwn/aerc/worker/types" +) + +func GetSortCriteria(args []string) ([]*types.SortCriterion, error) { + var sortCriteria []*types.SortCriterion + reverse := false + for _, arg := range args { + if arg == "-r" { + reverse = true + continue + } + field, err := parseSortField(arg) + if err != nil { + return nil, err + } + sortCriteria = append(sortCriteria, &types.SortCriterion{ + Field: field, + Reverse: reverse, + }) + reverse = false + } + if reverse { + return nil, errors.New("Expected argument to reverse") + } + return sortCriteria, nil +} + +func parseSortField(arg string) (types.SortField, error) { + switch strings.ToLower(arg) { + case "arrival": + return types.SortArrival, nil + case "cc": + return types.SortCc, nil + case "date": + return types.SortDate, nil + case "from": + return types.SortFrom, nil + case "read": + return types.SortRead, nil + case "size": + return types.SortSize, nil + case "subject": + return types.SortSubject, nil + case "to": + return types.SortTo, nil + default: + return types.SortArrival, fmt.Errorf("%v is not a valid sort criterion", arg) + } +} |