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.31 by root, Sat May 17 13:34:43 2014 UTC vs.
Revision 1.38 by sf-exg, Sun Jun 8 19:40:20 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:X_RESOURCE:%:string:activation hotkey keysym 5#:META:RESOURCE:%:string:activation hotkey keysym
6#:META:KEYSYM:M-s:searchable-scrollback:start 6#:META:BINDING:M-s:start
7 7
8=head1 NAME 8=head1 NAME
9 9
10searchable-scrollback<hotkey> - incremental scrollback search (enabled by default) 10searchable-scrollback - incremental scrollback search (enabled by default)
11 11
12=head1 DESCRIPTION 12=head1 DESCRIPTION
13 13
14Adds regex search functionality to the scrollback buffer, triggered 14Adds regex search functionality to the scrollback buffer, triggered by
15by a hotkey (default: C<M-s>). While in search mode, normal terminal 15the C<searchable-scrollback:start> action (bound to C<M-s> by
16default). While in search mode, normal terminal input/output is
16input/output is suspended and a regex is displayed at the bottom of the 17suspended and a regex is displayed at the bottom of the screen.
17screen.
18 18
19Inputting characters appends them to the regex and continues incremental 19Inputting characters appends them to the regex and continues incremental
20search. C<BackSpace> removes a character from the regex, C<Up> and C<Down> 20search. 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 21search upwards/downwards in the scrollback buffer, C<End> jumps to the
22bottom. C<Escape> leaves search mode and returns to the point where search 22bottom. C<Escape> leaves search mode and returns to the point where search
33=cut 33=cut
34 34
35sub on_init { 35sub on_init {
36 my ($self) = @_; 36 my ($self) = @_;
37 37
38 # only for backwards compatibility
38 my $hotkey = $self->{argv}[0] 39 my $hotkey = $self->{argv}[0]
39 || $self->x_resource ("%") 40 || $self->x_resource ("%")
40 || "M-s"; 41 || return;
41 42
42 $self->parse_keysym ($hotkey, "perl:searchable-scrollback:start") 43 $self->bind_action ($hotkey, "searchable-scrollback:start") # ugh
43 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";
44 45
45 () 46 ()
46} 47}
47 48
48sub on_user_command { 49sub on_action {
49 my ($self, $cmd) = @_; 50 my ($self, $action) = @_;
50 51
51 $cmd eq "searchable-scrollback:start" 52 $action eq "start"
52 and $self->enter; 53 and $self->enter;
53 54
54 () 55 ()
55} 56}
56 57
90 $self->disable ("key_press", "tt_write", "refresh_begin", "refresh_end"); 91 $self->disable ("key_press", "tt_write", "refresh_begin", "refresh_end");
91 $self->pty_ev_events ($self->{pty_ev_events}); 92 $self->pty_ev_events ($self->{pty_ev_events});
92 93
93 delete $self->{manpage_overlay}; 94 delete $self->{manpage_overlay};
94 delete $self->{overlay}; 95 delete $self->{overlay};
95 delete $self->{history};
96 delete $self->{search}; 96 delete $self->{search};
97} 97}
98 98
99sub idle { 99sub idle {
100 my ($self) = @_; 100 my ($self) = @_;
101 101
102 $self->msg ("(escape cancels) /$self->{search}█"); 102 $self->msg ("(escape cancels) /$self->{search}█");
103} 103}
104 104
105sub search { 105sub search {
106 my ($self, $dir) = @_; 106 my ($self, $dir, $row) = @_;
107
108 delete $self->{found};
109 my $row = $self->{row};
110 107
111 my $search = $self->special_encode ($self->{search}); 108 my $search = $self->special_encode ($self->{search});
112 109
113 no re 'eval'; # just to be sure 110 no re 'eval'; # just to be sure
114 if (my $re = eval { qr/$search/ }) { 111 if (my $re = eval { qr/$search/ }) {
116 my $line = $self->line ($row) 113 my $line = $self->line ($row)
117 or last; 114 or last;
118 115
119 my $text = $line->t; 116 my $text = $line->t;
120 if ($text =~ /$re/g) { 117 if ($text =~ /$re/g) {
118 delete $self->{found};
119
121 do { 120 do {
122 push @{ $self->{found} }, [$line->coord_of ($-[0]), $line->coord_of ($+[0])]; 121 push @{ $self->{found} }, [$line->coord_of ($-[0]), $line->coord_of ($+[0])];
123 } while $text =~ /$re/g; 122 } while $text =~ /$re/g;
124 123
125 $self->{row} = $row; 124 $self->{row} = $row;
167 $self->leave; 166 $self->leave;
168 } elsif ($keysym == 0xff57) { # end 167 } elsif ($keysym == 0xff57) { # end
169 $self->{row} = $self->nrow - 1; 168 $self->{row} = $self->nrow - 1;
170 $self->view_start (0); 169 $self->view_start (0);
171 } elsif ($keysym == 0xff52) { # up 170 } elsif ($keysym == 0xff52) { # up
172 $self->{row}-- if $self->{row} > $self->top_row; 171 my $line = $self->line ($self->{row});
173 $self->search (-1); 172 $self->search (-1, $line->beg - 1)
173 if $line->beg > $self->top_row;
174 } elsif ($keysym == 0xff54) { # down 174 } elsif ($keysym == 0xff54) { # down
175 $self->{row}++ if $self->{row} < $self->nrow; 175 my $line = $self->line ($self->{row});
176 $self->search (+1); 176 $self->search (+1, $line->end + 1)
177 if $line->end < $self->nrow;
177 } elsif ($keysym == 0xff08) { # backspace 178 } elsif ($keysym == 0xff08) { # backspace
178 substr $self->{search}, -1, 1, ""; 179 substr $self->{search}, -1, 1, "";
179 $self->search; 180 $self->search (+1, $self->{row});
180 $self->idle; 181 $self->idle;
181 } elsif ($string !~ /[\x00-\x1f\x80-\xaf]/) { 182 } elsif ($string !~ /[\x00-\x1f\x80-\xaf]/) {
182 return; # pass to tt_write 183 return; # pass to tt_write
183 } 184 }
184 185
191 $self->{search} .= $self->locale_decode ($data); 192 $self->{search} .= $self->locale_decode ($data);
192 193
193 $self->{search} =~ s/^\(\?i\)// 194 $self->{search} =~ s/^\(\?i\)//
194 if $self->{search} =~ /^\(.*[[:upper:]]/; 195 if $self->{search} =~ /^\(.*[[:upper:]]/;
195 196
197 delete $self->{found};
196 $self->search (-1); 198 $self->search (-1, $self->{row});
197 $self->idle; 199 $self->idle;
198 200
199 1 201 1
200} 202}
201 203

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines