SuperpowersCorp / refactorio

Refactorio is a tool with which you build and maintain software.
BSD 3-Clause "New" or "Revised" License
19 stars 0 forks source link

Disable colors when stdout is redirected. #25

Closed lgastako closed 6 years ago

lgastako commented 6 years ago

And provide a command line switch to disable/force colors.

lgastako commented 6 years ago

For detecting that stdout is redircted (via https://rosettacode.org/wiki/Check_output_device_is_a_terminal):

-- requires the unix package
-- https://hackage.haskell.org/package/unix
import System.Posix.Terminal (queryTerminal)
import System.Posix.IO (stdOutput)

main :: IO ()
main = do
  istty <- queryTerminal stdOutput
  putStrLn
    (if istty
       then "stdout is tty"
       else "stdout is not tty")