From ff7e2097b3ff2e56337361cab9c1d348413166a4 Mon Sep 17 00:00:00 2001 From: Shawn M Moore Date: Thu, 27 Jun 2013 14:37:20 -0400 Subject: Let readline present all matches and iterate over them --- lib/Reply/Plugin/ReadLine.pm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/Reply/Plugin/ReadLine.pm b/lib/Reply/Plugin/ReadLine.pm index e0675b6..f4ef2cd 100644 --- a/lib/Reply/Plugin/ReadLine.pm +++ b/lib/Reply/Plugin/ReadLine.pm @@ -90,18 +90,23 @@ sub DESTROY { sub _register_tab_complete { my $self = shift; + my $term = $self->{term}; my $completion_handler = $self->{tab_handler}; - if ($self->{term}->ReadLine eq 'Term::ReadLine::Gnu') { - $self->{term}->Attribs->{attempted_completion_function} = sub { + if ($term->ReadLine eq 'Term::ReadLine::Gnu') { + $term->Attribs->{attempted_completion_function} = sub { my ($text, $line, $start, $end) = @_; # discard everything after the cursor for completion purposes substr($line, $end) = ''; my @matches = $completion_handler->($line); + my $match_index = 0; - return @matches; + return $term->completion_matches($text, sub { + my ($text, $index) = @_; + return $matches[$index]; + }); }; } } -- cgit v1.2.3-54-g00ecf