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

Entering Chinese on windows will cause garbled code #766

Open
Ruokwok opened this issue Feb 6, 2022 · 2 comments
Open

Entering Chinese on windows will cause garbled code #766

Ruokwok opened this issue Feb 6, 2022 · 2 comments

Comments

@Ruokwok
Copy link

Ruokwok commented Feb 6, 2022

On the simplified Chinese version of windows, when you enter Chinese, you will get chaotic strings. I tried chcp 65001 / -Dfile.encoding=utf8 / encoding("utf8") and other methods, but they didn't solve the problem, or even got worse.

The problem only occurs on CMD and PowerShell of windows, and there is no problem in Linux or IDEA console.

My code is like this

Terminal terminal = TerminalBuilder.builder().encoding("gbk").build();
LineReader lineReader = LineReaderBuilder.builder().terminal(terminal).build();
while (true) {
    String line = lineReader.readLine(">");
    System.out.println(line);
}

It's not just input. If you change the above ">" to Chinese, it will also print "?????" or garbled.
Thank you.

@Ruokwok
Copy link
Author

Ruokwok commented Feb 6, 2022

If I use the encoding("utf8") method, Chinese will become ???, and ??? is a common garbled content when reading a gbk encoded file with utf8. But I tried all kinds of methods, but they didn't solve the problem.

@mattirn
Copy link
Collaborator

mattirn commented Feb 22, 2023

@Ruokwok, simplified Chinese (GBK) code page is 936.
Enter the following command in the dos prompt:

\> chcp 936

Then launch your JLine app using java option -Dfile.encoding=utf8.

I have tested using JLine repl demo... at least now copy and paste Chinese characters works.

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

No branches or pull requests

2 participants