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