all repos — min @ 2c2f847d8352c470dc473bd25c46892375516e91

A small but practical concatenative programming language.

Now using Nifty's StyledConsoleLogger.
h3rald h3rald@h3rald.com
Thu, 16 Feb 2017 12:01:03 +0100
commit

2c2f847d8352c470dc473bd25c46892375516e91

parent

4f0a90f14cab9bcd91700e306b5409d5c5b6a1cc

4 files changed, 18 insertions(+), 71 deletions(-)

jump to
M core/utils.nimcore/utils.nim

@@ -1,7 +1,6 @@

import strutils, critbits, - logging, terminal import parser,

@@ -10,74 +9,6 @@ scope,

interpreter # Library methods - -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) - #resetAttributes() - 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 proc define*(i: In, name: string): ref MinScope = var scope = new MinScope
M lib/min_lang.nimlib/min_lang.nim

@@ -12,6 +12,7 @@ ../core/parser,

../core/value, ../core/interpreter, ../core/utils, + ../packages/styled_console_logger, ../packages/nim-sgregex/sgregex, ../packages/nimline/nimline, ../core/scope

@@ -164,10 +165,10 @@ .symbol("loglevel") do (i: In):

var s: MinValue i.reqStringLike s var str = s.getString - notice "Log level: ", setLogLevel(str) + echo "Log level: ", setLogLevel(str) .symbol("loglevel?") do (i: In): - notice "Log level: ", getLogLevel() + echo "Log level: ", getLogLevel() # Language constructs
M minim.nimminim.nim

@@ -10,6 +10,7 @@ algorithm,

logging import packages/nimline/nimline, + packages/styled_console_logger, core/consts, core/parser, core/value,

@@ -31,6 +32,7 @@ export

parser, interpreter, utils, + styled_console_logger, value, scope, min_lang
M nifty.jsonnifty.json

@@ -2,6 +2,13 @@ {

"storage": "packages", "commands": { + "get": + { + "curl+src+name": + { + "cmd": "curl {{src}} -o {{name}}" + } + }, "install": { "git+src":

@@ -59,6 +66,12 @@ {

"name": "nimline", "src": "https://github.com/h3rald/nimline.git", "git": true + }, + "styled_console_logger.nim": + { + "name": "styled_console_logger.nim", + "src": "https://raw.githubusercontent.com/h3rald/nifty/master/lib/styled_console_logger.nim", + "curl": true } } }