From bf558b660b29dfb10e752c9982a6bdb1713c2b32 Mon Sep 17 00:00:00 2001 From: tokuhirom Date: Tue, 13 Aug 2013 13:20:26 +0900 Subject: Plugin::ReadLine: Added Term::ReadLine::Caroline support. --- lib/Reply/Plugin/ReadLine.pm | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/Reply/Plugin/ReadLine.pm b/lib/Reply/Plugin/ReadLine.pm index 31f0e80..55baa38 100644 --- a/lib/Reply/Plugin/ReadLine.pm +++ b/lib/Reply/Plugin/ReadLine.pm @@ -49,13 +49,14 @@ sub new { $self->{rl_gnu} = $self->{term}->ReadLine eq 'Term::ReadLine::Gnu'; $self->{rl_perl5} = $self->{term}->ReadLine eq 'Term::ReadLine::Perl5'; + $self->{rl_caroline} = $self->{term}->ReadLine eq 'Term::ReadLine::Caroline'; if ($self->{rl_perl5}) { # output compatible with Term::ReadLine::Gnu $readline::rl_scroll_nextline = 0; } - if ($self->{rl_perl5} || $self->{rl_gnu}) { + if ($self->{rl_perl5} || $self->{rl_gnu} || $self->{rl_caroline}) { $self->{term}->StifleHistory($opts{history_length}) if defined $opts{history_length} && $opts{history_length} >= 0; } @@ -90,7 +91,7 @@ sub DESTROY { return if defined $self->{history_length} && $self->{history_length} == 0; # XXX support more later - return unless ($self->{rl_gnu} || $self->{rl_perl5}); + return unless ($self->{rl_gnu} || $self->{rl_perl5} || $self->{rl_caroline}); $self->{term}->WriteHistory($self->{history_file}) or warn "Couldn't write history to $self->{history_file}"; @@ -132,6 +133,20 @@ sub _register_tab_complete { return scalar(@matches) ? @matches : (); }; } + + if ($self->{rl_caroline}) { + $term->caroline->completion_callback(sub { + my ($line) = @_; + + my @matches = $weakself->publish('tab_handler', $line); + # for variable completion, method name completion. + if (@matches && $line =~ /\W/) { + $line =~ s/[:\w]+\z//; + @matches = map { $line.$_ } @matches; + } + return scalar(@matches) ? @matches : (); + }); + } } 1; -- cgit v1.2.3