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

Comparing rxvt-unicode/src/perl/mark-urls (file contents):
Revision 1.1 by root, Thu Jan 5 01:04:10 2006 UTC vs.
Revision 1.11 by root, Sat May 20 18:17:38 2006 UTC

1#! perl 1#! perl
2 2
3# same url as used in "selection" 3# same url as used in "selection"
4my $url = 4my $url =
5 qr{( 5 qr{(
6 (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),]+ 6 (?:https?://|ftp://|news://|mailto:|file://)[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+
7 [^.] # do not include a trailing dot, its wrong too often 7 [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27()~] # exclude some trailing characters (heuristic)
8 )}x; 8 )}x;
9 9
10sub on_add_lines { 10sub on_start {
11 my ($term, $str) = @_; 11 my ($self) = @_;
12 12
13 $self->{browser} = $self->x_resource ("urlLauncher") || "x-www-browser";
14
15 ()
16}
17
18sub on_line_update {
19 my ($self, $row) = @_;
20
21 # fetch the line that has changed
22 my $line = $self->line ($row);
23 my $text = $line->t;
24
25 # find all urls (if any)
13 while ($str =~ $url) { 26 while ($text =~ /$url/g) {
14 # found a url, first output preceding text 27 my $rend = $line->r;
15 $term->scr_add_lines (substr $str, 0, $-[1], ""); 28
16 # then toggle underline 29 # mark all characters as underlined. we _must_ not toggle underline,
17 $term->rstyle ($term->rstyle ^ urxvt::RS_Uline); 30 # as we might get called on an already-marked url.
18 # now output the url 31 $_ |= urxvt::RS_Uline
19 $term->scr_add_lines (substr $str, 0, $+[1] - $-[1], ""); 32 for @{$rend}[ $-[1] .. $+[1] - 1];
20 # toggle undelrine again 33
21 $term->rstyle ($term->rstyle ^ urxvt::RS_Uline); 34 $line->r ($rend);
22 } 35 }
23 36
24 # output trailing text 37 ()
25 $term->scr_add_lines ($str);
26
27 1
28} 38}
29 39
40sub on_button_release {
41 my ($self, $event) = @_;
42
43 my $mask = $self->ModLevel3Mask | $self->ModMetaMask
44 | urxvt::ShiftMask | urxvt::ControlMask;
45
46 if ($event->{button} == 2 && ($event->{state} & $mask) == 0) {
47 my $row = $event->{row};
48 my $col = $event->{col};
49
50 my $line = $self->line ($row);
51 my $text = $line->t;
52
53 while ($text =~ /$url/g) {
54 if ($-[1] <= $col && $+[1] >= $col) {
55 $self->exec_async ($self->{browser}, $1);
56 return 1;
57 }
58 }
59 }
60
61 ()
62}
63

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines