Skip to content

Commit

Permalink
Windows: set UTF-8 code page for console output
Browse files Browse the repository at this point in the history
Otherwise unicode characters are garbled.
  • Loading branch information
mathiascode committed Dec 13, 2024
1 parent c5b1217 commit c34f68f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ private extern(C) void handle_termination(int) {
writefln("\n" ~ exit_message);
}

@trusted
private void set_console_code_page()
{
version (Windows) {
import core.sys.windows.wincon : SetConsoleOutputCP;
SetConsoleOutputCP(6_5001); // UTF-8
}
}

@trusted
private void setup_signal_handler()
{
Expand All @@ -33,6 +42,8 @@ private void setup_signal_handler()

private int main(string[] args)
{
set_console_code_page();
setup_signal_handler();

return run(args);
}

0 comments on commit c34f68f

Please sign in to comment.