summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/GHC/Driver/Session.hs3
-rw-r--r--compiler/main/SysTools/Terminal.hs12
2 files changed, 11 insertions, 4 deletions
diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs
index 8e66fef327..f500aa3501 100644
--- a/compiler/GHC/Driver/Session.hs
+++ b/compiler/GHC/Driver/Session.hs
@@ -1253,7 +1253,6 @@ initDynFlags dflags = do
`catchIOError` \_ -> return False
ghcNoUnicodeEnv <- lookupEnv "GHC_NO_UNICODE"
let useUnicode' = isNothing ghcNoUnicodeEnv && canUseUnicode
- canUseColor <- stderrSupportsAnsiColors
maybeGhcColorsEnv <- lookupEnv "GHC_COLORS"
maybeGhcColoursEnv <- lookupEnv "GHC_COLOURS"
let adjustCols (Just env) = Col.parseScheme env
@@ -1270,7 +1269,7 @@ initDynFlags dflags = do
nextWrapperNum = wrapperNum,
useUnicode = useUnicode',
useColor = useColor',
- canUseColor = canUseColor,
+ canUseColor = stderrSupportsAnsiColors,
colScheme = colScheme',
rtldInfo = refRtldInfo,
rtccInfo = refRtccInfo
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