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

fix: handle utf8 in input properly #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Nerixyz
Copy link
Contributor

@Nerixyz Nerixyz commented Mar 2, 2025

The input didn't handle UTF-16 to UTF-8 conversion properly (why is this converted in the first place?) - it truncated the bytes. For the ASCII subset of Unicode, this works fine. For other Unicode characters (e.g. emoji), this is invalid. Since we're on Windows, we can use WideCharToMultiByte.

Semi-related changes:

Console Example

  • Added --input
  • Turned the executable into a true console app instead of a GUI app (subsystem console)
  • Added an exit upon receiving a reply
  • Set the console code page to UTF-8 (required for UTF-8 to be printed correctly)

Qt Example

  • Added an "Add Input" checkbox
  • Note: this example doesn't require the console code page to be set to UTF-8 (Qt probably does that already)

I tested this with the input hello 😂😂😂😂 and verified that it prints correctly in the terminal (I used VS Code's terminal and MS terminal). This might not display correctly in CMD, so Microsoft's new Terminal has to be used. When testing the Qt version, set $Env:QT_WIN_DEBUG_CONSOLE="attach" (powershell), so the app prints to the parent console.

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.

1 participant