ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/mark-urls
Revision: 1.6
Committed: Thu Jan 12 01:30:53 2006 UTC (18 years, 4 months ago) by root
Branch: MAIN
Changes since 1.5: +9 -6 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #! perl
2    
3     # same url as used in "selection"
4     my $url =
5     qr{(
6 root 1.2 (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+
7 root 1.4 [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27()~] # exclude some trailing characters (heuristic)
8 root 1.1 )}x;
9    
10 root 1.5 sub on_start {
11     my ($self) = @_;
12    
13     $self->{browser} = urxvt::untaint $self->x_resource ("urlLauncher") || "x-www-browser";
14     }
15    
16 root 1.3 sub on_line_update {
17 root 1.4 my ($self, $row) = @_;
18 root 1.1
19 root 1.3 # fetch the line that has changed
20 root 1.4 my $line = $self->line ($row);
21 root 1.3 my $text = $line->t;
22    
23     # find all urls (if any)
24     while ($text =~ /$url/g) {
25     my $rend = $line->r;
26    
27     # mark all characters as underlined. we _must_ not toggle underline,
28     # as we might get called on an already-marked url.
29     $_ |= urxvt::RS_Uline
30     for @{$rend}[ $-[1] .. $+[1] - 1];
31    
32     $line->r ($rend);
33 root 1.1 }
34    
35 root 1.3 ()
36 root 1.1 }
37    
38 root 1.6 sub on_button_release {
39 root 1.5 my ($self, $event) = @_;
40     my $row = $event->{row};
41     my $col = $event->{col};
42    
43     my $line = $self->line ($row);
44     my $text = $line->t;
45    
46 root 1.6 if ($event->{button} == 2) {
47     while ($text =~ /$url/g) {
48     if ($-[0] <= $col && $+[0] >= $col) {
49     system "$self->{browser} \Q$1\E &";
50     return 1;
51     }
52     }
53 root 1.5 }
54 root 1.6
55 root 1.5 ()
56     }
57 root 1.4