Skip to content

Commit d1af958

Browse files
authored
terminal: fix fgColor/bgColor commands [backport] (nim-lang#15554)
Since nim-lang#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.
1 parent 0134e34 commit d1af958

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lib/pure/terminal.nim

+3-4
Original file line numberDiff line numberDiff line change
@@ -689,10 +689,9 @@ template styledEchoProcessArg(f: File, color: Color) =
689689
template styledEchoProcessArg(f: File, cmd: TerminalCmd) =
690690
when cmd == resetStyle:
691691
resetAttributes(f)
692-
when cmd == fgColor:
693-
fgSetColor = true
694-
when cmd == bgColor:
695-
fgSetColor = false
692+
elif cmd in {fgColor, bgColor}:
693+
let term = getTerminal()
694+
term.fgSetColor = cmd == fgColor
696695

697696
macro styledWrite*(f: File, m: varargs[typed]): untyped =
698697
## Similar to ``write``, but treating terminal style arguments specially.

tests/stdlib/tterminal.nim

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
discard """
2+
action: compile
3+
"""
4+
5+
import terminal, colors
6+
7+
styledEcho fgColor, colRed, "Test"
8+
styledEcho bgColor, colBlue, "Test"

0 commit comments

Comments
 (0)