From abb0450de4cb6b57dc44206768e00e4a6b2816e9 Mon Sep 17 00:00:00 2001 From: Jason Hood Date: Thu, 10 May 2018 21:57:52 +1000 Subject: [PATCH] Workaround a Windows 10 1803 bug I create a secondary buffer to assist with wrap detection. On Win10 1803 writing to this buffer outputs to the active buffer. Disable virtual terminal processing to prevent it. --- ANSI.c | 10 ++++++++-- ansicon.c | 2 +- readme.txt | 7 ++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ANSI.c b/ANSI.c index 37eb325..3192ef2 100644 --- a/ANSI.c +++ b/ANSI.c @@ -197,7 +197,7 @@ v1.83, 16 February, 2018: create the flush thread on first use. - v1.84-wip, 17 February, 26 April to 9 May, 2018: + v1.84-wip, 17 February, 26 April to 10 May, 2018: close the flush handles on detach; dynamically load WINMM.DLL; use sprintf/_snprintf/_snwprintf instead of wsprintf, avoiding USER32.DLL; @@ -208,7 +208,8 @@ remove dependency on the CRT; increase heap to 256KiB to fix logging of really long command lines; default to 7 or -7 if ANSICON_DEF could not be parsed; - scrolling will use the default attribute for new lines. + scrolling will use the default attribute for new lines; + workaround Windows 10 1803 console bug. */ #include "ansicon.h" @@ -771,6 +772,11 @@ void FlushBuffer( void ) SetConsoleMode( hConWrap, (awm) ? ENABLE_WRAP_AT_EOL_OUTPUT : 0 ); else if (!awm) SetConsoleMode( hConWrap, ENABLE_PROCESSED_OUTPUT ); + else if (cache[0].mode & 4) // ENABLE_VIRTUAL_TERMINAL_PROCESSING + { + // Windows 10 1803 writes to the active buffer if VT is enabled. + SetConsoleMode( hConWrap, cache[0].mode & ~4 ); + } WriteConsole( hConWrap, ChBuffer, nCharInBuffer, &nWritten, NULL ); GetConsoleScreenBufferInfo( hConWrap, &wi ); if (pState->tb_margins && CUR.Y + wi.CURPOS.Y > TOP + pState->bot_margin) diff --git a/ansicon.c b/ansicon.c index 7d94d0a..35ed130 100644 --- a/ansicon.c +++ b/ansicon.c @@ -94,7 +94,7 @@ import the DLL. */ -#define PDATE L"9 May, 2018" +#define PDATE L"10 May, 2018" #include "ansicon.h" #include "version.h" diff --git a/readme.txt b/readme.txt index 85aae99..a39aee6 100644 --- a/readme.txt +++ b/readme.txt @@ -339,12 +339,13 @@ Version History Legend: + added, - bug-fixed, * changed. - 1.84-wip - 9 May, 2018: + 1.84-wip - 10 May, 2018: - close the flush handles on detach; - WriteFile wasn't properly testing if its handle was for a console; - use remote load on Win8+ if the process has no IAT; - fix logging really long command lines; - default to 7 or -7 if ANSICON_DEF could not be parsed; + - workaround for a Windows 10 1803 console bug (doubled CMD prompt); * remove dependency on CRT & USER32, dynamically load WINMM; * exit process if the primary thread is detached (for processes on Win10 that return, rather than call ExitProcess); @@ -624,5 +625,5 @@ Distribution in LICENSE.txt. -======================== -Jason Hood, 9 May, 2018. +========================= +Jason Hood, 10 May, 2018.