terminal-size 0.3.1 → 0.3.2
raw patch · 3 files changed
+36/−7 lines, 3 filesdep +process
Dependencies added: process
Files
- CHANGELOG.markdown +5/−0
- src/System/Console/Terminal/Windows.hs +26/−5
- terminal-size.cabal +5/−2
CHANGELOG.markdown view
@@ -1,3 +1,8 @@+0.3.2+=====++ * Cygwin/MSYS support (https://github.com/biegunka/terminal-size/pull/8)+ 0.3.1 =====
src/System/Console/Terminal/Windows.hs view
@@ -8,6 +8,9 @@ import Foreign.Ptr import Foreign.Storable import Foreign.Marshal.Alloc+import System.Exit+import System.IO+import System.Process type HANDLE = Ptr () @@ -34,8 +37,26 @@ hdl <- c_GetStdHandle c_STD_OUTPUT_HANDLE allocaBytes sizeCONSOLE_SCREEN_BUFFER_INFO $ \p -> do b <- c_GetConsoleScreenBufferInfo hdl p- if not b then return Nothing else do- [left,top,right,bottom] <- forM [0..3] $ \i -> do- v <- peekByteOff p ((i*2) + posCONSOLE_SCREEN_BUFFER_INFO_srWindow)- return $ fromIntegral (v :: Word16)- return $ Just $ Window (1+bottom-top) (1+right-left)+ if not b+ then do -- This could happen on Cygwin or MSYS+ let stty = (shell "stty size") {+ std_in = UseHandle stdin+ , std_out = CreatePipe+ }+ (_, mbStdout, _, rStty) <- createProcess stty+ exStty <- waitForProcess rStty+ case exStty of+ ExitFailure _ -> return Nothing+ ExitSuccess ->+ maybe (return Nothing)+ (\hSize -> do+ sizeStr <- hGetContents hSize+ let [r, c] = map read $ words sizeStr :: [Int]+ return $ Just $ Window (fromIntegral r) (fromIntegral c)+ )+ mbStdout+ else do+ [left,top,right,bottom] <- forM [0..3] $ \i -> do+ v <- peekByteOff p ((i*2) + posCONSOLE_SCREEN_BUFFER_INFO_srWindow)+ return $ fromIntegral (v :: Word16)+ return $ Just $ Window (1+bottom-top) (1+right-left)
terminal-size.cabal view
@@ -1,5 +1,5 @@ name: terminal-size-version: 0.3.1+version: 0.3.2 synopsis: Get terminal window height and width description: Get terminal window height and width without ncurses dependency.@@ -21,7 +21,7 @@ source-repository this type: git location: https://github.com/biegunka/terminal-size- tag: 0.3.1+ tag: 0.3.2 library default-language:@@ -32,6 +32,9 @@ if impl(ghc >= 7.4 && < 7.6) build-depends: ghc-prim+ if os(windows)+ build-depends:+ process build-tools: hsc2hs