From 825f358c8b97da1f855e83aac27a23ec1a575934 Mon Sep 17 00:00:00 2001 From: alaviss Date: Tue, 13 Oct 2020 11:39:32 -0500 Subject: [PATCH] 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. (cherry picked from commit d1af9587b889bc1c9b080a48b9858436d2482599) --- lib/pure/terminal.nim | 7 +++---- tests/stdlib/tterminal.nim | 8 ++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 tests/stdlib/tterminal.nim diff --git a/lib/pure/terminal.nim b/lib/pure/terminal.nim index 43b1592328..ac62aacad1 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 0000000000..364c8d82e7 --- /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"