-
Notifications
You must be signed in to change notification settings - Fork 216
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
Encoding problems when using JNA Windows terminal implementation #133
Comments
It seems like changing the system encoding using |
The UTF-8 output seems to break due to the try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(FileDescriptor.out))) {
out.write("ыыыыыы");
} When I add the try (OutputStreamWriter out = new OutputStreamWriter(new AnsiOutputStream(new FileOutputStream(FileDescriptor.out)))) {
out.write("ыыыыыы");
} These characters are written with 2 bytes each so I think this is because the It works again if I add a try (OutputStreamWriter out = new OutputStreamWriter(new AnsiOutputStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out))))) {
out.write("ыыыыыы");
} |
As a summary, my suggested fix for this issue would be to either make it the default, or add some kind of "UTF-8 option" that does the following:
With the output code page manually set to I could be entirely wrong about this issue, so let me know what you think. |
Could you check the above patch ? If it works for you, I'll merge it to master. |
@gnodet Thanks! Your fix solves the problem with the input encoding. The characters are now read correctly, but are not displayed correctly in the console due to console output encoding problems:
|
@gnodet Thanks for the additional changes. I managed to get it working and have added two small comments to your commit. |
@gnodet Latest commit is working correctly now, thanks! |
I've a really simple command line app that reads from the console using a
LineReader
. (Basically just the example code from https://github.com/jline/jline3/wiki/Using-line-readers).I've now installed a standard English Windows 10 system and run the JAR with the JNA implementation. As long as I use ASCII characters everything is fine. However, when I switch the keyboard layout to e.g. Russian, all the Cyrillic characters get displayed as
?
.As far as I can see, the JNA implementation reads characters from the console using
Kernel32.ReadConsoleInput
. Everything is still correct at this point, JLine gets the unicode char from the Windows API and when I debug the code, the string builder inreadConsoleInput
has the correct Cyrillic character.However,
readConsoleInput
encodes all the characters again, with the standard system encoding. On my English system, this iswindows-1252
which doesn't support the Cyrillic characters. Consequently, it already gets encoded incorrectly at this point (to character 63,?
).It seems like the actual
InputStreamReader
will later read them using the current code page of the console. However, if all characters are actually read as unicode it might be better to keep them that way (or encode toUTF-8
) and instruct the reader to decode using the same encoding. I can imagine that there might be still problems with the output of these characters then (since that depends on the code page), but currently even the input fails no matter which code page I select in the console.The text was updated successfully, but these errors were encountered: