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

Comparing rxvt-unicode/src/perl/selection (file contents):
Revision 1.29 by root, Tue Jan 17 16:22:41 2006 UTC vs.
Revision 1.30 by elmex, Tue Jan 17 16:53:47 2006 UTC

1#! perl 1#! perl
2use Digest::MD5 qw/md5_hex/;
3
4my $timers = {};
5my $pastebin_cmd;
6my $pastebin_url;
7
8sub on_start {
9 my ($self) = @_;
10 $pastebin_cmd = $self->x_resource ("selection-pastebin-cmd")
11 or "scp -p % ruth:/var/www/www.ta-sa.org/files/txt/";
12
13 $pastebin_url = $self->x_resource ("selection-pastebin-url")
14 or "http://www.ta-sa.org/files/txt/";
15 ();
16}
17
18sub upload_paste {
19 my ($self) = @_;
20
21 my $txt = $self->selection;
22 my $filename = md5_hex ($txt) . ".txt";
23
24 my $tmpfile = "/tmp/$filename";
25
26 my $msg = "uploaded $filename";
27
28 if (open my $o, ">" . $tmpfile) {
29 print $o $txt;
30 close $o;
31 } else {
32 $msg = "couldn't write $tmpfile: $!";
33 }
34
35 my $cmd = $pastebin_cmd;
36 $cmd =~ s/%/$tmpfile/;
37
38 if (system ($cmd) == 0) {
39
40 my $url = $pastebin_url;
41 $url =~ s/%/$filename/;
42
43 $self->selection ($url);
44 } else {
45 $msg = "couldn't upload, '$cmd' failed";
46 }
47
48 my $ov = $timers->{ov} = $self->overlay (-1, 0, length ($msg), 1, urxvt::OVERLAY_RSTYLE, 0);
49 $ov->set (0, 0, $msg);
50
51 $timers->{t1} =
52 urxvt::timer
53 ->new
54 ->start ((int urxvt::NOW) + 5) # make sure we update "on" the second
55 ->interval (1)
56 ->cb (sub { delete $timers->{ov}; delete $timers->{t1}; });
57}
58 2
59sub on_keyboard_command { 3sub on_keyboard_command {
60 my ($self, $cmd) = @_; 4 my ($self, $cmd) = @_;
61 5
62 $cmd eq "selection:rot13" 6 $cmd eq "selection:rot13"
63 and $self->selection (map { y/A-Za-z/N-ZA-Mn-za-m/; $_ } $self->selection); 7 and $self->selection (map { y/A-Za-z/N-ZA-Mn-za-m/; $_ } $self->selection);
64
65 $cmd eq "selection:remote-pastebin"
66 and upload_paste ($self);
67 8
68 () 9 ()
69} 10}
70 11
71sub on_init { 12sub on_init {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines