Started development.
h3rald h3rald@h3rald.com
Fri, 18 Nov 2016 14:01:29 +0100
6 files changed,
192 insertions(+),
0 deletions(-)
A
lib/config.nim
@@ -0,0 +1,46 @@
+import + os, + parsecfg, + streams, + strutils, + logging + +import + logger + +const + cfgfile = "../nifty.nimble".slurp + +var + appname*: string + version*: string + appdesc*: string + f = newStringStream(cfgfile) + +if f != nil: + var p: CfgParser + open(p, f, "../minim.nimble") + while true: + var e = next(p) + case e.kind + of cfgEof: + break + of cfgKeyValuePair: + case e.key: + of "version": + version = e.value + of "name": + appname = e.value + of "description": + appdesc = e.value + else: + discard + of cfgError: + fatal("Configuration error.") + quit(1) + else: + discard + close(p) +else: + fatal("Cannot process configuration file.") + quit(2)
A
lib/logger.nim
@@ -0,0 +1,71 @@
+import + logging, + strutils, + terminal + +system.addQuitProc(resetAttributes) + +type + StyledConsoleLogger* = ref object of Logger + +proc logPrefix*(level: Level): tuple[msg: string, color: ForegroundColor] = + case level: + of lvlDebug: + return ("---", fgMagenta) + of lvlInfo: + return ("(i) ", fgCyan) + of lvlNotice: + return ("---", fgGreen) + of lvlWarn: + return ("(!)", fgYellow) + of lvlError: + return ("(!)", fgRed) + of lvlFatal: + return ("(x)", fgRed) + else: + return ("", fgWhite) + +method log*(logger: StyledConsoleLogger; level: Level; args: varargs[string, `$`]) = + var f = stdout + if level >= getLogFilter() and level >= logger.levelThreshold: + if level >= lvlWarn: + f = stderr + let ln = substituteLog(logger.fmtStr, level, args) + let prefix = level.logPrefix() + f.setForegroundColor(prefix.color) + f.write(prefix.msg) + f.write(ln) + f.write("\n") + resetAttributes() + if level in {lvlError, lvlFatal}: flushFile(f) + +proc newStyledConsoleLogger*(levelThreshold = lvlAll; fmtStr = " "): StyledConsoleLogger = + new result + result.fmtStr = fmtStr + result.levelThreshold = levelThreshold + +proc getLogLevel*(): string = + return LevelNames[getLogFilter()].toLowerAscii + +proc setLogLevel*(val: var string): string {.discardable.} = + var lvl: Level + case val: + of "debug": + lvl = lvlDebug + of "info": + lvl = lvlInfo + of "notice": + lvl = lvlNotice + of "warn": + lvl = lvlWarn + of "error": + lvl = lvlError + of "fatal": + lvl = lvlFatal + of "none": + lvl = lvlNone + else: + val = "warn" + lvl = lvlWarn + setLogFilter(lvl) + return val
A
nifty.nim
@@ -0,0 +1,39 @@
+import + json, + os, + parseopt2, + logging, + strutils + +import + lib/config, + lib/logger + +when isMainModule: + let usage* = """ $1 v$2 - $3 + """ % [appname, version, appdesc] + + var file, s: string = "" + setLogFilter(lvlNotice) + + for kind, key, val in getopt(): + case kind: + of cmdArgument: + file = key + of cmdLongOption, cmdShortOption: + case key: + of "log", "l": + var val = val + setLogLevel(val) + #of "evaluate", "e": + # s = val + of "help", "h": + echo usage + quit(0) + of "version", "v": + echo version + quit(0) + else: + discard + else: + discard
A
nifty.nim.cfg
@@ -0,0 +1,24 @@
+# https://gist.github.com/Drakulix/9881160 +amd64.windows.gcc.path = "/usr/local/mingw/bin" +amd64.windows.gcc.exe = "x86_64-w64-mingw32-gcc" +amd64.windows.gcc.linkerexe = "x86_64-w64-mingw32-gcc" + +# https://gist.github.com/Drakulix/9881160 +i386.windows.gcc.path = "/usr/local/mingw/bin" +i386.windows.gcc.exe = "i686-w64-mingw32-gcc" +i386.windows.gcc.linkerexe = "i686-w64-mingw32-gcc" + +# http://crossgcc.rts-software.org/doku.php?id=compiling_for_linux +i386.linux.gcc.path = "/usr/local/gcc-4.8.1-for-linux32/bin" +i386.linux.gcc.exe = "i586-pc-linux-gcc" +i386.linux.gcc.linkerexe = "i586-pc-linux-gcc" + +# http://crossgcc.rts-software.org/doku.php?id=compiling_for_linux +amd64.linux.gcc.path = "/usr/local/gcc-4.8.1-for-linux64/bin" +amd64.linux.gcc.exe = "x86_64-pc-linux-gcc" +amd64.linux.gcc.linkerexe = "x86_64-pc-linux-gcc" + +# http://www.jaredwolff.com/toolchains/ +arm.linux.gcc.path = "/usr/local/arm-none-linux-gnueabi/bin" +arm.linux.gcc.exe = "arm-none-linux-gnueabi-gcc" +arm.linux.gcc.linkerexe = "arm-none-linux-gnueabi-gcc"
A
nifty.nimble
@@ -0,0 +1,10 @@
+[Package] +name = "nifty" +version = "0.1.0" +author = "Fabio Cevasco" +description = "A pseudo package manager and script runner." +license = "MIT" +bin = "minim" + +[Deps] +requires: "nim >= 0.15.2"