--- rxvt-unicode/src/urxvt.pm 2006/01/08 00:07:18 1.49 +++ rxvt-unicode/src/urxvt.pm 2006/01/08 05:50:27 1.55 @@ -39,7 +39,7 @@ =over 4 -=item selection +=item selection (enabled by default) Intelligent selection. This extension tries to be more intelligent when the user extends selections (double-click). Right now, it tries to select @@ -58,6 +58,11 @@ =back +=item option-popup (enabled by default) + +Binds a popup menu to Ctrl-Button3 that lets you toggle (some) options at +runtime. + =item digital-clock Displays a digital clock using the built-in overlay. @@ -339,7 +344,7 @@ Mod3Mask, Mod4Mask, Mod5Mask, Button1Mask, Button2Mask, Button3Mask, Button4Mask, Button5Mask, AnyModifier -Various constants for use in X events. +Various constants for use in X calls and event processing. =back @@ -404,6 +409,7 @@ use Scalar::Util (); use List::Util (); +our $VERSION = 1; our $TERM; our @HOOKNAME; our %OPTION; @@ -483,22 +489,30 @@ if ($htype == 0) { # INIT my @dirs = ((split /:/, $TERM->resource ("perl_lib")), "$LIBDIR/perl"); - my @ext = (map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2); + my %want_ext; - while (@ext) { - my $ext = shift @ext; - if ($ext eq "default") { - unshift @ext, qw(selection); + for (map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2) { + if ($_ eq "default") { + $want_ext{$_}++ for qw(selection option-popup); + } elsif (/^-(.*)$/) { + delete $want_ext{$1}; } else { - my @files = grep -f $_, map "$_/$ext", @dirs; + $want_ext{$_}++; + } + } - if (@files) { - register_package extension_package $files[0]; - } else { - warn "perl extension '$ext' not found in perl library search path\n"; - } + for my $ext (keys %want_ext) { + my @files = grep -f $_, map "$_/$ext", @dirs; + + if (@files) { + register_package extension_package $files[0]; + } else { + warn "perl extension '$ext' not found in perl library search path\n"; } } + + eval "#line 1 \"--perl-eval resource/argument\"\n" . $TERM->resource ("perl_eval"); + warn $@ if $@; } $retval = undef; @@ -543,6 +557,8 @@ $retval } +# urxvt::term::proxy + sub urxvt::term::proxy::AUTOLOAD { $urxvt::term::proxy::AUTOLOAD =~ /:([^:]+)$/ or die "FATAL: \$AUTOLOAD '$urxvt::term::proxy::AUTOLOAD' unparsable"; @@ -558,6 +574,8 @@ goto &$urxvt::term::proxy::AUTOLOAD; } +# urxvt::destroy_hook + sub urxvt::destroy_hook::DESTROY { ${$_[0]}->(); } @@ -566,6 +584,68 @@ bless \shift, urxvt::destroy_hook:: } +# urxvt::anyevent + +package urxvt::anyevent; + +our $VERSION = 1; + +$INC{"urxvt/anyevent.pm"} = 1; # mark us as there +push @AnyEvent::REGISTRY, [urxvt => urxvt::anyevent::]; + +sub timer { + my ($class, %arg) = @_; + + my $cb = $arg{cb}; + + urxvt::timer + ->new + ->start (urxvt::NOW + $arg{after}) + ->cb (sub { + $_[0]->stop; # need to cancel manually + $cb->(); + }) +} + +sub io { + my ($class, %arg) = @_; + + my $cb = $arg{cb}; + + bless [$arg{fh}, urxvt::iow + ->new + ->fd (fileno $arg{fh}) + ->events (($arg{poll} =~ /r/ ? 1 : 0) + | ($arg{poll} =~ /w/ ? 2 : 0)) + ->start + ->cb (sub { + $cb->(($_[1] & 1 ? 'r' : '') + . ($_[1] & 2 ? 'w' : '')); + })], + urxvt::anyevent:: +} + +sub DESTROY { + $_[0][1]->stop; +} + +sub condvar { + bless \my $flag, urxvt::anyevent::condvar:: +} + +sub urxvt::anyevent::condvar::broadcast { + ${$_[0]}++; +} + +sub urxvt::anyevent::condvar::wait { + unless (${$_[0]}) { + require Carp; + Carp::croak ("AnyEvent->condvar blocking wait unsupported in urxvt, use a non-blocking API"); + } +} + +package urxvt::term; + =head2 The C Class =over 4 @@ -626,7 +706,7 @@ =cut -sub urxvt::term::resource($$;$) { +sub resource($$;$) { my ($self, $name) = (shift, shift); unshift @_, $self, $name, ($name =~ s/\s*\+\s*(\d+)$// ? $1 : 0); &urxvt::term::_resource @@ -723,7 +803,7 @@ =cut -sub urxvt::term::popup { +sub popup { my ($self, $event) = @_; $self->grab ($event->{time}, 1) @@ -923,7 +1003,7 @@ =cut -sub urxvt::term::line { +sub line { my ($self, $row) = @_; my $maxrow = $self->nrow - 1; @@ -1011,26 +1091,55 @@ =back +=cut + +package urxvt::popup; + =head2 The C Class =over 4 =cut -package urxvt::popup; - sub add_item { my ($self, $item) = @_; + $item->{rend}{normal} = "\x1b[0;30;47m" unless exists $item->{rend}{normal}; + $item->{rend}{hover} = "\x1b[0;30;46m" unless exists $item->{rend}{hover}; + $item->{rend}{active} = "\x1b[m" unless exists $item->{rend}{active}; + + $item->{render} ||= sub { $_[0]{text} }; + push @{ $self->{item} }, $item; } +sub add_separator { + my ($self, $sep) = @_; + + $sep ||= "═"; + + $self->add_item ({ + rend => { normal => "\x1b[0;30;47m", hover => "\x1b[0;30;47m", active => "\x1b[0;30;47m" }, + text => "", + render => sub { $sep x $urxvt::TERM->ncol }, + activate => sub { }, + }); +} + +sub add_title { + my ($self, $title) = @_; + + $self->add_item ({ + rend => { normal => "\x1b[38;5;11;44m", hover => "\x1b[38;5;11;44m", active => "\x1b[38;5;11;44m" }, + text => $title, + activate => sub { }, + }); +} + sub add_button { my ($self, $text, $cb) = @_; - $self->add_item ({ type => "button", text => "[ $text ]", activate => $cb, - render => sub { $_[0]{text} }, - }); + $self->add_item ({ type => "button", text => "[ $text ]", activate => $cb}); } sub add_toggle { @@ -1040,7 +1149,7 @@ type => "button", text => " $text", value => $value, - render => sub { ($item->{value} ? "✔" : " ") . $text }, + render => sub { ($item->{value} ? "* " : " ") . $text }, activate => sub { $cb->($item->{value} = !$item->{value}); }, };