diff options
author | Ron Yorston <rmy@pobox.com> | 2019-04-07 12:28:04 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2019-04-07 12:28:04 +0100 |
commit | 96ac4dc17b53f5bec3c4dd31b9b9a3c3e5fe3582 (patch) | |
tree | aa42a4936c09f12a152c6bc951e934a9760cb664 | |
parent | 379a8b313923db1f4892a3dd0d8d923bc6683d8a (diff) | |
download | busybox-w32-96ac4dc17b53f5bec3c4dd31b9b9a3c3e5fe3582.tar.gz busybox-w32-96ac4dc17b53f5bec3c4dd31b9b9a3c3e5fe3582.tar.bz2 busybox-w32-96ac4dc17b53f5bec3c4dd31b9b9a3c3e5fe3582.zip |
winansi: code shrink
Add a common function to clear a section of the screen buffer.
-rw-r--r-- | win32/winansi.c | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/win32/winansi.c b/win32/winansi.c index a2c49b7e7..38bd6824f 100644 --- a/win32/winansi.c +++ b/win32/winansi.c | |||
@@ -104,52 +104,45 @@ static void set_console_attr(void) | |||
104 | SetConsoleTextAttribute(console, attributes); | 104 | SetConsoleTextAttribute(console, attributes); |
105 | } | 105 | } |
106 | 106 | ||
107 | static void clear_buffer(DWORD len, COORD pos) | ||
108 | { | ||
109 | DWORD dummy; | ||
110 | |||
111 | FillConsoleOutputCharacterA(console, ' ', len, pos, &dummy); | ||
112 | FillConsoleOutputAttribute(console, plain_attr, len, pos, &dummy); | ||
113 | } | ||
114 | |||
107 | static void erase_in_line(void) | 115 | static void erase_in_line(void) |
108 | { | 116 | { |
109 | CONSOLE_SCREEN_BUFFER_INFO sbi; | 117 | CONSOLE_SCREEN_BUFFER_INFO sbi; |
110 | DWORD dummy; /* Needed for Windows 7 (or Vista) regression */ | ||
111 | 118 | ||
112 | if (!GetConsoleScreenBufferInfo(console, &sbi)) | 119 | if (!GetConsoleScreenBufferInfo(console, &sbi)) |
113 | return; | 120 | return; |
114 | FillConsoleOutputCharacterA(console, ' ', | 121 | clear_buffer(sbi.dwSize.X - sbi.dwCursorPosition.X, sbi.dwCursorPosition); |
115 | sbi.dwSize.X - sbi.dwCursorPosition.X, sbi.dwCursorPosition, | ||
116 | &dummy); | ||
117 | FillConsoleOutputAttribute(console, plain_attr, | ||
118 | sbi.dwSize.X - sbi.dwCursorPosition.X, sbi.dwCursorPosition, | ||
119 | &dummy); | ||
120 | } | 122 | } |
121 | 123 | ||
122 | static void erase_till_end_of_screen(void) | 124 | static void erase_till_end_of_screen(void) |
123 | { | 125 | { |
124 | CONSOLE_SCREEN_BUFFER_INFO sbi; | 126 | CONSOLE_SCREEN_BUFFER_INFO sbi; |
125 | DWORD dummy, len; | 127 | DWORD len; |
126 | 128 | ||
127 | if(!GetConsoleScreenBufferInfo(console, &sbi)) | 129 | if(!GetConsoleScreenBufferInfo(console, &sbi)) |
128 | return; | 130 | return; |
129 | len = sbi.dwSize.X - sbi.dwCursorPosition.X + | 131 | len = sbi.dwSize.X - sbi.dwCursorPosition.X + |
130 | sbi.dwSize.X * (sbi.srWindow.Bottom - sbi.dwCursorPosition.Y); | 132 | sbi.dwSize.X * (sbi.srWindow.Bottom - sbi.dwCursorPosition.Y); |
131 | 133 | clear_buffer(len, sbi.dwCursorPosition); | |
132 | FillConsoleOutputCharacterA(console, ' ', len, sbi.dwCursorPosition, | ||
133 | &dummy); | ||
134 | FillConsoleOutputAttribute(console, plain_attr, len, sbi.dwCursorPosition, | ||
135 | &dummy); | ||
136 | } | 134 | } |
137 | 135 | ||
138 | void reset_screen(void) | 136 | void reset_screen(void) |
139 | { | 137 | { |
140 | CONSOLE_SCREEN_BUFFER_INFO sbi; | 138 | CONSOLE_SCREEN_BUFFER_INFO sbi; |
141 | COORD pos; | 139 | COORD pos = { 0, 0 }; |
142 | DWORD dummy, len; | ||
143 | 140 | ||
144 | /* move to start of screen buffer and clear it all */ | 141 | /* move to start of screen buffer and clear it all */ |
145 | if (!GetConsoleScreenBufferInfo(console, &sbi)) | 142 | if (!GetConsoleScreenBufferInfo(console, &sbi)) |
146 | return; | 143 | return; |
147 | pos.X = 0; | ||
148 | pos.Y = 0; | ||
149 | SetConsoleCursorPosition(console, pos); | 144 | SetConsoleCursorPosition(console, pos); |
150 | len = sbi.dwSize.X * sbi.dwSize.Y; | 145 | clear_buffer(sbi.dwSize.X * sbi.dwSize.Y, pos); |
151 | FillConsoleOutputCharacterA(console, ' ', len, pos, &dummy); | ||
152 | FillConsoleOutputAttribute(console, plain_attr, len, pos, &dummy); | ||
153 | } | 146 | } |
154 | 147 | ||
155 | void move_cursor_row(int n) | 148 | void move_cursor_row(int n) |