clipboard: catch xsel errors

This commit is contained in:
Bert 2011-01-14 23:42:17 +01:00
parent d5a57b0266
commit cb889acf73

View File

@ -20,11 +20,14 @@ use strict;
sub copy { sub copy {
my ($self) = @_; my ($self) = @_;
open(CLIPBOARD, "| xsel -ib"); if (open(CLIPBOARD, "| xsel -ib")) {
my $sel = $self->selection(); my $sel = $self->selection();
utf8::encode($sel); utf8::encode($sel);
print CLIPBOARD $sel; print CLIPBOARD $sel;
close(CLIPBOARD); close(CLIPBOARD);
} else {
print STDERR "Error running xsel: $!\n";
}
() ()
} }
@ -33,8 +36,12 @@ sub paste {
my ($self) = @_; my ($self) = @_;
my $str = `xsel -ob`; my $str = `xsel -ob`;
if ($? == 0) {
$str =~ tr/\n/\r/; $str =~ tr/\n/\r/;
$self->tt_write($str); $self->tt_write($str);
} else {
print STDERR "Error running xsel: $!\n";
}
() ()
} }
@ -43,9 +50,13 @@ sub paste_escaped {
my ($self) = @_; my ($self) = @_;
my $str = `xsel -ob`; my $str = `xsel -ob`;
if ($? == 0) {
$str =~ tr/\n/\r/; $str =~ tr/\n/\r/;
$str =~ s/([!#\$%&\*\(\) ='"\\\|\[\]`~,<>\?])/\\\1/g; $str =~ s/([!#\$%&\*\(\) ='"\\\|\[\]`~,<>\?])/\\\1/g;
$self->tt_write($str); $self->tt_write($str);
} else {
print STDERR "Error running xsel: $!\n";
}
() ()
} }