… | |
… | |
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 |
… | |
… | |
36 | my ($self) = @_; |
36 | my ($self) = @_; |
37 | |
37 | |
38 | # only for backwards compatibility |
38 | # only for backwards compatibility |
39 | my $hotkey = $self->{argv}[0] |
39 | my $hotkey = $self->{argv}[0] |
40 | || $self->x_resource ("%") |
40 | || $self->x_resource ("%") |
41 | || "M-s"; |
41 | || return; |
42 | |
42 | |
43 | $self->bind_action ($hotkey, "searchable-scrollback:start") # ugh |
43 | $self->bind_action ($hotkey, "searchable-scrollback:start") # ugh |
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 | () |
… | |
… | |
91 | $self->disable ("key_press", "tt_write", "refresh_begin", "refresh_end"); |
91 | $self->disable ("key_press", "tt_write", "refresh_begin", "refresh_end"); |
92 | $self->pty_ev_events ($self->{pty_ev_events}); |
92 | $self->pty_ev_events ($self->{pty_ev_events}); |
93 | |
93 | |
94 | delete $self->{manpage_overlay}; |
94 | delete $self->{manpage_overlay}; |
95 | delete $self->{overlay}; |
95 | delete $self->{overlay}; |
96 | delete $self->{history}; |
|
|
97 | delete $self->{search}; |
96 | delete $self->{search}; |
98 | } |
97 | } |
99 | |
98 | |
100 | sub idle { |
99 | sub idle { |
101 | my ($self) = @_; |
100 | my ($self) = @_; |
102 | |
101 | |
103 | $self->msg ("(escape cancels) /$self->{search}█"); |
102 | $self->msg ("(escape cancels) /$self->{search}█"); |
104 | } |
103 | } |
105 | |
104 | |
106 | sub search { |
105 | sub search { |
107 | my ($self, $dir) = @_; |
106 | my ($self, $dir, $row) = @_; |
108 | |
107 | |
109 | delete $self->{found}; |
108 | delete $self->{found}; |
110 | my $row = $self->{row}; |
|
|
111 | |
109 | |
112 | my $search = $self->special_encode ($self->{search}); |
110 | my $search = $self->special_encode ($self->{search}); |
113 | |
111 | |
114 | no re 'eval'; # just to be sure |
112 | no re 'eval'; # just to be sure |
115 | if (my $re = eval { qr/$search/ }) { |
113 | if (my $re = eval { qr/$search/ }) { |
… | |
… | |
168 | $self->leave; |
166 | $self->leave; |
169 | } elsif ($keysym == 0xff57) { # end |
167 | } elsif ($keysym == 0xff57) { # end |
170 | $self->{row} = $self->nrow - 1; |
168 | $self->{row} = $self->nrow - 1; |
171 | $self->view_start (0); |
169 | $self->view_start (0); |
172 | } elsif ($keysym == 0xff52) { # up |
170 | } elsif ($keysym == 0xff52) { # up |
173 | $self->{row}-- if $self->{row} > $self->top_row; |
171 | my $line = $self->line ($self->{row}); |
174 | $self->search (-1); |
172 | $self->search (-1, $line->beg - 1) |
|
|
173 | if $line->beg > $self->top_row; |
175 | } elsif ($keysym == 0xff54) { # down |
174 | } elsif ($keysym == 0xff54) { # down |
176 | $self->{row}++ if $self->{row} < $self->nrow; |
175 | my $line = $self->line ($self->{row}); |
177 | $self->search (+1); |
176 | $self->search (+1, $line->end + 1) |
|
|
177 | if $line->end < $self->nrow; |
178 | } elsif ($keysym == 0xff08) { # backspace |
178 | } elsif ($keysym == 0xff08) { # backspace |
179 | substr $self->{search}, -1, 1, ""; |
179 | substr $self->{search}, -1, 1, ""; |
180 | $self->search; |
180 | $self->search (+1, $self->{row}); |
181 | $self->idle; |
181 | $self->idle; |
182 | } elsif ($string !~ /[\x00-\x1f\x80-\xaf]/) { |
182 | } elsif ($string !~ /[\x00-\x1f\x80-\xaf]/) { |
183 | return; # pass to tt_write |
183 | return; # pass to tt_write |
184 | } |
184 | } |
185 | |
185 | |
… | |
… | |
192 | $self->{search} .= $self->locale_decode ($data); |
192 | $self->{search} .= $self->locale_decode ($data); |
193 | |
193 | |
194 | $self->{search} =~ s/^\(\?i\)// |
194 | $self->{search} =~ s/^\(\?i\)// |
195 | if $self->{search} =~ /^\(.*[[:upper:]]/; |
195 | if $self->{search} =~ /^\(.*[[:upper:]]/; |
196 | |
196 | |
197 | $self->search (-1); |
197 | $self->search (-1, $self->{row}); |
198 | $self->idle; |
198 | $self->idle; |
199 | |
199 | |
200 | 1 |
200 | 1 |
201 | } |
201 | } |
202 | |
202 | |