From f63af26b8176121254831c7806f8f695ed5ed7fe Mon Sep 17 00:00:00 2001 From: Bert Date: Fri, 20 Aug 2010 16:58:37 +0200 Subject: [PATCH] nicer status area, fixed [fF;,] in keyboard-select --- keyboard-select | 44 +++++++++++++++++++++++--------------------- url-select | 6 +++--- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/keyboard-select b/keyboard-select index 9c3bdd0..e3ecc47 100644 --- a/keyboard-select +++ b/keyboard-select @@ -12,7 +12,7 @@ # Use Meta-Escape to activate selection mode, then use the following keys: # h/j/k/l: Move cursor left/down/up/right (also with arrow keys) -# g/G/0/^/$/H/M/L: More vi-like cursor movement keys +# g/G/0/^/$/H/M/L/f/F/;/,: More vi-like cursor movement keys # Ctrl-f/b: Scroll down/up one screen # Ctrl-d/u: Scroll down/up half a screen # v/V/Ctrl-v: Toggle normal/linewise/blockwise selection @@ -36,14 +36,19 @@ sub on_user_command { sub key_press { - my ($self, $event, $keysym) = @_; + my ($self, $event, $keysym, $char) = @_; my $key = chr($keysym); - if ($self->{move_to} && $key !~ m/[\x00-\x1f\x80-\xaf]/ && - length($key) > 0) { - $self->{move_char} = $key; - move_to($self, $self->{move_to}); - $self->{move_to} = 0; + if ($self->{move_to}) { + if ($keysym == 0xff1b) { + $self->{move_to} = 0; + status_area($self); + } elsif (length($char) > 0) { + $self->{move_char} = $key; + $self->{move_to} = 0; + move_to($self, $self->{move_dir}); + status_area($self); + } return 1; } @@ -92,9 +97,11 @@ sub key_press { ('fbdu' =~ m/\Q$key\E/ && $event->{state} & urxvt::ControlMask)) { move_cursor($self, $key); } elsif (lc($key) eq 'f') { - $self->{move_to} = $key eq 'F' ? -1 : 1; - } elsif ($key eq ';' || $key eq ',') { - move_to($self, $key eq ',' ? -1 : 1) if $self->{move_char}; + $self->{move_to} = 1; + $self->{move_dir} = $key eq 'F' ? -1 : 1; + status_area($self, $key); + } elsif (($key eq ';' || $key eq ',') && $self->{move_char}) { + move_to($self, $self->{move_dir} * ($key eq ',' ? -1 : 1)); } return 1; @@ -177,8 +184,6 @@ sub move_to { my $line = $self->line($cr); my $found = 0; - print "move_to: " . $self->{move_char} . " (" . ord($self->locale_decode($self->{move_char})) . ")\n"; - if ($dir > 0 && $self->{offset} < $line->l - 1) { my $text = substr($line->t, $self->{offset} + 1); if ($text =~ m/\Q$self->{move_char}\E/) { @@ -304,17 +309,13 @@ sub deactivate { sub status_area { - my ($self) = @_; + my ($self, $extra) = @_; my ($stat, $stat_len); if ($self->{select}) { - $stat = "V"; - if ($self->{select} ne 'n') { - $stat .= uc($self->{select}); - } - $stat .= " -- "; + $stat = "-V" . ($self->{select} ne 'n' ? uc($self->{select}) : "") . "- "; } - + if ($self->top_row == 0) { $stat .= "All"; } elsif ($self->view_start() == $self->top_row) { @@ -326,7 +327,8 @@ sub status_area { ($self->top_row - $self->view_start) * 100 / $self->top_row); } - $stat_len = length($stat); + $stat = "$extra $stat" if $extra; + $stat_len = length($stat) + 2; if (!$self->{overlay} || $self->{overlay_len} != $stat_len) { delete $self->{overlay} if $self->{overlay}; @@ -335,7 +337,7 @@ sub status_area { $self->{overlay_len} = $stat_len; } - $self->{overlay}->set(0, 0, $self->special_encode($stat)); + $self->{overlay}->set(1, 0, $self->special_encode($stat)); $self->{overlay}->show(); () diff --git a/url-select b/url-select index 4742641..e85bd22 100644 --- a/url-select +++ b/url-select @@ -2,7 +2,7 @@ # Author: Bert Muennich # Website: http://www.github.com/muennich/urxvt-perls # Based on: http://www.jukie.net/~bart/blog/urxvt-url-yank -# Version: 1.3 +# Version: git-20100820 # License: GPLv2 # Use keyboard shortcuts to select URLs. @@ -239,7 +239,7 @@ sub status_area { ($self->top_row - $self->view_start) * 100 / $self->top_row); } - my $text_len = length($text); + my $text_len = length($text) + 2; if ($self->{overlay_len} != $text_len) { delete $self->{overlay} if $self->{overlay}; @@ -248,7 +248,7 @@ sub status_area { $self->{overlay_len} = $text_len; } - $self->{overlay}->set(0, 0, $self->special_encode($text)); + $self->{overlay}->set(1, 0, $self->special_encode($text)); $self->{overlay}->show(); ()