diff options
author | Ben Gamari <ben@smart-cactus.org> | 2020-03-30 10:43:50 -0400 |
---|---|---|
committer | Ben Gamari <ben@well-typed.com> | 2020-03-31 12:47:54 -0400 |
commit | 4066f4e9c2f54770147f1d63d55bbb300edd866c (patch) | |
tree | 4b4dcb8953e44fe1f62b7586db57d6ae7723fe04 /compiler/main/SysTools/Terminal.hs | |
parent | 4b9c586472bf99425f7bbcf346472d7c54f05028 (diff) | |
download | haskell-wip/T17922.tar.gz |
Session: Memoize stderrSupportsAnsiColorswip/T17922
Not only is this a reasonable efficiency measure but it avoids making
reentrant calls into ncurses, which is not thread-safe. See #17922.
Diffstat (limited to 'compiler/main/SysTools/Terminal.hs')
-rw-r--r-- | compiler/main/SysTools/Terminal.hs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/compiler/main/SysTools/Terminal.hs b/compiler/main/SysTools/Terminal.hs index d1262db531..162dd32010 100644 --- a/compiler/main/SysTools/Terminal.hs +++ b/compiler/main/SysTools/Terminal.hs @@ -18,6 +18,8 @@ import qualified Graphics.Win32 as Win32 import qualified System.Win32 as Win32 #endif +import System.IO.Unsafe + #if defined(mingw32_HOST_OS) && !defined(WINAPI) # if defined(i386_HOST_ARCH) # define WINAPI stdcall @@ -28,9 +30,15 @@ import qualified System.Win32 as Win32 # endif #endif +-- | Does the controlling terminal support ANSI color sequences? +-- This memoized to avoid thread-safety issues in ncurses (see #17922). +stderrSupportsAnsiColors :: Bool +stderrSupportsAnsiColors = unsafePerformIO stderrSupportsAnsiColors' +{-# NOINLINE stderrSupportsAnsiColors #-} + -- | Check if ANSI escape sequences can be used to control color in stderr. -stderrSupportsAnsiColors :: IO Bool -stderrSupportsAnsiColors = do +stderrSupportsAnsiColors' :: IO Bool +stderrSupportsAnsiColors' = do #if defined(MIN_VERSION_terminfo) stderr_available <- queryTerminal stdError if stderr_available then |