| ... | @@ -209,7 +209,13 @@ fn refreshWithHeldLock(self: *Progress) void { | ... | @@ -209,7 +209,13 @@ fn refreshWithHeldLock(self: *Progress) void { |
| 209 | unreachable; | 209 | unreachable; |
| 210 | | 210 | |
| 211 | saved_cursor_pos = info.dwCursorPosition; | 211 | saved_cursor_pos = info.dwCursorPosition; |
| 212 | const fill_chars = @intCast(windows.DWORD, info.dwSize.X * (info.dwSize.Y - info.dwCursorPosition.Y) - info.dwCursorPosition.X); | 212 | |
| | 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; |
| | 215 | // Number of terminal cells to clear, starting from the cursor position |
| | 216 | // and ending at the window bottom right corner. |
| | 217 | const fill_chars = window_width * (window_width - @intCast(windows.DWORD, info.dwCursorPosition.Y - info.srWindow.Top)) - |
| | 218 | @intCast(windows.DWORD, info.dwCursorPosition.Y - info.srWindow.Top); |
| 213 | | 219 | |
| 214 | var written: windows.DWORD = undefined; | 220 | var written: windows.DWORD = undefined; |
| 215 | if (windows.kernel32.FillConsoleOutputAttribute( | 221 | if (windows.kernel32.FillConsoleOutputAttribute( |
| ... | @@ -271,11 +277,7 @@ fn refreshWithHeldLock(self: *Progress) void { | ... | @@ -271,11 +277,7 @@ fn refreshWithHeldLock(self: *Progress) void { |
| 271 | const seq_after = DECRC; | 277 | const seq_after = DECRC; |
| 272 | std.mem.copy(u8, self.output_buffer[end..], seq_after); | 278 | std.mem.copy(u8, self.output_buffer[end..], seq_after); |
| 273 | end += seq_after.len; | 279 | end += seq_after.len; |
| 274 | } else if (std.builtin.os.tag == .windows) { | 280 | } else if (std.builtin.os.tag != .windows) { |
| 275 | if (windows.kernel32.SetConsoleCursorPosition(file.handle, saved_cursor_pos) != windows.TRUE) { | | |
| 276 | unreachable; | | |
| 277 | } | | |
| 278 | } else { | | |
| 279 | self.output_buffer[end] = '\n'; | 281 | self.output_buffer[end] = '\n'; |
| 280 | end += 1; | 282 | end += 1; |
| 281 | } | 283 | } |
| ... | @@ -284,6 +286,12 @@ fn refreshWithHeldLock(self: *Progress) void { | ... | @@ -284,6 +286,12 @@ fn refreshWithHeldLock(self: *Progress) void { |
| 284 | // Stop trying to write to this file once it errors. | 286 | // Stop trying to write to this file once it errors. |
| 285 | self.terminal = null; | 287 | self.terminal = null; |
| 286 | }; | 288 | }; |
| | 289 | |
| | 290 | if (std.builtin.os.tag == .windows) { |
| | 291 | if (windows.kernel32.SetConsoleCursorPosition(file.handle, saved_cursor_pos) != windows.TRUE) |
| | 292 | unreachable; |
| | 293 | } |
| | 294 | |
| 287 | self.prev_refresh_timestamp = self.timer.read(); | 295 | self.prev_refresh_timestamp = self.timer.read(); |
| 288 | } | 296 | } |
| 289 | | 297 | |