Skip to content
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

Support printing unicode characters on windows #449

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

andrjohns
Copy link
Contributor

From #447, Unicode characters are not correctly printed to the console with console.log in some cases

@andrjohns
Copy link
Contributor Author

@ahaoboy Can you try this branch to check that it works for you? All works as expected for me locally, but good to double-check

@ahaoboy
Copy link

ahaoboy commented Jun 28, 2024

Can you try this branch to check that it works for you?

Cool~ It works!

@chqrlie
Copy link
Collaborator

chqrlie commented Jun 28, 2024

We might want to add an alternative function JS_ToWStringLen to convert a JS_STRING to a UTF-16 encoded wide string and use that for output. It would help if Microsoft would finally make it easy to use UTF-8 like the rest of the world.

quickjs-libc.c Outdated Show resolved Hide resolved
quickjs-libc.c Outdated Show resolved Hide resolved
@saghul
Copy link
Contributor

saghul commented Aug 1, 2024

@chqrlie Do you have any objections?

}
MultiByteToWideChar(CP_UTF8, 0, str, len, wstr, wlen);
wstr[wlen] = L'\0';
WriteConsoleW(hConsole, wstr, wlen, &written, NULL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this work?

DWORD prev = GetConsoleOutputCP();
SetConsoleOutputCP(CP_UTF8);
WriteConsoleA(hConsole, str, len, &written, NULL);
SetConsoleOutputCP(prev);

Maybe you don't even need to use WriteConsoleA:

DWORD prev = GetConsoleOutputCP();
SetConsoleOutputCP(CP_UTF8);
fwrite(str, 1, len, con);
SetConsoleOutputCP(prev);

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.

None yet

5 participants