*** empty log message ***
authorroot <root>
Tue, 3 Jan 2006 20:47:36 +0000 (20:47 +0000)
committerroot <root>
Tue, 3 Jan 2006 20:47:36 +0000 (20:47 +0000)
src/perl/digital-clock
src/perl/selection
src/rxvtperl.xs
src/urxvt.pm

index ad48eb6..29a6c76 100644 (file)
@@ -5,13 +5,13 @@
 sub on_init {
    my ($self) = @_;
 
-   $self->{digital_clock_overlay} = $self->overlay (-1, 0, 8, 1, urxvt::OVERLAY_RSTYLE, 0);
-   $self->{digital_clock_timer} = urxvt::timer
+   $self->{overlay} = $self->overlay (-1, 0, 8, 1, urxvt::OVERLAY_RSTYLE, 0);
+   $self->{timer} = urxvt::timer
                     ->new
                     ->start (int urxvt::NOW) # make sure we update "on" the second
                     ->interval (1)
                     ->cb (sub {
-                       $self->{digital_clock_overlay}->set (0, 0,
+                       $self->{overlay}->set (0, 0,
                           sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2,1,0]);
                     });
 
index efde7a2..f05cd99 100644 (file)
@@ -9,8 +9,28 @@ sub on_keyboard_command {
    ()
 }
 
+my @patterns = (
+   # urls
+   qr{ ([a-z0-9.+\-]+://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),]+) }x,
+);
+
 sub on_sel_extend {
    my ($self) = @_;
-   warn $self->selection;
+
+   my ($row, $col) = $self->selection_mark;
+   my $line = $self->line ($row);
+   my $offset = $line->offset_of ($row, $col);
+   my $text = $line->t;
+
+   for my $regex (@patterns) {
+      while ($text =~ /$regex/g) {
+         if ($-[0] <= $offset and $offset <= $+[0]) {
+            $self->selection_beg ($line->coord_of ($-[0]));
+            $self->selection_end ($line->coord_of ($+[0]));
+            return 1;
+         }
+      }
+   }
+
    ()
 }
index f621c66..23ff21e 100644 (file)
@@ -706,7 +706,7 @@ rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0)
        PPCODE:
 {
         if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
-          croak ("row_number number of out range");
+          XSRETURN_EMPTY;
 
         line_t &l = ROW(row_number);
 
@@ -753,7 +753,7 @@ rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0)
        PPCODE:
 {
         if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
-          croak ("row_number number of out range");
+          XSRETURN_EMPTY;
 
         line_t &l = ROW(row_number);
 
@@ -793,10 +793,10 @@ rxvt_term::ROW_l (int row_number, int new_length = -2)
        CODE:
 {
         if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
-          croak ("row_number number of out range");
+          XSRETURN_EMPTY;
 
         line_t &l = ROW(row_number);
-        RETVAL = l.l;
+        RETVAL = l.l < 0 ? THIS->ncol : l.l;
 
         if (new_length >= -1)
           l.l = new_length;
@@ -804,6 +804,19 @@ rxvt_term::ROW_l (int row_number, int new_length = -2)
         OUTPUT:
         RETVAL
 
+bool
+rxvt_term::ROW_is_longer (int row_number)
+       CODE:
+{
+        if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
+          XSRETURN_EMPTY;
+
+        line_t &l = ROW(row_number);
+        RETVAL = l.l < 0;
+}
+        OUTPUT:
+        RETVAL
+
 SV *
 rxvt_term::special_encode (SV *str)
        CODE:
index c66f6c5..167c63e 100644 (file)
@@ -407,8 +407,8 @@ sub urxvt::term::proxy::AUTOLOAD {
 
    eval qq{
       sub $urxvt::term::proxy::AUTOLOAD {
-         unshift \@_, shift->{term};
-         goto &urxvt::term::$1;
+         my \$proxy = shift;
+         \$proxy->{term}->$1 (\@_)
       }
       1
    } or die "FATAL: unable to compile method forwarder: $@";
@@ -585,7 +585,8 @@ Used after changing terminal contents to display them.
 Returns the text of the entire row with number C<$row_number>. Row C<0>
 is the topmost terminal line, row C<< $term->$ncol-1 >> is the bottommost
 terminal line. The scrollback buffer starts at line C<-1> and extends to
-line C<< -$term->nsaved >>.
+line C<< -$term->nsaved >>. Nothing will be returned if a nonexistent line
+is requested.
 
 If C<$new_text> is specified, it will replace characters in the current
 line, starting at column C<$start_col> (default C<0>), which is useful
@@ -617,10 +618,113 @@ See the section on RENDITION, above.
 
 =item $length = $term->ROW_l ($row_number[, $new_length])
 
-Returns the number of screen cells that are in use ("the line length"). If
-it is C<-1>, then the line is part of a multiple-row logical "line", which
-means all characters are in use and it is continued on the next row.
+Returns the number of screen cells that are in use ("the line
+length"). Unlike the urxvt core, this returns C<< $term->ncol >> if the
+line is joined with the following one.
 
+=item $bool = $term->is_longer ($row_number)
+
+Returns true if the row is part of a multiple-row logical "line" (i.e.
+joined with the following row), which means all characters are in use
+and it is continued on the next row (and possibly a continuation of the
+previous row(s)).
+
+=item $line = $term->line ($row_number)
+
+Create and return a new C<urxvt::line> object that stores information
+about the logical line that row C<$row_number> is part of. It supports the
+following methods:
+
+=over 4
+
+=item $text = $line->t
+
+Returns the full text of the line, similar to C<ROW_t>
+
+=item $rend = $line->r
+
+Returns the full rendition array of the line, similar to C<ROW_r>
+
+=item $length = $line->l
+
+Returns the length of the line in cells, similar to C<ROW_l>.
+
+=item $rownum = $line->beg
+
+=item $rownum = $line->end
+
+Return the row number of the first/last row of the line, respectively.
+
+=item $offset = $line->offset_of ($row, $col)
+
+Returns the character offset of the given row|col pair within the logical
+line.
+
+=item ($row, $col) = $line->coord_of ($offset)
+
+Translates a string offset into terminal coordinates again.
+
+=back
+
+=cut
+
+sub urxvt::term::line {
+   my ($self, $row) = @_;
+
+   my $maxrow = $self->nrow - 1;
+
+   my ($beg, $end) = ($row, $row);
+
+   --$beg while $self->ROW_is_longer ($beg - 1);
+   ++$end while $self->ROW_is_longer ($end) && $end < $maxrow;
+
+   bless {
+      term => $self,
+      beg  => $beg,
+      end  => $end,
+      len  => ($end - $beg) * $self->ncol + $self->ROW_l ($end),
+   }, urxvt::line::
+}
+
+sub urxvt::line::t {
+   my ($self) = @_;
+
+   substr +(join "", map $self->{term}->ROW_t ($_), $self->{beg} .. $self->{end}),
+          0, $self->{len}
+}
+
+sub urxvt::line::r {
+   my ($self) = @_;
+
+   my $rend = [
+      map @{ $self->{term}->ROW_r ($_) }, $self->{beg} .. $self->{end}
+   ];
+   $#$rend = $self->{len} - 1;
+   $rend
+}
+
+sub urxvt::line::beg { $_[0]{beg} }
+sub urxvt::line::end { $_[0]{end} }
+sub urxvt::line::l   { $_[0]{len} }
+
+sub urxvt::line::offset_of {
+   my ($self, $row, $col) = @_;
+
+   ($row - $self->{beg}) * $self->{term}->ncol + $col
+}
+
+sub urxvt::line::coord_of {
+   my ($self, $offset) = @_;
+
+   use integer;
+
+   (
+      $offset / $self->{term}->ncol + $self->{beg},
+      $offset % $self->{term}->ncol
+   )
+}
+
+=item ($row, $col) = $line->coord_of ($offset)
 =item $text = $term->special_encode $string
 
 Converts a perl string into the special encoding used by rxvt-unicode,