From be4fe555ee7131de29623b723cb3c37cb32f4594 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Thu, 5 Mar 2009 11:33:23 +0000 Subject: [PATCH] FIX #2189: re-enabled cooked mode for Console-connected Handles on Windows Patch from Sigbjorn Finne --- GHC/Handle.hs | 9 ++++++--- cbits/consUtils.c | 7 ++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/GHC/Handle.hs b/GHC/Handle.hs index e0995c2..c962edc 100644 --- a/GHC/Handle.hs +++ b/GHC/Handle.hs @@ -1374,10 +1374,13 @@ hSetBuffering handle mode = is_tty <- fdIsTTY (haFD handle_) when (is_tty && isReadableHandleType (haType handle_)) $ case mode of - -- Note: we used to disable 'cooked' mode setting - -- for mingw / win32 here, but it is now back on (and well - -- behaved for Console-connected Handles.) +#ifndef mingw32_HOST_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 +#else + NoBuffering -> return () +#endif _ -> setCooked (haFD handle_) True -- throw away spare buffers, they might be the wrong size diff --git a/cbits/consUtils.c b/cbits/consUtils.c index fa11000..7c50c7b 100644 --- a/cbits/consUtils.c +++ b/cbits/consUtils.c @@ -25,13 +25,10 @@ set_console_buffering__(int fd, int cooked) DWORD flgs = ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT; if ( (h = (HANDLE)_get_osfhandle(fd)) != INVALID_HANDLE_VALUE ) { - /* Only for console-connected Handles */ - if ( GetFileType(h) == FILE_TYPE_CHAR ) { if ( GetConsoleMode(h,&st) && - SetConsoleMode(h, cooked ? (st | flgs) : st & ~flgs) ) { + SetConsoleMode(h, cooked ? (st | ENABLE_LINE_INPUT) : st & ~flgs) ) { return 0; - } - } + } } return -1; } -- 1.7.10.4