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 --- src/soon/config.nim | 2 -- src/soon/tui.nim | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) (limited to 'src') 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