From ef259ef3fab9605fef316797cda3ff1a12c7d88d Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 17 Nov 2017 16:53:45 -0800 Subject: Revert "Fix console clear screen if buffer is full" This reverts commit 99a3f266c15af5bbb9a8cacda63ce11b094c10d1. Unfortunately Corinna's August 3, 2016 is unsatisfactory, and interferes with our patch for the issue cherry picked from cygnal-2.5.2 into cygnal-2.9.0-branch. When the screen-clearing escape sequence ESC[2J is issued material below the cursor is not cleared properly. For instance, in the TXR Lisp listener, the Ctrl-L command fails to clear the screen at all, because it first homes the cursor to the top line of the screen and then issues the clear screen. --- winsup/cygwin/fhandler_console.cc | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index 6f92a75d5..d3611eaaa 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -1683,47 +1683,38 @@ dev_console::scroll_window (HANDLE h, int x1, int y1, int x2, int y2) would move us beyond the buffer. What we do here is to scroll the console buffer upward by just as much so that the current last line becomes the last line just prior to the first window line. That - keeps the end of the console buffer intact, as desired. */ + keeps the end of the console buffer intact, as desired. + + Since we're moving the console buffer under the console window in + this case, we must not move the console window. */ SMALL_RECT br; COORD dest; CHAR_INFO fill; br.Left = 0; - br.Top = (b.srWindow.Bottom - b.srWindow.Top) + 1 - - (b.dwSize.Y - dwEnd.Y - 1); + br.Top = dwEnd.Y - b.srWindow.Top + 1; br.Right = b.dwSize.X - 1; br.Bottom = b.dwSize.Y - 1; dest.X = dest.Y = 0; fill.Char.UnicodeChar = L' '; fill.Attributes = current_win32_attr; - ScrollConsoleScreenBufferW (h, &br, NULL, dest, &fill); - /* Since we're moving the console buffer under the console window - we only have to move the console window if the user scrolled the - window upwards. The number of lines is the distance to the - buffer bottom. */ - toscroll = b.dwSize.Y - b.srWindow.Bottom - 1; - /* Fix dwEnd to reflect the new cursor line. Take the above scrolling - into account and subtract 1 to account for the increment below. */ - dwEnd.Y = b.dwCursorPosition.Y + toscroll - 1; + ScrollConsoleScreenBuffer (h, &br, NULL, dest, &fill); + /* Fix dwEnd to reflect the new cursor line (minus 1 to take the + increment a few lines later into account) */ + dwEnd.Y = b.dwCursorPosition.Y - 1; } - if (toscroll) + else { - /* FIXME: For some reason SetConsoleWindowInfo does not correctly - set the scrollbars. Calling SetConsoleCursorPosition here is - just a workaround which doesn't cover all cases. In some scenarios - the scrollbars are still off by one console window size. */ - /* The reminder of the console buffer is big enough to simply move the console window. We have to set the cursor first, otherwise the scroll bars will not be corrected. */ SetConsoleCursorPosition (h, dwEnd); - /* If the user scolled manually, setting the cursor position might scroll - the console window so that the cursor is not at the top. Correct + /* If we scroll backwards, setting the cursor position will scroll + the console window up so that the cursor is at the bottom. Correct the action by moving the window down again so the cursor is one line above the new window position. */ - GetConsoleScreenBufferInfo (h, &b); - if (b.dwCursorPosition.Y >= b.srWindow.Top) - toscroll = b.dwCursorPosition.Y - b.srWindow.Top + 1; + if (toscroll < 0) + toscroll = b.srWindow.Bottom - b.srWindow.Top; /* Move the window accordingly. */ sr.Top = sr.Bottom = toscroll; SetConsoleWindowInfo (h, FALSE, &sr); -- cgit v1.2.3