diff options
Diffstat (limited to 'win32')
-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 | } |