summary refs log tree commit diff stats
diff options
context:
space:
mode:
authoralaviss <leorize+oss@disroot.org>2020-10-13 11:39:32 -0500
committerGitHub <noreply@github.com>2020-10-13 17:39:32 +0100
commitd1af9587b889bc1c9b080a48b9858436d2482599 (patch)
treec673901bce0e7a911dbeb1255ba30a8b9bc8a08b
parent0134e34e035a139677413acb20e42b4f7f490021 (diff)
downloadNim-d1af9587b889bc1c9b080a48b9858436d2482599.tar.gz
terminal: fix fgColor/bgColor commands [backport] (#15554)
Since #8296, fgSetColor is no longer a global. These commands were
probably left out from the change as an oversight, so some tests have
been added to make sure this won't happen again.
-rw-r--r--lib/pure/terminal.nim7
-rw-r--r--tests/stdlib/tterminal.nim8
2 files changed, 11 insertions, 4 deletions
diff --git a/lib/pure/terminal.nim b/lib/pure/terminal.nim
index 968d6bd9a..ac6720771 100644
--- a/lib/pure/terminal.nim
+++ b/lib/pure/terminal.nim
@@ -689,10 +689,9 @@ template styledEchoProcessArg(f: File, color: Color) =
 template styledEchoProcessArg(f: File, cmd: TerminalCmd) =
   when cmd == resetStyle:
     resetAttributes(f)
-  when cmd == fgColor:
-    fgSetColor = true
-  when cmd == bgColor:
-    fgSetColor = false
+  elif cmd in {fgColor, bgColor}:
+    let term = getTerminal()
+    term.fgSetColor = cmd == fgColor
 
 macro styledWrite*(f: File, m: varargs[typed]): untyped =
   ## Similar to ``write``, but treating terminal style arguments specially.
diff --git a/tests/stdlib/tterminal.nim b/tests/stdlib/tterminal.nim
new file mode 100644
index 000000000..364c8d82e
--- /dev/null
+++ b/tests/stdlib/tterminal.nim
@@ -0,0 +1,8 @@
+discard """
+  action: compile
+"""
+
+import terminal, colors
+
+styledEcho fgColor, colRed, "Test"
+styledEcho bgColor, colBlue, "Test"