It seems like there are a few things going wrong with how Mac's Terminal app interacts with Perl's use of STDIN while typing and deleting Chinese characters via the keyboard:

(1) The "delete" key seems to operate on bytes; there are 3 bytes per utf8 Chinese character, so it actually takes three hits on "delete" to fully remove one character from the line that will be read on STDIN when you hit "enter".

(2) Unfortunately, each hit the "delete key also causes the cursor to move leftward one (Latin/ASCII) character cell on the display.

(3) As soon as a left-moving cursor moves into the span of a Chinese character (which occupies the width of two standard Latin/ASCII characters), the whole Chinese character disappears.

So, let's suppose you've typed two Chinese characters, and you want to delete the second one. The two characters occupy the same (horizontal) space as 4 Latin/ASCII characters. You have to hit "delete" 3 times to get rid of all three utf8 bytes for that one character, but as a result, the cursor moves over three spaces, causing both characters to disappear from view (even though the first character is still fully intact in the typing buffer - hit enter, and perl will read it.

I tried looking into Term::ReadLine, but that doesn't seem to play well with utf8, let alone any sort of method for keyboarding Chinese characters.

I wish I had a better answer for you (I hope some other monk will have one), but failing that, I'd rely on a browser for non-latin keyboard input to a perl process - that is, get your user input via an http-like interface.


In reply to Re: Deleting Chinese characters while reading by graff
in thread Deleting Chinese characters while reading by alexharv074

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.