Skip to content

std.os.windows: add SetConsoleMode - #17945

Closed
expikr wants to merge 1 commit into
ziglang:masterfrom
expikr:patch-9
Closed

std.os.windows: add SetConsoleMode#17945
expikr wants to merge 1 commit into
ziglang:masterfrom
expikr:patch-9

Conversation

@expikr

@expikrexpikr commented Nov 9, 2023

Copy link
Copy Markdown
Contributor

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 {
conststd=@import("std")
constkernel32=std.os.windows.kernel32;
varstdout_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 {
conststd=@import("std");
constkernel32=opaque {
usingnamespacestd.os.windows.kernel32;
extern"kernel32"fnSetConsoleMode(*anyopaque,u32) callconv(std.os.windows.WINAPI) c_int;
};
varstdout_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

Vexu commented Nov 21, 2023

Copy link
Copy Markdown
Member

Previously rejected in #15039

Sign up for freeto 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

@expikr@Vexu