forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefaultColorWhen.hs
More file actions
27 lines (24 loc) · 1.02 KB
/
DefaultColorWhen.hs
File metadata and controls
27 lines (24 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module Stack.DefaultColorWhen
( defaultColorWhen
) where
import Stack.Prelude (stdout)
import Stack.Types.Config (ColorWhen (ColorAuto, ColorNever))
import System.Console.ANSI (hSupportsANSIWithoutEmulation)
import System.Environment (lookupEnv)
-- | The default adopts the standard proposed at http://no-color.org/, that
-- color should not be added by default if the @NO_COLOR@ environment variable
-- is present.
defaultColorWhen :: IO ColorWhen
defaultColorWhen = do
-- On Windows, 'hSupportsANSIWithoutEmulation' has the side effect of enabling
-- ANSI for ANSI-capable native (ConHost) terminals, if not already
-- ANSI-enabled. Consequently, it is actioned even if @NO_COLOR@ might exist,
-- as @NO_COLOR@ might be overridden in a yaml configuration file or at the
-- command line.
supportsANSI <- hSupportsANSIWithoutEmulation stdout
mIsNoColor <- lookupEnv "NO_COLOR"
return $ case mIsNoColor of
Just _ -> ColorNever
_ -> case supportsANSI of
Just False -> ColorNever
_ -> ColorAuto