Allasso has asked for the wisdom of the Perl Monks concerning the following question:
I'm not sure if this problem is actually a perl issue, but I will start here.
I am running code to capture user input, attempting to do some stuff with the cursor conditionally (using system calls to tput) depending on which character is entered, then printing out each character so it appears on the screen (as they would if echo were enabled.) All works fine if the user is typing input, the problem appears if the input is pasted into the terminal. I've isolated the problem to observe that it seems related to making a system call in the loop. All the pasted characters get printed out okay, until the system call is made, where the next character prints, but none following get printed. If I don't make the system call, all characters get printed fine.
I have also observed that it doesn't matter what system call I make (eg, ls or whatever), the same thing happens, so it is not just related to calling tput.
I've reduced the code to minimally demonstrate the issue. In this example, if text is pasted in, only the first character gets printed. If the system call in the loop is commented out, then all the text gets printed as expected. Also note that one character will print, regardless of whether the system call comes before or after the print call. Also note that it doesn't matter if I use system() or backtick notation.
#!/usr/bin/perl $| = 1; use strict; use warnings; system "stty -icanon -isig -echo min 1 time 0"; system "tput clear"; print "enter some text:\n"; processText(); sub processText { while ( my $char = STDIN->getc() ) { if (ord($char) == 3) { # Ctrl-C system "stty icanon echo isig"; exit; } # System call causes only a single character to print out, apparen +tly can # be anything, eg `ls`. Get same behavior with shell exec using ba +ckticks. system "tput sc"; print($char); } } system "stty icanon echo isig";
|
|---|