]> ruderich.org/simon Gitweb - fcscs/fcscs.git/blobdiff - bin/fcscs
search mode: fix prompt drawing when aborting selection mode
[fcscs/fcscs.git] / bin / fcscs
index 50faa1adccef22af48defbfa9271a0f6c8760cbe..8194f9410c580991a4a8b08ab047ed1b1a44007a 100755 (executable)
--- a/bin/fcscs
+++ b/bin/fcscs
@@ -102,12 +102,15 @@ or another number to select the longer match. Use backspace to remove the last
 entered number.
 
 Press return before entering a number to select the last (lowest numbered)
-match. To abort without selecting any match either use "q".
+match (underlined by default). To abort without selecting any match use "q".
 
 To change the selection mode (e.g. paths, files, etc.) use one of the mappings
 explained below. Per default URLs are selected, see options for a way to
 change this.
 
+I<NOTE>: Opening URLs in the browser passes the URL via the command line which
+leaks URLs to other users on the current system via C<ps aux> or C<top>.
+
 I<NOTE>: When yanking (copying) a temporary file is used to pass the data to
 GNU screen/Tmux without exposing it to C<ps aux> or C<top>. However this may
 leak data if those temporary files are written to disk. To prevent this change
@@ -304,9 +307,13 @@ package Screen {
 
         my $attr_id     = $config->{attribute}{match_id};
         my $attr_string = $config->{attribute}{match_string};
+        my $attr_last   = $config->{attribute}{match_last};
 
         foreach (@{$matches_add}) {
-            $self->draw($_->{y}, $_->{x}, $attr_string, $_->{string});
+            my $attr = (defined $_->{id} and $_->{id} == 1)
+                     ? $attr_last
+                     : $attr_string;
+            $self->draw($_->{y}, $_->{x}, $attr, $_->{string});
             if (defined $_->{id}) {
                 $self->draw($_->{y}, $_->{x}, $attr_id, $_->{id});
             }
@@ -493,8 +500,8 @@ sub run_in_background {
         # closes the window (because the parent process has exited).
         local $SIG{HUP} = 'IGNORE';
 
-        # Necessary for GNU screen or it'll keep the window open until the
-        # paste command has run.
+        # Necessary for GNU screen or it'll keep the window open until an
+        # external command has run.
         close STDIN  or die $!;
         close STDOUT or die $!;
         close STDERR or die $!;
@@ -545,7 +552,8 @@ sub select_match {
             $number = $number * 10 + $char;
         } elsif ($char eq "\b" or $char eq "\x7f") { # backspace
             $number = int($number / 10);
-        } elsif ($char eq "\n") {
+        } elsif ($char eq "\n"
+                or $char eq $config->{setting}{alternative_return}) {
             if ($number == 0) { # number without selection matches last entry
                 $number = 1;
             }
@@ -608,6 +616,8 @@ sub extend_match {
 
     $screen->debug('extend_match', 'started');
 
+    return if not defined $match;
+
     $screen->prompt(name => 'extend', value => undef);
     $screen->draw_prompt($config);
 
@@ -621,8 +631,9 @@ sub extend_match {
         my $match_old = \%{$match};
 
         my $char = $screen->getch;
-        if ($char eq "\n") { # accept match
-            last;
+        if ($char eq "\n"
+                or $char eq $config->{setting}{alternative_return}) {
+            last; # accept match
 
         } elsif ($char eq 'w') { # select current word (both directions)
             extend_match_regex_left($line,  $match, qr/\w+/);
@@ -640,7 +651,7 @@ sub extend_match {
         } elsif ($char eq 'E') { # select current WORD (only right)
             extend_match_regex_right($line, $match, qr/\S+/);
 
-        } elsif ($char eq '^') { # select to beginning of line
+        } elsif ($char eq '0') { # select to beginning of line
             extend_match_regex_left($line, $match, qr/.+/);
         } elsif ($char eq '$') { # select to end of line
             extend_match_regex_right($line, $match, qr/.+/);
@@ -757,7 +768,7 @@ configurable at the moment):
 
 =item B<E> extend WORD to the right
 
-=item B<^> extend to beginning of line
+=item B<0> extend to beginning of line
 
 =item B<$> extend to end of line
 
@@ -819,6 +830,9 @@ sub mapping_mode_search {
 
     $screen->cursor(0);
 
+    $screen->prompt(name => undef, value => undef); # clear prompt
+    $screen->draw_prompt($config);
+
     return {
         select  => 'search',
         matches => \@last_matches,
@@ -1007,6 +1021,16 @@ The following simple mappings are available by default:
 
 =back
 
+The following additional mappings are available by default:
+
+=over
+
+=item B<\n> accept current selection (not customizable)
+
+=item B<s>  additional key to accept selection (B<alternative_return> option)
+
+=back
+
 All (single-byte) keys except numbers, backspace and return can be mapped.
 
 Unknown mappings are ignored when pressing keys.
@@ -1045,6 +1069,8 @@ Defaults in parentheses (foreground, background, attribute).
 
 =item B<match_string>  attribute for matches (yellow, default, normal)
 
+=item B<match_last>    attribute for the match selected by return (yellow, default, underline)
+
 =item B<prompt_name>   attribute for prompt name (standout)
 
 =item B<prompt_flags>  attribute for prompt flags (standout)
@@ -1063,6 +1089,8 @@ my %attribute = (
     match_id     => $screen->color_pair(Curses::COLOR_RED, -1)
                     | Curses::A_BOLD,
     match_string => $screen->color_pair(Curses::COLOR_YELLOW, -1),
+    match_last   => $screen->color_pair(Curses::COLOR_YELLOW, -1)
+                    | Curses::A_UNDERLINE,
     prompt_name  => Curses::A_STANDOUT,
     prompt_flags => Curses::A_STANDOUT,
 );
@@ -1073,21 +1101,23 @@ Defaults in parentheses.
 
 =over
 
-=item B<debug>          enable debug mode, writes to I<~/.config/fcscs/log> (C<0>)
+=item B<debug>              enable debug mode, writes to I<~/.config/fcscs/log> (C<0>)
+
+=item B<initial_mode>       start in this mode, must be a valid mode mapping (C<\&mapping_mode_url>)
 
-=item B<initial_mode>   start in this mode, must be a valid mode mapping (C<\&mapping_mode_url>)
+=item B<multiplexer>        set multiplexer ("screen" or "tmux") if not autodetected (C<undef>)
 
-=item B<multiplexer>    set multiplexer ("screen" or "tmux") if not autodetected (C<undef>)
+=item B<ignorecase>         ignore case when searching (C<0>)
 
-=item B<ignorecase>     ignore case when searching (C<0>)
+=item B<smartcase>          ignore case unless one uppercase character is searched (C<1>)
 
-=item B<smartcase>      ignore case unless one uppercase character is searched (C<1>)
+=item B<paste_sleep>        sleep x us before running paste command (C<100_000>)
 
-=item B<paste_sleep>    sleep x us before running paste command (C<100_000>)
+=item B<screen_msgwait>     GNU Screen's msgwait variable, used when yanking (C<5>)
 
-=item B<screen_msgwait> GNU Screen's msgwait variable, used when yanking (C<5>)
+=item B<alternative_return> additional accept key like return, set to C<\n> to disable (C<s>)
 
-=item B<browser>        browser command as array reference (C<['x-www-browser']>)
+=item B<browser>            browser command as array reference (C<['x-www-browser']>)
 
 =back
 
@@ -1099,15 +1129,17 @@ Example:
 =cut
 my %setting = (
     # options
-    debug          => 0,
-    initial_mode   => \&mapping_mode_url,
-    multiplexer    => undef,
-    ignorecase     => 0,
-    smartcase      => 1,
-    paste_sleep    => 100_000,
-    screen_msgwait => 5,
+    debug              => 0,
+    initial_mode       => \&mapping_mode_url,
+    multiplexer        => undef,
+    ignorecase         => 0,
+    smartcase          => 1,
+    paste_sleep        => 100_000,
+    screen_msgwait     => 5,
+    # global mappings
+    alternative_return => 's',
     # commands
-    browser        => ['x-www-browser'],
+    browser            => ['x-www-browser'],
 );
 
 =head2 REGEXPS
@@ -1373,8 +1405,8 @@ RESULT:
             $screen->debug('input', 'selecting match');
             my $tmp = $result;
             $result = select_match($result->{select},
-                                $screen, \%config, $input,
-                                $result->{matches});
+                                   $screen, \%config, $input,
+                                   $result->{matches});
             $result->{handler} = $tmp->{handler};
             $result->{extend}  = $tmp->{extend};
             goto RESULT; # reprocess special entries in result