Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,9 @@ reloads it afterwards. In Vim mode, `Ctrl+Z` suspends to the shell.
note titles, `!priority`, `#tags` and `@fields`. `:filters` / `:savefilter`
manage shared named queries. Prefix terminal operators with `where:`,
for example `where: is:open due:today -meeting`.
A task with `@repeat:` in a daily note counts from the date of that note,
as in the desktop app. The menu item Skip this time (`n`) cancels one
occurrence and writes the next.
The calendar has month, week and day views; `Esc` cycles them, and a
start in `calendar` mode always opens the month grid. On a narrow
terminal the month shows a compact grid with a count per day and the
Expand Down
59 changes: 59 additions & 0 deletions internal/cli/tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"slices"
"strings"
"testing"
"time"

"github.com/ZenNotes/tui/internal/vault"
)

// A `[-]` cancelled task is abandoned, so `zn task list` leaves it out by
Expand Down Expand Up @@ -77,3 +80,59 @@ func TestTaskTogglePrintsWhereARecurringTaskWent(t *testing.T) {
t.Fatalf("%q", data)
}
}

// The CLI counts a recurring task from today, as the app's MCP does, even in a
// daily note: only the terminal app counts from the date of the note. The note
// is three days old, so a weekly step from its date differs from one from today
// on every day.
func TestTaskToggleCountsARecurringTaskFromTodayInADailyNote(t *testing.T) {
isolatedCLI(t)
root := t.TempDir()
// Read once before the command runs; a run that crosses midnight counts
// from the next day.
start := time.Now()
noteDate := vault.TodayISO(start.AddDate(0, 0, -3))
rel := "Daily Notes/" + noteDate + ".md"
const body = "- [ ] water @repeat:7d\n"
files := map[string]string{
".zennotes/vault.json": `{"primaryNotesLocation":"root","dailyNotes":{"enabled":true}}`,
rel: body,
}
for name, text := range files {
abs := filepath.Join(root, filepath.FromSlash(name))
if err := os.MkdirAll(filepath.Dir(abs), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(abs, []byte(text), 0o644); err != nil {
t.Fatal(err)
}
}
captureOutput(t, func() {
if code := Main([]string{"task", "toggle", rel + "#0", "--vault", root}); code != 0 {
t.Fatalf("exit %d", code)
}
})
data, err := os.ReadFile(filepath.Join(root, filepath.FromSlash(rel)))
if err != nil {
t.Fatal(err)
}
roll := func(day time.Time, fallback string) string {
done, ok := vault.CompleteRecurringTaskAtIndex(body, 0, vault.DialectCLI, vault.RecurringOptions{Today: vault.TodayISO(day), FallbackDue: fallback})
if !ok {
t.Fatal("the task does not repeat")
}
return done.Body
}
counted := false
for _, day := range []time.Time{start, start.AddDate(0, 0, 1)} {
if string(data) == roll(day, "") {
counted = true
}
if string(data) == roll(day, noteDate) {
t.Fatalf("note counts from the note date %s: %q", noteDate, data)
}
}
if !counted {
t.Fatalf("note = %q, want a roll from today", data)
}
}
18 changes: 18 additions & 0 deletions internal/tui/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,24 @@ func (a *App) dailyDueByPath() map[string]string {
return out
}

// dailyDueOfPath is the date of the daily note at path. It is empty when the
// note is not a daily note, or when the settings do not count a task from the
// date of its note.
func (a *App) dailyDueOfPath(path string) string {
if a.idx == nil || !a.idx.settings.DailyNotes.Enabled || !a.idx.settings.DailyNotes.TasksDueOnNoteDate {
return ""
}
n, ok := a.noteMeta(path)
if !ok || n.Folder != vault.FolderInbox {
return ""
}
_, sub := a.folderOfPath(n.Path)
if date, ok := periodic.DateOf(periodic.Daily, sub, n.Title, a.idx.settings, a.primaryAtRoot()); ok {
return date.Format("2006-01-02")
}
return ""
}

// displayTasks are the tasks the Tasks surfaces show: daily-note due
// inference applied, archived notes retired unless the preference keeps them.
func (a *App) displayTasks() []vault.Task {
Expand Down
2 changes: 1 addition & 1 deletion internal/tui/helpdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func helpLines(a *App, filter string) []string {
"J K\tMove the task up or down inside its note (list in note order)",
"O / :order\tList order: note order or priority (high first in each group); shared with the desktop's Order menu via tasks_list_order",
"n f F A\tNew task in the daily note, filter, clear the filter, include archived",
"m\tTask menu (includes forward to today's daily note)",
"m\tTask menu (includes forward to today's daily note, and Skip this time for a task with @repeat:)",
"Board: h l j k\tMove between columns and cards; H L move the card; g cycles the grouping",
"Calendar: h j k l [ ] t\tMove days and months, t is today; Esc cycles month, week and day; Enter and Tab move focus to the day's tasks and the No-date strip; o opens the daily note",
"Calendar task: T @\tMove the focused task to today; pick its due date from a menu",
Expand Down
Loading
Loading