all repos — min @ 1b234efce79339aa3afcf847a8b5db569aa3f735

A small but practical concatenative programming language.

Added color symbol.
h3rald h3rald@h3rald.com
Sat, 04 May 2024 15:05:42 +0200
commit

1b234efce79339aa3afcf847a8b5db569aa3f735

parent

8311787ad1a4d61a01f67354ede6e2205e01e664

M min.ymlmin.yml

@@ -1,5 +1,5 @@

author: Fabio Cevasco description: A small but practical concatenative programming language and shell. -id: 153992690 +id: 154260810 name: min version: 0.44.0
M minpkg/core/env.nimminpkg/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.nimminpkg/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.nimminpkg/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.nimminpkg/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.mdnext-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.mdsite/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.#}