@@ -2,6 +2,7 @@
2{-# LANGUAGE ForeignFunctionInterface #-}
2{-# LANGUAGE ForeignFunctionInterface #-}
3{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE ScopedTypeVariables #-}
4{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE FlexibleInstances #-}
5+{-# OPTIONS_GHC -D_XOPEN_SOURCE=500 #-}
5module Graphics.Vty.Terminal.TerminfoBased ( terminal_instance
6module Graphics.Vty.Terminal.TerminfoBased ( terminal_instance
@@ -22,7 +23,8 @@ import Data.Bits ( (.&.) )
22import Data.Maybe ( isJust, isNothing, fromJust )
23import Data.Maybe ( isJust, isNothing, fromJust )
23import Data.Word
24import Data.Word
25−import Foreign.C.Types ( CLong )
26+import Foreign.Ptr
27+import Foreign.C.Types ( CLong, CSize )
27import qualified System.Console.Terminfo as Terminfo
29import qualified System.Console.Terminfo as Terminfo
28import System.IO
30import System.IO
@@ -164,12 +166,17 @@ instance Terminal Term where
165 -- Output the byte buffer of the specified size to the terminal device.
167 -- Output the byte buffer of the specified size to the terminal device.
166 output_byte_buffer _t out_ptr out_byte_count = do
168 output_byte_buffer _t out_ptr out_byte_count = do
167− if out_byte_count == 0
169+ -- flush is required *before* the c_output_byte_buffer call
168− then return ()
170+ -- otherwise there may still be data in GHC's internal stdout buffer.
169− else hPutBuf stdout out_ptr (fromEnum out_byte_count)
170 hFlush stdout
171 hFlush stdout
172+ if out_byte_count /= 0
173+ then c_output_byte_buffer out_ptr ( toEnum $! fromEnum out_byte_count )
176+foreign import ccall unsafe "output_buffer.h stdout_output_buffer" c_output_byte_buffer
177+ :: Ptr Word8 -> CSize -> IO ()
172−foreign import ccall "gwinsz.h c_get_window_size" c_get_window_size :: IO CLong
178+foreign import ccall "gwinsz.h c_get_window_size" c_get_window_size
174get_window_size :: IO (Int,Int)
181get_window_size :: IO (Int,Int)
175get_window_size = do
182get_window_size = do