Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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

by exilepanda (Pilgrim)
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?

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://960261]
Approved by moritz
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2017-09-20 08:14 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (234 votes). Check out past polls.