diff options
author | root <root> | 2012-09-04 22:41:11 +0000 |
---|---|---|
committer | root <root> | 2012-09-04 22:41:11 +0000 |
commit | d50a22a63f36f3d4fb5bd2f4d7d0f89f36d84e8f (patch) | |
tree | 64566414b54ff274345437c2b02a4f1e73b80e72 /src/perl/confirm-paste | |
parent | 5ee396e7ac453f939e8ec74546756dba45906827 (diff) |
*** empty log message ***
Diffstat (limited to 'src/perl/confirm-paste')
-rw-r--r-- | src/perl/confirm-paste | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/perl/confirm-paste b/src/perl/confirm-paste new file mode 100644 index 0000000..4b45238 --- /dev/null +++ b/src/perl/confirm-paste @@ -0,0 +1,57 @@ +#! perl + +=head1 NAME + +confirm-paste - ask for confirmation before pasting multiline text + +=head1 DESCRIPTION + +Displays a confirmation dialog when a paste containing at least a full +line is detected. + +=cut + +sub msg { + my ($self, $msg) = @_; + + $self->{overlay} = $self->overlay (0, -1, $self->ncol, 2, urxvt::OVERLAY_RSTYLE, 0); + $self->{overlay}->set (0, 0, $msg); +} + +sub on_tt_paste { + my ($self, $str) = @_; + + my $count = ($str =~ tr/\012\015//); + + return unless $count; + + $self->{paste} = \$str; + $self->msg ("Paste of $count lines, continue? (y/n)"); + my $preview = substr $self->locale_decode ($str), 0, $self->ncol; + $preview =~ s/\n/\\n/g; + $self->{overlay}->set (0, 1, $self->special_encode ($preview)); + $self->enable (key_press => \&key_press); + + 1 +} + +sub leave { + my ($self) = @_; + + $self->{paste} = undef; + delete $self->{overlay}; + $self->disable ("key_press"); +} + +sub key_press { + my ($self, $event, $keysym, $string) = @_; + + if ($keysym == 121) { # y + $self->tt_paste (${$self->{paste}}); + $self->leave; + } elsif ($keysym == 110) { # n + $self->leave; + } + + 1 +} |