TerryCavanagh / VVVVVV

The source code to VVVVVV! http://thelettervsixtim.es/
Other
6.94k stars 556 forks source link

Allow UTF-8 console output on Windows (for -console) #1043

Closed Daaaav closed 10 months ago

Daaaav commented 10 months ago

Changes:

Right now, Windows assumes all our console output is code page ????. That means our UTF-8 output appears mangled. (I ran into this while testing IME text input by outputting strings to the console)

For a moment I was scared we'd need to do UTF-16 conversions and call Windows-specific print functions like WriteConsoleW() in our vlog functions, but fortunately SetConsoleOutputCP(CP_UTF8) works just fine.

Example of vlog_warn(loc::gettext("return")) in German (just to make sure the encoding of the source file is not a factor) before this change:

zurCOUGHck

After:

zurück

Legal Stuff:

By submitting this pull request, I confirm that...

Daaaav commented 10 months ago

I'm not sure I really agree there to be honest - it doesn't seem critical and "alarm-worthy" if for example some older version of Windows only supports legacy console output (what's the user gonna do about it?) and for nearly all of our output it wouldn't make a difference since it's still in English. Adding an error check there does make the code a little less clean, and I don't think error checks being needed for some functions necessarily makes them needed for all functions.

If you'd like me to do it anyway, just say so.

InfoTeddy commented 10 months ago

Yes, add the check.

It's not alarm-worthy, but it's at least a warning. And it should be there to make it clear to the user that it's not our fault if UTF-8 output is mangled.

Daaaav commented 10 months ago

Okay well... For the error message to even show up, I had to move it down further, because there's no console output visible before the freopens. Furthermore, the message will be hidden away by all the other output (like the Viridian) because the window will scroll down instantly. Either way, done.