Added color symbol.
h3rald h3rald@h3rald.com
Sat, 04 May 2024 15:05:42 +0200
7 files changed,
22 insertions(+),
9 deletions(-)
M
minpkg/core/env.nim
→
minpkg/core/env.nim
@@ -22,4 +22,6 @@ var MINCOMPILED* {.threadvar.}: bool
MINCOMPILED = false var DEV* {.threadvar.}: bool DEV = false +var COLOR* {.threadvar.}: bool +COLOR = true
M
minpkg/core/niftylogger.nim
→
minpkg/core/niftylogger.nim
@@ -4,6 +4,9 @@ strutils,
terminal, exitprocs] +import + ./env + if isatty(stdin): addExitProc(resetAttributes)@@ -34,10 +37,12 @@ if level >= lvlWarn:
f = stderr let ln = substituteLog(logger.fmtStr, level, args) let prefix = level.logPrefix() - f.setForegroundColor(prefix.color) + if COLOR: + f.setForegroundColor(prefix.color) f.write(prefix.msg) f.write(ln) - resetAttributes() + if COLOR: + resetAttributes() f.write("\n") if level in {lvlError, lvlFatal}: flushFile(f)
M
minpkg/core/shell.nim
→
minpkg/core/shell.nim
@@ -99,7 +99,8 @@ elif f.dirExists:
f = f.replace("\\", "/") if f[f.len-1] != '/': f = f & "/" - return toSeq(walkDir(f, true)).mapIt("\"$1$2\"" % [f, it.path.replace("\\", "/")]) + return toSeq(walkDir(f, true)).mapIt("\"$1$2\"" % [f, it.path.replace( + "\\", "/")]) else: var dir: string if f.contains("/") or dir.contains("\\"):@@ -116,7 +117,7 @@ it.path.replace("\\", "/")])
return symbols proc p(s: string, color = fgWhite) = - if SIMPLEREPL: + if SIMPLEREPL or not COLOR: stdout.write(s) else: stdout.styledWrite(color, s)
M
minpkg/lib/min_io.nim
→
minpkg/lib/min_io.nim
@@ -46,6 +46,10 @@ let action = proc (ed: var LineEditor) {.closure.} =
ic.apply(q) KEYMAP[key] = action + def.symbol("color") do (i: In): + let vals = i.expect("bool") + COLOR = vals[0].boolVal + def.symbol("newline") do (i: In): echo ""
M
next-release.md
→
next-release.md
@@ -1,6 +1,4 @@
-### Fixes and Improvements +### New Features -- Upgraded OpenSSL to version 3.3.0. -- Nimble metadata are now specified statically in the `min.nimble` file (Fixes #193). -- Minor documentation fixes. +- Added a new `color` symbol to the `io` module to enable/disable terminal color output.
M
site/contents/reference-io.md
→
site/contents/reference-io.md
@@ -14,6 +14,9 @@ > If the user enters a number that matches one of the choices, then the corresponding quotation {{q1}} is executed, otherwise the choice menu is displayed again until a valid choice is made. #}
{#op||clear||{{none}}||{{none}}|| Clears the screen.#} + +{#op||color||{{b}}||{{none}}|| +Enables or disabled color output in terminal (enabled by default).#} {#op||column-print||{{q}} {{i}}||{{any}}|| Prints all elements of {{q}} to STDOUT, in {{i}} columns.#}