From: Simon Marlow Date: Thu, 5 Mar 2009 11:33:23 +0000 (+0000) Subject: FIX #2189: re-enabled cooked mode for Console-connected Handles on Windows X-Git-Tag: 2009-06-25~55 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=5f18f21db608de60eaf77bb16745937c58f798a9;p=ghc-base.git FIX #2189: re-enabled cooked mode for Console-connected Handles on Windows Patch from Sigbjorn Finne --- diff --git a/GHC/Handle.hs b/GHC/Handle.hs index c962edc..e0995c2 100644 --- a/GHC/Handle.hs +++ b/GHC/Handle.hs @@ -1374,13 +1374,10 @@ hSetBuffering handle mode = is_tty <- fdIsTTY (haFD handle_) when (is_tty && isReadableHandleType (haType handle_)) $ case mode of -#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. + -- 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.) 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 7c50c7b..fa11000 100644 --- a/cbits/consUtils.c +++ b/cbits/consUtils.c @@ -25,10 +25,13 @@ 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 | ENABLE_LINE_INPUT) : st & ~flgs) ) { + SetConsoleMode(h, cooked ? (st | flgs) : st & ~flgs) ) { return 0; - } + } + } } return -1; }