diff --git a/contrib/win32/win32compat/console.c b/contrib/win32/win32compat/console.c index e25bf9983..09d23e949 100644 --- a/contrib/win32/win32compat/console.c +++ b/contrib/win32/win32compat/console.c @@ -56,6 +56,8 @@ int ScrollBottom; int LastCursorX; int LastCursorY; BOOL isAnsiParsingRequired = FALSE; +/* 1 - We track the viewport (visible window) and restore it back because console renders badly when user scroll up/down */ +int track_view_port = 0; char *pSavedScreen = NULL; static COORD ZeroCoord = { 0,0 }; COORD SavedScreenSize = { 0,0 }; @@ -138,6 +140,10 @@ ConEnterRawMode() GetConsoleScreenBufferInfo(hOutputConsole, &csbi); + /* We track the view port, if conpty is not supported */ + if (!is_conpty_supported()) + track_view_port = 1; + /* if we are passing rawbuffer to console then we need to move the cursor to top * so that the clearscreen will not erase any lines. */ @@ -146,19 +152,19 @@ ConEnterRawMode() debug("console doesn't support the ansi parsing"); } else { debug("console supports the ansi parsing"); - if (is_conpty_supported()) { - console_out_cp_saved = GetConsoleOutputCP(); - console_in_cp_saved = GetConsoleCP(); - if (SetConsoleOutputCP(CP_UTF8)) - debug3("Successfully set console output code page from:%d to %d", console_out_cp_saved, CP_UTF8); - else - error("Failed to set console output code page from:%d to %d error:%d", console_out_cp_saved, CP_UTF8, GetLastError()); + console_out_cp_saved = GetConsoleOutputCP(); + console_in_cp_saved = GetConsoleCP(); + if (SetConsoleOutputCP(CP_UTF8)) + debug3("Successfully set console output code page from:%d to %d", console_out_cp_saved, CP_UTF8); + else + error("Failed to set console output code page from:%d to %d error:%d", console_out_cp_saved, CP_UTF8, GetLastError()); - if (SetConsoleCP(CP_UTF8)) - debug3("Successfully set console input code page from:%d to %d", console_in_cp_saved, CP_UTF8); - else - error("Failed to set console input code page from:%d to %d error:%d", console_in_cp_saved, CP_UTF8, GetLastError()); - } else { + if (SetConsoleCP(CP_UTF8)) + debug3("Successfully set console input code page from:%d to %d", console_in_cp_saved, CP_UTF8); + else + error("Failed to set console input code page from:%d to %d error:%d", console_in_cp_saved, CP_UTF8, GetLastError()); + + if (track_view_port) { ConSaveViewRect(); } } @@ -178,7 +184,7 @@ ConExitRawMode() SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), stdin_dwSavedAttributes); SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), stdout_dwSavedAttributes); - if (FALSE == isAnsiParsingRequired && is_conpty_supported()) { + if (FALSE == isAnsiParsingRequired) { if (console_out_cp_saved) { if(SetConsoleOutputCP(console_out_cp_saved)) debug3("Successfully set console output code page from %d to %d", CP_UTF8, console_out_cp_saved); @@ -256,7 +262,7 @@ ConSetScreenRect(int xSize, int ySize) bSuccess = SetConsoleScreenBufferSize(hOutputConsole, coordScreen); } - if (bSuccess && !is_conpty_supported()) + if (bSuccess && track_view_port) ConSaveViewRect(); /* if the current buffer *is* the size we want, don't do anything! */ @@ -303,7 +309,7 @@ ConSetScreenSize(int xSize, int ySize) bSuccess = SetConsoleWindowInfo(hOutputConsole, TRUE, &srWindowRect); } - if (bSuccess && !is_conpty_supported()) + if (bSuccess && track_view_port) ConSaveViewRect(); /* if the current buffer *is* the size we want, don't do anything! */ @@ -1622,7 +1628,7 @@ ConMoveCursorTopOfVisibleWindow() offset = csbi.dwCursorPosition.Y - csbi.srWindow.Top; ConMoveVisibleWindow(offset); - if(!is_conpty_supported()) + if(track_view_port) ConSaveViewRect(); } } diff --git a/contrib/win32/win32compat/tnnet.c b/contrib/win32/win32compat/tnnet.c index 8c3cc8b00..d92e65e9a 100644 --- a/contrib/win32/win32compat/tnnet.c +++ b/contrib/win32/win32compat/tnnet.c @@ -42,6 +42,7 @@ #define dwBuffer 4096 extern BOOL isAnsiParsingRequired; +extern int track_view_port; extern bool gbVTAppMode; BOOL isFirstPacket = TRUE; @@ -62,7 +63,6 @@ processBuffer(HANDLE handle, char *buf, DWORD len, unsigned char **respbuf, size const char *normalModeSeq = "\x1b[?1l"; const DWORD normalModeSeqLen = (DWORD)strlen(normalModeSeq); const char *clsSeq = "\x1b[2J"; - static int track_view_port = 1; if (len == 0) return; @@ -71,9 +71,6 @@ processBuffer(HANDLE handle, char *buf, DWORD len, unsigned char **respbuf, size if(isFirstPacket) { isFirstPacket = FALSE; - if (is_conpty_supported()) - track_view_port = 0; - /* Windows server at first sends the "cls" after the connection is established. * There is a bug in the conhost which causes the visible window data to loose so to * mitigate that issue we need to first move the visible window so that the cursor is at the top of the visible window.