src/perl/block-graphics-to-ascii
src/perl/digital-clock
src/perl/option-popup
+src/perl/selection-popup
src/perl/urxvt-popup
src/perl/selection
src/perl/mark-urls
sub on_start {
my ($self) = @_;
- $self->grab_button (3, urxvt::ControlMask);
+ $self->grab_button (2, urxvt::ControlMask);
}
sub on_button_press {
my ($self, $event) = @_;
- if ($event->{button} == 3 && $event->{state} & urxvt::ControlMask) {
+ if ($event->{button} == 2 && $event->{state} & urxvt::ControlMask) {
my $popup = $self->popup ($event)
- or return;
+ or return 1;
$popup->add_title ("Options");
$popup->add_separator;
--- /dev/null
+#! perl
+
+sub on_start {
+ my ($self) = @_;
+
+ $self->grab_button (3, urxvt::ControlMask);
+}
+
+sub on_button_press {
+ my ($self, $event) = @_;
+
+ if ($event->{button} == 3 && $event->{state} & urxvt::ControlMask) {
+ my $popup = $self->popup ($event)
+ or return 1;
+
+ $popup->add_title ("Convert Selection");
+
+ my $text = $self->selection;
+
+ my $title = $text;
+ $title =~ s/[\x00-\x1f\x80-\x9f]/ยท/g;
+ substr $title, 40, -1, "..." if 40 < length $title;
+ $popup->add_title ($title);
+ $popup->add_separator;
+
+ my $add_button = sub {
+ my ($title, $cb) = @_;
+
+ $popup->add_button ($title => sub {
+ for ($text) {
+ $cb->();
+ $self->selection ($_);
+ }
+ });
+ };
+
+ for ($text) {
+ /^(\S+):(\d+):?$/
+ and $add_button->("vi-commands to load '$1'" => sub { s/^(\S+):(\d+):?$/\x1b:e $1\x0d:$2\x0d/ });
+ /%[0-9a-fA-F]{2}/ && !/%[^0-9a-fA-F]/ && !/%.[^0-9a-fA-F]/
+ and $add_button->("uri unescape" => sub { s/%([0-9a-fA-F]{2})/chr hex $1/ge });
+ /^(http|ftp|telnet|irc|news):\//
+ and $add_button->("run x-www-browser" => sub { system "x-www-browser \Q$_\E &" });
+ }
+
+ $popup->show;
+
+ return 1;
+ }
+
+ ()
+}
+
}
}
+static void
+ungrab (rxvt_term *THIS)
+{
+ if (THIS->perl.grabtime)
+ {
+ XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime);
+ XUngrabPointer (THIS->display->display, THIS->perl.grabtime);
+ THIS->perl.grabtime = 0;
+ }
+}
+
bool
rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
{
LEAVE;
if (SvTRUE (ERRSV))
- rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
+ {
+ rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
+ ungrab (term); // better lose the grab than the session
+ }
if (htype == HOOK_DESTROY)
{
CODE:
rxvt_fatal ("%s", msg);
+SV *
+untaint (SV *sv)
+ CODE:
+ RETVAL = newSVsv (sv);
+ SvTAINTED_off (RETVAL);
+ OUTPUT:
+ RETVAL
+
NV
NOW ()
CODE:
void
rxvt_term::ungrab ()
CODE:
-{
- if (THIS->perl.grabtime)
- {
- XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime);
- XUngrabPointer (THIS->display->display, THIS->perl.grabtime);
- THIS->perl.grabtime = 0;
- }
-}
+ ungrab (THIS);
int
rxvt_term::strwidth (SV *str)
PPCODE:
{
if (GIMME_V != G_VOID)
- XPUSHs (taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))));
+ XPUSHs (THIS->selection.text
+ ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))
+ : &PL_sv_undef);
if (newtext)
{
=item option-popup (enabled by default)
-Binds a popup menu to Ctrl-Button3 that lets you toggle (some) options at
+Binds a popup menu to Ctrl-Button2 that lets you toggle (some) options at
runtime.
+=item selection-popup (enabled by default)
+
+Binds a popup menu to Ctrl-Button3 that lets you convert the selection
+text into various other formats/action.
+
=item digital-clock
Displays a digital clock using the built-in overlay.
unless $msg =~ /\n$/;
urxvt::warn ($msg);
};
+
+ $ENV{PATH} = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/bin:/opt/sbin";
+ delete $ENV{CDPATH};
}
my @hook_count;
open my $fh, "<:raw", $path
or die "$path: $!";
- my $source = "package $pkg; use strict; use utf8;\n"
+ my $source = untaint "package $pkg; use strict; use utf8;\n"
. "use base urxvt::term::proxy::;\n"
. "#line 1 \"$path\"\n{\n"
. (do { local $/; <$fh> })
. "\n};\n1";
- $source =~ /(.*)/s and $source = $1; # untaint
-
eval $source or die "$path: $@";
$pkg
for (map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2) {
if ($_ eq "default") {
- $want_ext{$_}++ for qw(selection option-popup);
+ $want_ext{$_}++ for qw(selection option-popup selection-popup);
} elsif (/^-(.*)$/) {
delete $want_ext{$1};
} else {