From 7160f7669b35f89d6a4bedb46aa976ed60ebc3b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCtow?= <1224732+snonux@users.noreply.github.com> Date: Fri, 20 Jun 2025 18:22:36 +0300 Subject: Add debug logging and fix edit for started tasks --- internal/task/task.go | 23 +++++++++++++++++++++++ internal/ui/table.go | 8 ++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) (limited to 'internal') diff --git a/internal/task/task.go b/internal/task/task.go index 20a4f48..9b59cfb 100644 --- a/internal/task/task.go +++ b/internal/task/task.go @@ -4,9 +4,12 @@ import ( "bufio" "bytes" "encoding/json" + "fmt" + "io" "os" "os/exec" "strconv" + "strings" ) // Task represents a taskwarrior task as returned by `task export`. @@ -30,6 +33,23 @@ type Task struct { Annotations []Annotation `json:"annotations"` } +var debugWriter io.Writer + +// SetDebugLog enables logging of executed commands to the given file. +// Passing an empty path disables logging. +func SetDebugLog(path string) error { + if path == "" { + debugWriter = nil + return nil + } + f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o644) + if err != nil { + return err + } + debugWriter = f + return nil +} + // Add creates a new task with the given description and tags. func Add(description string, tags []string) error { args := []string{"add"} @@ -79,6 +99,9 @@ func Export(filters ...string) ([]Task, error) { } func run(args ...string) error { + if debugWriter != nil { + fmt.Fprintln(debugWriter, "task "+strings.Join(args, " ")) + } cmd := exec.Command("task", args...) return cmd.Run() } diff --git a/internal/ui/table.go b/internal/ui/table.go index 1136428..3f86376 100644 --- a/internal/ui/table.go +++ b/internal/ui/table.go @@ -6,6 +6,8 @@ import ( "strings" "time" + "github.com/charmbracelet/x/ansi" + tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" @@ -130,13 +132,15 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, tea.Quit case "e", "E": if row := m.tbl.SelectedRow(); row != nil { - if id, err := strconv.Atoi(row[0]); err == nil { + idStr := ansi.Strip(row[0]) + if id, err := strconv.Atoi(idStr); err == nil { return m, editCmd(id) } } case "s": if row := m.tbl.SelectedRow(); row != nil { - if id, err := strconv.Atoi(row[0]); err == nil { + idStr := ansi.Strip(row[0]) + if id, err := strconv.Atoi(idStr); err == nil { started := false for _, tsk := range m.tasks { if tsk.ID == id { -- cgit v1.2.3