[Git][ghc/ghc][master] Fix colors in emacs terminal
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Sat Feb 4 23:48:48 UTC 2023
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
5a54ac0b by Bodigrim at 2023-02-04T18:48:32-05:00
Fix colors in emacs terminal
- - - - -
2 changed files:
- compiler/GHC/SysTools/Terminal.hs
- utils/ghc-pkg/Main.hs
Changes:
=====================================
compiler/GHC/SysTools/Terminal.hs
=====================================
@@ -5,6 +5,7 @@ module GHC.SysTools.Terminal (stderrSupportsAnsiColors) where
import GHC.Prelude
#if !defined(mingw32_HOST_OS)
+import System.Environment (lookupEnv)
import System.IO (hIsTerminalDevice, stderr)
#else
import GHC.IO (catchException)
@@ -36,8 +37,10 @@ stderrSupportsAnsiColors = unsafePerformIO stderrSupportsAnsiColors'
stderrSupportsAnsiColors' :: IO Bool
stderrSupportsAnsiColors' = do
#if !defined(mingw32_HOST_OS)
- -- Coloured text is a part of ANSI standard, no reason to query terminfo
- hIsTerminalDevice stderr
+ -- Equivalent of https://hackage.haskell.org/package/ansi-terminal/docs/System-Console-ANSI.html#v:hSupportsANSI
+ isTerminal <- hIsTerminalDevice stderr
+ term <- lookupEnv "TERM"
+ pure $ isTerminal && term /= Just "dumb"
#else
h <- Win32.getStdHandle Win32.sTD_ERROR_HANDLE
`catchException` \ (_ :: IOError) ->
=====================================
utils/ghc-pkg/Main.hs
=====================================
@@ -86,6 +86,7 @@ import qualified Data.ByteString as BS
#if defined(mingw32_HOST_OS)
import GHC.ConsoleHandler
#else
+import System.Environment (lookupEnv)
import System.Posix hiding (fdToHandle)
#endif
@@ -1591,8 +1592,9 @@ listPackages verbosity my_flags mPackageName mModuleName = do
pkg = display (mungedId p)
is_tty <- hIsTerminalDevice stdout
- -- Coloured text is a part of ANSI standard, no reason to query terminfo
- mapM_ (if is_tty then show_colour else show_normal) stack
+ -- Equivalent of https://hackage.haskell.org/package/ansi-terminal/docs/System-Console-ANSI.html#v:hSupportsANSI
+ term <- lookupEnv "TERM"
+ mapM_ (if is_tty && term /= Just "dumb" then show_colour else show_normal) stack
#endif
simplePackageList :: [Flag] -> [InstalledPackageInfo] -> IO ()
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5a54ac0b2b915889950c83e04bf1beb08631891e
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5a54ac0b2b915889950c83e04bf1beb08631891e
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230204/b3921ee4/attachment-0001.html>
More information about the ghc-commits
mailing list