diff --git a/ncurses-6.4.orig/ncurses/win32con/win32_driver.c b/ncurses-6.4/ncurses/win32con/win32_driver.c index 45aadf2f59..354015ba62 100644 --- a/ncurses-6.4.orig/ncurses/win32con/win32_driver.c +++ b/ncurses-6.4/ncurses/win32con/win32_driver.c @@ -2213,14 +2196,23 @@ InitConsole(void) for (i = 0; i < NUMPAIRS; i++) CON.pairs[i] = a; - CON.inp = GetStdHandle(STD_INPUT_HANDLE); - CON.out = GetStdHandle(STD_OUTPUT_HANDLE); - b = AllocConsole(); if (!b) b = AttachConsole(ATTACH_PARENT_PROCESS); + /* When the standard handles have been redirected (such as inside + * a text editor or the less utility), keystrokes must be read from + * the console rather than the redirected handle. The standard + * output handle suffers from a similar problem. + * Both handles are not closed once opened. The console shall be + * considered reachable throughout the process. + */ + CON.inp = CreateFile(TEXT("CONIN$"), GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); + CON.out = CreateFile(TEXT("CONOUT$"), GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0); + if (getenv("NCGDB") || getenv("NCURSES_CONSOLE2")) { T(("... will not buffer console")); buffered = FALSE;