From 50d9193da2d1258f742d27b9e3b529ad610c48c3 Mon Sep 17 00:00:00 2001 From: Sterling Camden Date: Sat, 3 Sep 2011 18:47:03 -0700 Subject: Added support for reversing the order of numbered labels, so that the last link is always "1". Enable by setting resource "URxvt.url-picker.order" to "descending". --- README | 5 +++++ url-picker | 24 +++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/README b/README index 42e589a..230a443 100644 --- a/README +++ b/README @@ -58,6 +58,10 @@ anything. Enter launches the URL associated with the number that has been typed, if that number matches one of the URL labels. Otherwise, nothing happens. +The labels are numbered in ascending order starting with 1 by default. You can +cause them to be numbered in reverse order (so that the last link is always +number 1) by setting the resource "URxvt.url-picker.order" to "descending". + When typing numbers, if the number typed so far uniquely identifies a URL, that URL is launched immediately. Otherwise, the labels that do not match the numbers typed so far will be hidden. @@ -79,6 +83,7 @@ URxvt.url-picker.input.foregroundColor Fg color for numbers typed URxvt.url-picker.label.backgroundColor Bg color for numbered labels URxvt.url-picker.label.foregroundColor Fg color for numbered labels URxvt.url-picker.launcher Browser override +URXVT.url-picker.order "descending" numbers in reverse URxvt.url-picker.prompt.backgroundColor Bg color for "Follow:" prompt URxvt.url-picker.prompt.foregroundColor Fg color for "Follow:" prompt URxvt.url-picker.status.backgroundColor Bg color for status messages diff --git a/url-picker b/url-picker index 0dc4e65..577e83c 100644 --- a/url-picker +++ b/url-picker @@ -26,6 +26,7 @@ sub on_user_command { my $text = ''; my $label_rend = $self->get_rend("label", urxvt::OVERLAY_RSTYLE); my $label_urls = sub { + my @overlays; while ($text =~ /$url/g) { my $ndx = $-[0]; my $href = $&; @@ -39,15 +40,19 @@ sub on_user_command { last; } } - if ($row >= 0) { # must be visible - $num++; - my $overlay = $self->overlay( - $col, $row, $self->strwidth($num), 1, $label_rend, 0 - ); - $overlay->set(0,0,$num); - $labels->{$num} = $overlay; - $hrefs->{$num} = $href; - } + my @ov = ($col, $row, $href); + push(@overlays, \@ov) if ($row >= 0); + } + @overlays = reverse @overlays if ($self->{descending}); + for my $ov (@overlays) { + my ($col, $row, $href) = @$ov; + $num++; + my $overlay = $self->overlay( + $col, $row, $self->strwidth($num), 1, $label_rend, 0 + ); + $overlay->set(0,0,$num); + $labels->{$num} = $overlay; + $hrefs->{$num} = $href; } }; my ($brow, $bcol) = $self->selection_beg(); @@ -200,6 +205,7 @@ sub on_start { $self->{launcher} = $self->my_resource("launcher") || $self->x_resource("urlLauncher") || "sensible-browser"; + $self->{descending} = ($self->my_resource("order") eq "descending"); $self->{url_picker} = (); } -- cgit v1.2.3