--- rxvt-unicode/src/perl/mark-urls 2006/01/05 01:07:31 1.2 +++ rxvt-unicode/src/perl/mark-urls 2006/01/11 02:13:56 1.5 @@ -4,26 +4,51 @@ my $url = qr{( (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+ - [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27(),~] # do not include a trailing dot, its wrong too often + [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27()~] # exclude some trailing characters (heuristic) )}x; -sub on_add_lines { - my ($term, $str) = @_; +sub on_start { + my ($self) = @_; - while ($str =~ $url) { - # found a url, first output preceding text - $term->scr_add_lines (substr $str, 0, $-[1], ""); - # then toggle underline - $term->rstyle ($term->rstyle ^ urxvt::RS_Uline); - # now output the url - $term->scr_add_lines (substr $str, 0, $+[1] - $-[1], ""); - # toggle undelrine again - $term->rstyle ($term->rstyle ^ urxvt::RS_Uline); + $self->{browser} = urxvt::untaint $self->x_resource ("urlLauncher") || "x-www-browser"; +} + +sub on_line_update { + my ($self, $row) = @_; + + # fetch the line that has changed + my $line = $self->line ($row); + my $text = $line->t; + + # find all urls (if any) + while ($text =~ /$url/g) { + my $rend = $line->r; + + # mark all characters as underlined. we _must_ not toggle underline, + # as we might get called on an already-marked url. + $_ |= urxvt::RS_Uline + for @{$rend}[ $-[1] .. $+[1] - 1]; + + $line->r ($rend); } - # output trailing text - $term->scr_add_lines ($str); + () +} + +sub on_button_press { + my ($self, $event) = @_; + my $row = $event->{row}; + my $col = $event->{col}; + + my $line = $self->line ($row); + my $text = $line->t; - 1 + while($text =~ /$url/g) { + if ($-[0] <= $col && $+[0] >= $col) { + system "$self->{browser} \Q$1\E &"; + return 1; + } + } + () }