On a Windows (10) box, why can I print the 'black flag' (U+2691) character in certain places but not others (cmd.exe in particular)?
Update with proposed hints in comments (no answers yet): - [From Kevin] CMD.exe Unicode support is dubious (unspecified, but write off the issue I am having as strange CMD.exe behavior) - [From Mark] The process should write to the ConsoleAPI instead of stdout. - [From Mr. Lister] Change the font.
I changed the font in Webstorm. It was using monospaced
, and displayed the flag properly. I switched to Consolas
, Lucida Sans
, and Courier New
and it worked in all of them. I looked at the list of supported unicode chars for Lucida Console and indeed, U+2691 is not on there. So Webstorm might have some fallback mechanism to support the character.
I ran ConEmu, and set the base font to Lucida Console, and Alternative font to DejaVu Sans, which I downloaded from here. I had to adjust the Unicode range manually, setting it to 2013-3000. And voila, the black flag showed. So although part one is now (kindof) solved, I still don't really know what is going on with fonts vs graphics and code pages here. I think the codepage is a red herring when dealing with some unicode... So please, if someone has anything definitive, I would love a proper answer. ;-)
Note, I have the cmd.exe font set to Lucida Console and Current Code Page to (UTF-8) 65001. I have also tried other fonts...and chcp 1252. And yes, I have read the Spolsky post, which is excellent. I think what I was missing is what Kevin said in the comment (cmd.exe does not have proper Unicode support) and what Mark said about bypassing stdout. This explains cmd.exe but would love to know more about VS vs VS Code vs NP++...
I can see the character fine in chrome:
http://graphemica.com/⚑
http://graphemica.com/%E2%9A%91
I can see it fine in one of these:
- Office (Word, Outlook)
- WebStorm
- Visual Studio
However, I cannot see it here (shows up as a box):
- Notepad++
- Visual Studio Code
- cmd.exe
If I run this in node:
console.log('\u2691:', '\u2691');
console.log('Flag:', '⚑')
It just dumps boxes (which when I copy and paste in here are fine).
Then there are other characters like: heavy check mark (U+2714)
http://graphemica.com/%E2%9C%94 http://graphemica.com/✔
Which 'show up' in Visual Studio Code (which could not show the flag) but wont show up in cmd.exe.
There appear to be a lot of moving parts here: Unicode, char codes, code pages, fonts, and lots more.
Can someone help me sort this out? What exactly is going on here?
Why does the character display in some places and not in the other?
Is there anything I can do to show the characters in cmd.exe?
cmd.exe
requires using the console API directly and bypassing standard output. – Mark Ransomcmd
,Notepad
etc. (e.g.DejaVu Sans Mono
contains much more character glyphs than commonly usedCourier
orLucida Console
monospace fonts). – JosefZ