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

Add UTF-8 console encoding support for Windows #734

Closed
wants to merge 2 commits into from

Conversation

zaryar
Copy link

@zaryar zaryar commented Dec 10, 2024

Fixes #726

Problem

When displaying Unicode characters (like chess pieces ♔) on Windows systems, the console shows '?' instead of the actual characters. This works correctly on Linux systems.
I saw the post in the effective programming with effekt course. I had the same problem because I want to create chess with effekt.

Solution

Added Windows-specific console configuration:

  • Set console codepage to 65001 (UTF-8) using chcp command
  • Configure stdout to use UTF-8 encoding

Notes

This change only affects Windows systems and has no impact on other platforms.

Copy link
Contributor

@jiribenes jiribenes left a comment

Choose a reason for hiding this comment

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

Hi, thanks for the contribution, this is wonderful!
Could you take a look at my comment? Is there anything we can do to minimise the side-effectful calls?

libraries/common/io/console.effekt Show resolved Hide resolved
if (process.platform === 'win32') {
// Set UTF-8 codepage
require('child_process').execSync('chcp 65001');
process.stdout.setDefaultEncoding('utf8');
Copy link
Contributor

Choose a reason for hiding this comment

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

👀 I think something like this would belong to a jsNode block above the definition of println in libraries/common/effekt.effekt to ensure that the output of println itself is UTF-8. Otherwise this line of code only gets interpreted if someone imports console...

@jiribenes
Copy link
Contributor

Could you perhaps try to set up your cmd process according to this guide? https://stackoverflow.com/a/57134096
Then the require('child_process').execSync('chcp 65001'); line shouldn't be needed anymore.
If it works, we could add it to the install guide on the website or something 🤔

@zaryar
Copy link
Author

zaryar commented Dec 17, 2024

Could you perhaps try to set up your cmd process according to this guide? https://stackoverflow.com/a/57134096 Then the require('child_process').execSync('chcp 65001'); line shouldn't be needed anymore. If it works, we could add it to the install guide on the website or something 🤔

sorry was gone the last few days, will try :)

@zaryar
Copy link
Author

zaryar commented Dec 17, 2024

image

works perfect, I did not even have to set the $OutputEncoding var for the PowerShell 🤔

@jiribenes
Copy link
Contributor

Since that works, I think that the next move would be to close the PR and update the Getting Started guide in the Windows section :)

@zaryar zaryar closed this Dec 17, 2024
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.

Cannot print fancier characters with Node.js on Windows in VSCode
2 participants