in reply to Re^3: about Term::ReadLine and it's imported function The Solution
in thread about Term::ReadLine and it's imported function
Term::ReadLine is indeed very confusing and it took me many attempts to understand the debugger and long studies of the documentation of gnu-readline (i.e. the original c-library) including sample scripts in Term::ReadLine::Gnu to get used to it.
IMHO gnu-readline predates T'RL and it was originally only thought as a wrapper with a thin Stub as fall back. People were meant to know gnu-readline and to understand the limitations.
> and a strange behaviour (still obscure to me)
as I told you it's using Autoloading, i.e. the function is installed after first use, such that exists fails before that.
> continue{ &define_completion_func($hr);}
this really confused me, till I understood that you want to set up a new set of commands in the $hr hashref.
But since its a closed over variable in the completion-function you might also simply reset it with something like %$hr=%CMD .
PLEASE NOTE that your code should now work with most Term::ReadLine::* sub-packages (except ::Stub of course)
The following code is a proof of concept I wrote yesterday, you can pass the name of the implementation module to test it or hardcode the module to test by default.
#!/usr/bin/perl use strict; use warnings; my $module; BEGIN { my $opt = $ARGV[0]; $ENV{PERL_RL} = $opt || qw(Gnu Perl Zoid)[0]; # choose module $module = $ENV{PERL_RL}; } use Term::ReadLine; my $term = Term::ReadLine->new('sample'); my $attribs = $term->Attribs; completion_words('print', 'list', 'quit', 'run', 'status'); $term->readline("$module> "); sub completion_words { my @basic_commands = @_; my $c_completion = sub { my ($text, $line, $start) = @_; #return () if $start != 0; # only at start grep(/^$text/, @basic_commands); }; $attribs->{completion_function} = $c_completion; }
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
|
|---|