summaryrefslogtreecommitdiffstats
path: root/pasteit
blob: f286342b6f29bd2288dfa220a32d3768c66e0f42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#! perl
# Original paste script modified for num of lines > 1 case

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//);

   if ($count == 1){
       chomp($str);
      $self->{paste} = \$str;
      $self->leave;
      return;
   }

   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
}