diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-07-17 06:49:06 -0700 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-07-17 06:49:06 -0700 |
commit | 643ab1ddd6a1db397ac55b16414ce88a08ab25a8 (patch) | |
tree | 6210e581ae9da0d2f33489188d1271c34867187f | |
parent | 2d1766a3b7dc94218edbd73422ec7256477e73c3 (diff) | |
parent | d0bf25e0cb81888a0e42a072b652a771db8ee4fc (diff) | |
download | reply-643ab1ddd6a1db397ac55b16414ce88a08ab25a8.tar.gz reply-643ab1ddd6a1db397ac55b16414ce88a08ab25a8.zip |
Merge pull request #20 from co-me/readline-perl
Support Term::ReadLine::Perl5
-rw-r--r-- | lib/Reply/Plugin/ReadLine.pm | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/Reply/Plugin/ReadLine.pm b/lib/Reply/Plugin/ReadLine.pm index 6465369..18c944b 100644 --- a/lib/Reply/Plugin/ReadLine.pm +++ b/lib/Reply/Plugin/ReadLine.pm @@ -46,7 +46,12 @@ sub new { $history ); - if ($self->{term}->ReadLine eq 'Term::ReadLine::Gnu') { + if ($self->{term}->ReadLine eq 'Term::ReadLine::Perl5') { + # output compatible with Term::ReadLine::Gnu + $readline::rl_scroll_nextline = 0; + } + + 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 +86,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 +115,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; |