-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Unicode input on windows command line does not work #15028
Comments
For anyone saying that windows command line does not support unicode, here is some quick code I wrote in C++ which correctly reads and writes unicode from and to the console: wstring read() {
auto in = GetStdHandle(STD_INPUT_HANDLE);
array<wchar_t, 0x1000> buf;
unsigned long read;
ReadConsoleW(in, buf.data(), buf.size(), &read, nullptr);
return{buf.begin(), buf.begin() + read};
}
void write(wstring p_str) {
auto out = GetStdHandle(STD_OUTPUT_HANDLE);
unsigned long wrote;
WriteConsoleW(out, p_str.c_str(), p_str.size(), &wrote, nullptr);
}
int main() {
write(read());
} Here is a screenshot of that code working: |
A patch for unicode input in libuv is currently going through the process, which will fix libgreen's unicode input. |
Created a PR to address the issue in libnative: #15051 The libuv patch has been merged into libuv master, so that's waiting for libuv to release a new version and then rustuv to update to that new version |
This implementation does have the minor issue of not handling things correctly when a codepoint is split across multiple writes or reads, but its better than not having unicode support at all. Adds a Windows specific struct `WindowsTTY` in `libnative` and make `tty_open` create that struct on Windows. Adds needed functions and constants to `c_win32.rs`. Also updates the libuv submodule. This fixes #15028 for both libnative and libgreen.
This implementation does have the minor issue of not handling things correctly when a codepoint is split across multiple writes or reads, but its better than not having unicode support at all. Adds a Windows specific struct `WindowsTTY` in `libnative` and make `tty_open` create that struct on Windows. Adds needed functions and constants to `c_win32.rs`. Libuv still needs to be updated before #15028 can be closed.
Since |
@retep998 how relevant is this now? |
@nagisa For the most part it works. However the current code still cannot cope when characters encoded using multiple codeunits are broken across a read/write boundary. Plus having the API take [u8] is hardly ideal when we should be using the new |
Issue subsumed by #23344 |
internal: Give rustfmt jobs a separate thread Some light testing suggests that this fixes the waiting on formatting popup in vscode when the project is still building (which is usually the way for me to encounter it, as r-a is either waiting or getting little resources causing the tasks to block formatting)
When using stdin with my rust program run from either the windows command line or git bash, any unicode characters are turned into question marks.
So "Алло" becomes
[63, 63, 63, 63]
.If I change the codepage of the windows command line to utf-8 via
chcp 65001
, then when I enter in any unicode characters stdin returns EndOfFile.On the flip side, output using libgreen works fine (because libuv translates utf-8 to utf-16 and calls
WriteConsoleW
), while output using libnative produces garbage for unicode because it writes utf-8 as if it were ascii.Using windows 8.1 x64, with 32-bit Rust nightly.
The text was updated successfully, but these errors were encountered: