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

Commit

Permalink
Check if the output supports colors (fixes #244)
Browse files Browse the repository at this point in the history
This avoids using colors when the output is, e.g., redirected to a
file. This requried a change to avoid passing the `--colour` flag to
shake (so that hadrian is in charge of colors).

Finally, I've changed the color for `putBuild` - using white
foreground color is problematic (this was not a problem before due to
passing the `--color` flag to shake that was forcing different color).

Signed-off-by: Michal Terepeta <michal.terepeta@gmail.com>
  • Loading branch information
michalt committed May 15, 2016
1 parent fda4673 commit ec3c4be
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 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 \
"$@"
10 changes: 7 additions & 3 deletions src/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,22 @@ 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 supported $ setSGR a

-- | Make oracle output more distinguishable
putOracle :: String -> Action ()
putOracle = putColoured Blue

-- | Make build output more distinguishable
putBuild :: String -> Action ()
putBuild = putColoured White
putBuild = putColoured Blue

-- | A more colourful version of success message
putSuccess :: String -> Action ()
Expand Down

0 comments on commit ec3c4be

Please sign in to comment.