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

Comparing rxvt-unicode/src/perl/matcher (file contents):
Revision 1.16 by sf-exg, Wed May 28 17:01:32 2014 UTC vs.
Revision 1.19 by sf-exg, Sat Jun 7 20:07:38 2014 UTC

60 }x; 60 }x;
61 61
62sub on_key_press { 62sub on_key_press {
63 my ($self, $event, $keysym, $octets) = @_; 63 my ($self, $event, $keysym, $octets) = @_;
64 64
65 if (! $self->{showing} ) { 65 return unless $self->{overlay};
66 return; 66
67 } 67 delete $self->{overlay};
68 68
69 my $i = ($keysym == 96 ? 0 : $keysym - 48); 69 my $i = ($keysym == 96 ? 0 : $keysym - 48);
70 if (($i > scalar(@{$self->{urls}})) || ($i < 0)) { 70 if ($i >= 0 && $i < @{ $self->{matches} }) {
71 $self->matchlist(); 71 my @exec = @{ $self->{matches}[$i] };
72 return; 72 shift @exec;
73 $self->exec_async (@exec);
74 }
75
73 } 76 1
74
75 my @args = ($self->{urls}[ -$i-1 ]);
76 $self->matchlist();
77
78 $self->exec_async( $self->{launcher}, @args );
79} 77}
80 78
81# backwards compat 79# backwards compat
82sub on_user_command { 80sub on_user_command {
83 my ($self, $cmd) = @_; 81 my ($self, $cmd) = @_;
96 () 94 ()
97} 95}
98 96
99sub matchlist { 97sub matchlist {
100 my ($self) = @_; 98 my ($self) = @_;
101 if ( $self->{showing} ) { 99
102 $self->{url_overlay}->hide;
103 $self->{showing} = 0;
104 return;
105 }
106 @{$self->{urls}} = (); 100 @{ $self->{matches} } = ();
107 my $line; 101 my $row = $self->nrow - 1;
108 for (my $i = 0; $i < $self->nrow; $i ++) { 102 while ($row >= 0 && @{ $self->{matches} } < 10) {
109 $line = $self->line($i); 103 my $line = $self->line ($row);
110 next if ($line->beg != $i); 104 my $text = $line->t;
111 for my $url ($self->get_urls_from_line($line->t)) { 105
112 if (scalar(@{$self->{urls}}) == 10) { 106 # FIXME: code duplicated from 'command_for'
113 shift @{$self->{urls}}; 107 my @matches;
108 for my $matcher (@{$self->{matchers}}) {
109 my $launcher = $matcher->[1] || $self->{launcher};
110 while ($text =~ /$matcher->[0]/g) {
111 my $match = substr ($text, $-[0], $+[0] - $-[0]);
112 my @beg = @-;
113 my @end = @+;
114 my @exec;
115
116 if ($launcher !~ /\$/) {
117 @exec = ($launcher, $match);
118 } else {
119 @exec = map { s/\$(\d+)|\$\{(\d+)\}/
120 substr ($text, $beg[$1 || $2], $end[$1 || $2] - $beg[$1 || $2])
121 /egx; $_ } split /\s+/, $launcher;
114 } 122 }
115 push @{$self->{urls}}, $url; 123
124 push @matches, [ $beg[0], $match, @exec ];
125 }
116 } 126 }
117 }
118 127
119 if (! scalar(@{$self->{urls}})) { 128 for (sort { $b->[0] <=> $a->[0] } @matches) {
120 return; 129 shift @$_;
121 } 130 push @{ $self->{matches} }, $_;
122 131 last if @{ $self->{matches} } == 10;
123 my $max = 0;
124 my $i = scalar( @{$self->{urls}} ) - 1 ;;
125
126 my @temp = ();
127
128 for my $url (@{$self->{urls}}) {
129 my $url = "$i-$url";
130 my $xpos = 0;
131
132 if ($self->ncol + (length $url) >= $self->ncol) {
133 $url = substr( $url, 0, $self->ncol );
134 } 132 }
135 133
136 push @temp, $url; 134 $row = $line->beg - 1;
137
138 if( length $url > $max ) {
139 $max = length $url;
140 }
141
142 $i--;
143 } 135 }
144 136
145 @temp = reverse @temp; 137 return unless @{ $self->{matches} };
146 138
147 $self->{url_overlay} = $self->overlay(0, 0, $max, scalar( @temp ), urxvt::OVERLAY_RSTYLE, 2); 139 my $width = 0;
140
148 my $i = 0; 141 my $i = 0;
149 for my $url (@temp) { 142 for my $match (@{ $self->{matches} }) {
150 $self->{url_overlay}->set( 0, $i, $url, [(urxvt::OVERLAY_RSTYLE) x length $url]); 143 my $text = $match->[0];
151 $self->{showing} = 1; 144 my $w = $self->strwidth ("$i-$text");
145
146 $width = $w if $w > $width;
152 $i++; 147 $i++;
153 } 148 }
149
150 $width = $self->ncol - 2 if $width > $self->ncol - 2;
151
152 $self->{overlay} = $self->overlay (0, 0, $width, scalar (@{ $self->{matches} }), urxvt::OVERLAY_RSTYLE, 2);
153 my $i = 0;
154 for my $match (@{ $self->{matches} }) {
155 my $text = $match->[0];
156
157 $self->{overlay}->set (0, $i, "$i-$text");
158 $i++;
159 }
154 160
155} 161}
156 162
157sub most_recent { 163sub most_recent {
158 my ($self) = shift; 164 my ($self) = shift;
190sub on_start { 196sub on_start {
191 my ($self) = @_; 197 my ($self) = @_;
192 198
193 $self->{launcher} = $self->my_resource ("launcher") || $self->x_resource("url-launcher") || "sensible-browser"; 199 $self->{launcher} = $self->my_resource ("launcher") || $self->x_resource("url-launcher") || "sensible-browser";
194 200
195 $self->{urls} = []; 201 $self->{matches} = [];
196 $self->{showing} = 0;
197 $self->{button} = 2; 202 $self->{button} = 2;
198 $self->{state} = 0; 203 $self->{state} = 0;
199 if($self->{argv}[0] || $self->my_resource ("button")) { 204 if($self->{argv}[0] || $self->my_resource ("button")) {
200 my @mods = split '', $self->{argv}[0] || $self->my_resource ("button"); 205 my @mods = split '', $self->{argv}[0] || $self->my_resource ("button");
201 for my $mod (@mods) { 206 for my $mod (@mods) {
224 unshift @matchers, [qr($res)x,$launcher,$rend]; 229 unshift @matchers, [qr($res)x,$launcher,$rend];
225 } 230 }
226 $self->{matchers} = \@matchers; 231 $self->{matchers} = \@matchers;
227 232
228 () 233 ()
229}
230
231sub get_urls_from_line {
232 my ($self, $line) = @_;
233 my @urls;
234 for my $matcher (@{$self->{matchers}}) {
235 while ($line =~ /$matcher->[0]/g) {
236 push @urls, substr( $line, $-[0], $+[0] - $-[0] );
237 }
238 }
239 return @urls;
240} 234}
241 235
242sub on_line_update { 236sub on_line_update {
243 my ($self, $row) = @_; 237 my ($self, $row) = @_;
244 238
330 324
331 if($row == $event->{row} && abs($col-$event->{col}) < 2 325 if($row == $event->{row} && abs($col-$event->{col}) < 2
332 && join("\x00", @$cmd) eq join("\x00", $self->command_for($row,$col))) { 326 && join("\x00", @$cmd) eq join("\x00", $self->command_for($row,$col))) {
333 if($self->valid_button($event)) { 327 if($self->valid_button($event)) {
334 328
335 $self->exec_async (@$cmd); 329 $self->exec_async (@$cmd);
336 330
337 } 331 }
338 } 332 }
339 333
340 1; 334 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines