Experimental feature: Sorting the queue entries

This commit is contained in:
Jan Philipp Timme 2019-01-01 02:45:08 +01:00
parent 3d893015a3
commit dd47907270
1 changed files with 16 additions and 0 deletions

16
main.go
View File

@ -6,6 +6,7 @@ import (
"io" "io"
"os" "os"
"os/exec" "os/exec"
"sort"
"strconv" "strconv"
) )
@ -49,6 +50,21 @@ func showQueue() {
fmt.Printf("Could not fetch queue entries: %s\n", err.Error()) fmt.Printf("Could not fetch queue entries: %s\n", err.Error())
os.Exit(1) os.Exit(1)
} }
// Experiment: Sort queue by Date
sort.Slice(queue.Entries, func(a int, b int) bool {
//var sortBy []string = []string{"Status", "Sender", "Date"}
//for _, sortAttribute := range sortBy {
//if sort attributes are equal continue
//else return a < b
//}
if queue.Entries[a].Date.Equal(queue.Entries[b].Date) {
return queue.Entries[a].Sender > queue.Entries[b].Sender
} else {
return queue.Entries[a].Date.Before(queue.Entries[b].Date)
}
})
if settings["usePager"] == "true" { if settings["usePager"] == "true" {
pagerReader, pagerWriter := io.Pipe() pagerReader, pagerWriter := io.Pipe()
pagerDone := make(chan bool) pagerDone := make(chan bool)