-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Zig runtime should set console output mode to utf-8 by default on Windows #7600
Comments
Note that if the zig runtime does not do this, every zig developer who wants to ensure that they correctly output UTF-8 encoded text on all Windows machines will have to insert os-specific logic in their startup code, which makes writing portable zig code a bit more of a headache and a bit less of a happens-by-default thing. |
zig can be used to create libraries (both static and dynamic) where we cannot rely on any code being called at startup. On windows we may need to use |
It might be worth looking at the click Python project for an idea of what it takes to make the Windows console API reasonably ergonomic when dealing with unicode. https://click.palletsprojects.com/en/7.x/wincmd/ https://github.com/pallets/click/blob/master/src/click/_winconsole.py |
It seems that |
When would you call |
If this can somehow be done from the standard library, I think that that should be favored over being part of the compiler. That would be better in case the programmer doesn't want to call the functions to set output mode for whatever reason they might have. It also seems more natural that this would be part of the same system that the programmer already uses for console output. Even if it meant calling a function like |
Poor kitty, its face has been replaced by encoding errors!
The zig documentation has this to say about string literals:
If this is true of all standard library functions,
std.log
and writers that refer to console output streams are expecting utf-8 encoded strings, and callers likely expect these functions to output these strings to the console as they appear in their source files or data sources. Users of zig command-line applications (and zig developers) may not have configured Windows to use utf-8 by default, but this can be overridden for a given console session bySetConsoleOutputCP
.I propose that the zig runtime should, at program startup, call
SetConsoleOutputCP
with an argument of 65001 to amend terminal output to correctly show utf-8 strings in all cases. If zig developers want legacy behavior or alternative code pages, they can call this function again with a different argument in their program's entry point.(Aside: in this case, the zig compiler does not have the correct behavior by default either, and will print source code with the incorrect encoding in error messages):
The text was updated successfully, but these errors were encountered: