summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKosuke Asami <tfortress58@gmail.com>2013-07-17 17:44:35 +0900
committerKosuke Asami <tfortress58@gmail.com>2013-07-17 17:44:35 +0900
commit7753e6bbb8e20223f057b8ee95b0fc87eacbf34a (patch)
treedd866b079142d6b754620b0d2df1e23f2d0a6677
parent2d1766a3b7dc94218edbd73422ec7256477e73c3 (diff)
downloadreply-7753e6bbb8e20223f057b8ee95b0fc87eacbf34a.tar.gz
reply-7753e6bbb8e20223f057b8ee95b0fc87eacbf34a.zip
Enable completion when use ReadLine::Perl5
-rw-r--r--lib/Reply/Plugin/ReadLine.pm17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/Reply/Plugin/ReadLine.pm b/lib/Reply/Plugin/ReadLine.pm
index 6465369..bea2712 100644
--- a/lib/Reply/Plugin/ReadLine.pm
+++ b/lib/Reply/Plugin/ReadLine.pm
@@ -46,7 +46,7 @@ sub new {
$history
);
- if ($self->{term}->ReadLine eq 'Term::ReadLine::Gnu') {
+ if ($self->{term}->ReadLine eq ('Term::ReadLine::Gnu' or 'Term::ReadLine::Perl5')) {
$self->{term}->StifleHistory($opts{history_length})
if defined $opts{history_length} && $opts{history_length} >= 0;
}
@@ -81,7 +81,7 @@ sub DESTROY {
return if defined $self->{history_length} && $self->{history_length} == 0;
# XXX support more later
- return unless $self->{term}->ReadLine eq 'Term::ReadLine::Gnu';
+ return unless $self->{term}->ReadLine eq ('Term::ReadLine::Gnu' or 'Term::ReadLine::Perl5');
$self->{term}->WriteHistory($self->{history_file})
or warn "Couldn't write history to $self->{history_file}";
@@ -110,6 +110,19 @@ sub _register_tab_complete {
});
};
}
+
+ if ($term->ReadLine eq 'Term::ReadLine::Perl5') {
+ $term->Attribs->{completion_function} = sub {
+ my ($text, $line, $start) = @_;
+ my $end = $start + length($text);
+
+ # discard everything after the cursor for completion purposes
+ substr($line, $end) = '';
+
+ my @matches = $weakself->publish('tab_handler', $line);
+ return scalar(@matches) ? @matches : ();
+ };
+ }
}
1;