Skip to content

std.os.windows: add SetConsoleMode #17945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

std.os.windows: add SetConsoleMode #17945

wants to merge 1 commit into from

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