summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn M Moore <code@sartak.org>2013-06-27 13:37:38 -0400
committerShawn M Moore <code@sartak.org>2013-06-27 13:54:52 -0400
commitbf09193613e1130f3e02ace7bc2acb09f6685714 (patch)
tree74437a297a89d53090528728e4ca1a52250e3afc
parent0f576f029744b633cbce147d3681205f33001e2e (diff)
downloadreply-bf09193613e1130f3e02ace7bc2acb09f6685714.tar.gz
reply-bf09193613e1130f3e02ace7bc2acb09f6685714.zip
Register the tab_handler with ReadLine
-rw-r--r--lib/Reply/Plugin/ReadLine.pm22
1 files changed, 22 insertions, 0 deletions
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;