| 1 |
root |
1.1 |
#! perl |
| 2 |
|
|
|
| 3 |
|
|
# same url as used in "selection" |
| 4 |
|
|
my $url = |
| 5 |
|
|
qr{( |
| 6 |
root |
1.12 |
(?: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 |
root |
1.8 |
$self->{browser} = $self->x_resource ("urlLauncher") || "x-www-browser"; |
| 14 |
root |
1.7 |
|
| 15 |
|
|
() |
| 16 |
root |
1.5 |
} |
| 17 |
|
|
|
| 18 |
root |
1.3 |
sub on_line_update { |
| 19 |
root |
1.4 |
my ($self, $row) = @_; |
| 20 |
root |
1.1 |
|
| 21 |
root |
1.3 |
# fetch the line that has changed |
| 22 |
root |
1.4 |
my $line = $self->line ($row); |
| 23 |
root |
1.3 |
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 |
root |
1.1 |
} |
| 36 |
|
|
|
| 37 |
root |
1.3 |
() |
| 38 |
root |
1.1 |
} |
| 39 |
|
|
|
| 40 |
root |
1.6 |
sub on_button_release { |
| 41 |
root |
1.5 |
my ($self, $event) = @_; |
| 42 |
|
|
|
| 43 |
root |
1.7 |
my $mask = $self->ModLevel3Mask | $self->ModMetaMask |
| 44 |
|
|
| urxvt::ShiftMask | urxvt::ControlMask; |
| 45 |
root |
1.5 |
|
| 46 |
root |
1.7 |
if ($event->{button} == 2 && ($event->{state} & $mask) == 0) { |
| 47 |
root |
1.10 |
my $row = $event->{row}; |
| 48 |
|
|
my $col = $event->{col}; |
| 49 |
|
|
|
| 50 |
|
|
my $line = $self->line ($row); |
| 51 |
|
|
my $text = $line->t; |
| 52 |
|
|
|
| 53 |
root |
1.6 |
while ($text =~ /$url/g) { |
| 54 |
root |
1.7 |
if ($-[1] <= $col && $+[1] >= $col) { |
| 55 |
root |
1.9 |
$self->exec_async ($self->{browser}, $1); |
| 56 |
root |
1.6 |
return 1; |
| 57 |
|
|
} |
| 58 |
|
|
} |
| 59 |
root |
1.5 |
} |
| 60 |
root |
1.6 |
|
| 61 |
root |
1.5 |
() |
| 62 |
|
|
} |
| 63 |
root |
1.4 |
|