From 248a2600a2f4b442101ad568d1994b908bb28d4b Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 26 Apr 2016 16:48:38 +0100 Subject: winansi: revert to previous console behaviour for vi/less Recent changes to make the Windows console behave more like a *nix terminal didn't work too well for vi/less. On *nix the terminal buffer can't be scrolled while such screen-based applications are running. In the Windows console this remained possible and led to confusion. Add a new routine to allow vi/less to revert to their previous behaviour where the cursor is positioned at the top of the buffer and the entire buffer is cleared. --- editors/vi.c | 5 +++++ include/mingw.h | 1 + miscutils/less.c | 2 +- win32/winansi.c | 18 ++++++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/editors/vi.c b/editors/vi.c index b2d185193..75ce8d396 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -3074,7 +3074,12 @@ static void go_bottom_and_clear_to_eol(void) //----- Erase from cursor to end of screen ----------------------- static void clear_to_eos(void) { +#if !ENABLE_PLATFORM_MINGW32 write1(ESC_CLEAR2EOS); +#else + /* in practice clear_to_eos() always clears the entire screen */ + reset_screen(); +#endif } //----- Start standout mode ------------------------------------ diff --git a/include/mingw.h b/include/mingw.h index 5faef41bf..555fa96b7 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -155,6 +155,7 @@ int mingw_pclose(FILE *fd); */ void move_cursor_row(int n); +void reset_screen(void); int winansi_putchar(int c); int winansi_puts(const char *s); size_t winansi_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); diff --git a/miscutils/less.c b/miscutils/less.c index 014a649e0..cc0e20bc7 100644 --- a/miscutils/less.c +++ b/miscutils/less.c @@ -1068,7 +1068,7 @@ static void reinitialize(void) printf("\033[999;999H" "\033[6n"); #endif #if ENABLE_PLATFORM_MINGW32 - puts(CLEAR); + reset_screen(); #endif buffer_fill_and_print(); } diff --git a/win32/winansi.c b/win32/winansi.c index ebe831593..d61e8a2cf 100644 --- a/win32/winansi.c +++ b/win32/winansi.c @@ -122,7 +122,25 @@ static void erase_till_end_of_screen(void) &dummy); FillConsoleOutputAttribute(console, plain_attr, len, sbi.dwCursorPosition, &dummy); +} + +void reset_screen(void) +{ + CONSOLE_SCREEN_BUFFER_INFO sbi; + COORD pos; + DWORD dummy, len; + if (!console) + return; + + /* move to start of screen buffer and clear it all */ + GetConsoleScreenBufferInfo(console, &sbi); + pos.X = 0; + pos.Y = 0; + SetConsoleCursorPosition(console, pos); + len = sbi.dwSize.X * sbi.dwSize.Y; + FillConsoleOutputCharacterA(console, ' ', len, pos, &dummy); + FillConsoleOutputAttribute(console, plain_attr, len, pos, &dummy); } void move_cursor_row(int n) -- cgit v1.2.3-55-g6feb