]> ruderich.org/simon Gitweb - fcscs/fcscs.git/blobdiff - bin/fcscs
expose debug to config API
[fcscs/fcscs.git] / bin / fcscs
index 675b7f2f2daf33265e6b8db32cfa67e729281607..8cffebd6ff049e78dbcc54f0ae2634e4747e89e0 100755 (executable)
--- a/bin/fcscs
+++ b/bin/fcscs
@@ -673,7 +673,7 @@ sub handler_yank {
     # Use a temporary file to prevent leaking the yanked data to other users
     # with the command line, e.g. ps aux or top.
     my ($fh, $tmp) = File::Temp::tempfile(); # dies on its own
-    print $fh $screen->encode($match->{string});
+    print $fh $screen->encode($match->{value});
     close $fh or die $!;
 
     if ($config->{setting}{multiplexer} eq 'screen') {
@@ -729,16 +729,12 @@ sub handler_paste {
 sub handler_url {
     my ($screen, $config, $match) = @_;
 
-    debug $config, 'handler_url', 'started';
+    debug $config, 'handler_url', "opening $match->{value}";
 
     run_in_background($config, sub {
-        my $url = defined $match->{url}
-                ? $match->{url}
-                : $match->{string};
-
         my @cmd = map { $screen->encode($_) } (
             @{$config->{setting}{browser}},
-            $url,
+            $match->{value},
         );
         run_command($config, \@cmd);
     });
@@ -990,10 +986,9 @@ Example:
     $config{handler}{url} = sub {
         my ($screen, $config, $match) = @_;
 
-        my $url = defined $match->{url} ? $match->{url} : $match->{string};
-        if ($url =~ m{^https://www.youtube.com/}) {
+        if ($match->{value} =~ m{^https://www.youtube.com/}) {
             return run_in_background($config, sub {
-                run_command($config, ['youtube-dl-wrapper', $url]);
+                run_command($config, ['youtube-dl-wrapper', $match->{value}]);
             });
         }
         handler_url(@_);
@@ -1039,6 +1034,7 @@ Used as mappings, see L</MAPPINGS> above.
 
 Used as handler to yank, paste selection or open URL in browser.
 
+    debug()
     get_regex_matches()
     select_match()
     run_command()
@@ -1071,6 +1067,8 @@ package Fcscs {
     sub handler_paste { return main::handler_paste(@_); }
     sub handler_url { return main::handler_url(@_); }
 
+    sub debug { return main::debug(@_); }
+
     sub get_regex_matches { return main::get_regex_matches(@_); }
     sub select_match { return main::select_match(@_); }
 
@@ -1211,11 +1209,25 @@ RESULT:
             goto RESULT; # reprocess special entries in result
         }
         if (defined $result->{match}) {
+            if (not defined $result->{match}->{value}) {
+                $result->{match}->{value} = $result->{match}->{string};
+            }
+
             debug \%config, 'input', 'running handler';
-            my $handler = $config{state}{handler};                 # set by user
-            $handler = $result->{handler} unless defined $handler; # set by mapping
-            $handler = $config{handler}{yank} unless defined $handler; # fallback
-            $handler->($screen, \%config, $result->{match});
+
+            # Choose handler with falling priority.
+            my @handlers = (
+                $config{state}{handler},     # set by user
+                $result->{match}->{handler}, # set by match
+                $result->{handler},          # set by mapping
+                $config{handler}{yank},      # fallback
+            );
+            foreach my $handler (@handlers) {
+                next unless defined $handler;
+
+                $handler->($screen, \%config, $result->{match});
+                last;
+            }
             last;
         }