Skip to content
This repository has been archived by the owner on Aug 2, 2020. It is now read-only.

Commit

Permalink
Merge pull request #253 from michalt/colors/1
Browse files Browse the repository at this point in the history
Check if the output supports colors, see #244
  • Loading branch information
snowleopard committed May 16, 2016
2 parents 03f89a6 + 0f7bc96 commit a9f43e5
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
1 change: 0 additions & 1 deletion build.cabal-new.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,4 @@ popd
"$root/.shake/build" \
--lint \
--directory "$root/.." \
--colour \
"$@"
1 change: 0 additions & 1 deletion build.cabal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ fi
cabal run hadrian -- \
--lint \
--directory "$absoluteRoot/.." \
--colour \
"$@"
1 change: 0 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,4 @@ ghc \
"$root/hadrian" \
--lint \
--directory "$root/.." \
--colour \
"$@"
1 change: 0 additions & 1 deletion build.stack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ stack build --no-library-profiling
stack exec hadrian -- \
--lint \
--directory "$absoluteRoot/.." \
--colour \
"$@"
12 changes: 10 additions & 2 deletions src/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Development.Shake hiding (parallel, unit, (*>), Normal)
import Development.Shake.Classes
import Development.Shake.FilePath
import System.Console.ANSI
import qualified System.Info as Info
import System.IO

-- TODO: reexport Stage, etc.?
Expand Down Expand Up @@ -99,10 +100,17 @@ infixr 6 -/-
-- | A more colourful version of Shake's putNormal
putColoured :: Color -> String -> Action ()
putColoured colour msg = do
liftIO $ setSGR [SetColor Foreground Vivid colour]
liftIO $ set [SetColor Foreground Vivid colour]
putNormal msg
liftIO $ setSGR []
liftIO $ set []
liftIO $ hFlush stdout
where
set a = do
supported <- hSupportsANSI stdout
when (win || supported) $ setSGR a
-- An ugly hack to always try to print colours when on mingw and cygwin.
-- See: https://github.com/snowleopard/hadrian/pull/253
win = "mingw" `isPrefixOf` Info.os || "cygwin" `isPrefixOf` Info.os

-- | Make oracle output more distinguishable
putOracle :: String -> Action ()
Expand Down

0 comments on commit a9f43e5

Please sign in to comment.