clipboard: source refactored

This commit is contained in:
Bert 2010-08-03 00:39:34 +02:00
parent 33024bb68c
commit 211a5c8470

View File

@ -19,10 +19,10 @@ use strict;
use utf8; use utf8;
sub copy { sub copy {
my ($term) = @_; my ($self) = @_;
open(CLIPBOARD, "| xsel -ib"); open(CLIPBOARD, "| xsel -ib");
my $sel = $term->selection(); my $sel = $self->selection();
utf8::encode($sel); utf8::encode($sel);
print CLIPBOARD $sel; print CLIPBOARD $sel;
close(CLIPBOARD); close(CLIPBOARD);
@ -31,35 +31,35 @@ sub copy {
} }
sub paste { sub paste {
my ($term) = @_; my ($self) = @_;
my $str = `xsel -ob`; my $str = `xsel -ob`;
$str =~ tr/\n/\r/; $str =~ tr/\n/\r/;
$term->tt_write($str); $self->tt_write($str);
() ()
} }
sub paste_escaped { sub paste_escaped {
my ($term) = @_; my ($self) = @_;
my $str = `xsel -ob`; my $str = `xsel -ob`;
$str =~ tr/\n/\r/; $str =~ tr/\n/\r/;
$str =~ s/([!#\$%&\*\(\) ='"\\\|\[\]`~,<>\?])/\\\1/g; $str =~ s/([!#\$%&\*\(\) ='"\\\|\[\]`~,<>\?])/\\\1/g;
$term->tt_write($str); $self->tt_write($str);
() ()
} }
sub on_user_command { sub on_user_command {
my ($term, $cmd) = @_; my ($self, $cmd) = @_;
if ($cmd eq "clipboard:copy") { if ($cmd eq "clipboard:copy") {
$term->copy; $self->copy;
} elsif ($cmd eq "clipboard:paste") { } elsif ($cmd eq "clipboard:paste") {
$term->paste; $self->paste;
} elsif ($cmd eq "clipboard:paste_escaped") { } elsif ($cmd eq "clipboard:paste_escaped") {
$term->paste_escaped; $self->paste_escaped;
} }
() ()