Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Unicode stdout on Windows command prompt #7940

Closed
sindresorhus opened this issue Jul 13, 2014 · 15 comments
Closed

Unicode stdout on Windows command prompt #7940

sindresorhus opened this issue Jul 13, 2014 · 15 comments

Comments

@sindresorhus
Copy link

With Node.js 0.10.28 running the following:

node -e "process.stdout.write('✔');"

Outputs on OS X, but only shows the following on Windows 8.1 command prompt:

screen shot 2014-07-13 at 23 24 25

It would be very useful if Unicode characters would show on Windows too. Right now I have to implement annoying fallbacks for Windows.

@dougwilson
Copy link
Member

You have to install a Console font that actually has Unicode characters in cmd.exe to actually see them. I recommend DejaVu Sans Mono (http://dejavu-fonts.org/wiki/Main_Page). Install it, edit your registry to get cme.exe to list it as an available font, yadda yadda, and then boom, Unicode characters in cmd.exe!

@sindresorhus
Copy link
Author

That's not really solution though. I can't require everyone to do that.

I don't personally use Windows, but I'm tired of being trolled by Windows users about the use of Unicode characters.

@dougwilson
Copy link
Member

That's not really solution though. I can't require everyone to do that.

My point is that it's impossible to display those symbols on cmd.exe without the user doing that, because the font that is in the cmd.exe does not have those symbols in it. A program that runs in cmd.exe does not have the power to change the font, either.

@tylerdmace
Copy link

Rather than writing fall backs - perhaps just abandon the check mark symbol entirely for something less succinct (just until that support on Win32 becomes more common).

@TooTallNate
Copy link

Try running chcp 65001 in the cmd.exe to change the charset to a unicode-enabled one. See http://stackoverflow.com/a/18439832/376773.

@tylerdmace
Copy link

The problem is that these are fixes each individual node user would have to deploy just to see the correct chars under Windows -- which is, as I understand, what @sindresorhus is trying to avoid.

@indutny
Copy link
Member

indutny commented Jul 14, 2014

I'm not sure what do you expect from a core developers to do in this case? We can't provide working APIs for DNS queries if no DNS servers are reachable, and we can't display unicode properly if the terminal doesn't support it.

In fact, people who are using node on windows via cmd.exe should already be comfortable with typing commands in console.

Thanks for sharing, though!

@indutny indutny closed this as completed Jul 14, 2014
@sindresorhus
Copy link
Author

@indutny I wasn't expecting anything. I was hoping there was a way to somehow polyfill it on Windows (like changing the charset programatically or something) like Node (libuv) does with most other things, eg joyent/libuv@68cd6d6. Not being able to use Unicode in the output is very limiting and requiring every user to change the charset isn't feasible. One of the things I love about Node is (mostly) not having to care about platform differences.

@indutny
Copy link
Member

indutny commented Jul 14, 2014

cc @saghul and @orangemocha

@saghul
Copy link
Member

saghul commented Jul 14, 2014

@indutny that's for reading, not writing. For the writing side I see we already use the unicode version: https://github.com/joyent/libuv/blob/master/src/win/tty.c#L959. @sindresorhus Is this a problem in cmd.exe or in any terminal? Does what @TooTallNate said avoid the problem? If so maybe you could execSync it? Or perhaps use a tiny binary addon which does it?

@sindresorhus
Copy link
Author

Is this a problem in cmd.exe or in any terminal?

I haven't tried all the Windows terminals, but neither cmd.exe nor PowerShell seems to display this correctly.

Does what @TooTallNate said avoid the problem?

No, but from researching this it might be because the Lucida Console font doesn't support that glyph. On other systems you can use unsupported glyphs which just falls back to the system default, but this doesn't seem to be the case on Windows.

Similar Python issue: http://bugs.python.org/issue1602

@Mithgol
Copy link

Mithgol commented Jul 15, 2014

You can't change anything with chcp 65001 because Node.js already generates Unicode output.

I agree that it's unreasonable to expect each individual node user changing something. Therefore you have to use a Windows-supported character of a similar shape (such as '√') as a workaround; that's your only reasonable option.

See some Mocha source code for example.

@sindresorhus
Copy link
Author

@Mithgol I came to that conclusion too. Just annoying as that's very limiting. I ended up doing https://github.com/sindresorhus/figures for my own usecase.

@Mithgol
Copy link

Mithgol commented Jul 19, 2014

@sindresorhus Well, theoretically speaking, you could also npm install windows (programmatically) and then use that package's methods to alter the Windows registry in such way that would change fonts (in all console windows) to some font from your package.

But some end users might hate you for that. (I definitely would.)

@robberphex
Copy link

When I call console.log to print CJK char(in codepage 936), I will get unreadable char.

In my option, I think the code and the text input can be other charset. Before node execute it, the code and the text input convert to utf8.

For output, also can add a wrapper to convert utf8 to using charset.

PS:In Windows, child_process.exec("chcp 65001 | dir") can work, but I think it's a good solution.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants