diff options
author | Ron Yorston <rmy@pobox.com> | 2020-02-06 16:35:50 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2020-02-06 16:35:50 +0000 |
commit | 87bc3fa0843f308a1b9175b8ae57c03f67a9116e (patch) | |
tree | 1af52269a1f36bfa179304d5a3c8fc44d8940457 | |
parent | 092ef6dbc4b7feed34fca061612bfc91d7ceb093 (diff) | |
download | busybox-w32-87bc3fa0843f308a1b9175b8ae57c03f67a9116e.tar.gz busybox-w32-87bc3fa0843f308a1b9175b8ae57c03f67a9116e.tar.bz2 busybox-w32-87bc3fa0843f308a1b9175b8ae57c03f67a9116e.zip |
winansi: fix alternate screen buffer in Windows 7
Closing 'vi' in Windows 7 resulted in the console window failing to
echo any output correctly until the 'reset' builtin was run. This
didn't happen in Windows XP, 8 or 10.
The problem is fixed by only duplicating the console handle when switching
*to* the alternate screen buffer.
Add sanity checks so that switching to the alternate buffer requires
the cached handled to be invalid, while it must be valid when switching
from the alternate buffer.
-rw-r--r-- | win32/winansi.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/win32/winansi.c b/win32/winansi.c index 41ca3ccca..dcfdd7e1f 100644 --- a/win32/winansi.c +++ b/win32/winansi.c | |||
@@ -87,15 +87,16 @@ static void use_alt_buffer(int flag) | |||
87 | static HANDLE console_orig = INVALID_HANDLE_VALUE; | 87 | static HANDLE console_orig = INVALID_HANDLE_VALUE; |
88 | HANDLE console, h; | 88 | HANDLE console, h; |
89 | 89 | ||
90 | console = get_console(); | ||
91 | console_orig = dup_handle(console); | ||
92 | if (console_orig == INVALID_HANDLE_VALUE) | ||
93 | return; | ||
94 | |||
95 | if (flag) { | 90 | if (flag) { |
96 | SECURITY_ATTRIBUTES sa; | 91 | SECURITY_ATTRIBUTES sa; |
97 | CONSOLE_SCREEN_BUFFER_INFO sbi; | 92 | CONSOLE_SCREEN_BUFFER_INFO sbi; |
98 | 93 | ||
94 | if (console_orig != INVALID_HANDLE_VALUE) | ||
95 | return; | ||
96 | |||
97 | console = get_console(); | ||
98 | console_orig = dup_handle(console); | ||
99 | |||
99 | // handle should be inheritable | 100 | // handle should be inheritable |
100 | memset(&sa, 0, sizeof(sa)); | 101 | memset(&sa, 0, sizeof(sa)); |
101 | sa.nLength = sizeof(sa); | 102 | sa.nLength = sizeof(sa); |
@@ -109,13 +110,16 @@ static void use_alt_buffer(int flag) | |||
109 | if (h == INVALID_HANDLE_VALUE) | 110 | if (h == INVALID_HANDLE_VALUE) |
110 | return; | 111 | return; |
111 | 112 | ||
112 | console = get_console(); | ||
113 | if (GetConsoleScreenBufferInfo(console, &sbi)) | 113 | if (GetConsoleScreenBufferInfo(console, &sbi)) |
114 | SetConsoleScreenBufferSize(h, sbi.dwSize); | 114 | SetConsoleScreenBufferSize(h, sbi.dwSize); |
115 | } | 115 | } |
116 | else { | 116 | else { |
117 | if (console_orig == INVALID_HANDLE_VALUE) | ||
118 | return; | ||
119 | |||
117 | // revert to original buffer | 120 | // revert to original buffer |
118 | h = dup_handle(console_orig); | 121 | h = dup_handle(console_orig); |
122 | console_orig = INVALID_HANDLE_VALUE; | ||
119 | if (h == INVALID_HANDLE_VALUE) | 123 | if (h == INVALID_HANDLE_VALUE) |
120 | return; | 124 | return; |
121 | } | 125 | } |