From e910517fd39c1508e6868520d3a9b4ac4461c289 Mon Sep 17 00:00:00 2001 From: Erik Winter Date: Sun, 5 Jan 2025 08:29:10 +0100 Subject: [PATCH] list formatting --- plan/command/list.go | 47 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/plan/command/list.go b/plan/command/list.go index 2ea8810..c86458d 100644 --- a/plan/command/list.go +++ b/plan/command/list.go @@ -136,15 +136,46 @@ type ListResult struct { } func (lr ListResult) Render() string { - data := [][]string{{"id", "project", "date", "dur", "title"}} + var showRec, showDur bool for _, tl := range lr.Tasks { - data = append(data, []string{ - fmt.Sprintf("%d", tl.LocalID), - tl.Task.Project, - tl.Task.Date.String(), - tl.Task.Duration.String(), - tl.Task.Title, - }) + if tl.Task.Recurrer != nil { + showRec = true + } + if tl.Task.Duration > time.Duration(0) { + showDur = true + } + } + + title := []string{"id"} + if showRec { + title = append(title, "rec") + } + title = append(title, "project", "date") + if showDur { + title = append(title, "dur") + } + title = append(title, "title") + + data := [][]string{title} + for _, tl := range lr.Tasks { + row := []string{fmt.Sprintf("%d", tl.LocalID)} + if showRec { + recStr := "" + if tl.Task.Recurrer != nil { + recStr = "*" + } + row = append(row, recStr) + } + row = append(row, tl.Task.Project, tl.Task.Date.String()) + if showDur { + durStr := "" + if tl.Task.Duration > time.Duration(0) { + durStr = tl.Task.Duration.String() + } + row = append(row, durStr) + } + row = append(row, tl.Task.Title) + data = append(data, row) } return fmt.Sprintf("\n%s\n", format.Table(data))