ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/confirm-paste
Revision: 1.8
Committed: Thu Feb 6 23:41:15 2020 UTC (4 years, 3 months ago) by root
Branch: MAIN
CVS Tags: rxvt-unicode-rel-9_26, rxvt-unicode-rel-9_25
Changes since 1.7: +3 -2 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/[\x00-\x1f\x80-\x9f]//);
25
26 return unless $count;
27
28 $self->{paste} = \$str;
29 $self->msg ("Pasting $count control characters, continue? (y/n)");
30 my $preview = substr $self->locale_decode ($str), 0, $self->ncol;
31 $preview =~ s/\n/\\n/g;
32 $preview =~ s/([\x00-\x1f\x80-\x9f])/sprintf "\\x%02x", ord $1/ge;
33 $self->{overlay}->set (0, 1, $self->special_encode ($preview));
34 $self->enable (key_press => \&key_press);
35
36 1
37 }
38
39 sub leave {
40 my ($self) = @_;
41
42 $self->{paste} = undef;
43 delete $self->{overlay};
44 $self->disable ("key_press");
45 }
46
47 sub key_press {
48 my ($self, $event, $keysym, $string) = @_;
49
50 if ($keysym == 121) { # y
51 $self->tt_paste (${$self->{paste}});
52 $self->leave;
53 } elsif ($keysym == 110) { # n
54 $self->leave;
55 }
56
57 1
58 }