[project @ 2003-02-14 17:11:59 by sof]
authorsof <unknown>
Fri, 14 Feb 2003 17:12:00 +0000 (17:12 +0000)
committersof <unknown>
Fri, 14 Feb 2003 17:12:00 +0000 (17:12 +0000)
- add missing config.h include to Handle.hs
- Handle.hSetBuffering: don't bother putting the handle's FD into
  'raw' mode under Win32. 'raw' mode is just too specialised and
  potentially confusing (see comments.)

GHC/Handle.hs
GHC/Posix.hs

index c7ebee0..6760b1f 100644 (file)
@@ -47,6 +47,8 @@ module GHC.Handle (
 
  ) where
 
+#include "config.h"
+
 import Control.Monad
 import Data.Bits
 import Data.Maybe
@@ -939,7 +941,11 @@ hSetBuffering handle mode =
          is_tty <- fdIsTTY (haFD handle_)
          when (is_tty && isReadableHandleType (haType handle_)) $
                case mode of
+#ifndef mingw32_TARGET_OS
+       -- 'raw' mode under win32 is a bit too specialised (and troublesome
+       -- for most common uses), so simply disable its use here.
                  NoBuffering -> setCooked (haFD handle_) False
+#endif
                  _           -> setCooked (haFD handle_) True
 
          -- throw away spare buffers, they might be the wrong size
index 53b0902..ca7dc2f 100644 (file)
@@ -218,7 +218,14 @@ tcSetAttr fd options p_tios = do
 
 #else
 
--- bogus defns for win32
+-- 'raw' mode for Win32 means turn off 'line input' (=> buffering and
+-- character translation for the console.) The Win32 API for doing
+-- this is GetConsoleMode(), which also requires echoing to be disabled
+-- when turning off 'line input' processing. Notice that turning off
+-- 'line input' implies enter/return is reported as '\r' (and it won't
+-- report that character until another character is input..odd.) This
+-- latter feature doesn't sit too well with IO actions like IO.hGetLine..
+-- consider yourself warned.
 setCooked :: Int -> Bool -> IO ()
 setCooked fd cooked = do
   x <- set_console_buffering (fromIntegral fd) (if cooked then 1 else 0)
@@ -229,6 +236,8 @@ setCooked fd cooked = do
 ioe_unk_error loc msg 
  = IOError Nothing OtherError loc msg Nothing
 
+-- Note: echoing goes hand in hand with enabling 'line input' / raw-ness
+-- for Win32 consoles, hence setEcho ends up being the inverse of setCooked.
 setEcho :: Int -> Bool -> IO ()
 setEcho fd on = do
   x <- set_console_echo (fromIntegral fd) (if on then 1 else 0)