Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Gnu ReadLine word completion question

by rmcgowan (Sexton)
on Mar 18, 2005 at 06:34 UTC ( [id://440634]=perlquestion: print w/replies, xml ) Need Help??

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

I have an application that uses the ReadLine::Gnu module to provide list completion for data input. For example, I have a list of 2 or more items that the user is to select from. If the user already knows the value, it's ok to just type it in, but if not, I want the user to be able to press the tab key to get either the full list, partial list, or word competion, as appropriate.

If I don't use the .inputrc 'set show-all-if-ambiguous On', the user has to press the tab key twice to get the full or partial list. With the variable 'On', a single tab press is enough.

I want to set this programatically so users don't have to create a .inputrc file (and so the thing works as advertised, my input prompt says 'Press TAB key for a list'.

I've found the attribute variable 'completion_type', but setting it does not have any impact on the script operation.

My code looks like this (basically from the pftp example in the eg/ directory of the distribution):

sub doInput($$;$) { my $term = ${$_[0]}; my $selectList = $_[1]; # This is already a REFERENCE! my $promptStr = $_[2] if $_[2]; # Set the prompt string to empty string if there is no 3rd arg. ! $promptStr and $promptStr = ''; # The code below, up to the return(), is pulled from the pftp # readline example file. Thanks to Hiroo Hayashi for the Gnu # ReadLine code. my $attribs = $term->Attribs; # This is the list of things to expand on. $attribs->{completion_word} = $selectList; $attribs->{completion_append_character} = ''; $attribs->{completion_entry_function} = $attribs->{'list_completion_function'}; # Check the length of $promptStr, if > 78 characters, append # newline length $promptStr > 78 and $promptStr .= "\n"; my $userInput = $term->readline($promptStr); $attribs->{completion_append_character} = ' '; $attribs->{completion_entry_function} = undef; return $userInput; }

Thanks for the help,

Bob

Update:

I tried the rl_set(...) call suggested by Tanktalus, which resulted in the error:

Cannot do `rl_set' in Term::ReadLine::Gnu at /usr/lib/perl5/site_perl/ +5.6.1/etrack.pl line 1587

I've also tried setting the attribute I thought is the one that controls this, as follows:

$attribs->{completion_type} = 33; # '!' in decimal

which does nothing. According to the documentation, the Gnu interger type variable 'rl_completion_type' "...describing the type of completion Readline is currently attempting...", so it sounds like it's actually an internal state record, not to be used to actually set the state.

If anyone has any pointers to some decent tutorials on Gnu ReadLine itself, or the Perl module interface to it, I'd be deeply grateful.

Bob

Replies are listed 'Best First'.
Re: Gnu ReadLine word completion question
by Tanktalus (Canon) on Mar 18, 2005 at 15:13 UTC

    Cheating and looking at the readline code ... I wonder if $term->rl_set(ShowAllIfAmbiguous => 'On') would work.

    Disclaimer: completely untested. I only have Term::ReadLine installed because I like using it with the perl debugger, not because I actually code with it. I'm posting this because no one has yet responded - not because I'm an expert. Take two aspirin and call someone else in the morning. :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://440634]
Approved by kvale
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-25 07:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found