authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2024-05-28 17:13:53-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-28 22:46:12-04:00
logd750a78b2c0265bd7bb2b924c4c739cad5aa6666
tree5841b156d890f9f8850a3c6f54ba00029fa249a9
parent6b020c3d1529ff27bc5d4bbe53b1b354aa063f4b

std.Progress: Fix Windows console API implementation

3a3d2187f986066859cfb793fb7ee1cae4dfea08 unintentionally broke some of the Windows console API implementation. - The 'marker' character was no longer being written at all - The ANSI escape codes for syncing were being written unconditionally

1 files changed, 18 insertions(+), 4 deletions(-)

lib/std/Progress.zig+18-4
......@@ -472,6 +472,14 @@ fn updateThreadRun() void {
472472 }
473473}
474474
475fn windowsApiWriteMarker() void {
476 // Write the marker that we will use to find the beginning of the progress when clearing.
477 // Note: This doesn't have to use WriteConsoleW, but doing so avoids dealing with the code page.
478 var num_chars_written: windows.DWORD = undefined;
479 const handle = global_progress.terminal.handle;
480 _ = windows.kernel32.WriteConsoleW(handle, &[_]u16{windows_api_start_marker}, 1, &num_chars_written, null);
481}
482
475483fn windowsApiUpdateThreadRun() void {
476484 var serialized_buffer: Serialized.Buffer = undefined;
477485
......@@ -483,6 +491,7 @@ fn windowsApiUpdateThreadRun() void {
483491 const buffer = computeRedraw(&serialized_buffer);
484492 if (stderr_mutex.tryLock()) {
485493 defer stderr_mutex.unlock();
494 windowsApiWriteMarker();
486495 write(buffer) catch return;
487496 }
488497 }
......@@ -502,6 +511,7 @@ fn windowsApiUpdateThreadRun() void {
502511 if (stderr_mutex.tryLock()) {
503512 defer stderr_mutex.unlock();
504513 clearWrittenWindowsApi() catch return;
514 windowsApiWriteMarker();
505515 write(buffer) catch return;
506516 }
507517 }
......@@ -1048,8 +1058,10 @@ fn computeRedraw(serialized_buffer: *Serialized.Buffer) []u8 {
10481058 var i: usize = 0;
10491059 const buf = global_progress.draw_buffer;
10501060
1051 buf[i..][0..start_sync.len].* = start_sync.*;
1052 i += start_sync.len;
1061 if (global_progress.terminal_mode == .ansi_escape_codes) {
1062 buf[i..][0..start_sync.len].* = start_sync.*;
1063 i += start_sync.len;
1064 }
10531065
10541066 switch (global_progress.terminal_mode) {
10551067 .off => unreachable,
......@@ -1061,8 +1073,10 @@ fn computeRedraw(serialized_buffer: *Serialized.Buffer) []u8 {
10611073 const root_node_index: Node.Index = @enumFromInt(0);
10621074 i = computeNode(buf, i, serialized, children, root_node_index);
10631075
1064 buf[i..][0..finish_sync.len].* = finish_sync.*;
1065 i += finish_sync.len;
1076 if (global_progress.terminal_mode == .ansi_escape_codes) {
1077 buf[i..][0..finish_sync.len].* = finish_sync.*;
1078 i += finish_sync.len;
1079 }
10661080
10671081 return buf[0..i];
10681082}