Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

How to print utf8 char in Term::Screen::Win32 ?

by exilepanda (Monk)
on Mar 18, 2012 at 06:23 UTC ( #960261=perlquestion: print w/ replies, xml ) Need Help??
exilepanda has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, I have problems on printing utf8 or big5 with Screen::Term::Win32. I am not sure that's the getch() problem, or the puts() ( as well as print() ) problem.
require Term::Screen::Win32; use utf8; binmode STDOUT, ":utf8"; binmode STDIN, ":utf8"; $scr = new Term::Screen::Win32; unless ($scr) { die " Something's wrong \n"; } $scr->clrscr(); my @buff; while ( 1 ) { my $k = $scr->getch() ; if ( ord ( $k ) == 13 ) { # dump on Enter $scr->puts($_) foreach @buff; print $/; print scalar ( @buff ) ; } else { push @buff, $k } ; }
I had tried many combinations, like if to use utf8 or not, binmode STD handles or not. use array or direct dump, But whatever it goes, I always get the print widechar warning, and the (Chinese) chars I pushed into the array are incorrectly dumped ever. Anything I missed here?

Comment on How to print utf8 char in Term::Screen::Win32 ?
Download Code
Re: How to print utf8 char in Term::Screen::Win32 ?
by Anonymous Monk on Mar 18, 2012 at 07:59 UTC

    Two things, you need to tell cmd.exe to accept/display utf8, which is one of

    Win32::Console::OutputCP( 1253); Win32::Console::ANSI::ScriptCP( 1253 );
    and setting console to some truetype font, See Re: Character Encoding and Windows Console woes, chcp 65001

    If Term::Screen::Win32 doesn't use STDIN/STDOUT, you need to binmode whatever handle it uses , or you may need to decode the characters/bytes you get from Term::...

      Thank you very much! As you said, things go weir when I am not using STDIN. Whatever code page I use, and whatever long char I type, the getch give me 65533... =( Still investigation..

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://960261]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2015-07-05 09:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (61 votes), past polls