How to block Term :: ReadLine by default?

How can I disable Term::ReadLine

the default, or rather, make it stop suggesting file name revisions at some point?

For example, what do I need to replace return()

in order to prevent the default of the second word?

None of these works:

    $attribs->{'filename_completion_function'}=undef;
    $attribs->{'rl_inhibit_completion'}=1;

      

use Term::ReadLine;

my $term    = new Term::ReadLine 'sample';
my $attribs = $term->Attribs;
$attribs->{attempted_completion_function} = \&sample_completion;

sub sample_completion {
    my ( $text, $line, $start, $end ) = @_;

    # If first word then username completion, else filename completion
    if ( substr( $line, 0, $start ) =~ /^\s*$/ ) {

        return $term->completion_matches( $text,
            $attribs->{'username_completion_function'} );
    }
    else {
        return ();
    }
}

while ( my $input = $term->readline( "> " ) ) {
    ...
}

      

+3


source to share


1 answer


Define completion_function

instead attempted_completion_function

:

$attribs->{completion_function} = \&completion;

      

And then return undef

if completion should stop, and return $term->completion_matches($text, $attribs->{filename_completion_function})

if completion of the filename is complete.



The following example does not suggest anything for the first parameter, but filenames for the second parameter.

use Term::ReadLine;

my $term = new Term::ReadLine 'sample';
my $attribs = $term->Attribs;
$attribs->{completion_function} = \&completion;

sub completion {

  my ( $text, $line, $start ) = @_;

  if ( substr( $line, 0, $start ) =~ /^\s*$/) {

    return 

  } else {

    return $term->completion_matches($text, $attribs->{filename_completion_function})

  }
}

while ( my $input = $term->readline ("> ") ) {
  exit 0 if $input eq "q";
}

      

+1


source







All Articles