diff options
| author | historia <[not public]> | 2026-06-29 15:23:54 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-29 15:23:54 -0400 |
| commit | 776c172ffdc3f37ba1a1794e978f907ab33e92f3 (patch) | |
| tree | 732e4166b7438489e14ba7ba563435f380296060 /src | |
| parent | a5aa547597e7fa0d133b58a6baf4fb70a63c7a80 (diff) | |
| download | soon-776c172ffdc3f37ba1a1794e978f907ab33e92f3.tar.gz | |
added comments to config file
Diffstat (limited to 'src')
| -rw-r--r-- | src/soon/config.nim | 2 | ||||
| -rw-r--r-- | src/soon/tui.nim | 42 |
2 files changed, 42 insertions, 2 deletions
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) + |
