@@ -1,12 +1,17 @@
1−{-# LANGUAGE CPP #-}
1+{-# LANGUAGE CPP, ForeignFunctionInterface #-}
22module Util.System(tempfile,withTempdir,rmFile,catchIO, isWindows,
33 writeSource, writeSourceText, readSource,
4− setupBundledCC) where
4+ setupBundledCC, isATTY) where
55
66-- System helper functions.
7+
8+import Control.Exception as CE
79import Control.Monad (when)
810import qualified Data.Text as T
911import qualified Data.Text.IO as TIO
12+
13+import Foreign.C
14+
1015import System.Directory (getTemporaryDirectory
1116 , removeFile
1217 , removeDirectoryRecursive
@@ -17,7 +22,6 @@ import System.FilePath ((</>), normalise, isAbsolute, dropFileName)
1722import System.IO
1823import System.Info
1924import System.IO.Error
20−import Control.Exception as CE
2125
2226#ifdef FREESTANDING
2327import Tools_idris
@@ -51,6 +55,13 @@ writeSource f s = withFile f WriteMode (\h -> hSetEncoding h utf8 >> hPutStr h s
5155writeSourceText :: FilePath -> T.Text -> IO ()
5256writeSourceText f s = withFile f WriteMode (\h -> hSetEncoding h utf8 >> TIO.hPutStr h s)
5357
58+foreign import ccall "isatty" isATTYRaw :: CInt -> IO CInt
59+
60+isATTY :: IO Bool
61+isATTY = do
62+ tty <- isATTYRaw 1 -- fd stdout
63+ return $ tty /= 0
64+
5465withTempdir :: String -> (FilePath -> IO a) -> IO a
5566withTempdir subdir callback
5667 = do dir <- getTemporaryDirectory