1 | #! perl |
1 | #! perl |
|
|
2 | |
|
|
3 | 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 | } |
2 | |
15 | |
3 | sub on_start { |
16 | sub on_start { |
4 | my ($self) = @_; |
17 | my ($self) = @_; |
5 | |
18 | |
6 | $self->grab_button (3, urxvt::ControlMask); |
19 | $self->grab_button (3, urxvt::ControlMask); |
… | |
… | |
26 | my $add_button = sub { |
39 | my $add_button = sub { |
27 | my ($title, $cb) = @_; |
40 | my ($title, $cb) = @_; |
28 | |
41 | |
29 | $popup->add_button ($title => sub { |
42 | $popup->add_button ($title => sub { |
30 | for ($text) { |
43 | for ($text) { |
|
|
44 | my $orig = $_; |
31 | $cb->(); |
45 | $cb->(); |
|
|
46 | |
|
|
47 | if ($orig ne $_) { |
32 | $self->selection ($_); |
48 | $self->selection ($_); |
|
|
49 | $self->msg ("Selection replaced by", $_); |
|
|
50 | } |
33 | } |
51 | } |
34 | }); |
52 | }); |
35 | }; |
53 | }; |
36 | |
54 | |
37 | for ($text) { |
55 | for ($text) { |
38 | $add_button->("rot13" => sub { y/A-Za-z/N-ZA-Mn-za-m/ }); |
56 | $add_button->("rot13" => sub { y/A-Za-z/N-ZA-Mn-za-m/ }); |
39 | |
57 | |
|
|
58 | urxvt::safe |
|
|
59 | and $add_button->("eval perl expression" => sub { $_ = eval urxvt::untaint $_ }); |
|
|
60 | |
40 | /^(\S+):(\d+):?$/ |
61 | /^(\S+):(\d+):?$/ |
41 | and $add_button->("vi-commands to load '$1'" => sub { s/^(\S+):(\d+):?$/\x1b:e $1\x0d:$2\x0d/ }); |
62 | and $add_button->("vi-commands to load '$1'" => sub { s/^(\S+):(\d+):?$/\x1b:e $1\x0d:$2\x0d/ }); |
42 | |
63 | |
43 | /%[0-9a-fA-F]{2}/ && !/%[^0-9a-fA-F]/ && !/%.[^0-9a-fA-F]/ |
64 | /%[0-9a-fA-F]{2}/ && !/%[^0-9a-fA-F]/ && !/%.[^0-9a-fA-F]/ |
44 | and $add_button->("uri unescape" => sub { s/%([0-9a-fA-F]{2})/chr hex $1/ge }); |
65 | and $add_button->("uri unescape" => sub { s/%([0-9a-fA-F]{2})/chr hex $1/ge }); |
|
|
66 | |
|
|
67 | /[\\"'\ \t|&;<>()]/ |
|
|
68 | and $add_button->("shell quote" => sub { $_ = "\Q$_" }); |
45 | |
69 | |
46 | /^(http|ftp|telnet|irc|news):\// |
70 | /^(http|ftp|telnet|irc|news):\// |
47 | and $add_button->("run x-www-browser" => sub { system "x-www-browser \Q$_\E &" }); |
71 | and $add_button->("run x-www-browser" => sub { system "x-www-browser \Q$_\E &" }); |
48 | } |
72 | } |
49 | |
73 | |