Don't print colors when $TERM is 'dumb' or unset (fixes #2260)
This commit is contained in:
parent
0d58337cdd
commit
364c33395e
|
@ -6,6 +6,7 @@
|
|||
### Fixed
|
||||
- SC2102 about repetitions in ranges no longer triggers on [[ -v arr[xx] ]]
|
||||
- SC2290: Warn about misused = in declare & co, which were not caught by SC2270+
|
||||
- The flag --color=auto no longer outputs color when TERM is "dumb" or unset
|
||||
|
||||
### Changed
|
||||
- SC2048: Warning about $\* now also applies to ${array[\*]}
|
||||
|
|
|
@ -28,6 +28,7 @@ import Data.Array
|
|||
import Data.List
|
||||
import System.IO
|
||||
import System.Info
|
||||
import System.Environment
|
||||
|
||||
-- A formatter that carries along an arbitrary piece of data
|
||||
data Formatter = Formatter {
|
||||
|
@ -68,12 +69,14 @@ makeNonVirtual comments contents =
|
|||
|
||||
|
||||
shouldOutputColor :: ColorOption -> IO Bool
|
||||
shouldOutputColor colorOption = do
|
||||
term <- hIsTerminalDevice stdout
|
||||
shouldOutputColor colorOption =
|
||||
case colorOption of
|
||||
ColorAlways -> return True
|
||||
ColorNever -> return False
|
||||
ColorAuto -> do
|
||||
isTerminal <- hIsTerminalDevice stdout
|
||||
term <- lookupEnv "TERM"
|
||||
let windows = "mingw" `isPrefixOf` os
|
||||
let isUsableTty = term && not windows
|
||||
let useColor = case colorOption of
|
||||
ColorAlways -> True
|
||||
ColorNever -> False
|
||||
ColorAuto -> isUsableTty
|
||||
return useColor
|
||||
let dumbTerm = term `elem` [Just "dumb", Just "", Nothing]
|
||||
let isUsableTty = isTerminal && not windows && not dumbTerm
|
||||
return isUsableTty
|
||||
|
|
Loading…
Reference in New Issue