This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.
fnclearWrittenWindowsApi(io: Io) WindowsApiError!void {
// This uses a 'marker' strategy. The idea is:
// - Always write a marker (in this case U+25BA or ►) at the beginning of the progress
// - Get the current cursor position (at the end of the progress)
// - Subtract the number of lines written to get the expected start of the progress
// - Check to see if the first character at the start of the progress is the marker
// - If it's not the marker, keep checking the line before until we find it
// - Clear the screen from that position down, and set the cursor position to the start
//
// This strategy works even if there is line wrapping, and can handle the window
// being resized/scrolled arbitrarily.
//
// Notes:
// - Ideally, the marker would be a zero-width character, but the Windows console
// doesn't seem to support rendering zero-width characters (they show up as a space)
// - This same marker idea could technically be done with an attribute instead
// (https://learn.microsoft.com/en-us/windows/console/console-screen-buffers#character-attributes)
// but it must be a valid attribute and it actually needs to apply to the first
// character in order to be readable via ReadConsoleOutputAttribute. It doesn't seem
// like any of the available attributes are invisible/benign.
if (!global_progress.need_clear) return;
constterminal = global_progress.terminal;
constscreen_area = @as(windows.DWORD, global_progress.cols) * global_progress.rows;
varget_console_info = windows.CONSOLE.USER_IO.GET_SCREEN_BUFFER_INFO;
switch (tryget_console_info.operate(io, terminal)) {
.SUCCESS => {},
else => |status| returnwindows.unexpectedStatus(status),
}
varfill_spaces = windows.CONSOLE.USER_IO.FILL(
.{ .WideCharacter = ' ' },
screen_area,
get_console_info.Data.dwCursorPosition,
);
switch (tryfill_spaces.operate(io, terminal)) {
.SUCCESS => {},
else => |status| returnwindows.unexpectedStatus(status),
}
}