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

How on earth do ya get up arrow and tab completion to work in Term::ReadLine?

There must be a way to do it since the example on the man page does the addhistory. There's a bunch of talk about ornaments and Features in the man pages too. Perhaps it takes a working knowledge of the C version of readline?

I don't think the Term::ReadLine stuff is supposed to be the end of the line. I read somewhere that they intended it to be a base object for other packages?

#!/looser/nib/perl use strict; use Term::ReadLine; &start_stupid_math_shell; sub start_stupid_math_shell { my $term = new Term::ReadLine 'Simple Perl calc'; my $prompt = "Enter your arithmetic expression: "; while ( defined ($_ = $term->readline($prompt)) ) { my $res = eval($_), "\n"; warn $@ if $@; print $res, "\n" unless $@; $term->addhistory($_) if /\S/; } }

Replies are listed 'Best First'.
Re: ReadLine Tabn'Up?
by KM (Priest) on Aug 11, 2000 at 19:58 UTC
    I haven't used Term::Readline, but giving a quick look at the module I saw:

    sub addhistory {}

    So, it is a dummy method. I think what you want is Term::ReadLine::Gnu (Perl extension for the GNU Readline/History Library) or Term::ReadLine::Perl

    Cheers,
    KM

      Term::ReadLine by itself only provides very basic functionality, mostly stubs for functions that are actually provided by other packages, namely Term::ReadLine::Gnu, Term::ReadLine::Perl and others. But you do not use these modules directly. You always use Term::ReadLine, and it detects which ones are installed and picks the best one (for some definition of "best"). There is a minimum set of supported methods, and you can check what other features you have available through the Features method.

      As for history, if you have Term::ReadLine::Gnu, it is enabled automatically and you can access it using ctrl-p/uparrow and ctrl-n/downarrow. You can also manually add lines or otherwise manipulate the history. See the documentation for Term::ReadLine::Gnu for details.

      I have never used tab completion, but there are a number of functions that deal with that in the documentation, so you should be able to figure it out.

      --ZZamboni