From bf09193613e1130f3e02ace7bc2acb09f6685714 Mon Sep 17 00:00:00 2001 From: Shawn M Moore Date: Thu, 27 Jun 2013 13:37:38 -0400 Subject: Register the tab_handler with ReadLine --- lib/Reply/Plugin/ReadLine.pm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/Reply/Plugin/ReadLine.pm b/lib/Reply/Plugin/ReadLine.pm index 7c4ddd0..e0675b6 100644 --- a/lib/Reply/Plugin/ReadLine.pm +++ b/lib/Reply/Plugin/ReadLine.pm @@ -37,6 +37,7 @@ sub new { my $self = $class->SUPER::new(@_); $self->{term} = Term::ReadLine->new('Reply'); + $self->{tab_handler} = $opts{tab_handler}; my $history = $opts{history_file} || '.reply_history'; $self->{history_file} = File::Spec->catfile( (File::Spec->file_name_is_absolute($history) @@ -62,6 +63,8 @@ sub new { if -e $self->{history_file}; } + $self->_register_tab_complete; + return $self; } @@ -84,4 +87,23 @@ sub DESTROY { or warn "Couldn't write history to $self->{history_file}"; } +sub _register_tab_complete { + my $self = shift; + + my $completion_handler = $self->{tab_handler}; + + if ($self->{term}->ReadLine eq 'Term::ReadLine::Gnu') { + $self->{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); + + return @matches; + }; + } +} + 1; -- cgit v1.2.3-54-g00ecf