ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/selection-popup
Revision: 1.5
Committed: Mon Jan 9 06:29:47 2006 UTC (18 years, 4 months ago) by root
Branch: MAIN
Changes since 1.4: +1 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #! perl
2    
3 root 1.4 sub msg {
4     my ($self, $msg1, $msg2) = @_;
5    
6     my $overlay = $self->overlay (0, 0,
7     (List::Util::max map $self->strwidth ($_), $msg1, $msg2), 2);
8     $overlay->set (0, 0, $msg1);
9     $overlay->set (0, 1, $msg2);
10     my $iow; $iow = urxvt::timer->new->start (urxvt::NOW + 1)->cb (sub {
11     undef $overlay;
12     undef $iow;
13     });
14     }
15    
16 root 1.1 sub on_start {
17     my ($self) = @_;
18    
19     $self->grab_button (3, urxvt::ControlMask);
20     }
21    
22     sub on_button_press {
23     my ($self, $event) = @_;
24    
25     if ($event->{button} == 3 && $event->{state} & urxvt::ControlMask) {
26     my $popup = $self->popup ($event)
27     or return 1;
28    
29     $popup->add_title ("Convert Selection");
30    
31     my $text = $self->selection;
32    
33     my $title = $text;
34     $title =~ s/[\x00-\x1f\x80-\x9f]/·/g;
35     substr $title, 40, -1, "..." if 40 < length $title;
36     $popup->add_title ($title);
37     $popup->add_separator;
38    
39     my $add_button = sub {
40     my ($title, $cb) = @_;
41    
42     $popup->add_button ($title => sub {
43     for ($text) {
44 root 1.4 my $orig = $_;
45 root 1.1 $cb->();
46 root 1.4
47     if ($orig ne $_) {
48     $self->selection ($_);
49 root 1.5 s/[\x00-\x1f\x80-\x9f]/·/g;
50 root 1.4 $self->msg ("Selection replaced by", $_);
51     }
52 root 1.1 }
53     });
54     };
55    
56     for ($text) {
57 root 1.2 $add_button->("rot13" => sub { y/A-Za-z/N-ZA-Mn-za-m/ });
58    
59 root 1.3 urxvt::safe
60     and $add_button->("eval perl expression" => sub { $_ = eval urxvt::untaint $_ });
61    
62 root 1.1 /^(\S+):(\d+):?$/
63     and $add_button->("vi-commands to load '$1'" => sub { s/^(\S+):(\d+):?$/\x1b:e $1\x0d:$2\x0d/ });
64 root 1.2
65 root 1.1 /%[0-9a-fA-F]{2}/ && !/%[^0-9a-fA-F]/ && !/%.[^0-9a-fA-F]/
66     and $add_button->("uri unescape" => sub { s/%([0-9a-fA-F]{2})/chr hex $1/ge });
67 root 1.2
68 root 1.4 /[\\"'\ \t|&;<>()]/
69     and $add_button->("shell quote" => sub { $_ = "\Q$_" });
70    
71 root 1.1 /^(http|ftp|telnet|irc|news):\//
72     and $add_button->("run x-www-browser" => sub { system "x-www-browser \Q$_\E &" });
73     }
74    
75     $popup->show;
76    
77     return 1;
78     }
79    
80     ()
81     }
82