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

Re: Deleting Chinese characters while reading

by graff (Chancellor)
on Mar 01, 2015 at 11:14 UTC ( [id://1118258]=note: print w/replies, xml ) Need Help??


in reply to Deleting Chinese characters while reading

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.

  • Comment on Re: Deleting Chinese characters while reading

Replies are listed 'Best First'.
Re^2: Deleting Chinese characters while reading
by alexharv074 (Initiate) on Mar 02, 2015 at 00:30 UTC
    Actually this isn't quite what I observe:

    If I enter the sequence of characters/keystrokes 中文<delete><delete> I will see 中 with the cursor positioned immediately after it. If I hit <delete> again, however, the cursor doesn't move now. (That is there's no way of removing the phantom 中 character from the line.) This is just a screen display issue, however. If I hit <enter> now, the value read in by the perl program will be an empty string.

    Or if I enter a sequence of characters/keystrokes 中文很难<delete><delete><delete><delete> I will see 中文.

    If I enter a sequence of characters/keystrokes 中文<delete> I will see 中 whereas the cursor will be positioned one ASCII character to the right of 中 and if I hit enter at that point, 中 will be read in without a space.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1118258]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2024-04-24 11:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found