aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-11 23:05:34 -0400
committerhistoria <[not public]>2026-06-11 23:05:34 -0400
commit6b559be14142bf89b971159fb969c8e414807b20 (patch)
tree3801901c306c23eefdc8658406699559abd54ed8
parent05d4fa5e4ccadc8521dc7bc3a2f4bc01ebafd40b (diff)
downloadsoon-6b559be14142bf89b971159fb969c8e414807b20.tar.gz
fix: todo behavior with tui works now
-rw-r--r--soon.conf.example2
-rw-r--r--src/soon.nim4
-rw-r--r--src/soon/archive.nim27
-rw-r--r--src/soon/config.nim4
-rw-r--r--src/soon/todos.nim23
-rw-r--r--src/soon/tui.nim19
6 files changed, 20 insertions, 59 deletions
diff --git a/soon.conf.example b/soon.conf.example
index af0d69f..9c722ec 100644
--- a/soon.conf.example
+++ b/soon.conf.example
@@ -8,8 +8,6 @@ defaultCommand=atd
[Todo List]
alwaysPrint=true
-saveCompletedTodos=false
-completedTodoFile=/home/user/.config/soon/done
[Archive]
path=/home/user/.config/soon/archive
diff --git a/src/soon.nim b/src/soon.nim
index e6c545d..4e459f9 100644
--- a/src/soon.nim
+++ b/src/soon.nim
@@ -167,8 +167,8 @@ proc processCommands(commands: seq[string], conf: StringTableRef, interactive: b
of "w": agenda.printAgenda(calendar, 0, 7, conf, arch)
of "m": agenda.printAgenda(calendar, 0, 28, conf, arch)
of "y": agenda.printAgenda(calendar, 0, 365, conf, arch)
- of "t": todos.printTodos(calendar, arch)
- of "d": todos.printDeadlineTodos(calendar, arch)
+ of "t": todos.printTodos(calendar)
+ of "d": todos.printDeadlineTodos(calendar)
of "c": printReference()
of "e": openEditor(conf)
of "s": openConfig(conf)
diff --git a/src/soon/archive.nim b/src/soon/archive.nim
index fef59e2..de7f00e 100644
--- a/src/soon/archive.nim
+++ b/src/soon/archive.nim
@@ -3,7 +3,6 @@ import std/[os, sets, strutils, times]
type
ArchiveData* = object
events*: HashSet[string]
- todos*: HashSet[string]
proc loadArchive*(path: string): ArchiveData =
if not fileExists(path):
@@ -13,9 +12,8 @@ proc loadArchive*(path: string): ArchiveData =
if stripped.len == 0:
continue
if stripped.startsWith('-'):
- result.todos.incl(stripped)
- else:
- result.events.incl(stripped)
+ continue
+ result.events.incl(stripped)
proc archiveEvent*(path: string, date: DateTime, eventName: string) =
let line = date.format("yyyy-MM-dd") & "|" & eventName
@@ -34,27 +32,6 @@ proc unarchiveEvent*(path: string, date: DateTime, eventName: string) =
f.writeLine(line)
f.close()
-proc completeTodo*(path: string, todoName: string) =
- let line = "- " & todoName
- let f = open(path, fmAppend)
- f.writeLine(line)
- f.close()
-
-proc uncompleteTodo*(path: string, todoName: string) =
- let target = "- " & todoName
- if not fileExists(path):
- return
- let content = readFile(path)
- let f = open(path, fmWrite)
- for line in content.splitLines():
- if line.strip != target:
- f.writeLine(line)
- f.close()
-
proc isEventArchived*(archive: ArchiveData, date: DateTime, eventName: string): bool =
let key = date.format("yyyy-MM-dd") & "|" & eventName
return archive.events.contains(key)
-
-proc isTodoCompleted*(archive: ArchiveData, todoName: string): bool =
- let key = "- " & todoName
- return archive.todos.contains(key)
diff --git a/src/soon/config.nim b/src/soon/config.nim
index 38becf5..d4408a6 100644
--- a/src/soon/config.nim
+++ b/src/soon/config.nim
@@ -12,8 +12,6 @@ proc createDefaultConfigFile(path: string) =
config.setSectionKey("Calendar", "defaultCommand", "atd")
config.setSectionKey("Calendar", "", "")
config.setSectionKey("Todo List", "alwaysPrint", "true")
- config.setSectionKey("Todo List", "saveCompletedTodos", "false")
- config.setSectionKey("Todo List", "completedTodoFile", path / "done")
config.setSectionKey("Todo List", "", "")
config.setSectionKey("Archive", "path", path / "archive")
config.setSectionKey("Archive", "showFutureArchivedEvents", "true")
@@ -34,8 +32,6 @@ proc loadConfigFromFile(file: string): StringTableRef =
config["editor"] = c.getSectionValue("Calendar", "editor")
config["defaultCommand"] = c.getSectionValue("Calendar", "defaultCommand")
config["printtodos"] = c.getSectionValue("Todo List", "alwaysPrint")
- config["saveCompletedTodos"] = c.getSectionValue("Todo List", "saveCompletedTodos")
- config["completedFile"] = c.getSectionValue("Todo List", "completedTodoFile")
config["archiveFile"] = c.getSectionValue("Archive", "path")
config["showFutureArchived"] = c.getSectionValue("Archive", "showFutureArchivedEvents")
config["showPastArchived"] = c.getSectionValue("Archive", "showPastArchivedEvents")
diff --git a/src/soon/todos.nim b/src/soon/todos.nim
index a0c1df6..c3040a0 100644
--- a/src/soon/todos.nim
+++ b/src/soon/todos.nim
@@ -1,5 +1,5 @@
import std/[times, strutils, re, options, terminal]
-import conditionchecker, columnize, archive
+import conditionchecker, columnize
type
Todo* = object
@@ -61,30 +61,21 @@ proc toLine(todo: Todo): Line =
result.attachments = todo.attachments
# TODO: Sort on deadlines
-proc printDeadlineTodos*(calendar: seq[string], arch: archive.ArchiveData) =
+proc printDeadlineTodos*(calendar: seq[string]) =
let todos = getTodosFromCalendar(calendar)
let (regulars, deadlines) = splitRegularAndDeadlineTodos(todos)
- var activeDeadlines = newSeq[Todo]()
- for todo in deadlines:
- if not archive.isTodoCompleted(arch, removeHyphen(todo.name)):
- activeDeadlines.add(todo)
- if activeDeadlines.len == 0: return
+ if deadlines.len == 0: return
echo "\nUpcoming Deadlines:"
var lines = newSeq[Line]()
- for todo in activeDeadlines:
+ for todo in deadlines:
lines.add(todo.toLine)
columnize.echo(lines)
-proc printTodos*(calendar: seq[string], arch: archive.ArchiveData) =
+proc printTodos*(calendar: seq[string]) =
let todos = getTodosFromCalendar(calendar)
- let (regulars, deadlines) = splitRegularAndDeadlineTodos(todos)
- var activeTodos = newSeq[Todo]()
- for todo in todos:
- if not archive.isTodoCompleted(arch, removeHyphen(todo.name)):
- activeTodos.add(todo)
- if activeTodos.len == 0: return
+ if todos.len == 0: return
echo "\nTodo List:"
- for todo in activeTodos:
+ for todo in todos:
echo todo.name
for attachment in todo.attachments:
stdout.styledWriteLine(fgMagenta, attachment)
diff --git a/src/soon/tui.nim b/src/soon/tui.nim
index 67000fc..1e4d06d 100644
--- a/src/soon/tui.nim
+++ b/src/soon/tui.nim
@@ -70,7 +70,6 @@ proc buildItems(cal: seq[string], past: int, future: int,
timeStr: "",
name: name,
attachments: todo.attachments,
- isArchived: arch.todos.contains("- " & name),
))
# ---- Layout computation ----------------------------------------
@@ -184,7 +183,7 @@ proc drawEventLine(tb: var TerminalBuffer, x, y: int, item: Selectable, active:
tb.setStyle({})
proc drawTodoLine(tb: var TerminalBuffer, x, y: int, item: Selectable, active: bool) =
- let completed = item.isArchived or item.newlyCompleted
+ let completed = item.newlyCompleted
if active:
if completed:
@@ -247,7 +246,7 @@ proc draw(tb: var TerminalBuffer, items: seq[Selectable], layout: seq[LayoutLine
elif line.attachmentIdx >= 0:
let item = items[line.itemIndex]
let archived = item.isArchived or item.newlyArchived
- let completed = item.isArchived or item.newlyCompleted
+ let completed = item.newlyCompleted
let dimmed = (item.kind == skEvent and archived) or (item.kind == skTodo and completed)
if item.kind == skEvent:
drawAttachment(tb, 39, screenY, item.attachments[line.attachmentIdx], dimmed)
@@ -298,6 +297,8 @@ proc findAndRemoveTodo(calDir: string, todoName: string) =
skip = false
newLines.add(line)
if found:
+ while newLines.len > 0 and newLines[^1].strip.len == 0:
+ newLines.setLen(newLines.len - 1)
var f = open(file, fmWrite)
for nl in newLines:
f.writeLine(nl)
@@ -310,7 +311,9 @@ proc start*(cal: seq[string], conf: StringTableRef,
past: int, future: int,
showAgenda: bool, showTodos: bool, showDeadlines: bool) =
illwillInit(fullScreen=true)
- defer: illwillDeinit()
+ defer:
+ illwillDeinit()
+ stdout.write("\e[2J\e[H")
let archiveFile = conf.getOrDefault("archiveFile",
conf.getOrDefault("path", "") / "archive")
@@ -364,15 +367,11 @@ proc start*(cal: seq[string], conf: StringTableRef,
items[cursor].newlyArchived = true
archive.archiveEvent(archiveFile, items[cursor].date, items[cursor].name)
of skTodo:
- if items[cursor].isArchived or items[cursor].newlyCompleted:
- items[cursor].newlyCompleted = false
- archive.uncompleteTodo(archiveFile, items[cursor].name)
- else:
- items[cursor].newlyCompleted = true
- archive.completeTodo(archiveFile, items[cursor].name)
+ items[cursor].newlyCompleted = not items[cursor].newlyCompleted
else:
discard
for item in items:
if item.kind == skTodo and item.newlyCompleted:
findAndRemoveTodo(calDir, item.name)
+