Skip to content

Conversation

@expikr
Copy link
Contributor

@expikr expikr commented Nov 9, 2023

This is crucial for enabling ANSI escape sequences on Windows. If Zig is not going to enable it by default, at least make the sys calls easily available for the boilerplate init procedure:

test {

    const std = @import("std")
    const kernel32 = std.os.windows.kernel32;
    var stdout_mode: u32 = undefined;
    _ = kernel32.GetConsoleMode(std.io.getStdOut().handle, &stdout_mode);
    _ = kernel32.SetConsoleMode(std.io.getStdOut().handle, stdout_mode|4);

    std.debug.print("\n\x1b[30;47m" ++ "That's all," ++ "\x1b[m" ++ " folks\n", .{});

}

Whereas before, without this change you'd need to do:

test {

    const std = @import("std");
    const kernel32 = opaque {
        usingnamespace std.os.windows.kernel32;
        extern "kernel32" fn SetConsoleMode(*anyopaque,u32) callconv(std.os.windows.WINAPI) c_int;
    };
    var stdout_mode: u32 = undefined;
    _ = kernel32.GetConsoleMode(std.io.getStdOut().handle, &stdout_mode);
    _ = kernel32.SetConsoleMode(std.io.getStdOut().handle, stdout_mode|4);

    std.debug.print("\n\x1b[30;47m" ++ "That's all," ++ "\x1b[m" ++ " folks\n", .{});

}

@Vexu
Copy link
Member

Vexu commented Nov 21, 2023

Previously rejected in #15039

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants