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

Unicode input on windows command line does not work #15028

Closed
retep998 opened this issue Jun 19, 2014 · 8 comments
Closed

Unicode input on windows command line does not work #15028

retep998 opened this issue Jun 19, 2014 · 8 comments
Labels
O-windows Operating system: Windows

Comments

@retep998
Copy link
Member

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.

@retep998
Copy link
Member Author

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:

It works!

@retep998
Copy link
Member Author

A patch for unicode input in libuv is currently going through the process, which will fix libgreen's unicode input.

joyent/libuv#1323

@retep998
Copy link
Member Author

Currently working on writing up a patch for libnative unicode console support. Output works so far:

Still working on input.

@retep998
Copy link
Member Author

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

bors added a commit that referenced this issue Jul 3, 2014
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.
bors added a commit that referenced this issue Jul 4, 2014
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.
@retep998
Copy link
Member Author

retep998 commented Oct 6, 2014

Since libnative has been fixed by #15051 and librustuv no longer exists, this issue is nearly done. Code still needs to be written to handle multi-codeunit codepoints broken across reads/writes.

@nagisa
Copy link
Member

nagisa commented Feb 16, 2015

@retep998 how relevant is this now?

@retep998
Copy link
Member Author

@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 OsStr thing.

@retep998
Copy link
Member Author

Issue subsumed by #23344

lnicola pushed a commit to lnicola/rust that referenced this issue Jun 19, 2023
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-windows Operating system: Windows
Projects
None yet
Development

No branches or pull requests

4 participants