New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terminal.nim colored output is not GCSAFE. #8294

cheatfate opened this Issue Jul 12, 2018 · 2 comments


None yet
3 participants
Copy link

cheatfate commented Jul 12, 2018

Using terminal.nim with colored output generates many GCSAFE problem warnings, because of global variables usage for caching ANSI codes.

  hasThreadSupport = compileOption("threads")

when not hasThreadSupport:
  import tables
    colorsFGCache = initTable[Color, string]()
    colorsBGCache = initTable[Color, string]()
    styleCache = initTable[int, string]()

  trueColorIsSupported: bool
  trueColorIsEnabled: bool
  fgSetColor: bool

Possible solution is to move this caches into {.threadvar.} variable.


This comment has been minimized.

Copy link

Araq commented Jul 12, 2018

Re-open if this is still a problem. I think you fixed it.

@Araq Araq closed this Jul 12, 2018


This comment has been minimized.

Copy link

stefantalpalaru commented Jan 15, 2019

I got a related compilation error on Windows, with latest HEAD:

import terminal

proc f() {.gcsafe.} =


nim c -r --threads:on terminal_test.nim output:

Nim\lib\pure\terminal.nim(42, 6) Warning: 'getTerminal' is not GC-safe as it calls 'newTerminal' [GcUnsafe2]
Nim\lib\pure\terminal.nim(461, 6) Warning: 'resetAttributes' is not GC-safe as it calls 'getTerminal' [GcUnsafe2]
Nim\lib\pure\terminal.nim(848, 6) Warning: 'resetAttributes' is not GC-safe as it calls 'resetAttributes' [GcUnsafe2]
terminal_test.nim(3, 6) Error: 'f' is not GC-safe as it calls 'resetAttributes'

@stefantalpalaru stefantalpalaru referenced this issue Jan 15, 2019


GC safety of Nimbus-related projects #209

22 of 25 tasks complete

@Araq Araq reopened this Jan 15, 2019

@Araq Araq closed this in 27e366e Jan 15, 2019

stefantalpalaru added a commit to status-im/Nim that referenced this issue Jan 16, 2019

narimiran added a commit that referenced this issue Jan 25, 2019

fixes #8294 [backport]
(cherry picked from commit 27e366e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment