Skip to content

Commit

Permalink
ENH No colour output when NO_COLOR is defined
Browse files Browse the repository at this point in the history
  • Loading branch information
luispedro committed Oct 28, 2018
1 parent 92a7841 commit 1592615
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Version 0.9.1+
* Add __extra_megahit_args to assemble() (issue #86)
* Better error message when user mis-specifies the ngless version string
(issue #84)
* Support NO_COLOR environment variable (issue #83)

Version 0.9.1 2018-07-17 by luispedro
* Add biorxiv citation
Expand Down
6 changes: 4 additions & 2 deletions NGLess/Output.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Text.Printf (printf)
import System.IO (hIsTerminalDevice, stdout)
import System.IO.Unsafe (unsafePerformIO)
import System.IO.SafeWrite (withOutputFile)
import Data.Maybe (maybeToList, fromMaybe)
import Data.Maybe (maybeToList, fromMaybe, isJust)
import Data.IORef (IORef, newIORef, modifyIORef, readIORef)
import Data.List (sort)
import Data.Aeson ((.=))
Expand All @@ -45,6 +45,7 @@ import qualified Data.ByteString.Lazy.Char8 as BL8
import qualified Data.ByteString.Lazy as BL
import qualified Graphics.Rendering.Chart.Easy as G
import qualified Graphics.Rendering.Chart.Backend.Cairo as G
import System.Environment (lookupEnv)


import Data.FastQ (FastQEncoding(..), encodingName)
Expand Down Expand Up @@ -175,14 +176,15 @@ shouldPrint True ot Normal = ot >= InfoOutput
output :: OutputType -> Int -> String -> NGLessIO ()
output !ot !lno !msg = do
isTerm <- liftIO $ hIsTerminalDevice stdout
hasNOCOLOR <- isJust <$> liftIO (lookupEnv "NO_COLOR")
verb <- nConfVerbosity <$> nglConfiguration
traceSet <- nConfTrace <$> nglConfiguration
colorOpt <- nConfColor <$> nglConfiguration
let sp = traceSet || shouldPrint isTerm ot verb
doColor = case colorOpt of
ForceColor -> True
NoColor -> False
AutoColor -> isTerm
AutoColor -> isTerm && not hasNOCOLOR
c <- colorFor ot
liftIO $ do
t <- getZonedTime
Expand Down

0 comments on commit 1592615

Please sign in to comment.