line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Term::ReadLine::Zoid::ISearch; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
2113
|
use strict; |
|
1
|
|
|
|
|
23
|
|
|
1
|
|
|
|
|
56
|
|
4
|
1
|
|
|
1
|
|
6
|
use base 'Term::ReadLine::Zoid'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
127
|
|
5
|
1
|
|
|
1
|
|
7
|
no warnings; # undef == '' down here |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1374
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = 0.06; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our %_keymap = ( |
10
|
|
|
|
|
|
|
backspace => 'backward_delete_char', |
11
|
|
|
|
|
|
|
ctrl_R => 'isearch_again', |
12
|
|
|
|
|
|
|
_on_switch => 'is_switch', |
13
|
|
|
|
|
|
|
_default => 'self_insert' |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
0
|
1
|
|
sub keymap { return \%_keymap } |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub is_switch { |
19
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
20
|
0
|
|
|
|
|
|
$$self{is_lock} = undef; |
21
|
0
|
|
|
|
|
|
$$self{is_hist_p} = -1; |
22
|
0
|
|
|
|
|
|
$$self{is_save} = [[''], [0,0], undef]; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub is_switch_back { |
26
|
0
|
|
|
0
|
0
|
|
my ($self, $key) = @_; |
27
|
0
|
|
|
|
|
|
$$self{_hist_save} = $self->save(); |
28
|
0
|
|
|
|
|
|
@$self{qw/lines pos hist_p/} = @{$$self{is_save}}; |
|
0
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
$self->switch_mode(); |
30
|
0
|
|
|
|
|
|
$self->do_key($key); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub draw { # rendering this inc mode is kinda consuming |
34
|
0
|
|
|
0
|
0
|
|
my ($self, @args) = @_; |
35
|
0
|
|
|
|
|
|
my $save = $self->save(); |
36
|
0
|
|
|
|
|
|
my $string = join "\n", @{$$self{lines}}; |
|
0
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$$self{prompt} = "i-search qr($string): "; |
38
|
0
|
0
|
|
|
|
|
goto DRAW unless length $string; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my ($result, $match, $hist_p) = (undef, '', $$self{is_hist_p}); |
41
|
0
|
|
|
|
|
|
$$self{last_search} = ['b', $string]; |
42
|
0
|
|
|
|
|
|
my $reg = eval { qr/^(.*?$string)/ }; |
|
0
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
goto DRAW if $@; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
while ($hist_p < $#{$$self{history}}) { |
|
0
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$hist_p++; |
47
|
0
|
0
|
|
|
|
|
next unless $$self{history}[$hist_p] =~ $reg; |
48
|
0
|
|
|
|
|
|
($result, $match) = ($$self{history}[$hist_p], $1); |
49
|
0
|
|
|
|
|
|
last; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
if (defined $result) { |
53
|
0
|
|
|
|
|
|
push @{$$self{last_search}}, $hist_p; |
|
0
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
$$self{is_lock} = undef; |
55
|
0
|
|
|
|
|
|
$$self{lines} = [ split /\n/, $result ]; |
56
|
0
|
|
|
|
|
|
my @match = split /\n/, $match; |
57
|
0
|
|
|
|
|
|
$$self{pos} = [length($match[-1]), $#match]; |
58
|
|
|
|
|
|
|
} |
59
|
0
|
|
|
|
|
|
else { $$self{is_lock} = 1 } |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
DRAW: Term::ReadLine::Zoid::draw($self, @args); |
62
|
0
|
|
|
|
|
|
$$self{is_save} = [ $$self{lines}, $$self{pos}, $hist_p]; |
63
|
0
|
|
|
|
|
|
$self->restore($save); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub self_insert { |
67
|
0
|
0
|
|
0
|
0
|
|
if ($_[0]{is_lock}) { $_[0]->bell } |
|
0
|
0
|
|
|
|
|
|
68
|
|
|
|
|
|
|
elsif ($_[0]->key_binding($_[1], $_[0]{config}{default_mode})) { |
69
|
0
|
|
|
|
|
|
goto \&is_switch_back; |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
|
else { goto \&Term::ReadLine::Zoid::self_insert } |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
0
|
0
|
|
sub isearch_again { $_[0]{is_hist_p} = $_[0]{last_search}[-1] if $_[0]{last_search} } |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
__END__ |