I'm using Term::ReadLine and have an odd issue where I need to hit the up arrow twice to retrieve items from addhistory. Here's the script I'm using.
use Term::ReadLine;
my $term = Term::ReadLine->new('Term1');
print $term->ReadLine."\n";
while (defined(my $cmd = $term->readline())) {
$term->addhistory($cmd) if $cmd =~ /\S/;
}
To test, I'll input a few "commands" then try to retrieve those commands with the up arrow. I hit the up arrow once and the last item comes up immediately, but I'll need to hit the up arrow twice before each following item is retrieved.
I encountered this issue earlier in a little project I'm working on, and came across someone with the same issue. The resolution to this issue is a modification to the addhistory line as follows:
$term->addhistory($cmd) if $cmd !~ /\S||\n/;
It worked so I moved on until Tanktalus brought this up in another question I posted. Perl Term::ReadLine::Gnu Signal Handling Difficulties
He asks "what is /\S||\n/ supposed to do?". Ok well, let me go find that page that suggested this as a fix... Yeah...can't find it. So while I can make it work with the modification I posted I'm a bit stuck since A. I don't know why it fixes it, and B. Why do I seem to be the only one with this issue?
Any help or advice would be appreciated! :)
Tested the above script with the following versions:
Perl - 5.12.4 and 5.16.1
Term::ReadLine::Gnu - 1.20
Term::ReadLine::Perl - 1.0303 (Just tried it to make sure it wasn't Gnu)
Term::ReadLine - 1.10