@@ -26,10 +26,10 @@ import Data.Word
26import Foreign.Ptr
26import Foreign.Ptr
27import Foreign.C.Types ( CLong, CSize, CInt )
27import Foreign.C.Types ( CLong, CSize, CInt )
29import qualified System.Console.Terminfo as Terminfo
31import qualified System.Console.Terminfo as Terminfo
30import System.IO
32import System.IO
31−import System.Posix.IO
32−import System.Posix.Types ( Fd(..) )
34data Term = Term
34data Term = Term
35 { term_info_ID :: String
35 { term_info_ID :: String
@@ -44,7 +44,7 @@ data Term = Term
44 , set_default_attr :: CapExpression
44 , set_default_attr :: CapExpression
45 , clear_screen :: CapExpression
45 , clear_screen :: CapExpression
46 , display_attr_caps :: DisplayAttrCaps
46 , display_attr_caps :: DisplayAttrCaps
47− , term_fd :: Fd
47+ , term_handle :: Handle
50data DisplayAttrCaps = DisplayAttrCaps
50data DisplayAttrCaps = DisplayAttrCaps
@@ -93,7 +93,7 @@ terminal_instance in_ID = do
93 case parse_result of
93 case parse_result of
94 Left e -> fail $ show e
94 Left e -> fail $ show e
95 Right cap -> return $ Just cap
95 Right cap -> return $ Just cap
96− the_fd <- liftIO $ dup stdOutput
96+ the_handle <- liftIO $ hDuplicate stdout
98 <*> pure in_ID
98 <*> pure in_ID
99 <*> pure ti
99 <*> pure ti
@@ -107,7 +107,7 @@ terminal_instance in_ID = do
107 <*> require_cap "sgr0"
107 <*> require_cap "sgr0"
108 <*> require_cap "clear"
108 <*> require_cap "clear"
109 <*> current_display_attr_caps ti
109 <*> current_display_attr_caps ti
110− <*> pure the_fd
110+ <*> pure the_handle
112current_display_attr_caps :: ( Applicative m, MonadIO m )
112current_display_attr_caps :: ( Applicative m, MonadIO m )
113 => Terminfo.Terminal
113 => Terminfo.Terminal
@@ -137,7 +137,7 @@ instance Terminal Term where
137 release_terminal t = do
137 release_terminal t = do
138 liftIO $ marshall_cap_to_terminal t set_default_attr []
138 liftIO $ marshall_cap_to_terminal t set_default_attr []
139 liftIO $ marshall_cap_to_terminal t cnorm []
139 liftIO $ marshall_cap_to_terminal t cnorm []
140− liftIO $ closeFd $ term_fd t
140+ liftIO $ hClose $ term_handle t
141 return ()
141 return ()
143 reserve_display t = do
143 reserve_display t = do
@@ -177,13 +177,12 @@ instance Terminal Term where
177 -- flush is required *before* the c_output_byte_buffer call
177 -- flush is required *before* the c_output_byte_buffer call
178 -- otherwise there may still be data in GHC's internal stdout buffer.
178 -- otherwise there may still be data in GHC's internal stdout buffer.
179 -- _ <- handleToFd stdout
179 -- _ <- 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 )
180+ hPutBuf (term_handle t) out_ptr (fromEnum out_byte_count)
182+ output_handle t = return (term_handle t)
185−foreign import ccall unsafe "output_buffer.h stdout_output_buffer" c_output_byte_buffer
184+-- foreign import ccall unsafe "output_buffer.h stdout_output_buffer" c_output_byte_buffer
186− :: CInt -> Ptr Word8 -> CSize -> IO ()
185+-- :: CInt -> Ptr Word8 -> CSize -> IO ()
187foreign import ccall "gwinsz.h c_get_window_size" c_get_window_size
186foreign import ccall "gwinsz.h c_get_window_size" c_get_window_size
188 :: IO CLong
187 :: IO CLong
189-- foreign import ccall "fdatasync" c_fdatasync
188-- foreign import ccall "fdatasync" c_fdatasync