Don't print colors when $TERM is 'dumb' or unset (fixes #2260)

This commit is contained in:
Vidar Holen 2021-07-25 14:41:49 -07:00
parent 0d58337cdd
commit 364c33395e
2 changed files with 13 additions and 9 deletions

View File

@ -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[\*]}

View File

@ -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
let windows = "mingw" `isPrefixOf` os
let isUsableTty = term && not windows
let useColor = case colorOption of
ColorAlways -> True
ColorNever -> False
ColorAuto -> isUsableTty
return useColor
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 dumbTerm = term `elem` [Just "dumb", Just "", Nothing]
let isUsableTty = isTerminal && not windows && not dumbTerm
return isUsableTty