AnyEvent::ReadLine::Gnu - how to get working history *and* a changing prompt?

Moritz Lenz moritz.lenz at noris.de
Thu Dec 4 09:41:06 CET 2014


Hi,

I have a legacy application that now needs to respond to some networking 
events in the background. Since this application mostly waits for user 
input, I thought I replaced the current readline by AnyEvent::ReadLine::Gnu.

So I tried this, because it fits the structure of the existing 
application best:

use 5.014;
use utf8;
use AnyEvent::ReadLine::Gnu;

my $rl = AnyEvent::ReadLine::Gnu->new(on_line => sub {}, prompt => '');
my $cnt = 0;
while (my $line = $rl->readline("$cnt: ")) {
     $cnt++
}
__END__

However, this way the history function doesn't work. When I press the 
"Up" key, it merely prints a [A into the terminal.

So my next attempt was to use the more AnyEvent-ish way of doing things:

use 5.014;
use utf8;
use AnyEvent::ReadLine::Gnu;
use AnyEvent;

my $cnt = 0;
my $rl;
$rl = AnyEvent::ReadLine::Gnu->new(
     on_line => sub {
         my $line = shift;
         $rl->hide;
         $cnt++;
         $rl->{prompt} = "$cnt: ";
         $rl->show;
     },
     prompt => "$cnt: "
);
my $cv = AnyEvent->condvar;
$cv->recv;
__END__

However that complains:

Gnu.xs:_rl_store_str: store to read only variable at 
/usr/lib/perl5/Term/ReadLine/Gnu.pm line 648.

So, what do I do to get both a working history and a changing prompt?

Cheers,
Moritz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 6348 bytes
Desc: not available
URL: <http://lists.schmorp.de/pipermail/anyevent/attachments/20141204/e09adff5/attachment.bin>


More information about the anyevent mailing list