ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/remote-clipboard
(Generate patch)

Comparing rxvt-unicode/src/perl/remote-clipboard (file contents):
Revision 1.2 by root, Wed Jan 25 15:33:43 2006 UTC vs.
Revision 1.13 by root, Sat May 17 13:38:23 2014 UTC

1#! perl 1#! perl
2
3#:META:RESOURCE:%.store:string:the command used to store the selection
4#:META:RESOURCE:%.fetch:string:the command used to fetch the selection
5
6=head1 NAME
7
8remote-clipboard - manage a shared and possibly remote clipboard
9
10=head1 DESCRIPTION
11
12Somewhat of a misnomer, this extension adds two menu entries to the
13selection popup that allows one to run external commands to store the
14selection somewhere and fetch it again.
15
16We use it to implement a "distributed selection mechanism", which just
17means that one command uploads the file to a remote server, and another
18reads it.
19
20The commands can be set using the C<URxvt.remote-selection.store> and
21C<URxvt.remote-selection.fetch> resources. The first should read the
22selection to store from STDIN (always in UTF-8), the second should provide
23the selection data on STDOUT (also in UTF-8).
24
25The defaults (which are likely useless to you) use rsh and cat:
26
27 URxvt.remote-selection.store: rsh ruth 'cat >/tmp/distributed-selection'
28 URxvt.remote-selection.fetch: rsh ruth 'cat /tmp/distributed-selection'
29
30=cut
2 31
3use Fcntl (); 32use Fcntl ();
4 33
5sub msg { 34sub msg {
6 my ($self, $msg) = @_; 35 my ($self, $msg) = @_;
38 if (my $pid = open my $fh, "|-:utf8", $self->{store_cmd}) { 67 if (my $pid = open my $fh, "|-:utf8", $self->{store_cmd}) {
39 fcntl $fh, &Fcntl::F_SETFL, &Fcntl::O_NONBLOCK; 68 fcntl $fh, &Fcntl::F_SETFL, &Fcntl::O_NONBLOCK;
40 $self->{iow} = urxvt::iow 69 $self->{iow} = urxvt::iow
41 ->new 70 ->new
42 ->fd (fileno $fh) 71 ->fd (fileno $fh)
43 ->events (urxvt::EVENT_WRITE) 72 ->events (urxvt::EV_WRITE)
44 ->start 73 ->start
45 ->cb (sub { 74 ->cb (sub {
46 if (my $len = syswrite $fh, $txt) { 75 if (my $len = syswrite $fh, $txt) {
47 substr $txt, 0, $len, ""; 76 substr $txt, 0, $len, "";
48 $self->msg ((length $txt) . " chars to go..."); 77 $self->msg ((length $txt) . " chars to go...");
63 if (my $pid = open my $fh, "-|:utf8", $self->{fetch_cmd}) { 92 if (my $pid = open my $fh, "-|:utf8", $self->{fetch_cmd}) {
64 fcntl $fh, &Fcntl::F_SETFL, &Fcntl::O_NONBLOCK; 93 fcntl $fh, &Fcntl::F_SETFL, &Fcntl::O_NONBLOCK;
65 $self->{iow} = urxvt::iow 94 $self->{iow} = urxvt::iow
66 ->new 95 ->new
67 ->fd (fileno $fh) 96 ->fd (fileno $fh)
68 ->events (urxvt::EVENT_READ) 97 ->events (urxvt::EV_READ)
69 ->start 98 ->start
70 ->cb (sub { 99 ->cb (sub {
71 if (my $len = sysread $fh, $txt, 8192, length $txt) { 100 if (my $len = sysread $fh, $txt, 8192, length $txt) {
72 $self->msg ((length $txt) . " chars read..."); 101 $self->msg ((length $txt) . " chars read...");
73 } else { 102 } else {
74 delete $self->{iow}; 103 delete $self->{iow};
75 $self->selection_clear; 104 $self->selection_clear;
76 $self->selection ($txt); 105 $self->selection ($txt);
77 $self->selection_grab (urxvt::CurrentTime); 106 $self->selection_grab (urxvt::CurrentTime);
78 close $fh;
79 my $status = $? >> 8;
80 $self->msg ("selection fetched (status $status)"); 107 $self->msg ("selection fetched");
81 } 108 }
82 }); 109 });
83 } 110 }
84} 111}
85 112
86sub on_start { 113sub on_start {
87 my ($self) = @_; 114 my ($self) = @_;
88 115
89 $self->{store_cmd} = $self->x_resource ("remote-selection.store") 116 $self->{store_cmd} = $self->x_resource ("%.store")
90 || "rsh ruth 'cat >/tmp/distributed-selection'"; 117 || "rsh ruth 'cat >/tmp/distributed-selection'";
91 118
92 $self->{fetch_cmd} = $self->x_resource ("remote-selection.fetch") 119 $self->{fetch_cmd} = $self->x_resource ("%.fetch")
93 || "rsh ruth 'cat /tmp/distributed-selection'"; 120 || "rsh ruth 'cat /tmp/distributed-selection'";
94 121
95 push @{ $self->{term}{selection_popup_hook} }, sub { 122 push @{ $self->{term}{selection_popup_hook} }, sub {
96 ("selection => remote" => sub { $self->store }) 123 ("selection => remote" => sub { $self->store })
97 }; 124 };
100 }; 127 };
101 128
102 () 129 ()
103} 130}
104 131
105sub on_user_command {
106 my ($self, $cmd) = @_;
107 132
108 if ($cmd eq "selection-pastebin:remote-pastebin") {
109 $self->upload_paste;
110 }
111
112 ()
113}
114

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines