ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/confirm-paste
Revision: 1.7
Committed: Tue Sep 4 22:41:11 2012 UTC (11 years, 8 months ago) by root
Branch: MAIN
CVS Tags: rxvt-unicode-rel-9_16, rxvt-unicode-rel-9_19, rxvt-unicode-rel-9_18, rxvt-unicode-rel-9_17, rxvt-unicode-rel-9_22, rxvt-unicode-rel-9_20, rxvt-unicode-rel-9_21
Changes since 1.6: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #! perl
2
3 =head1 NAME
4
5 confirm-paste - ask for confirmation before pasting multiline text
6
7 =head1 DESCRIPTION
8
9 Displays a confirmation dialog when a paste containing at least a full
10 line is detected.
11
12 =cut
13
14 sub msg {
15 my ($self, $msg) = @_;
16
17 $self->{overlay} = $self->overlay (0, -1, $self->ncol, 2, urxvt::OVERLAY_RSTYLE, 0);
18 $self->{overlay}->set (0, 0, $msg);
19 }
20
21 sub on_tt_paste {
22 my ($self, $str) = @_;
23
24 my $count = ($str =~ tr/\012\015//);
25
26 return unless $count;
27
28 $self->{paste} = \$str;
29 $self->msg ("Paste of $count lines, continue? (y/n)");
30 my $preview = substr $self->locale_decode ($str), 0, $self->ncol;
31 $preview =~ s/\n/\\n/g;
32 $self->{overlay}->set (0, 1, $self->special_encode ($preview));
33 $self->enable (key_press => \&key_press);
34
35 1
36 }
37
38 sub leave {
39 my ($self) = @_;
40
41 $self->{paste} = undef;
42 delete $self->{overlay};
43 $self->disable ("key_press");
44 }
45
46 sub key_press {
47 my ($self, $event, $keysym, $string) = @_;
48
49 if ($keysym == 121) { # y
50 $self->tt_paste (${$self->{paste}});
51 $self->leave;
52 } elsif ($keysym == 110) { # n
53 $self->leave;
54 }
55
56 1
57 }