From dd4790727096d236dc739a38003bb219436563dd Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Tue, 1 Jan 2019 02:45:08 +0100 Subject: [PATCH] Experimental feature: Sorting the queue entries --- main.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/main.go b/main.go index 5d99744..150f2c4 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "io" "os" "os/exec" + "sort" "strconv" ) @@ -49,6 +50,21 @@ func showQueue() { fmt.Printf("Could not fetch queue entries: %s\n", err.Error()) 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" { pagerReader, pagerWriter := io.Pipe() pagerDone := make(chan bool)