Integrate tasktable

This commit is contained in:
Martin Pander
2026-02-26 22:49:00 +01:00
parent 9eda92503e
commit f6ce2e30dc
8 changed files with 778 additions and 109 deletions

View File

@@ -5,6 +5,8 @@ import (
"strconv"
"strings"
"image/color"
"fmt"
"time"
"tasksquire/internal/taskwarrior"
@@ -82,10 +84,10 @@ func NewStyles(config *taskwarrior.TWConfig) *Styles {
styles.Base = lipgloss.NewStyle().Foreground(styles.Palette.Text.GetForeground())
styles.TableStyle = TableStyle{
// Header: lipgloss.NewStyle().Bold(true).Padding(0, 1).BorderBottom(true),
Cell: lipgloss.NewStyle().Padding(0, 1, 0, 0),
Header: lipgloss.NewStyle().Bold(true).Padding(0, 1, 0, 0).Underline(true).Foreground(styles.Palette.Primary.GetForeground()),
Selected: lipgloss.NewStyle().Bold(true).Reverse(true).Foreground(styles.Palette.Accent.GetForeground()),
// Selected: lipgloss.NewStyle().Bold(true).Reverse(true).Foreground(styles.Palette.Accent.GetForeground()),
Selected: lipgloss.NewStyle().Bold(true).Reverse(true),
}
// formTheme := huh.ThemeBase()
@@ -232,3 +234,77 @@ var colorStrings = map[string]int{
"bright cyan": 14,
"bright white": 15,
}
func GetTaskTabelStyle(task *taskwarrior.Task, com Common) lipgloss.Style {
if task.Status == "deleted" {
if c, ok := com.Styles.Colors["deleted"]; ok && c != nil {
return c.Inherit(com.Styles.TableStyle.Cell).Margin(com.Styles.TableStyle.Cell.GetMargin()).Padding(com.Styles.TableStyle.Cell.GetPadding())
}
}
if task.Status == "completed" {
if c, ok := com.Styles.Colors["completed"]; ok && c != nil {
return c.Inherit(com.Styles.TableStyle.Cell).Margin(com.Styles.TableStyle.Cell.GetMargin()).Padding(com.Styles.TableStyle.Cell.GetPadding())
}
}
if task.Status == "pending" && task.Start != "" {
if c, ok := com.Styles.Colors["active"]; ok && c != nil {
return c.Inherit(com.Styles.TableStyle.Cell).Margin(com.Styles.TableStyle.Cell.GetMargin()).Padding(com.Styles.TableStyle.Cell.GetPadding())
}
}
// TODO: implement keyword
// TODO: implement tag
if task.HasTag("next") {
if c, ok := com.Styles.Colors["tag.next"]; ok && c != nil {
return c.Inherit(com.Styles.TableStyle.Cell).Margin(com.Styles.TableStyle.Cell.GetMargin()).Padding(com.Styles.TableStyle.Cell.GetPadding())
}
}
// TODO: implement project
if !task.GetDate("due").IsZero() && task.GetDate("due").Before(time.Now()) {
if c, ok := com.Styles.Colors["overdue"]; ok && c != nil {
return c.Inherit(com.Styles.TableStyle.Cell).Margin(com.Styles.TableStyle.Cell.GetMargin()).Padding(com.Styles.TableStyle.Cell.GetPadding())
}
}
if task.Scheduled != "" {
if c, ok := com.Styles.Colors["scheduled"]; ok && c != nil {
return c.Inherit(com.Styles.TableStyle.Cell).Margin(com.Styles.TableStyle.Cell.GetMargin()).Padding(com.Styles.TableStyle.Cell.GetPadding())
}
}
if !task.GetDate("due").IsZero() && task.GetDate("due").Truncate(24*time.Hour).Equal(time.Now().Truncate(24*time.Hour)) {
if c, ok := com.Styles.Colors["due.today"]; ok && c != nil {
return c.Inherit(com.Styles.TableStyle.Cell).Margin(com.Styles.TableStyle.Cell.GetMargin()).Padding(com.Styles.TableStyle.Cell.GetPadding())
}
}
if task.Due != "" {
if c, ok := com.Styles.Colors["due"]; ok && c != nil {
return c.Inherit(com.Styles.TableStyle.Cell).Margin(com.Styles.TableStyle.Cell.GetMargin()).Padding(com.Styles.TableStyle.Cell.GetPadding())
}
}
if len(task.Depends) > 0 {
if c, ok := com.Styles.Colors["blocked"]; ok && c != nil {
return c.Inherit(com.Styles.TableStyle.Cell).Margin(com.Styles.TableStyle.Cell.GetMargin()).Padding(com.Styles.TableStyle.Cell.GetPadding())
}
}
// TODO implement blocking
if task.Recur != "" {
if c, ok := com.Styles.Colors["recurring"]; ok && c != nil {
return c.Inherit(com.Styles.TableStyle.Cell).Margin(com.Styles.TableStyle.Cell.GetMargin()).Padding(com.Styles.TableStyle.Cell.GetPadding())
}
}
// TODO: make styles optional and discard if empty
if len(task.Tags) > 0 {
if c, ok := com.Styles.Colors["tagged"]; ok && c != nil {
return c.Inherit(com.Styles.TableStyle.Cell).Margin(com.Styles.TableStyle.Cell.GetMargin()).Padding(com.Styles.TableStyle.Cell.GetPadding())
}
}
if len(com.Udas) > 0 {
for _, uda := range com.Udas {
if u, ok := task.Udas[uda.Name]; ok {
if c, ok := com.Styles.Colors[fmt.Sprintf("uda.%s.%s", uda.Name, u)]; ok {
return c.Inherit(com.Styles.TableStyle.Cell).Margin(com.Styles.TableStyle.Cell.GetMargin()).Padding(com.Styles.TableStyle.Cell.GetPadding())
}
}
}
}
return com.Styles.Base.Inherit(com.Styles.TableStyle.Cell).Margin(com.Styles.TableStyle.Cell.GetMargin()).Padding(com.Styles.TableStyle.Cell.GetPadding())
}