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.12 by root, Wed Jan 11 02:13:56 2006 UTC vs.
Revision 1.13 by root, Thu Jan 12 05:22:47 2006 UTC

34sub enter { 34sub enter {
35 my ($self) = @_; 35 my ($self) = @_;
36 36
37 return if $self->{overlay}; 37 return if $self->{overlay};
38 38
39 $self->{history} = [];
40 $self->{view_start} = $self->view_start; 39 $self->{view_start} = $self->view_start;
41 $self->{pty_ev_events} = $self->pty_ev_events (urxvt::EVENT_NONE); 40 $self->{pty_ev_events} = $self->pty_ev_events (urxvt::EVENT_NONE);
41 $self->{row} = $self->nrow - 1;
42 42
43 $self->enable ( 43 $self->enable (
44 key_press => \&key_press, 44 key_press => \&key_press,
45 tt_write => \&tt_write, 45 tt_write => \&tt_write,
46 refresh_begin => \&refresh, 46 refresh_begin => \&refresh,
60 $self->pty_ev_events ($self->{pty_ev_events}); 60 $self->pty_ev_events ($self->{pty_ev_events});
61 61
62 delete $self->{manpage_overlay}; 62 delete $self->{manpage_overlay};
63 delete $self->{overlay}; 63 delete $self->{overlay};
64 delete $self->{history}; 64 delete $self->{history};
65 delete $self->{search};
65} 66}
66 67
67sub idle { 68sub idle {
68 my ($self) = @_; 69 my ($self) = @_;
69 70
70 $self->msg ("escape=exit, enter=accept, /=start search, n=next, p=previous, G=bottom"); 71 $self->msg ("(escape cancels) /$self->{search}█");
71
72 delete $self->{in_search};
73} 72}
74 73
75sub search { 74sub search {
76 my ($self, $offset) = @_; 75 my ($self, $dir) = @_;
77
78 my $row = -$self->view_start + ($self->nrow >> 1) + $offset;
79 76
80 delete $self->{found}; 77 delete $self->{found};
78 my $row = $self->{row};
81 79
82 my $search = $self->special_encode ($self->{search}); 80 my $search = $self->special_encode ($self->{search});
83 81
84 no re 'eval'; # just to be sure 82 no re 'eval'; # just to be sure
85 my $re = qr/$search/; 83 my $re = qr/$search/;
86 84
87 while ($row > -$self->nsaved) { 85 while ($self->nrow > $row && $row > -$self->nsaved) {
88 my $line = $self->line ($row) 86 my $line = $self->line ($row)
89 or last; 87 or last;
90 88
91 my $text = $line->t; 89 my $text = $line->t;
92 if ($text =~ /$re/g) { 90 if ($text =~ /$re/g) {
93 do { 91 do {
94 push @{ $self->{found} }, [$line->coord_of ($-[0]), $line->coord_of ($+[0])]; 92 push @{ $self->{found} }, [$line->coord_of ($-[0]), $line->coord_of ($+[0])];
95 } while $text =~ /$re/g; 93 } while $text =~ /$re/g;
96 94
95 $self->{row} = $row;
97 $self->view_start (-$row + ($self->nrow >> 1)); 96 $self->view_start (-$row + ($self->nrow >> 1));
97 $self->want_refresh;
98 last; 98 last;
99 } 99 }
100 100
101 $row = $line->beg - 1; 101 $row = $dir < 0 ? $line->beg - 1 : $line->end + 1;
102 } 102 }
103 103
104 $self->msg ("enter/type/backspace: /$self->{search}_"
105 . ($self->{found} ? "" : " (not found)"));
106 $self->scr_bell unless $self->{found}; 104 $self->scr_bell unless $self->{found};
107} 105}
108 106
109sub refresh { 107sub refresh {
110 my ($self) = @_; 108 my ($self) = @_;
111 109
112 return unless $self->{found}; 110 my $xor = urxvt::RS_RVid | urxvt::RS_Uline;
113
114 $self->scr_xor_span (@$_, urxvt::SET_FGCOLOR (urxvt::RS_RVid, 15))
115 for @{ $self->{found} }; 111 for (@{ $self->{found} }) {
112 $self->scr_xor_span (@$_, $xor);
113 $xor = urxvt::RS_RVid;
114 }
116 115
117 () 116 ()
118} 117}
119 118
120sub key_press { 119sub key_press {
121 my ($self, $event, $keysym, $string) = @_; 120 my ($self, $event, $keysym, $string) = @_;
122 121
123 if (exists $self->{in_search}) { 122 delete $self->{manpage_overlay};
123
124 if ($keysym == 0xff0d || $keysym == 0xff8d) { 124 if ($keysym == 0xff0d || $keysym == 0xff8d) {
125 if ($self->{found}) {
126 my ($br, $bc, $er, $ec) = @{ $self->{found}[0] };
127 $self->selection_beg ($br, $bc);
128 $self->selection_end ($er, $ec);
129 $self->selection_make ($event->{time});
130 }
131 $self->leave;
132 } elsif ($keysym == 0xff1b) {
133 $self->view_start ($self->{view_start});
134 $self->leave;
135 } elsif ($keysym == 0xff57) {
136 $self->{row} = $self->nrow - 1;
137 $self->view_start (0);
138 } elsif ($keysym == 0xff52) {
139 $self->{row}-- if $self->{row} > -$self->nsaved;
140 $self->search (-1);
141 } elsif ($keysym == 0xff54) {
142 $self->{row}++ if $self->{row} < $self->nrow;
143 $self->search (+1);
144 } elsif ($string eq "n") {
145 if ($self->{found} && @{ $self->{found} }) {
146 push @{ $self->{history} }, [$self->view_start, $self->{found}];
147 $self->search (-1);
125 $self->idle; 148 $self->idle;
126 } elsif ($keysym == 0xff1b) {
127 $self->view_start ($self->{in_search});
128 $self->idle;
129 } elsif ($keysym == 0xff08) {
130 substr $self->{search}, -1, 1, "";
131 $self->search;
132 } elsif ($string ne "") {
133 return;
134 } 149 }
135
136 } else {
137 if ($keysym == 0xff0d || $keysym == 0xff8d) {
138 # TODO: set selection
139 $self->leave;
140 } elsif ($keysym == 0xff1b) {
141 $self->view_start ($self->{view_start});
142 $self->leave;
143 } elsif ($keysym == 0xff52) {
144 $self->view_start ($self->view_start + 1);
145 } elsif ($keysym == 0xff54) {
146 $self->view_start ($self->view_start - 1);
147 } elsif ($string eq "/") {
148 delete $self->{manpage_overlay};
149 $self->{in_search} = $self->view_start;
150 $self->search;
151 } elsif ($string eq "G") {
152 $self->{history} = [];
153 $self->view_start (0);
154 } elsif ($string eq "n") {
155 if ($self->{found} && @{ $self->{found} }) {
156 push @{ $self->{history} }, [$self->view_start, $self->{found}];
157 $self->search (-1);
158 $self->idle;
159 }
160 } elsif ($string eq "p" or $string eq "N") { 150 } elsif ($string eq "p" or $string eq "N") {
161 if (my $prev = pop @{ $self->{history} }) { 151 if (my $prev = pop @{ $self->{history} }) {
162 $self->view_start ($prev->[0]); 152 $self->view_start ($prev->[0]);
163 $self->{found} = $prev->[1]; 153 $self->{found} = $prev->[1];
164 $self->want_refresh; 154 $self->want_refresh;
165 }
166 } elsif ($string ne "") {
167 $self->scr_bell;
168 } 155 }
156 } elsif ($keysym == 0xff08) {
157 substr $self->{search}, -1, 1, "";
158 $self->search;
159 $self->idle;
160 } elsif ($string =~ /^[^\x00-\x1f\x80-\xaf]+$/) {
161 return; # pass to tt_write
169 } 162 }
170 163
171 1 164 1
172} 165}
173 166
174sub tt_write { 167sub tt_write {
175 my ($self, $data) = @_; 168 my ($self, $data) = @_;
176 169
177 $self->{search} .= $self->locale_decode ($data); 170 $self->{search} .= $self->locale_decode ($data);
178 $self->search; 171 $self->search (-1);
172 $self->idle;
179 173
180 1 174 1
181} 175}
182 176
183 177

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines