1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | # this extension implements scrollback buffer search |
3 | # this extension implements scrollback buffer search |
4 | |
4 | |
|
|
5 | #:META:X_RESOURCE:%:string:activation hotkey keysym |
|
|
6 | |
|
|
7 | =head1 NAME |
|
|
8 | |
|
|
9 | searchable-scrollback<hotkey> - incremental scrollback search (enabled by default) |
|
|
10 | |
|
|
11 | =head1 DESCRIPTION |
|
|
12 | |
|
|
13 | Adds regex search functionality to the scrollback buffer, triggered |
|
|
14 | by a hotkey (default: C<M-s>). While in search mode, normal terminal |
|
|
15 | input/output is suspended and a regex is displayed at the bottom of the |
|
|
16 | screen. |
|
|
17 | |
|
|
18 | Inputting characters appends them to the regex and continues incremental |
|
|
19 | search. C<BackSpace> removes a character from the regex, C<Up> and C<Down> |
|
|
20 | search upwards/downwards in the scrollback buffer, C<End> jumps to the |
|
|
21 | bottom. C<Escape> leaves search mode and returns to the point where search |
|
|
22 | was started, while C<Enter> or C<Return> stay at the current position and |
|
|
23 | additionally stores the first match in the current line into the primary |
|
|
24 | selection if the C<Shift> modifier is active. |
|
|
25 | |
|
|
26 | The regex defaults to "(?i)", resulting in a case-insensitive search. To |
|
|
27 | get a case-sensitive search you can delete this prefix using C<BackSpace> |
|
|
28 | or simply use an uppercase character which removes the "(?i)" prefix. |
|
|
29 | |
|
|
30 | See L<perlre> for more info about perl regular expression syntax. |
|
|
31 | |
|
|
32 | =cut |
|
|
33 | |
5 | sub on_init { |
34 | sub on_init { |
6 | my ($self) = @_; |
35 | my ($self) = @_; |
7 | |
36 | |
8 | my $hotkey = $self->{argv}[0] |
37 | my $hotkey = $self->{argv}[0] |
9 | || $self->x_resource ("searchable-scrollback") |
38 | || $self->x_resource ("%") |
10 | || "M-s"; |
39 | || "M-s"; |
11 | |
40 | |
12 | $self->parse_keysym ($hotkey, "perl:searchable-scrollback:start") |
41 | $self->parse_keysym ($hotkey, "perl:searchable-scrollback:start") |
13 | or warn "unable to register '$hotkey' as scrollback search start hotkey\n"; |
42 | or warn "unable to register '$hotkey' as scrollback search start hotkey\n"; |
14 | |
43 | |
… | |
… | |
80 | |
109 | |
81 | my $search = $self->special_encode ($self->{search}); |
110 | my $search = $self->special_encode ($self->{search}); |
82 | |
111 | |
83 | no re 'eval'; # just to be sure |
112 | no re 'eval'; # just to be sure |
84 | if (my $re = eval { qr/$search/ }) { |
113 | if (my $re = eval { qr/$search/ }) { |
85 | while ($self->nrow > $row && $row > $self->top_row) { |
114 | while ($self->nrow > $row && $row >= $self->top_row) { |
86 | my $line = $self->line ($row) |
115 | my $line = $self->line ($row) |
87 | or last; |
116 | or last; |
88 | |
117 | |
89 | my $text = $line->t; |
118 | my $text = $line->t; |
90 | if ($text =~ /$re/g) { |
119 | if ($text =~ /$re/g) { |
… | |
… | |
160 | |
189 | |
161 | $self->{search} .= $self->locale_decode ($data); |
190 | $self->{search} .= $self->locale_decode ($data); |
162 | |
191 | |
163 | $self->{search} =~ s/^\(\?i\)// |
192 | $self->{search} =~ s/^\(\?i\)// |
164 | if $self->{search} =~ /^\(.*[[:upper:]]/; |
193 | if $self->{search} =~ /^\(.*[[:upper:]]/; |
165 | |
194 | |
166 | $self->search (-1); |
195 | $self->search (-1); |
167 | $self->idle; |
196 | $self->idle; |
168 | |
197 | |
169 | 1 |
198 | 1 |
170 | } |
199 | } |