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
|
### Fixed
|
||||||
- SC2102 about repetitions in ranges no longer triggers on [[ -v arr[xx] ]]
|
- 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+
|
- 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
|
### Changed
|
||||||
- SC2048: Warning about $\* now also applies to ${array[\*]}
|
- SC2048: Warning about $\* now also applies to ${array[\*]}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import Data.Array
|
||||||
import Data.List
|
import Data.List
|
||||||
import System.IO
|
import System.IO
|
||||||
import System.Info
|
import System.Info
|
||||||
|
import System.Environment
|
||||||
|
|
||||||
-- A formatter that carries along an arbitrary piece of data
|
-- A formatter that carries along an arbitrary piece of data
|
||||||
data Formatter = Formatter {
|
data Formatter = Formatter {
|
||||||
|
@ -68,12 +69,14 @@ makeNonVirtual comments contents =
|
||||||
|
|
||||||
|
|
||||||
shouldOutputColor :: ColorOption -> IO Bool
|
shouldOutputColor :: ColorOption -> IO Bool
|
||||||
shouldOutputColor colorOption = do
|
shouldOutputColor colorOption =
|
||||||
term <- hIsTerminalDevice stdout
|
case colorOption of
|
||||||
|
ColorAlways -> return True
|
||||||
|
ColorNever -> return False
|
||||||
|
ColorAuto -> do
|
||||||
|
isTerminal <- hIsTerminalDevice stdout
|
||||||
|
term <- lookupEnv "TERM"
|
||||||
let windows = "mingw" `isPrefixOf` os
|
let windows = "mingw" `isPrefixOf` os
|
||||||
let isUsableTty = term && not windows
|
let dumbTerm = term `elem` [Just "dumb", Just "", Nothing]
|
||||||
let useColor = case colorOption of
|
let isUsableTty = isTerminal && not windows && not dumbTerm
|
||||||
ColorAlways -> True
|
return isUsableTty
|
||||||
ColorNever -> False
|
|
||||||
ColorAuto -> isUsableTty
|
|
||||||
return useColor
|
|
||||||
|
|
Loading…
Reference in New Issue