mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-21 16:31:39 +00:00
* fix #9394 by replacing `fmt` with normal string append Until issue #7632 is fixed, use string append. * use `strutils.%` instead of normal string add
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
|
||||
import macros
|
||||
import strformat
|
||||
from strutils import toLowerAscii
|
||||
from strutils import toLowerAscii, `%`
|
||||
import colors, tables
|
||||
|
||||
when defined(windows):
|
||||
@@ -635,7 +635,8 @@ proc ansiForegroundColorCode*(color: Color): string =
|
||||
|
||||
template ansiForegroundColorCode*(color: static[Color]): string =
|
||||
const rgb = extractRGB(color)
|
||||
(static(fmt"{fgPrefix}{rgb.r};{rgb.g};{rgb.b}m"))
|
||||
# no usage of `fmt`, see issue #7632
|
||||
(static("$1$2;$3;$4m" % [$fgPrefix, $(rgb.r), $(rgb.g), $(rgb.b)]))
|
||||
|
||||
proc ansiBackgroundColorCode*(color: Color): string =
|
||||
let rgb = extractRGB(color)
|
||||
@@ -643,7 +644,8 @@ proc ansiBackgroundColorCode*(color: Color): string =
|
||||
|
||||
template ansiBackgroundColorCode*(color: static[Color]): string =
|
||||
const rgb = extractRGB(color)
|
||||
(static(fmt"{bgPrefix}{rgb.r};{rgb.g};{rgb.b}m"))
|
||||
# no usage of `fmt`, see issue #7632
|
||||
(static("$1$2;$3;$4m" % [$bgPrefix, $(rgb.r), $(rgb.g), $(rgb.b)]))
|
||||
|
||||
proc setForegroundColor*(f: File, color: Color) =
|
||||
## Sets the terminal's foreground true color.
|
||||
|
||||
7
tests/stdlib/t9394.nim
Normal file
7
tests/stdlib/t9394.nim
Normal file
@@ -0,0 +1,7 @@
|
||||
import terminal, colors
|
||||
|
||||
let codeFg = ansiForegroundColorCode(colAliceBlue)
|
||||
let codeBg = ansiBackgroundColorCode(colAliceBlue)
|
||||
|
||||
doAssert codeFg == "\27[38;2;240;248;255m"
|
||||
doAssert codeBg == "\27[48;2;240;248;255m"
|
||||
Reference in New Issue
Block a user