diff --git a/cmd/cli/format/format.go b/cmd/cli/format/format.go index 20c8d6a..8284192 100644 --- a/cmd/cli/format/format.go +++ b/cmd/cli/format/format.go @@ -16,7 +16,7 @@ func FormatTaskTable(tasks []*task.LocalTask) string { return "no tasks to display\n" } - sort.Sort(task.ByDue(tasks)) + sort.Sort(task.ByDefault(tasks)) var output string for _, t := range tasks { diff --git a/internal/task/localtask.go b/internal/task/localtask.go index ab5a72b..80d0258 100644 --- a/internal/task/localtask.go +++ b/internal/task/localtask.go @@ -35,6 +35,22 @@ func (lt ByDue) Len() int { return len(lt) } func (lt ByDue) Swap(i, j int) { lt[i], lt[j] = lt[j], lt[i] } func (lt ByDue) Less(i, j int) bool { return lt[j].Due.After(lt[i].Due) } +type ByDefault []*LocalTask + +func (lt ByDefault) Len() int { return len(lt) } +func (lt ByDefault) Swap(i, j int) { lt[i], lt[j] = lt[j], lt[i] } +func (lt ByDefault) Less(i, j int) bool { + if !lt[j].Due.Equal(lt[i].Due) { + return lt[j].Due.After(lt[i].Due) + } + + if lt[i].Project != lt[j].Project { + return lt[i].Project < lt[j].Project + } + + return lt[i].LocalId < lt[j].LocalId +} + type LocalUpdate struct { Action string Project string