From 09541776d0120b0e5c66511c307417333a0a1cae Mon Sep 17 00:00:00 2001 From: sof Date: Thu, 18 Jul 2002 22:01:50 +0000 Subject: [PATCH] [project @ 2002-07-18 22:01:50 by sof] win32 console-based implementations of setCooked, {get,set}Echo --- GHC/Posix.hs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/GHC/Posix.hs b/GHC/Posix.hs index 7dc08b3..5ae6c0c 100644 --- a/GHC/Posix.hs +++ b/GHC/Posix.hs @@ -211,13 +211,37 @@ tcSetAttr fd options p_tios = do -- bogus defns for win32 setCooked :: Int -> Bool -> IO () -setCooked fd cooked = return () +setCooked fd cooked = do + x <- set_console_buffering (fromIntegral fd) (if cooked then 1 else 0) + if (x /= 0) + then ioException (ioe_unk_error "setCooked" "failed to set buffering") + else return () + +ioe_unk_error loc msg + = IOError Nothing OtherError loc msg Nothing setEcho :: Int -> Bool -> IO () -setEcho fd on = return () +setEcho fd on = do + x <- set_console_echo (fromIntegral fd) (if on then 1 else 0) + if (x /= 0) + then ioException (ioe_unk_error "setEcho" "failed to set echoing") + else return () getEcho :: Int -> IO Bool -getEcho fd = return False +getEcho fd = do + r <- get_console_echo (fromIntegral fd) + if (r == (-1)) + then ioException (ioe_unk_error "getEcho" "failed to get echoing") + else return (r == 1) + +foreign import ccall unsafe "consUtils.h set_console_buffering__" + set_console_buffering :: CInt -> CInt -> IO CInt + +foreign import ccall unsafe "consUtils.h set_console_echo__" + set_console_echo :: CInt -> CInt -> IO CInt + +foreign import ccall unsafe "consUtils.h get_console_echo__" + get_console_echo :: CInt -> IO CInt #endif -- 1.7.10.4