… | |
… | |
5 | #:META:RESOURCE:%:string:activation hotkey keysym |
5 | #:META:RESOURCE:%:string:activation hotkey keysym |
6 | #:META:BINDING:M-s:start |
6 | #:META:BINDING:M-s:start |
7 | |
7 | |
8 | =head1 NAME |
8 | =head1 NAME |
9 | |
9 | |
10 | searchable-scrollback<hotkey> - incremental scrollback search (enabled by default) |
10 | searchable-scrollback - incremental scrollback search (enabled by default) |
11 | |
11 | |
12 | =head1 DESCRIPTION |
12 | =head1 DESCRIPTION |
13 | |
13 | |
14 | Adds regex search functionality to the scrollback buffer, triggered |
14 | Adds regex search functionality to the scrollback buffer, triggered by |
15 | by a hotkey (default: C<M-s>). While in search mode, normal terminal |
15 | the C<searchable-scrollback:start> action (bound to C<M-s> by |
|
|
16 | default). While in search mode, normal terminal input/output is |
16 | input/output is suspended and a regex is displayed at the bottom of the |
17 | suspended and a regex is displayed at the bottom of the screen. |
17 | screen. |
|
|
18 | |
18 | |
19 | Inputting characters appends them to the regex and continues incremental |
19 | Inputting characters appends them to the regex and continues incremental |
20 | search. C<BackSpace> removes a character from the regex, C<Up> and C<Down> |
20 | search. C<BackSpace> removes a character from the regex, C<Up> and C<Down> |
21 | search upwards/downwards in the scrollback buffer, C<End> jumps to the |
21 | search upwards/downwards in the scrollback buffer, C<End> jumps to the |
22 | bottom. C<Escape> leaves search mode and returns to the point where search |
22 | bottom. C<Escape> leaves search mode and returns to the point where search |
… | |
… | |
44 | or warn "unable to register '$hotkey' as scrollback search start hotkey\n"; |
44 | or warn "unable to register '$hotkey' as scrollback search start hotkey\n"; |
45 | |
45 | |
46 | () |
46 | () |
47 | } |
47 | } |
48 | |
48 | |
|
|
49 | sub on_user_command { |
|
|
50 | my ($self, $cmd) = @_; |
|
|
51 | |
|
|
52 | $cmd eq "searchable-scrollback:start" |
|
|
53 | and $self->enter; |
|
|
54 | |
|
|
55 | () |
|
|
56 | } |
|
|
57 | |
49 | sub on_action { |
58 | sub on_action { |
50 | my ($self, $action) = @_; |
59 | my ($self, $action) = @_; |
51 | |
60 | |
52 | $action eq "start" |
61 | $action eq "start" |
53 | and $self->enter; |
62 | and $self->enter; |
… | |
… | |
91 | $self->disable ("key_press", "tt_write", "refresh_begin", "refresh_end"); |
100 | $self->disable ("key_press", "tt_write", "refresh_begin", "refresh_end"); |
92 | $self->pty_ev_events ($self->{pty_ev_events}); |
101 | $self->pty_ev_events ($self->{pty_ev_events}); |
93 | |
102 | |
94 | delete $self->{manpage_overlay}; |
103 | delete $self->{manpage_overlay}; |
95 | delete $self->{overlay}; |
104 | delete $self->{overlay}; |
96 | delete $self->{history}; |
|
|
97 | delete $self->{search}; |
105 | delete $self->{search}; |
|
|
106 | delete $self->{found}; |
98 | } |
107 | } |
99 | |
108 | |
100 | sub idle { |
109 | sub idle { |
101 | my ($self) = @_; |
110 | my ($self) = @_; |
102 | |
111 | |
103 | $self->msg ("(escape cancels) /$self->{search}█"); |
112 | $self->msg ("(escape cancels) /$self->{search}█"); |
104 | } |
113 | } |
105 | |
114 | |
106 | sub search { |
115 | sub search { |
107 | my ($self, $dir) = @_; |
116 | my ($self, $dir, $row) = @_; |
108 | |
|
|
109 | delete $self->{found}; |
|
|
110 | my $row = $self->{row}; |
|
|
111 | |
117 | |
112 | my $search = $self->special_encode ($self->{search}); |
118 | my $search = $self->special_encode ($self->{search}); |
113 | |
119 | |
114 | no re 'eval'; # just to be sure |
120 | no re 'eval'; # just to be sure |
115 | if (my $re = eval { qr/$search/ }) { |
121 | if (my $re = eval { qr/$search/ }) { |
… | |
… | |
117 | my $line = $self->line ($row) |
123 | my $line = $self->line ($row) |
118 | or last; |
124 | or last; |
119 | |
125 | |
120 | my $text = $line->t; |
126 | my $text = $line->t; |
121 | if ($text =~ /$re/g) { |
127 | if ($text =~ /$re/g) { |
|
|
128 | delete $self->{found}; |
|
|
129 | |
122 | do { |
130 | do { |
123 | push @{ $self->{found} }, [$line->coord_of ($-[0]), $line->coord_of ($+[0])]; |
131 | push @{ $self->{found} }, [$line->coord_of ($-[0]), $line->coord_of ($+[0])]; |
124 | } while $text =~ /$re/g; |
132 | } while $text =~ /$re/g; |
125 | |
133 | |
126 | $self->{row} = $row; |
134 | $self->{row} = $row; |
127 | $self->view_start (List::Util::min 0, $row - ($self->nrow >> 1)); |
135 | $self->view_start (List::Util::min 0, $row - ($self->nrow >> 1)); |
128 | $self->want_refresh; |
136 | $self->want_refresh; |
129 | last; |
137 | return; |
130 | } |
138 | } |
131 | |
139 | |
132 | $row = $dir < 0 ? $line->beg - 1 : $line->end + 1; |
140 | $row = $dir < 0 ? $line->beg - 1 : $line->end + 1; |
133 | } |
141 | } |
134 | } |
142 | } |
135 | |
143 | |
136 | $self->scr_bell unless $self->{found}; |
144 | $self->scr_bell; |
137 | } |
145 | } |
138 | |
146 | |
139 | sub refresh { |
147 | sub refresh { |
140 | my ($self) = @_; |
148 | my ($self) = @_; |
141 | |
149 | |
… | |
… | |
168 | $self->leave; |
176 | $self->leave; |
169 | } elsif ($keysym == 0xff57) { # end |
177 | } elsif ($keysym == 0xff57) { # end |
170 | $self->{row} = $self->nrow - 1; |
178 | $self->{row} = $self->nrow - 1; |
171 | $self->view_start (0); |
179 | $self->view_start (0); |
172 | } elsif ($keysym == 0xff52) { # up |
180 | } elsif ($keysym == 0xff52) { # up |
173 | $self->{row}-- if $self->{row} > $self->top_row; |
181 | my $line = $self->line ($self->{row}); |
174 | $self->search (-1); |
182 | $self->search (-1, $line->beg - 1) |
|
|
183 | if $line->beg > $self->top_row; |
175 | } elsif ($keysym == 0xff54) { # down |
184 | } elsif ($keysym == 0xff54) { # down |
176 | $self->{row}++ if $self->{row} < $self->nrow; |
185 | my $line = $self->line ($self->{row}); |
177 | $self->search (+1); |
186 | $self->search (+1, $line->end + 1) |
|
|
187 | if $line->end < $self->nrow; |
178 | } elsif ($keysym == 0xff08) { # backspace |
188 | } elsif ($keysym == 0xff08) { # backspace |
179 | substr $self->{search}, -1, 1, ""; |
189 | substr $self->{search}, -1, 1, ""; |
180 | $self->search; |
190 | $self->search (+1, $self->{row}); |
181 | $self->idle; |
191 | $self->idle; |
182 | } elsif ($string !~ /[\x00-\x1f\x80-\xaf]/) { |
192 | } elsif ($string !~ /[\x00-\x1f\x80-\xaf]/) { |
183 | return; # pass to tt_write |
193 | return; # pass to tt_write |
184 | } |
194 | } |
185 | |
195 | |
… | |
… | |
192 | $self->{search} .= $self->locale_decode ($data); |
202 | $self->{search} .= $self->locale_decode ($data); |
193 | |
203 | |
194 | $self->{search} =~ s/^\(\?i\)// |
204 | $self->{search} =~ s/^\(\?i\)// |
195 | if $self->{search} =~ /^\(.*[[:upper:]]/; |
205 | if $self->{search} =~ /^\(.*[[:upper:]]/; |
196 | |
206 | |
|
|
207 | delete $self->{found}; |
197 | $self->search (-1); |
208 | $self->search (-1, $self->{row}); |
198 | $self->idle; |
209 | $self->idle; |
199 | |
210 | |
200 | 1 |
211 | 1 |
201 | } |
212 | } |
202 | |
213 | |