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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libraries/common/io/console.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ namespace js {

extern jsNode """
const readline = require('node:readline');
if (process.platform === 'win32') {
// Set UTF-8 codepage
require('child_process').execSync('chcp 65001');
jiribenes marked this conversation as resolved.
Show resolved Hide resolved
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...

}
"""

extern type JSConsole
Expand All @@ -32,6 +37,7 @@ namespace js {
jsNode """readline.createInterface({
input: process.stdin,
output: process.stdout,
encoding: 'utf8',
})"""

extern io def close(console: JSConsole): Unit =
Expand Down
Loading