@@ -38,6 +38,11 @@ import System.FilePath (dropFileName, isAbsolute, searchPathSeparator)
3838import Tools_idris
3939#endif
4040
41+#ifdef mingw32_HOST_OS
42+import Graphics.Win32.Misc (getStdHandle, sTD_OUTPUT_HANDLE)
43+import System.Console.MinTTY (isMinTTYHandle)
44+#endif
45+
4146catchIO :: IO a -> (IOError -> IO a) -> IO a
4247catchIO = CE.catch
4348
@@ -67,8 +72,23 @@ foreign import ccall "isatty" isATTYRaw :: CInt -> IO CInt
6772
6873isATTY :: IO Bool
6974isATTY = do
70− tty <- isATTYRaw 1 -- fd stdout
71− return $ tty /= 0
75+ tty <- isATTYRaw 1 -- fd stdout
76+ mintty <- isMinTTY
77+ return $ (tty /= 0) || mintty
78+
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
7292
7393withTempdir :: String -> (FilePath -> IO a) -> IO a
7494withTempdir subdir callback