Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Term::ReadLine handle wide character poorly

by vincentaxhe (Novice)
on May 14, 2024 at 02:08 UTC ( [id://11159429]=perlquestion: print w/replies, xml ) Need Help??

vincentaxhe has asked for the wisdom of the Perl Monks concerning the following question:

I use Term::ReadLine, but It handle wide character(chinese) poorly, though the input is recognized correctly, is there a better module be able to deal wide character input, if just like type in a normal console

state $term = Term::ReadLine->new('note'); my $prompt = "LINE:"; chomp($note = $term->readline($prompt)); $note = decode 'UTF-8', $note; $term->addhistory($note) if $note =~ /\S/;

Replies are listed 'Best First'.
Re: Term::ReadLine handle wide character poorly
by The_Dj (Beadle) on May 14, 2024 at 03:33 UTC
    Hi

    I tested your code above without the decode and it worked perfectly* as I expected.

    By default it was using Term::ReadLine::Gnu but I also tried using Term::ReadLine::Perl5 and it also worked exactly the same

    * I don't have a chinese keyboard, but I was copying 弛 and 地 from wikipedia

    What exactly is it doing wrong for you?

      It swallow wide character to squeeze in a non-wide character length, it start to do that after input eight or nine wide characters, it keeps doing that, then wrap line upward, very clumsy line input environment

      Can you paste a string here I could test with?
        sorry, its alacritty I use, kitty and foot works fine.

        Its behavior varies depending you paste repeatly and type in, paste will show '[27m', type in will squeeze character, neither is desirable. try paste '一生'.

        I use fcitx in arch, you will need 'fcitx5 fcitx5-chinese-addons fcitx5-configtool fcitx5-gtk-git fcitx5-pinyin-zhwiki fcitx5-qt', relogin and some environment settings. here is my hyprland env settings related to fcitx. make it work takes some efforts.

        env = XMODIFIERS, @im=fcitx # env = GTK_IM_MODULE, fcitx env = QT_IM_MODULE, fcitx env = SDL_IM_MODULE, fcitx env = ECORE_IMF_MODULE,xim
Re: Term::ReadLine handle wide character poorly
by The_Dj (Beadle) on May 15, 2024 at 03:38 UTC
    I see an issue in your sample code;
    You don't need $term->addhistory($note) if $note =~ /\S/; - The readline method already adds to the history.
    But using addhistory you are doubling everything in your history.

      indeed, I preload some history by     $term->addhistory($_) foreach split "\n", $tasks[$selectedtask]{note} // ""; I assume its all manually, and perldoc also give example like this. thx
Re: Term::ReadLine handle wide character poorly
by ForgotPasswordAgain (Priest) on May 14, 2024 at 16:24 UTC
    I haven't tried it, but from what I read you might be able to do: binmode($term->IN, ':utf8');
      sorry, its alacritty I use, kitty and foot works fine.

        That does rather point the finger at alacritty then. Are you on the latest version? If so, maybe raise the issue with them?


        🦛

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11159429]
Approved by marto
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-05-26 22:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found