From 776c172ffdc3f37ba1a1794e978f907ab33e92f3 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Mon, 29 Jun 2026 15:23:54 -0400 Subject: added comments to config file --- soon.conf.example | 20 +++++++++++++++++++- src/soon/config.nim | 2 -- src/soon/tui.nim | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/soon.conf.example b/soon.conf.example index 9c722ec..bf5466a 100644 --- a/soon.conf.example +++ b/soon.conf.example @@ -1,9 +1,16 @@ [Calendar] +# Path and filename of calendar file path=/home/user/.config/soon defaultFile=calendar.soon + +# Number of default past and future days to display past=0 future=14 + +# Editor for soon -e command to open calendar editor=vim + +# Default soon arguments, e.g. soon -atd defaultCommand=atd [Todo List] @@ -11,9 +18,20 @@ alwaysPrint=true [Archive] path=/home/user/.config/soon/archive + +# Whether archived events in the past/future show on the calendar showFutureArchivedEvents=true showPastArchivedEvents=false + +# Keep all events on the calendar until manually archived +# If you use calendars like a todo list you might want this +# E.g. you put things like "Oil change" on your calendar but you don't always +# do it in time so you want it to stick around alwaysShowUnarchivedEvents=true + +# Everything before this date is considered archived startDate=2026-01-01 + +# When you archive the last instance of an event from the TUI, this will delete +# the event from your calendar deleteFromCalendarFile=true -autoPurge=true diff --git a/src/soon/config.nim b/src/soon/config.nim index d4408a6..6802655 100644 --- a/src/soon/config.nim +++ b/src/soon/config.nim @@ -19,7 +19,6 @@ proc createDefaultConfigFile(path: string) = config.setSectionKey("Archive", "alwaysShowUnarchivedEvents", "false") config.setSectionKey("Archive", "startDate", now().format("yyyy-MM-dd")) config.setSectionKey("Archive", "deleteFromCalendarFile", "true") - config.setSectionKey("Archive", "autoPurge", "true") config.writeConfig(path / "soon.conf") proc loadConfigFromFile(file: string): StringTableRef = @@ -38,7 +37,6 @@ proc loadConfigFromFile(file: string): StringTableRef = config["alwaysShowUnarchived"] = c.getSectionValue("Archive", "alwaysShowUnarchivedEvents") config["startDate"] = c.getSectionValue("Archive", "startDate") config["deleteArchivedEvents"] = c.getSectionValue("Archive", "deleteFromCalendarFile") - config["autoPurge"] = c.getSectionValue("Archive", "autoPurge") return config proc loadConfig*(configPath: string = ""): StringTableRef = diff --git a/src/soon/tui.nim b/src/soon/tui.nim index a66d4b6..e93a2a0 100644 --- a/src/soon/tui.nim +++ b/src/soon/tui.nim @@ -275,6 +275,34 @@ proc getFirstNonWhitespaceChar(s: string): char = return c return '\0' +proc findAndRemoveEvent(calDir: string, eventName: string) = + for file in walkDirRec(calDir): + if not file.toLower().endsWith(".soon"): + continue + var lines = readFile(file).splitLines(keepEol = false) + var newLines: seq[string] + var skip = false + var found = false + for line in lines: + let stripped = line.strip + let first = getFirstNonWhitespaceChar(stripped) + if first notin {'#', '-', '+'} and stripped.len > 0: + let split = line.split(",", maxsplit = 1) + if split.len >= 2 and split[1].strip == eventName: + found = true + skip = true + continue + if first == '+' and skip: + continue + else: + skip = false + newLines.add(line) + if found: + while newLines.len > 0 and newLines[^1].strip.len == 0: + newLines.setLen(newLines.len - 1) + writeFile(file, newLines.join("\n") & "\n") + return + proc findAndRemoveTodo(calDir: string, todoName: string) = let strippedName = todoName.strip(chars = {' ', '-'}) for file in walkDirRec(calDir): @@ -377,3 +405,17 @@ proc start*(cal: seq[string], conf: StringTableRef, if item.kind == skTodo and item.newlyCompleted: findAndRemoveTodo(calDir, item.name) + if conf.getOrDefault("deleteArchivedEvents", "true") == "true": + var fullyArchivedNames: HashSet[string] + var namesWithUnarchived: HashSet[string] + for item in items: + if item.kind == skEvent: + if not item.isArchived and not item.newlyArchived: + namesWithUnarchived.incl(item.name) + elif item.newlyArchived: + fullyArchivedNames.incl(item.name) + for name in namesWithUnarchived: + fullyArchivedNames.excl(name) + for name in fullyArchivedNames: + findAndRemoveEvent(calDir, name) + -- cgit v1.2.3