Skip to content

Commit d750a78

Browse files
squeek502andrewrk
authored andcommitted
std.Progress: Fix Windows console API implementation
3a3d218 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 parent 6b020c3 commit d750a78

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lib/std/Progress.zig

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,14 @@ fn updateThreadRun() void {
472472
}
473473
}
474474

475+
fn 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+
475483
fn 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
}

0 commit comments

Comments
 (0)