summaryrefslogtreecommitdiffstats
path: root/lib/Reply/Plugin/ReadLine.pm
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-05-31 04:51:29 -0500
committerJesse Luehrs <doy@tozt.net>2013-05-31 04:51:29 -0500
commit84640f1b3b402d2a64a5005d757f7171df2d658d (patch)
tree4c916aeffe0cecc9049400592a809f6e2b697135 /lib/Reply/Plugin/ReadLine.pm
parentcf4edf5661ed8cfaa392e5ee63b0d75a70ac0c87 (diff)
downloadreply-84640f1b3b402d2a64a5005d757f7171df2d658d.tar.gz
reply-84640f1b3b402d2a64a5005d757f7171df2d658d.zip
add some configuration to a couple plugins
Diffstat (limited to 'lib/Reply/Plugin/ReadLine.pm')
-rw-r--r--lib/Reply/Plugin/ReadLine.pm25
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/Reply/Plugin/ReadLine.pm b/lib/Reply/Plugin/ReadLine.pm
index 29ad5a0..54c262b 100644
--- a/lib/Reply/Plugin/ReadLine.pm
+++ b/lib/Reply/Plugin/ReadLine.pm
@@ -8,15 +8,26 @@ use File::HomeDir;
use File::Spec;
use Term::ReadLine;
-my $history = File::Spec->catfile(File::HomeDir->my_data, '.reply_history');
-
sub new {
my $class = shift;
+ my %opts = @_;
my $self = $class->SUPER::new(@_);
$self->{term} = Term::ReadLine->new('Reply');
+ my $history = $opts{history_file} || '.reply_history';
+ $self->{history_file} = File::Spec->catfile(
+ (File::Spec->file_name_is_absolute($history)
+ ? ()
+ : (File::HomeDir->my_data)),
+ $history
+ );
+
+ if ($self->{term}->ReadLine eq 'Term::ReadLine::Gnu') {
+ $self->{term}->StifleHistory($opts{history_length})
+ if defined $opts{history_length} && $opts{history_length} >= 0;
+ }
- if (open my $fh, '<', $history) {
+ if (open my $fh, '<', $self->{history_file}) {
for my $line (<$fh>) {
chomp $line;
$self->{term}->addhistory($line);
@@ -24,8 +35,8 @@ sub new {
}
else {
my $e = $!;
- warn "Couldn't open $history for reading: $e"
- if -e $history;
+ warn "Couldn't open $self->{history_file} for reading: $e"
+ if -e $self->{history_file};
}
return $self;
@@ -44,8 +55,8 @@ sub DESTROY {
# XXX support more later
return unless $self->{term}->ReadLine eq 'Term::ReadLine::Gnu';
- $self->{term}->WriteHistory($history)
- or warn "Couldn't write history to $history";
+ $self->{term}->WriteHistory($self->{history_file})
+ or warn "Couldn't write history to $self->{history_file}";
}
1;