@@ -26,10 +26,10 @@ import Data.Word
2626import Foreign.Ptr
2727import Foreign.C.Types ( CLong, CSize, CInt )
2828
29+import GHC.Handle
30+
2931import qualified System.Console.Terminfo as Terminfo
3032import System.IO
31−import System.Posix.IO
32−import System.Posix.Types ( Fd(..) )
3333
3434data Term = Term
3535 { term_info_ID :: String
@@ -44,7 +44,7 @@ data Term = Term
4444 , set_default_attr :: CapExpression
4545 , clear_screen :: CapExpression
4646 , display_attr_caps :: DisplayAttrCaps
47− , term_fd :: Fd
47+ , term_handle :: Handle
4848 }
4949
5050data DisplayAttrCaps = DisplayAttrCaps
@@ -93,7 +93,7 @@ terminal_instance in_ID = do
9393 case parse_result of
9494 Left e -> fail $ show e
9595 Right cap -> return $ Just cap
96− the_fd <- liftIO $ dup stdOutput
96+ the_handle <- liftIO $ hDuplicate stdout
9797 pure Term
9898 <*> pure in_ID
9999 <*> pure ti
@@ -107,7 +107,7 @@ terminal_instance in_ID = do
107107 <*> require_cap "sgr0"
108108 <*> require_cap "clear"
109109 <*> current_display_attr_caps ti
110− <*> pure the_fd
110+ <*> pure the_handle
111111
112112current_display_attr_caps :: ( Applicative m, MonadIO m )
113113 => Terminfo.Terminal
@@ -137,7 +137,7 @@ instance Terminal Term where
137137 release_terminal t = do
138138 liftIO $ marshall_cap_to_terminal t set_default_attr []
139139 liftIO $ marshall_cap_to_terminal t cnorm []
140− liftIO $ closeFd $ term_fd t
140+ liftIO $ hClose $ term_handle t
141141 return ()
142142
143143 reserve_display t = do
@@ -177,13 +177,12 @@ instance Terminal Term where
177177 -- flush is required *before* the c_output_byte_buffer call
178178 -- otherwise there may still be data in GHC's internal stdout buffer.
179179 -- _ <- handleToFd stdout
180− let Fd c_fd = term_fd t
181− if out_byte_count /= 0
182− then c_output_byte_buffer c_fd out_ptr ( toEnum $! fromEnum out_byte_count )
183− else return ()
180+ hPutBuf (term_handle t) out_ptr (fromEnum out_byte_count)
181+
182+ output_handle t = return (term_handle t)
184183
185−foreign import ccall unsafe "output_buffer.h stdout_output_buffer" c_output_byte_buffer
186− :: CInt -> Ptr Word8 -> CSize -> IO ()
184+-- foreign import ccall unsafe "output_buffer.h stdout_output_buffer" c_output_byte_buffer
185+-- :: CInt -> Ptr Word8 -> CSize -> IO ()
187186foreign import ccall "gwinsz.h c_get_window_size" c_get_window_size
188187 :: IO CLong
189188-- foreign import ccall "fdatasync" c_fdatasync