http://qs1969.pair.com?node_id=1168760


in reply to Revising Input Method

According to the documentation the package is just a front end to some other packages. It's a stub to set up a common interface to the various ReadLine implementations found on CPAN (under the Term::ReadLine::* namespace). If you haven't installed any additional packages like Term::Readline::Gnu or Term::ReadLine::EditLine, it will default to an internal default package called Term::ReadLine::Stub, this default package is very simple, and does not understand things like arrow keys. You can use $term->ReadLine to determine which package it is actually using, see below example.

I tried to install Term::ReadLine::Gnu on my Ubuntu laptop:

$ sudo apt-get install libncurses5-dev libreadline6-dev $ cpanm Term::ReadLine::Gnu
Then I tried
use feature qw(say); use strict; use warnings; use Term::ReadLine; my $term = Term::ReadLine->new('Test', \*STDIN, \*STDOUT); say "I am using the following ReadLine package: " . $term->ReadLine; $term->ornaments( 0 ); $term->addhistory("sample text added to history"); while (1) { my $line = $term->readline( 'Enter input: ' ); say "You entered: '$line'"; }

Now the up and down arrow keys are recoginzed, and used to recall the history lines. There are also some useful Emacs keybindings available, see Command Line Editing in the Gnu Bash manual for more information.