good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: Deleting Chinese characters while readingby graff (Chancellor) |
on Mar 01, 2015 at 11:14 UTC ( [id://1118258]=note: print w/replies, xml ) | Need Help?? |
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 Section
Seekers of Perl Wisdom
|
|