diff options
author | Ron Yorston <rmy@pobox.com> | 2016-04-26 16:40:18 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2016-04-26 16:40:18 +0100 |
commit | 0d9e95c2dbc422ffa3db10132db3154357c461be (patch) | |
tree | 3b38aa7146062aadb7bd7ad4e7923bcdfd74ecb5 | |
parent | b66e6daaddddd696a802349bbec1eb29add35b03 (diff) | |
download | busybox-w32-0d9e95c2dbc422ffa3db10132db3154357c461be.tar.gz busybox-w32-0d9e95c2dbc422ffa3db10132db3154357c461be.tar.bz2 busybox-w32-0d9e95c2dbc422ffa3db10132db3154357c461be.zip |
winansi: speed up clearing of screen
Various tasks on the shell command line (e.g. backspace, DEL,
reverse search) were found to be slow when the console screen
buffer was very large. This was because the entire buffer was
being cleared in erase_till_end_of_screen().
Rewrite erase_till_end_of_screen() to only clear to the end of the
visible screen and to be tidier. (Based on a suggestion by GitHub
user avih.)
Also, modify move_cursor to use coordinates relative to the current
display (as ANSI escapes expect) rather than relative to the screen
buffer.
-rw-r--r-- | win32/winansi.c | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/win32/winansi.c b/win32/winansi.c index 0a637670c..5d4adbec8 100644 --- a/win32/winansi.c +++ b/win32/winansi.c | |||
@@ -109,27 +109,20 @@ static void erase_in_line(void) | |||
109 | static void erase_till_end_of_screen(void) | 109 | static void erase_till_end_of_screen(void) |
110 | { | 110 | { |
111 | CONSOLE_SCREEN_BUFFER_INFO sbi; | 111 | CONSOLE_SCREEN_BUFFER_INFO sbi; |
112 | COORD pos; | 112 | DWORD dummy, len; |
113 | DWORD dummy; | ||
114 | 113 | ||
115 | if (!console) | 114 | if (!console) |
116 | return; | 115 | return; |
117 | 116 | ||
118 | GetConsoleScreenBufferInfo(console, &sbi); | 117 | GetConsoleScreenBufferInfo(console, &sbi); |
119 | FillConsoleOutputCharacterA(console, ' ', | 118 | len = sbi.dwSize.X - sbi.dwCursorPosition.X + |
120 | sbi.dwSize.X - sbi.dwCursorPosition.X, sbi.dwCursorPosition, | 119 | sbi.dwSize.X * (sbi.srWindow.Bottom - sbi.dwCursorPosition.Y); |
120 | |||
121 | FillConsoleOutputCharacterA(console, ' ', len, sbi.dwCursorPosition, | ||
121 | &dummy); | 122 | &dummy); |
122 | FillConsoleOutputAttribute(console, plain_attr, | 123 | FillConsoleOutputAttribute(console, plain_attr, len, sbi.dwCursorPosition, |
123 | sbi.dwSize.X - sbi.dwCursorPosition.X, sbi.dwCursorPosition, | ||
124 | &dummy); | 124 | &dummy); |
125 | 125 | ||
126 | pos.X = 0; | ||
127 | for (pos.Y = sbi.dwCursorPosition.Y+1; pos.Y < sbi.dwSize.Y; pos.Y++) { | ||
128 | FillConsoleOutputCharacterA(console, ' ', sbi.dwSize.X, | ||
129 | pos, &dummy); | ||
130 | FillConsoleOutputAttribute(console, plain_attr, sbi.dwSize.X, | ||
131 | pos, &dummy); | ||
132 | } | ||
133 | } | 126 | } |
134 | 127 | ||
135 | static void move_cursor_row(int n) | 128 | static void move_cursor_row(int n) |
@@ -159,12 +152,14 @@ static void move_cursor_column(int n) | |||
159 | static void move_cursor(int x, int y) | 152 | static void move_cursor(int x, int y) |
160 | { | 153 | { |
161 | COORD pos; | 154 | COORD pos; |
155 | CONSOLE_SCREEN_BUFFER_INFO sbi; | ||
162 | 156 | ||
163 | if (!console) | 157 | if (!console) |
164 | return; | 158 | return; |
165 | 159 | ||
166 | pos.X = x; | 160 | GetConsoleScreenBufferInfo(console, &sbi); |
167 | pos.Y = y; | 161 | pos.X = sbi.srWindow.Left + x; |
162 | pos.Y = sbi.srWindow.Top + y; | ||
168 | SetConsoleCursorPosition(console, pos); | 163 | SetConsoleCursorPosition(console, pos); |
169 | } | 164 | } |
170 | 165 | ||