Closed lgastako closed 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")
And provide a command line switch to disable/force colors.