How to make the following code work with Unicode (CJK) in Command Prompt/LameShell?
main = getLine >>= putStrLn
(Windows 8.1, Haskell Platform 2014)
No, chcp 65001
doesn't work, nor chcp 10000
.
No, I don't want to change System Local (Control Panel/Clock, Language, and Region/Language/Change date, time, or number formats/Administrative) from English(United States) to others.
Yes, I have set font to Lucida Console.
I've tried ConEmu/Cmder/Console2, they all said "Exception: : hGetLine: end of file". I also tried Emacs, (I use Vim), it didn't crash, but I always get spaces, no matter what I input.
Patch GHC and recompile it is acceptable, if there is no other way.
Any idea?
Thanks.
For input: allow HEX input of Unicode. One more gotcha with “Pasting” into a console application (very technical): HEX input delivers a character on KeyUpof Alt; allthe other ways to deliver a character happen on KeyDown; so many applications are not ready to see a character on KeyUp.
Windows’ console has A LOT of support for Unicode — but it is not perfect (just “good enough”; see below). chcp 65001 is very dangerous. Unless a program was specially designed to work around defects in the Windows’ API (or uses a C runtime library which has these workarounds), it would not work reliably.
CMD.exe is a just one of programs which are ready to “work inside” a console (“console applications”). AFAIK, CMD has perfect support for Unicode; you can enter/output all Unicode chars when any codepage is active. Windows’ console has A LOT of support for Unicode — but it is not perfect (just “good enough”; see below).
– phuclv May 28 '17 at 4:07 2 @LưuVĩnhPhúc - No, this is about passing unicode command line arguments, rather than displaying text in the console. Console might not get involved at all. – Vilx- May 28 '17 at 11:08
PowerShell supports UTF natively. Assuming I understand your example (main = getLine >>= putStrLn
) properly:
$var = Read-Host
Write "$var"
Or simply:
Read-Host
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With