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

I am using Term::ReadLine to grab user input and return it, for now. However, I seem to find the need (on cygwin) to press "Enter" twice for a line to "take." Anyway, here is my code sample:
#!/usr/bin/perl use Term::Cap; use Term::ReadKey; use Term::ReadLine; ReadMode 4; $term = new Term::ReadLine 'fakeTerminal'; $prompt = "input: "; @fakeArray = ("The first", "The second", "The third", "The fourth"); for ($i = 0; $i < scalar(@fakeArray); $i++) { print $i+1, ". \t", $fakeArray[$i], "\n"; } while( defined ($_ = $term->readline($prompt))) { if($_){ last if $_ =~ /^\s*quit/i; print $_, "\n"; } } #$key = ReadKey(0); #print "you typed $key\n"; ReadMode 0;
I also have a second question, will using ReadMode 4 with Term::ReadLine still prevent escape attempts using CTRL characters?

If you make something idiot-proof, eventually someone will make a better idiot.
I am that better idiot.

Replies are listed 'Best First'.
Re: Term::ReadLine question, double enter
by jlongino (Parson) on Sep 26, 2002 at 04:49 UTC
    I believe the code works as you would expect it to (it seems to under Solaris 2.8). Yes "Readmode 4" will prevent the user from using ^C, ^D, ^Z, etc. to escape from the input.

    To solve the double Enter problem try using "ReadMode 5" instead. It behaves just like ReadMode4 except that no CR/LF translation is performed, and if possible, parity will be disabled (only if not being used by the terminal, however. It is no different from mode 4 under Windows.): an excerpt from the perldoc Term::ReadKey docs. But since you are using cygwin, there may be an exception in that case.


Re: Term::ReadLine question, double enter
by jdavidboyd (Friar) on Sep 26, 2002 at 15:19 UTC
    Yes, I've had this problem since updating to Perl 5.8.0. I always have to double enter when using CPAN now.

    I think that at one time I went back and tried Perl 5.6.1 again, and the problem went away.

    And that is as far as I got in my troubleshooting. On my main Linux machine, it works fine. Only on Cygwin is it a problem, so I don't use that machine very often

    Also, I just grabbed your script and tried it under Cygwin, and the modes 1, 2, 3, & 4 all acted exactly the same. Mode 5 was flakey to say the least. Especially wierd, mode 2, which isn't supposed to echo, but does.