HOWTO: print non US-ASCII characters using jansi

189 views
Skip to first unread message

Christian Migowski

unread,
Feb 24, 2013, 5:56:02 PM2/24/13
to jans...@googlegroups.com
Hi,

it took me a while and finally a look into AnsiConsole's source to figure it out, so I am documenting it here, maybe it helps others in future:

normal ms windows console does not seem to output non-ASCII java characters well, try outputting e.g. the chars "ÄÖÜ üöä" and you'll see what I mean. For making this work with System.out you can do

   System.setOut(new java.io.PrintStream(System.out, true, "CP850"));

as found everywhere in the web, unfortunately this is not supported jansi's AnsiConsole in any way directly (i.e. using AnsiConsole out() nor AnsiConsole.systemInstall()), so you have to do:

    PrintStream ps  = new PrintStream(AnsiConsole.out(), true, "CP850");

and then use ps everywhere you would have used AnsiConsole.out() or System.out. (after using systemInstall()).

This issue was brought up in this list some time ago and no replies to it, so probably it won't happen, but my suggestion is to extend the API with

public void AnsiConsole.systemInstall(String codePage) and
public PrintStream AnsiConsole.getOutWithCodePage(String codePage)  



cheers,
christian

Mihai Nita

unread,
Feb 27, 2013, 4:39:10 AM2/27/13
to jans...@googlegroups.com
The trouble is, the code page in PrintStream should match the code page of the console.
For English that is 437, not 850 (and 932 for Japanese, 949 Korean, and so on, the so called "OEM" code pages)
Unfortunately there is no way to access that from Java, only what you pass in the file.encoding (and some hard-coded
associations between locale and code page).

You can also try
    chcp 1252 (in console)
and using "windows-1252" or "cp1252" in PrintStream

There is a way to output Unicode, no matter the code page in the console, using jansi
I can try to write an article documenting how to do that (there are some drawbacks when the output is redirected)...
You can output anything, and you can see everything that the console font supports (for instance Latin 1 + Latin 2 + Cyrillic + Greek)
And even Japanese + Hindi + Arabic + Korean in a smarter console (like ConEmu)

Mihai

--
You received this message because you are subscribed to the Google Groups "jansi-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jansi-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages