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


In reply to Gnu ReadLine word completion question by rmcgowan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.