repo: rxvt-unicode-sixel
action: commit
revision: 
path_from: 
revision_from: 0a48ab2f385225c7ff445b327ba07e3b49fee3eb:
path_to: 
revision_to: 
git.thebackupbox.net
rxvt-unicode-sixel
git clone git://git.thebackupbox.net/rxvt-unicode-sixel
commit 0a48ab2f385225c7ff445b327ba07e3b49fee3eb
Author: Emanuele Giaquinta 
Date:   Mon Jan 27 22:14:26 2014 +0000

    Add clipboard perl extension by Bert Münnich.

diff --git a/Changes b/Changes
index 39e8be3fed0658ac721b4371b281c5df9f4f2fde..
index ..2a93f14022bd7ae7e4d37547f60aca8ec2d18fe5 100644
--- a/Changes
+++ b/Changes
@@ -33,6 +33,7 @@ TODO IMPL: recalc bg only when not fully covering (no alpha, repeat|extend etc..
 TODO IMPL: colour-change event with index
 TODO IMPL: recalc bg always on bg colour change

+        - add clipboard perl extension by Bert Münnich.
         - (libptytty) fix bug that prevented urxvtd from writing utmp
           entries when using --fork (reported by Ryan Kavanagh).
 	- fix build when perl is enabled and fading is disabled.
diff --git a/MANIFEST b/MANIFEST
index feabd718b602ff5323a812400644a9d7fbc83408..
index ..f91a6052a069c5a97f803be0ca0f136b9de4d060 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -155,6 +155,7 @@ src/rxvtperl.xs
 src/perl/background
 src/perl/bell-command
 src/perl/block-graphics-to-ascii
+src/perl/clipboard
 src/perl/clipboard-osc
 src/perl/confirm-paste
 src/perl/digital-clock
diff --git a/src/perl/clipboard b/src/perl/clipboard
new file mode 100644
index 0000000000000000000000000000000000000000..2128789645f1f8b6d5f9750b153a88c900d29c37
--- /dev/null
+++ b/src/perl/clipboard
@@ -0,0 +1,109 @@
+#! perl -w
+# Author:   Bert Muennich
+# Website:  http://www.github.com/muennich/urxvt-perls
+# License:  GPLv2
+
+# Use keyboard shortcuts to copy the selection to the clipboard and to paste
+# the clipboard contents (optionally escaping all special characters).
+# Requires xsel to be installed!
+
+# Usage: put the following lines in your .Xdefaults/.Xresources:
+#   URxvt.perl-ext-common: ...,clipboard
+#   URxvt.keysym.M-c:   perl:clipboard:copy
+#   URxvt.keysym.M-v:   perl:clipboard:paste
+#   URxvt.keysym.M-C-v: perl:clipboard:paste_escaped
+
+# Options:
+#   URxvt.clipboard.autocopy: If true, PRIMARY overwrites clipboard
+
+# You can also overwrite the system commands to use for copying/pasting.
+# The default ones are:
+#   URxvt.clipboard.copycmd:  xsel -ib
+#   URxvt.clipboard.pastecmd: xsel -ob
+# If you prefer xclip, then put these lines in your .Xdefaults/.Xresources:
+#   URxvt.clipboard.copycmd:  xclip -i -selection clipboard
+#   URxvt.clipboard.pastecmd: xclip -o -selection clipboard
+# On Mac OS X, put these lines in your .Xdefaults/.Xresources:
+#   URxvt.clipboard.copycmd:  pbcopy
+#   URxvt.clipboard.pastecmd: pbpaste
+
+# The use of the functions should be self-explanatory!
+
+use strict;
+
+sub on_start {
+   my ($self) = @_;
+
+   $self->{copy_cmd} = $self->x_resource('clipboard.copycmd') || 'xsel -ib';
+   $self->{paste_cmd} = $self->x_resource('clipboard.pastecmd') || 'xsel -ob';
+
+   if ($self->x_resource('clipboard.autocopy') eq 'true') {
+      $self->enable(sel_grab => \&sel_grab);
+   }
+
+   ()
+}
+
+sub copy {
+   my ($self) = @_;
+
+   if (open(CLIPBOARD, "| $self->{copy_cmd}")) {
+      my $sel = $self->selection();
+      utf8::encode($sel);
+      print CLIPBOARD $sel;
+      close(CLIPBOARD);
+   } else {
+      print STDERR "error running '$self->{copy_cmd}': $!\n";
+   }
+
+   ()
+}
+
+sub paste {
+   my ($self) = @_;
+
+   my $str = `$self->{paste_cmd}`;
+   if ($? == 0) {
+      $self->tt_paste($str);
+   } else {
+      print STDERR "error running '$self->{paste_cmd}': $!\n";
+   }
+
+   ()
+}
+
+sub paste_escaped {
+   my ($self) = @_;
+
+   my $str = `$self->{paste_cmd}`;
+   if ($? == 0) {
+      $str =~ s/([!#\$%&\*\(\) ='"\\\|\[\]`~,<>\?])/\\\1/g;
+      $self->tt_paste($str);
+   } else {
+      print STDERR "error running '$self->{paste_cmd}': $!\n";
+   }
+
+   ()
+}
+
+sub on_user_command {
+   my ($self, $cmd) = @_;
+
+   if ($cmd eq "clipboard:copy") {
+      $self->copy;
+   } elsif ($cmd eq "clipboard:paste") {
+      $self->paste;
+   } elsif ($cmd eq "clipboard:paste_escaped") {
+      $self->paste_escaped;
+   }
+
+   ()
+}
+
+sub sel_grab {
+   my ($self) = @_;
+
+   $self->copy;
+
+   ()
+}

-----END OF PAGE-----