Description
It seems like Dart cannot properly print unicode characters to the Windows console (cmd.exe
or powershell.exe
seem to be equally affected). Example test.dart
Program:
main() {
print("These are three black spades: ♠♠♠");
}
Actual console output of dart test.dart
:
These are three black spades: ΓÖáΓÖáΓÖá
Ideally, this should have shown the three spades, or - in case those are not available in the font used in the console - it should have show Unicode's missing character symbol (e.g. �).
While researching this issue on the web I realized that properly printing Unicode to the Windows console is actually fairly hard to do. However, it seems like the people over at Python just figured out how to properly do this in python 3.6.0, which was just released last month. Example test.py
program:
#!/usr/bin/python
# -*- coding: utf-8 -*-
print("These are three black spades: ♠♠♠")
Actual console output of python test.py
(requires python 3.6.0!):
These are three black spades: ♠♠♠
Yeah! \o/
It would be most awesome-st if Dart could also fix the unicode printing behavior on Windows. That would really help us in Flutter, where we make extensive use of unicode in console output (flutter/flutter#7714).
In case it is helpful, here are the relevant discussions around fixing this in python:
- http://bugs.python.org/issue1602 - bug discussing the issue (has been open for 7 years, relevant bits for fixing the issue are towards the end)
- https://www.python.org/dev/peps/pep-0528/ - Python Enhancement Proposal describing the fix
- https://hg.python.org/cpython/rev/6142d2d3c471 - commit including the fix
From the python discussions, it seems like WriteConsoleW()
from the Windows API should be used to write strings to the console in order to get unicode support.