1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | # same url as used in "selection" |
3 | # same url as used in "selection" |
4 | my $url = |
4 | my $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(),~] # do not include a trailing dot, its wrong too often |
8 | )}x; |
8 | )}x; |
9 | |
9 | |
10 | sub on_add_lines { |
10 | sub on_line_update { |
11 | my ($term, $str) = @_; |
11 | my ($term, $row) = @_; |
12 | |
12 | |
|
|
13 | # fetch the line that has changed |
|
|
14 | my $line = $term->line ($row); |
|
|
15 | my $text = $line->t; |
|
|
16 | |
|
|
17 | # find all urls (if any) |
13 | while ($str =~ $url) { |
18 | while ($text =~ /$url/g) { |
14 | # found a url, first output preceding text |
19 | my $rend = $line->r; |
15 | $term->scr_add_lines (substr $str, 0, $-[1], ""); |
20 | |
16 | # then toggle underline |
21 | # mark all characters as underlined. we _must_ not toggle underline, |
17 | $term->rstyle ($term->rstyle ^ urxvt::RS_Uline); |
22 | # as we might get called on an already-marked url. |
18 | # now output the url |
23 | $_ |= urxvt::RS_Uline |
19 | $term->scr_add_lines (substr $str, 0, $+[1] - $-[1], ""); |
24 | for @{$rend}[ $-[1] .. $+[1] - 1]; |
20 | # toggle undelrine again |
25 | |
21 | $term->rstyle ($term->rstyle ^ urxvt::RS_Uline); |
26 | $line->r ($rend); |
22 | } |
27 | } |
23 | |
28 | |
24 | # output trailing text |
29 | () |
25 | $term->scr_add_lines ($str); |
|
|
26 | |
|
|
27 | 1 |
|
|
28 | } |
30 | } |
29 | |
31 | |