mirror of
https://github.com/koalaman/shellcheck
synced 2025-08-14 02:27:30 -07:00
Add initial support for --color
This commit is contained in:
parent
bd359c5c0f
commit
a3d4101d6c
4 changed files with 40 additions and 8 deletions
|
@ -46,11 +46,11 @@ colorForLevel level =
|
|||
otherwise -> 0 -- none
|
||||
|
||||
outputError file error = do
|
||||
color <- getColorFunc
|
||||
hPutStrLn stderr $ color "error" $ file ++ ": " ++ error
|
||||
color <- getColorFunc $ ColorAuto -- FIXME: should respect --color
|
||||
hPutStrLn stderr $ color "error ZZZ" $ file ++ ": " ++ error
|
||||
|
||||
outputResult result contents = do
|
||||
color <- getColorFunc
|
||||
color <- getColorFunc $ crColorOption result
|
||||
let comments = crComments result
|
||||
let fileLines = lines contents
|
||||
let lineCount = fromIntegral $ length fileLines
|
||||
|
@ -75,10 +75,15 @@ cuteIndent comment =
|
|||
|
||||
code code = "SC" ++ show code
|
||||
|
||||
getColorFunc = do
|
||||
getColorFunc colorOption = do
|
||||
term <- hIsTerminalDevice stdout
|
||||
let windows = "mingw" `isPrefixOf` os
|
||||
return $ if term && not windows then colorComment else const id
|
||||
let isUsableTty = term && not windows
|
||||
let useColor = case colorOption of
|
||||
ColorAlways -> True
|
||||
ColorNever -> False
|
||||
ColorAuto -> isUsableTty
|
||||
return $ if useColor then colorComment else const id
|
||||
where
|
||||
colorComment level comment =
|
||||
ansi (colorForLevel level) ++ comment ++ clear
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue