Commit | Line | Data |
9d03fe04 |
1 | # First cut at using the readline history directly rather than reimplementing |
2 | # it. It does save history but it's a little crappy; still playing with it ;) |
3 | # |
4 | # epitaph, 22nd April 2007 |
5 | |
6 | package Devel::REPL::Plugin::ReadLineHistory; |
7 | |
8 | use Moose::Role; |
9 | |
10 | my $hist_file=$ENV{PERLREPL_HISTFILE} || |
11 | (($ENV{HOME} || (getpwuid($<))[7]) . "/.perlreplhist"); |
12 | # HISTLEN should probably be in a config file to stop people accidentally |
13 | # truncating their history if they start the program and forget to set |
14 | # PERLREPL_HISTLEN |
15 | my $hist_len=$ENV{PERLREPL_HISTLEN} || 100; |
16 | |
17 | around 'run' => sub { |
18 | my $orig=shift; |
19 | my ($self, @args)=@_; |
20 | $self->term->stifle_history($hist_len); |
21 | -f($hist_file) && $self->term->ReadHistory($hist_file); |
22 | $self->term->Attribs->{do_expand}=1; |
23 | $self->$orig(@args); |
24 | $self->term->WriteHistory($hist_file) || |
25 | $self->print("warning: failed to write history file $hist_file"); |
26 | }; |
27 | |
28 | 1; |
29 | |