authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-03-12 17:14:50+01:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-03-12 17:14:50+01:00
logb0724a350f07c5e2e8fab572951ffaaa92860b2c
treee63e09aec7a18514e2c955c53345143f17ed9a20
parentb5a50a26ebac6a08dacf79f5d1db9bdd94ba33a5

Handle some weird edge cases of Win32 API

Sometimes the viewport srWindow may report an invalid rectangle where the top row is below the bottom one.

1 files changed, 7 insertions(+), 5 deletions(-)

lib/std/Progress.zig+7-5
...@@ -210,13 +210,15 @@ fn refreshWithHeldLock(self: *Progress) void {...@@ -210,13 +210,15 @@ fn refreshWithHeldLock(self: *Progress) void {
210210
211 saved_cursor_pos = info.dwCursorPosition;211 saved_cursor_pos = info.dwCursorPosition;
212212
213 const window_height = @intCast(windows.DWORD, info.srWindow.Bottom - info.srWindow.Top) + 1;213 const window_height = @intCast(windows.DWORD, info.srWindow.Bottom - info.srWindow.Top + 1);
214 const window_width = @intCast(windows.DWORD, info.srWindow.Right - info.srWindow.Left) + 1;214 const window_width = @intCast(windows.DWORD, info.srWindow.Right - info.srWindow.Left + 1);
215 // Number of terminal cells to clear, starting from the cursor position215 // Number of terminal cells to clear, starting from the cursor position
216 // and ending at the window bottom right corner.216 // and ending at the window bottom right corner.
217 const fill_chars = window_width * (window_height -217 const fill_chars = if (window_width == 0 or window_height == 0) 0 else chars: {
218 @intCast(windows.DWORD, info.dwCursorPosition.Y - info.srWindow.Top)) -218 break :chars window_width * (window_height -
219 @intCast(windows.DWORD, info.dwCursorPosition.X - info.srWindow.Left);219 @intCast(windows.DWORD, info.dwCursorPosition.Y - info.srWindow.Top)) -
220 @intCast(windows.DWORD, info.dwCursorPosition.X - info.srWindow.Left);
221 };
220222
221 var written: windows.DWORD = undefined;223 var written: windows.DWORD = undefined;
222 if (windows.kernel32.FillConsoleOutputAttribute(224 if (windows.kernel32.FillConsoleOutputAttribute(