--- rxvt-unicode/src/urxvt.pm 2006/01/07 20:29:28 1.46 +++ rxvt-unicode/src/urxvt.pm 2006/01/09 00:34:36 1.59 @@ -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,16 @@ =back +=item option-popup (enabled by default) + +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. @@ -333,6 +343,14 @@ Returns the "current time" (as per the event loop). +=item urxvt::CurrentTime + +=item urxvt::ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, +Mod3Mask, Mod4Mask, Mod5Mask, Button1Mask, Button2Mask, Button3Mask, +Button4Mask, Button5Mask, AnyModifier + +Various constants for use in X calls and event processing. + =back =head2 RENDITION @@ -391,11 +409,15 @@ package urxvt; +use utf8; use strict; use Scalar::Util (); +use List::Util (); +our $VERSION = 1; our $TERM; our @HOOKNAME; +our %OPTION; our $LIBDIR; BEGIN { @@ -408,6 +430,9 @@ 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; @@ -450,7 +475,7 @@ 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> }) @@ -471,8 +496,20 @@ if ($htype == 0) { # INIT my @dirs = ((split /:/, $TERM->resource ("perl_lib")), "$LIBDIR/perl"); + + my %want_ext; + + for (map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2) { + if ($_ eq "default") { + $want_ext{$_}++ for qw(selection option-popup selection-popup); + } elsif (/^-(.*)$/) { + delete $want_ext{$1}; + } else { + $want_ext{$_}++; + } + } - for my $ext (map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2) { + for my $ext (keys %want_ext) { my @files = grep -f $_, map "$_/$ext", @dirs; if (@files) { @@ -481,6 +518,9 @@ 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; @@ -502,7 +542,10 @@ @_, ) and last; }; - warn $@ if $@;#d# + if ($@) { + $TERM->ungrab; # better to lose the grab than the session + warn $@; + } } } @@ -525,6 +568,8 @@ $retval } +# urxvt::term::proxy + sub urxvt::term::proxy::AUTOLOAD { $urxvt::term::proxy::AUTOLOAD =~ /:([^:]+)$/ or die "FATAL: \$AUTOLOAD '$urxvt::term::proxy::AUTOLOAD' unparsable"; @@ -540,6 +585,12 @@ goto &$urxvt::term::proxy::AUTOLOAD; } +sub urxvt::term::proxy::DESTROY { + # nop +} + +# urxvt::destroy_hook + sub urxvt::destroy_hook::DESTROY { ${$_[0]}->(); } @@ -548,6 +599,76 @@ bless \shift, urxvt::destroy_hook:: } +package urxvt::anyevent; + +=head2 The C Class + +The sole purpose of this class is to deliver an interface to the +C module - any module using it will work inside urxvt without +further work. The only exception is that you cannot wait on condition +variables, but non-blocking condvar use is ok. What this means is that you +cannot use blocking APIs, but the non-blocking variant should work. + +=cut + +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 @@ -556,6 +677,22 @@ Destroy the terminal object (close the window, free resources etc.). +=item $isset = $term->option ($optval[, $set]) + +Returns true if the option specified by C<$optval> is enabled, and +optionally change it. All option values are stored by name in the hash +C<%urxvt::OPTION>. Options not enabled in this binary are not in the hash. + +Here is a a likely non-exhaustive list of option names, please see the +source file F to see the actual list: + + borderLess console cursorBlink cursorUnderline hold iconic insecure + intensityStyles jumpScroll loginShell mapAlert meta8 mouseWheelScrollPage + pastableTabs pointerBlank reverseVideo scrollBar scrollBar_floating + scrollBar_right scrollTtyKeypress scrollTtyOutput scrollWithBuffer + secondaryScreen secondaryScroll skipBuiltinGlyphs transparent + tripleclickwords utmpInhibit visualBell + =item $value = $term->resource ($name[, $newval]) Returns the current resource value associated with a given name and @@ -574,8 +711,8 @@ terminal is destroyed, so changing options frequently will eat memory. Here is a a likely non-exhaustive list of resource names, not all of which -are supported in every build, please see the source to see the actual -list: +are supported in every build, please see the source file F +to see the actual list: answerbackstring backgroundPixmap backspace_key boldFont boldItalicFont borderLess color cursorBlink cursorUnderline cutchars delete_key @@ -592,7 +729,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 @@ -689,7 +826,7 @@ =cut -sub urxvt::term::popup { +sub popup { my ($self, $event) = @_; $self->grab ($event->{time}, 1) @@ -778,6 +915,15 @@ Return various integers describing terminal characteristics. +=item $modifiermask = $term->ModLevel3Mask + +=item $modifiermask = $term->ModMetaMask + +=item $modifiermask = $term->ModNumLockMask + +Return the modifier masks corresponding to the "ISO Level 3 Shift" (often +AltGr), the meta key (often Alt) and the num lock key, if applicable. + =item $view_start = $term->view_start ([$newvalue]) Returns the negative row number of the topmost line. Minimum value is @@ -880,7 +1026,7 @@ =cut -sub urxvt::term::line { +sub line { my ($self, $row) = @_; my $maxrow = $self->nrow - 1; @@ -968,24 +1114,69 @@ =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 }); + $self->add_item ({ type => "button", text => "[ $text ]", activate => $cb}); +} + +sub add_toggle { + my ($self, $text, $cb, $value) = @_; + + my $item; $item = { + type => "button", + text => " $text", + value => $value, + render => sub { ($_[0]{value} ? "* " : " ") . $text }, + activate => sub { $cb->($_[0]{value} = !$_[0]{value}); }, + }; + + $self->add_item ($item); } sub show { @@ -1002,6 +1193,7 @@ sub DESTROY { my ($self) = @_; + delete $self->{term}{_destroy}{$self}; $self->{term}->ungrab; } @@ -1115,11 +1307,11 @@ =over 4 -=item =0 - only fatal messages +=item == 0 - fatal messages -=item =3 - script loading and management +=item >= 3 - script loading and management -=item =10 - all events received +=item >=10 - all events received =back