ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/mark-urls
Revision: 1.8
Committed: Tue Jan 17 16:22:41 2006 UTC (18 years, 4 months ago) by root
Branch: MAIN
Changes since 1.7: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #! perl
2
3 # same url as used in "selection"
4 my $url =
5 qr{(
6 (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+
7 [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27()~] # exclude some trailing characters (heuristic)
8 )}x;
9
10 sub on_start {
11 my ($self) = @_;
12
13 $self->{browser} = $self->x_resource ("urlLauncher") || "x-www-browser";
14
15 ()
16 }
17
18 sub 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)
26 while ($text =~ /$url/g) {
27 my $rend = $line->r;
28
29 # mark all characters as underlined. we _must_ not toggle underline,
30 # as we might get called on an already-marked url.
31 $_ |= urxvt::RS_Uline
32 for @{$rend}[ $-[1] .. $+[1] - 1];
33
34 $line->r ($rend);
35 }
36
37 ()
38 }
39
40 sub on_button_release {
41 my ($self, $event) = @_;
42 my $row = $event->{row};
43 my $col = $event->{col};
44
45 my $line = $self->line ($row);
46 my $text = $line->t;
47
48 my $mask = $self->ModLevel3Mask | $self->ModMetaMask
49 | urxvt::ShiftMask | urxvt::ControlMask;
50
51 if ($event->{button} == 2 && ($event->{state} & $mask) == 0) {
52 while ($text =~ /$url/g) {
53 if ($-[1] <= $col && $+[1] >= $col) {
54 urxvt::exec_async $self->{browser}, $1;
55 return 1;
56 }
57 }
58 }
59
60 ()
61 }
62