Skip to content

Commit

Permalink
fix nim-lang#9394 by replacing fmt with strutils.% (nim-lang#9417)
Browse files Browse the repository at this point in the history
* fix nim-lang#9394 by replacing `fmt` with normal string append

Until issue nim-lang#7632 is fixed, use string append.

* use `strutils.%` instead of normal string add
  • Loading branch information
Vindaar authored and narimiran committed Oct 31, 2018
1 parent 9c092ed commit 8c0a86c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/pure/terminal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import macros
import strformat
from strutils import toLowerAscii
from strutils import toLowerAscii, `%`
import colors, tables

when defined(windows):
Expand Down Expand Up @@ -635,15 +635,17 @@ 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)
result = fmt"{bgPrefix}{rgb.r};{rgb.g};{rgb.b}m"

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.
Expand Down
7 changes: 7 additions & 0 deletions tests/stdlib/t9394.nim
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 8c0a86c

Please sign in to comment.