How can I get case insensitive using Term :: ReadLine :: Gnu?

I cannot get case insensitive when using Term :: ReadLine :: Gnu . Take this example script:

use strict; use warnings; use 5.010; use Term::ReadLine; my $term = Term::ReadLine->new('test'); say "Using " . $term->ReadLine; if (my $attr = $term->Attribs) { $term->ornaments(0); $attr->{basic_word_break_characters} = ". \t\n"; $attr->{completer_word_break_characters} = " \t\n"; $attr->{completion_function} = \&complete_word; } # end if attributes my @words = qw(apple approve Adam America UPPER UPPERCASE UNUSED); sub complete_word { my ($text, $line, $start) = @_; return grep(/^$text/i, @words); } # end complete_word while (1) { $_ = $term->readline(']'); last unless /\S/; # quit on empty input } # end while 1 

Note that complete_word not case sensitive. If I run this with Term :: ReadLine :: Perl (by doing PERL_RL=Perl perl script.pl ), it works as I expect. Entering a<TAB><TAB> contains all 4 words. Entering u<TAB><TAB> converts u to u and lists 3 words.

When I use Term :: ReadLine :: Gnu instead ( PERL_RL=Gnu perl script.pl or just perl script.pl ), it is case-sensitive completion only. Entering a<TAB> gives the app . The input u<TAB><TAB> does not contain any terminations.

I even have set completion-ignore-case on in my /etc/inputrc , but it still doesn't work. (However, it works fine in bash .)

Is there a way to get Term :: ReadLine :: Gnu to complete case-insensitive?

+4
source share
1 answer

It would seem that the problem is in Term::ReadLine::Gnu::XS::_trp_completion_function() (shell for a custom completion function).

Your matches are correctly extracted from your complete_word() function, but the following snippet from the wrapper matches its case:

 for (; $_i <= $#_matches; $_i++) { return $_matches[$_i] if ($_matches[$_i] =~ /^\Q$text/); } 

where @_matches is the result of your complete_word() and $text is the completed text.

So it looks like the answer is no, there is no supported way to get Term::ReadLine::Gnu to complete case-insensitive. You will have to override the private Term::ReadLine::Gnu::XS::_trp_completion_function (ugly hack to be sure) - or modify XS.pm directly (possibly even an uglier hack).

EDIT: Term::ReadLine::Gnu version used: 1.20

+3
source

Source: https://habr.com/ru/post/1380438/


All Articles