aboutsummaryrefslogtreecommitdiff
path: root/src/then.nim
diff options
context:
space:
mode:
authorhistoria <gravel.justness270@slmail.me>2024-08-06 20:08:43 -0400
committerhistoria <gravel.justness270@slmail.me>2024-08-06 20:08:43 -0400
commit1320375ebc0e87956807c0c543abe9f9a9f1dd6e (patch)
treec5bb8db27be90ffa4c7b321d8fd9a907ad47e6fb /src/then.nim
parent0139b8b7896f6fcc89b3e2481d315e96af82ec4a (diff)
downloadsoon-1320375ebc0e87956807c0c543abe9f9a9f1dd6e.tar.gz
Config added. Name change to Soon.
Diffstat (limited to 'src/then.nim')
-rw-r--r--src/then.nim137
1 files changed, 0 insertions, 137 deletions
diff --git a/src/then.nim b/src/then.nim
deleted file mode 100644
index 4f4199d..0000000
--- a/src/then.nim
+++ /dev/null
@@ -1,137 +0,0 @@
-import std/[times, os, strutils, strbasics, strscans, sets, strtabs, tables], parseopt
-import then/[conditions, config, typechecker]
-
-const VERSION = "0.1"
-const configDir = expandTilde("~/.config/then/")
-const defaultConfigFile = configDir & "then.toml"
-const defaultCalendarFile = configDir & "calendar.then"
-
-const MONTHS = DefaultLocale.MMM.toHashSet + DefaultLocale.MMMM.toHashSet
-const WEEKDAYS = DefaultLocale.ddd.toHashSet + DefaultLocale.dddd.toHashSet
-
-proc printHelp(badCmd: string) =
- if badCmd != "":
- echo badCmd & " is not a valid option\n"
- echo """
-Usage:
- then [options] [commands]
-
-OPTIONS
- -h, --help show list of CLI options
- -v, --version show then version
- --future=DAYS set future
- --past=DAYS set past
-
-COMMANDS
- a print upcoming agenda (default command)
- e open default calendar file in $EDITOR
- j print the modified julian day
- """
- quit()
-
-proc printVersion() =
- echo "then " & VERSION
- quit()
-
-# 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 getEvents(cal: seq[string], date: DateTime): seq[string] =
- var events: seq[string] = newSeq[string]()
- for line in cal:
- var (success, dateConditions, event) = scanTuple(line, "$*,$*")
- if success:
- dateConditions.strip
- event.strip
- let conditions = parseDateToTable(dateConditions)
- var match = true
- # key = Condition Type (e.g. month), cs = Seq of conditions
- for k,cs in conditions:
- var keyMatched = false
- for c in cs:
- if checkCond(c, date) == true:
- keyMatched = true
- break
- if not keyMatched:
- match = false
- break
- if match:
- events.add(event)
- else:
- echo "WARNING: Cannot parse line: ", line
- return events
-
-proc printEvents(cal: seq[string], date: DateTime, format: string) =
- let events = getEvents(cal, date)
- if events.len > 0:
- for e in events:
- echo date.format(format), " ", e
-
-proc openCal(file: string): seq[string] =
- let f = open(file)
- var cal: seq[string]
- for line in f.lines:
- if line == "": continue
- if line.strip[0] == '#': continue
- cal.add(line)
- f.close()
- return cal
-
-proc printCalendar() =
- let cal = openCal(defaultCalendarFile)
- var past = -3
- var future = 7
- let now = now()
-
- for i in past..future:
- let curDay = now + i.days
- printEvents(cal, curDay, "ddd yyyy MMM dd")
-
-proc main() =
- var config = loadConfig()
- echo config
- var past: int = 1
- var future: int = 14
- var noArg: bool = true
- for kind, key, val in getopt():
- case kind
- of cmdLongOption, cmdShortOption:
- noArg = false
- case key
- of "help", "h":
- printHelp("")
- of "version", "v":
- printVersion()
- else:
- printHelp(key)
- else:
- discard
-
- if noArg:
- printCalendar()
-
-when isMainModule:
- main()