on master help sign in
Allow colored output on MinTTY consoles on Windows
fb221e8Ryan Scott
idris.cabal+2−1
@@ -328,7 +328,8 @@ Library
328 if os(darwin)
328 if os(darwin)
329 build-depends: unix < 2.8
329 build-depends: unix < 2.8
330 if os(windows)
330 if os(windows)
331− build-depends: Win32 < 2.4
331+ build-depends: mintty >= 0.1 && < 0.2
332+ , Win32 < 2.4
332 if flag(FFI)
333 if flag(FFI)
333 build-depends: libffi < 0.2
334 build-depends: libffi < 0.2
334 cpp-options: -DIDRIS_FFI
335 cpp-options: -DIDRIS_FFI
src/Idris/Main.hs+3−2
@@ -105,8 +105,9 @@ idrisMain opts =
105
105
106 when (DefaultTotal `elem` opts) $ do i <- getIState
106 when (DefaultTotal `elem` opts) $ do i <- getIState
107 putIState (i { default_total = DefaultCheckingTotal })
107 putIState (i { default_total = DefaultCheckingTotal })
108− tty <- runIO isATTY
108+ tty <- runIO isATTY
109+ mintty <- runIO isMinTTY
109− setColourise $ not quiet && last (tty : opt getColour opts)
110+ setColourise $ not quiet && last ((tty || mintty) : opt getColour opts)
110
111
111
112
112
113
src/Idris/Output.hs+5−3
@@ -20,7 +20,7 @@ import Idris.IdeMode
20
20
21import Util.Pretty
21import Util.Pretty
22import Util.ScreenSize (getScreenWidth)
22import Util.ScreenSize (getScreenWidth)
23−import Util.System (isATTY)
23+import Util.System (isATTY, isMinTTY)
24
24
25import Prelude hiding ((<$>))
25import Prelude hiding ((<$>))
26
26
@@ -65,14 +65,16 @@ iRender d = do w <- getWidth
65 let ideMode = case idris_outputmode ist of
65 let ideMode = case idris_outputmode ist of
66 IdeMode _ _ -> True
66 IdeMode _ _ -> True
67 _ -> False
67 _ -> False
68− tty <- runIO isATTY
68+ tty <- runIO isATTY
69+ mintty <- runIO isMinTTY
69 case w of
70 case w of
70 InfinitelyWide -> return $ renderPretty 1.0 1000000000 d
71 InfinitelyWide -> return $ renderPretty 1.0 1000000000 d
71 ColsWide n -> return $
72 ColsWide n -> return $
72 if n < 1
73 if n < 1
73 then renderPretty 1.0 1000000000 d
74 then renderPretty 1.0 1000000000 d
74 else renderPretty 0.8 n d
75 else renderPretty 0.8 n d
75− AutomaticWidth | ideMode || not tty -> return $ renderPretty 1.0 80 d
76+ AutomaticWidth | ideMode || not (tty || mintty) ->
77+ return $ renderPretty 1.0 80 d
76 | otherwise -> do width <- runIO getScreenWidth
78 | otherwise -> do width <- runIO getScreenWidth
77 return $ renderPretty 0.8 width d
79 return $ renderPretty 0.8 width d
78
80
src/Util/System.hs+20
@@ -16,6 +16,7 @@ module Util.System( tempfile
16 , readSource
16 , readSource
17 , setupBundledCC
17 , setupBundledCC
18 , isATTY
18 , isATTY
19+ , isMinTTY
19 ) where
20 ) where
20
21
21import Control.Exception as CE
22import Control.Exception as CE
@@ -38,6 +39,11 @@ import System.FilePath (dropFileName, isAbsolute, searchPathSeparator)
38import Tools_idris
39import Tools_idris
39#endif
40#endif
40
41
42+#ifdef mingw32_HOST_OS
43+import Graphics.Win32.Misc (getStdHandle, sTD_OUTPUT_HANDLE)
44+import System.Console.MinTTY (isMinTTYHandle)
45+#endif
46+
41catchIO :: IO a -> (IOError -> IO a) -> IO a
47catchIO :: IO a -> (IOError -> IO a) -> IO a
42catchIO = CE.catch
48catchIO = CE.catch
43
49
@@ -70,6 +76,20 @@ isATTY = do
70 tty <- isATTYRaw 1 -- fd stdout
76 tty <- isATTYRaw 1 -- fd stdout
71 return $ tty /= 0
77 return $ tty /= 0
72
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
92+
73withTempdir :: String -> (FilePath -> IO a) -> IO a
93withTempdir :: String -> (FilePath -> IO a) -> IO a
74withTempdir subdir callback
94withTempdir subdir callback
75 = do dir <- getTemporaryDirectory
95 = do dir <- getTemporaryDirectory