aboutsummaryrefslogtreecommitdiff
path: root/src/soon.nim
diff options
context:
space:
mode:
Diffstat (limited to 'src/soon.nim')
-rw-r--r--src/soon.nim84
1 files changed, 5 insertions, 79 deletions
diff --git a/src/soon.nim b/src/soon.nim
index d154846..cede38c 100644
--- a/src/soon.nim
+++ b/src/soon.nim
@@ -1,13 +1,7 @@
-import std/[times, os, strutils, strbasics, sequtils, strscans, sets, strtabs, tables], parseopt
-import soon/[conditions, config, typechecker]
+import std/[os, strutils, strtabs, sequtils, parseopt]
+import soon/[config, agenda, todos]
const VERSION = "0.1"
-const configDir = expandTilde("~/.config/soon/")
-const defaultConfigFile = configDir & "soon.toml"
-const defaultCalendarFile = configDir & "calendar.soon"
-
-const MONTHS = DefaultLocale.MMM.toHashSet + DefaultLocale.MMMM.toHashSet
-const WEEKDAYS = DefaultLocale.ddd.toHashSet + DefaultLocale.dddd.toHashSet
proc printHelp(badCmd: string) =
if badCmd != "":
@@ -41,73 +35,6 @@ proc createDefaultCalendarFile(file: string) =
if not fileExists(file):
writeFile(file, "# This is your first calendar file. Put events and todos in here.")
-# Splits a string on whitespace, but maintains whitespace in date groups
-proc splitWhitespaceExceptParens(str:string): seq[string] =
- var output: seq[string] = newSeq[string]()
- var inParens = false
- for token in str.splitWhitespace:
- if inParens:
- output.add(output.pop & ' ' & token)
- else:
- output.add(token)
- for c in token:
- if c == '(': inParens = true
- if c == ')': inParens = false
- return output
-
-# Returns Table[conditionType, seq of conditions]
-proc parseDateToTable(date:string): Table[string, seq[string]] =
- var table = initTable[string,seq[string]]()
- let conditions = splitWhitespaceExceptParens(date)
- for c in conditions:
- let condType = checkType(c)
- if not table.hasKey(condType):
- table[condType] = @[]
- table[condType].add(c)
- return table
-
-proc checkAllConditions(dateConditions: string, date: DateTime): bool =
- let conditions = parseDateToTable(dateConditions.strip)
- for k,cs in conditions:
- var keyMatched = false
- for c in cs:
- if checkCond(c, date) == true:
- keyMatched = true
- break
- if not keyMatched:
- return false
- return true
-
-# Returns Table[eventName, eventAttachedLines]
-proc getEventsForDate(cal: seq[string], date: DateTime): Table[string, seq[string]] =
- var lastInsertion = ""
- for line in cal:
- var (success, dateConditions, event) = scanTuple(line, "$*,$*")
- if success:
- if checkAllConditions(dateConditions, date) == true:
- event.strip
- result[event] = @[]
- lastInsertion = event
- elif line.strip[0] == '+':
- if result.hasKey(lastInsertion):
- result[lastInsertion].add(line)
- else:
- echo "WARNING: Cannot parse line: ", line
-
-proc printEvents(cal: seq[string], date: DateTime, format: string) =
- let events = getEventsForDate(cal, date)
- if events.len > 0:
- for e in events.keys:
- echo date.format(format), " ", e
- for attachment in events[e]:
- echo attachment.indent(date.format(format).len + 2)
-
-proc printAgenda(calendar: seq[string], past: int, future: int) =
- let now = now()
- for i in past..future:
- let curDay = now + i.days
- printEvents(calendar, curDay, "ddd yyyy MMM dd")
-
proc getCalendarFileLines(file: string): seq[string] =
let f = open(file)
for line in f.lines:
@@ -121,7 +48,8 @@ proc processCalendars(calendarPath: string, past: int, future: int) =
for file in os.walkDirRec(calendarPath):
if file.toLower().endsWith(".soon"):
calendar = calendar.concat(getCalendarFileLines(file))
- printAgenda(calendar, past, future)
+ agenda.printAgenda(calendar, past, future)
+ todos.printTodos(calendar)
proc parseArgs(config: StringTableRef): seq[string] =
for kind, key, val in getopt():
@@ -145,9 +73,7 @@ proc main() =
var conf = config.loadConfig()
let commands = parseArgs(conf)
validateConfig(conf)
- let past = 0 - parseInt(conf["past"])
- let future = parseInt(conf["future"])
- processCalendars(conf["calendarPath"], past, future)
+ processCalendars(conf["calendarPath"], 0 - parseInt(conf["past"]), parseInt(conf["future"]))
when isMainModule:
main()