ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/searchable-scrollback
(Generate patch)

Comparing rxvt-unicode/src/perl/searchable-scrollback (file contents):
Revision 1.33 by root, Sat May 17 15:25:04 2014 UTC vs.
Revision 1.42 by root, Fri Dec 26 18:58:19 2014 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines