summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-19 23:59:05 +0300
committerPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-19 23:59:05 +0300
commit81fbc1b949f4c5e394e8fc20fa5d4801f338f36e (patch)
tree8bdd31825f08b70b604f5160aad6fdaf024e7acc /cmd
parentbf39c17221d1df1815c9cd78fa33b144c9d5dfb6 (diff)
Add table-based UI and extend task fields
Diffstat (limited to 'cmd')
-rw-r--r--cmd/tasksamurai/main.go66
1 files changed, 51 insertions, 15 deletions
diff --git a/cmd/tasksamurai/main.go b/cmd/tasksamurai/main.go
index 95aef13..424d0d8 100644
--- a/cmd/tasksamurai/main.go
+++ b/cmd/tasksamurai/main.go
@@ -3,12 +3,14 @@ package main
import (
"fmt"
"os"
+ "strconv"
+ "strings"
+ "time"
- "tasksamurai/internal"
"tasksamurai/internal/task"
"tasksamurai/internal/ui"
- "github.com/charmbracelet/bubbles/list"
+ "github.com/charmbracelet/bubbles/table"
tea "github.com/charmbracelet/bubbletea"
)
@@ -19,19 +21,15 @@ func main() {
os.Exit(1)
}
- var items []list.Item
+ var rows []table.Row
for _, t := range tasks {
- if t.Status != "completed" {
- items = append(items, taskItem{t})
+ if t.Status == "completed" {
+ continue
}
+ rows = append(rows, taskToRow(t))
}
- delegate := list.NewDefaultDelegate()
- l := list.New(items, delegate, 0, 0)
- l.Title = fmt.Sprintf("tasksamurai %s", internal.Version)
- l.SetShowStatusBar(false)
- l.SetFilteringEnabled(false)
- m := ui.New(l)
+ m := ui.New(rows)
p := tea.NewProgram(&m)
if _, err := p.Run(); err != nil {
@@ -40,8 +38,46 @@ func main() {
}
}
-type taskItem struct{ t task.Task }
+func taskToRow(t task.Task) table.Row {
+ active := ""
+ if t.Start != "" {
+ active = "yes"
+ }
+
+ age := ""
+ if ts, err := time.Parse("20060102T150405Z", t.Entry); err == nil {
+ days := int(time.Since(ts).Hours() / 24)
+ age = fmt.Sprintf("%dd", days)
+ }
+
+ tags := strings.Join(t.Tags, ",")
+ urg := fmt.Sprintf("%.1f", t.Urgency)
+
+ var anns []string
+ for _, a := range t.Annotations {
+ anns = append(anns, a.Description)
+ }
-func (i taskItem) Title() string { return i.t.Description }
-func (i taskItem) Description() string { return "" }
-func (i taskItem) FilterValue() string { return i.t.Description }
+ return table.Row{
+ strconv.Itoa(t.ID),
+ t.Description,
+ active,
+ age,
+ t.Priority,
+ tags,
+ t.Recur,
+ formatDate(t.Due),
+ urg,
+ strings.Join(anns, "; "),
+ }
+}
+
+func formatDate(s string) string {
+ if s == "" {
+ return ""
+ }
+ if ts, err := time.Parse("20060102T150405Z", s); err == nil {
+ return ts.Format("2006-01-02")
+ }
+ return s
+}