summaryrefslogtreecommitdiff
path: root/internal/task
diff options
context:
space:
mode:
authorPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-21 20:25:28 +0300
committerPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-21 20:25:28 +0300
commit273d493170abe8838252c61a40b558ef4edc3db8 (patch)
treeb037cd8b3ee8a89060607f10f5dd8dd77715edd4 /internal/task
parentd1228ab2c5af89a35929ce313c39db9eb076f3e6 (diff)
Add dynamic column widths and overdue sorting
Diffstat (limited to 'internal/task')
-rw-r--r--internal/task/task.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/internal/task/task.go b/internal/task/task.go
index 4acfec9..64dfc0d 100644
--- a/internal/task/task.go
+++ b/internal/task/task.go
@@ -242,7 +242,8 @@ func Edit(id int) error {
// SortTasks orders tasks by start status, priority, due date, tag names and id.
// Started tasks are always placed before non-started ones. Tasks without a due
-// date are placed after tasks with a due date.
+// date are placed after tasks with a due date. Overdue tasks are placed at the
+// very top regardless of other properties.
func SortTasks(tasks []Task) {
joinTags := func(tags []string) string {
if len(tags) == 0 {
@@ -277,9 +278,18 @@ func SortTasks(tasks []Task) {
return t, true
}
+ overdue := func(t Task) bool {
+ du, ok := parseDue(t.Due)
+ return ok && time.Now().After(du)
+ }
+
sort.Slice(tasks, func(i, j int) bool {
ti, tj := tasks[i], tasks[j]
+ if oi, oj := overdue(ti), overdue(tj); oi != oj {
+ return oi
+ }
+
startedI := ti.Start != "" && ti.Status != "completed"
startedJ := tj.Start != "" && tj.Status != "completed"
if startedI != startedJ {