@@ -16,6 +16,7 @@ module Util.System( tempfile
1616 , readSource
1717 , setupBundledCC
1818 , isATTY
19+ , isMinTTY
1920 ) where
2021
2122import Control.Exception as CE
@@ -38,6 +39,11 @@ import System.FilePath (dropFileName, isAbsolute, searchPathSeparator)
3839import Tools_idris
3940#endif
4041
42+#ifdef mingw32_HOST_OS
43+import Graphics.Win32.Misc (getStdHandle, sTD_OUTPUT_HANDLE)
44+import System.Console.MinTTY (isMinTTYHandle)
45+#endif
46+
4147catchIO :: IO a -> (IOError -> IO a) -> IO a
4248catchIO = CE.catch
4349
@@ -70,6 +76,20 @@ isATTY = do
7076 tty <- isATTYRaw 1 -- fd stdout
7177 return $ tty /= 0
7278
79+-- | Return 'True' if the process's standard output is attached to a MinTTY
80+-- console (e.g., Cygwin or MSYS) on Windows. Return 'False' otherwise.
81+--
82+-- Unfortunately, we must check this separately since 'isATTY' always returns
83+-- 'False' on MinTTY consoles.
84+isMinTTY :: IO Bool
85+#ifdef mingw32_HOST_OS
86+isMinTTY = do
87+ h <- getStdHandle sTD_OUTPUT_HANDLE
88+ isMinTTYHandle h
89+#else
90+isMinTTY = return False
91+#endif
92+
7393withTempdir :: String -> (FilePath -> IO a) -> IO a
7494withTempdir subdir callback
7595 = do dir <- getTemporaryDirectory