summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-20 18:22:36 +0300
committerPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-20 18:22:36 +0300
commit7160f7669b35f89d6a4bedb46aa976ed60ebc3b9 (patch)
tree58693754d3f99842cbb4daab8666a6359f57bfae
parentafad8eec02ca5f0dfd37917c1d4f07399d773604 (diff)
Add debug logging and fix edit for started tasks
-rw-r--r--cmd/tasksamurai/main.go7
-rw-r--r--go.mod2
-rw-r--r--internal/task/task.go23
-rw-r--r--internal/ui/table.go8
4 files changed, 37 insertions, 3 deletions
diff --git a/cmd/tasksamurai/main.go b/cmd/tasksamurai/main.go
index 9b97554..65358e1 100644
--- a/cmd/tasksamurai/main.go
+++ b/cmd/tasksamurai/main.go
@@ -5,6 +5,7 @@ import (
"fmt"
"os"
+ "tasksamurai/internal/task"
"tasksamurai/internal/ui"
tea "github.com/charmbracelet/bubbletea"
@@ -12,8 +13,14 @@ import (
func main() {
filter := flag.String("filter", "", "task filter expression")
+ debugLog := flag.String("debug-log", "", "path to debug log file")
flag.Parse()
+ if err := task.SetDebugLog(*debugLog); err != nil {
+ fmt.Fprintln(os.Stderr, "failed to enable debug log:", err)
+ os.Exit(1)
+ }
+
m, err := ui.New(*filter)
if err != nil {
fmt.Fprintln(os.Stderr, "failed to load tasks:", err)
diff --git a/go.mod b/go.mod
index 9ba3205..c8998a4 100644
--- a/go.mod
+++ b/go.mod
@@ -6,12 +6,12 @@ require (
github.com/charmbracelet/bubbles v0.21.0
github.com/charmbracelet/bubbletea v1.3.5
github.com/charmbracelet/lipgloss v1.1.0
+ github.com/charmbracelet/x/ansi v0.8.0
)
require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
- github.com/charmbracelet/x/ansi v0.8.0 // indirect
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
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 {