ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/urxvt.pm
(Generate patch)

Comparing rxvt-unicode/src/urxvt.pm (file contents):
Revision 1.54 by root, Sun Jan 8 01:59:29 2006 UTC vs.
Revision 1.59 by root, Mon Jan 9 00:34:36 2006 UTC

58 58
59=back 59=back
60 60
61=item option-popup (enabled by default) 61=item option-popup (enabled by default)
62 62
63Binds a popup menu to Ctrl-Button3 that lets you toggle (some) options at 63Binds a popup menu to Ctrl-Button2 that lets you toggle (some) options at
64runtime. 64runtime.
65
66=item selection-popup (enabled by default)
67
68Binds a popup menu to Ctrl-Button3 that lets you convert the selection
69text into various other formats/action.
65 70
66=item digital-clock 71=item digital-clock
67 72
68Displays a digital clock using the built-in overlay. 73Displays a digital clock using the built-in overlay.
69 74
342 347
343=item urxvt::ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, 348=item urxvt::ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask,
344Mod3Mask, Mod4Mask, Mod5Mask, Button1Mask, Button2Mask, Button3Mask, 349Mod3Mask, Mod4Mask, Mod5Mask, Button1Mask, Button2Mask, Button3Mask,
345Button4Mask, Button5Mask, AnyModifier 350Button4Mask, Button5Mask, AnyModifier
346 351
347Various constants for use in X events. 352Various constants for use in X calls and event processing.
348 353
349=back 354=back
350 355
351=head2 RENDITION 356=head2 RENDITION
352 357
407use utf8; 412use utf8;
408use strict; 413use strict;
409use Scalar::Util (); 414use Scalar::Util ();
410use List::Util (); 415use List::Util ();
411 416
417our $VERSION = 1;
412our $TERM; 418our $TERM;
413our @HOOKNAME; 419our @HOOKNAME;
414our %OPTION; 420our %OPTION;
415our $LIBDIR; 421our $LIBDIR;
416 422
422 my $msg = join "", @_; 428 my $msg = join "", @_;
423 $msg .= "\n" 429 $msg .= "\n"
424 unless $msg =~ /\n$/; 430 unless $msg =~ /\n$/;
425 urxvt::warn ($msg); 431 urxvt::warn ($msg);
426 }; 432 };
433
434 $ENV{PATH} = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/bin:/opt/sbin";
435 delete $ENV{CDPATH};
427} 436}
428 437
429my @hook_count; 438my @hook_count;
430my $verbosity = $ENV{URXVT_PERL_VERBOSITY}; 439my $verbosity = $ENV{URXVT_PERL_VERBOSITY};
431 440
464 verbose 3, "loading extension '$path' into package '$pkg'"; 473 verbose 3, "loading extension '$path' into package '$pkg'";
465 474
466 open my $fh, "<:raw", $path 475 open my $fh, "<:raw", $path
467 or die "$path: $!"; 476 or die "$path: $!";
468 477
469 my $source = "package $pkg; use strict; use utf8;\n" 478 my $source = untaint "package $pkg; use strict; use utf8;\n"
470 . "use base urxvt::term::proxy::;\n" 479 . "use base urxvt::term::proxy::;\n"
471 . "#line 1 \"$path\"\n{\n" 480 . "#line 1 \"$path\"\n{\n"
472 . (do { local $/; <$fh> }) 481 . (do { local $/; <$fh> })
473 . "\n};\n1"; 482 . "\n};\n1";
474 483
490 499
491 my %want_ext; 500 my %want_ext;
492 501
493 for (map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2) { 502 for (map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2) {
494 if ($_ eq "default") { 503 if ($_ eq "default") {
495 $want_ext{$_}++ for qw(selection option-popup); 504 $want_ext{$_}++ for qw(selection option-popup selection-popup);
496 } elsif (/^-(.*)$/) { 505 } elsif (/^-(.*)$/) {
497 delete $want_ext{$1}; 506 delete $want_ext{$1};
498 } else { 507 } else {
499 $want_ext{$_}++; 508 $want_ext{$_}++;
500 } 509 }
507 register_package extension_package $files[0]; 516 register_package extension_package $files[0];
508 } else { 517 } else {
509 warn "perl extension '$ext' not found in perl library search path\n"; 518 warn "perl extension '$ext' not found in perl library search path\n";
510 } 519 }
511 } 520 }
521
522 eval "#line 1 \"--perl-eval resource/argument\"\n" . $TERM->resource ("perl_eval");
523 warn $@ if $@;
512 } 524 }
513 525
514 $retval = undef; 526 $retval = undef;
515 527
516 if (my $cb = $TERM->{_hook}[$htype]) { 528 if (my $cb = $TERM->{_hook}[$htype]) {
528 $proxy 540 $proxy
529 }, 541 },
530 @_, 542 @_,
531 ) and last; 543 ) and last;
532 }; 544 };
533 warn $@ if $@;#d# 545 if ($@) {
546 $TERM->ungrab; # better to lose the grab than the session
547 warn $@;
548 }
534 } 549 }
535 } 550 }
536 551
537 if ($htype == 1) { # DESTROY 552 if ($htype == 1) { # DESTROY
538 # remove hooks if unused 553 # remove hooks if unused
551 } 566 }
552 567
553 $retval 568 $retval
554} 569}
555 570
571# urxvt::term::proxy
572
556sub urxvt::term::proxy::AUTOLOAD { 573sub urxvt::term::proxy::AUTOLOAD {
557 $urxvt::term::proxy::AUTOLOAD =~ /:([^:]+)$/ 574 $urxvt::term::proxy::AUTOLOAD =~ /:([^:]+)$/
558 or die "FATAL: \$AUTOLOAD '$urxvt::term::proxy::AUTOLOAD' unparsable"; 575 or die "FATAL: \$AUTOLOAD '$urxvt::term::proxy::AUTOLOAD' unparsable";
559 576
560 eval qq{ 577 eval qq{
566 } or die "FATAL: unable to compile method forwarder: $@"; 583 } or die "FATAL: unable to compile method forwarder: $@";
567 584
568 goto &$urxvt::term::proxy::AUTOLOAD; 585 goto &$urxvt::term::proxy::AUTOLOAD;
569} 586}
570 587
588sub urxvt::term::proxy::DESTROY {
589 # nop
590}
591
592# urxvt::destroy_hook
593
571sub urxvt::destroy_hook::DESTROY { 594sub urxvt::destroy_hook::DESTROY {
572 ${$_[0]}->(); 595 ${$_[0]}->();
573} 596}
574 597
575sub urxvt::destroy_hook(&) { 598sub urxvt::destroy_hook(&) {
576 bless \shift, urxvt::destroy_hook:: 599 bless \shift, urxvt::destroy_hook::
577} 600}
601
602package urxvt::anyevent;
603
604=head2 The C<urxvt::anyevent> Class
605
606The sole purpose of this class is to deliver an interface to the
607C<AnyEvent> module - any module using it will work inside urxvt without
608further work. The only exception is that you cannot wait on condition
609variables, but non-blocking condvar use is ok. What this means is that you
610cannot use blocking APIs, but the non-blocking variant should work.
611
612=cut
613
614our $VERSION = 1;
615
616$INC{"urxvt/anyevent.pm"} = 1; # mark us as there
617push @AnyEvent::REGISTRY, [urxvt => urxvt::anyevent::];
618
619sub timer {
620 my ($class, %arg) = @_;
621
622 my $cb = $arg{cb};
623
624 urxvt::timer
625 ->new
626 ->start (urxvt::NOW + $arg{after})
627 ->cb (sub {
628 $_[0]->stop; # need to cancel manually
629 $cb->();
630 })
631}
632
633sub io {
634 my ($class, %arg) = @_;
635
636 my $cb = $arg{cb};
637
638 bless [$arg{fh}, urxvt::iow
639 ->new
640 ->fd (fileno $arg{fh})
641 ->events (($arg{poll} =~ /r/ ? 1 : 0)
642 | ($arg{poll} =~ /w/ ? 2 : 0))
643 ->start
644 ->cb (sub {
645 $cb->(($_[1] & 1 ? 'r' : '')
646 . ($_[1] & 2 ? 'w' : ''));
647 })],
648 urxvt::anyevent::
649}
650
651sub DESTROY {
652 $_[0][1]->stop;
653}
654
655sub condvar {
656 bless \my $flag, urxvt::anyevent::condvar::
657}
658
659sub urxvt::anyevent::condvar::broadcast {
660 ${$_[0]}++;
661}
662
663sub urxvt::anyevent::condvar::wait {
664 unless (${$_[0]}) {
665 require Carp;
666 Carp::croak ("AnyEvent->condvar blocking wait unsupported in urxvt, use a non-blocking API");
667 }
668}
669
670package urxvt::term;
578 671
579=head2 The C<urxvt::term> Class 672=head2 The C<urxvt::term> Class
580 673
581=over 4 674=over 4
582 675
634 shade term_name title transparent transparent_all tripleclickwords 727 shade term_name title transparent transparent_all tripleclickwords
635 utmpInhibit visualBell 728 utmpInhibit visualBell
636 729
637=cut 730=cut
638 731
639sub urxvt::term::resource($$;$) { 732sub resource($$;$) {
640 my ($self, $name) = (shift, shift); 733 my ($self, $name) = (shift, shift);
641 unshift @_, $self, $name, ($name =~ s/\s*\+\s*(\d+)$// ? $1 : 0); 734 unshift @_, $self, $name, ($name =~ s/\s*\+\s*(\d+)$// ? $1 : 0);
642 &urxvt::term::_resource 735 &urxvt::term::_resource
643} 736}
644 737
731C<$event> I<must> be the event causing the menu to pop up (a button event, 824C<$event> I<must> be the event causing the menu to pop up (a button event,
732currently). 825currently).
733 826
734=cut 827=cut
735 828
736sub urxvt::term::popup { 829sub popup {
737 my ($self, $event) = @_; 830 my ($self, $event) = @_;
738 831
739 $self->grab ($event->{time}, 1) 832 $self->grab ($event->{time}, 1)
740 or return; 833 or return;
741 834
931 1024
932=back 1025=back
933 1026
934=cut 1027=cut
935 1028
936sub urxvt::term::line { 1029sub line {
937 my ($self, $row) = @_; 1030 my ($self, $row) = @_;
938 1031
939 my $maxrow = $self->nrow - 1; 1032 my $maxrow = $self->nrow - 1;
940 1033
941 my ($beg, $end) = ($row, $row); 1034 my ($beg, $end) = ($row, $row);
1019Converts rxvt-unicodes text reprsentation into a perl string. See 1112Converts rxvt-unicodes text reprsentation into a perl string. See
1020C<< $term->ROW_t >> for details. 1113C<< $term->ROW_t >> for details.
1021 1114
1022=back 1115=back
1023 1116
1117=cut
1118
1119package urxvt::popup;
1120
1024=head2 The C<urxvt::popup> Class 1121=head2 The C<urxvt::popup> Class
1025 1122
1026=over 4 1123=over 4
1027 1124
1028=cut 1125=cut
1029
1030package urxvt::popup;
1031 1126
1032sub add_item { 1127sub add_item {
1033 my ($self, $item) = @_; 1128 my ($self, $item) = @_;
1034 1129
1035 $item->{rend}{normal} = "\x1b[0;30;47m" unless exists $item->{rend}{normal}; 1130 $item->{rend}{normal} = "\x1b[0;30;47m" unless exists $item->{rend}{normal};
1075 1170
1076 my $item; $item = { 1171 my $item; $item = {
1077 type => "button", 1172 type => "button",
1078 text => " $text", 1173 text => " $text",
1079 value => $value, 1174 value => $value,
1080 render => sub { ($item->{value} ? "* " : " ") . $text }, 1175 render => sub { ($_[0]{value} ? "* " : " ") . $text },
1081 activate => sub { $cb->($item->{value} = !$item->{value}); }, 1176 activate => sub { $cb->($_[0]{value} = !$_[0]{value}); },
1082 }; 1177 };
1083 1178
1084 $self->add_item ($item); 1179 $self->add_item ($item);
1085} 1180}
1086 1181
1096} 1191}
1097 1192
1098sub DESTROY { 1193sub DESTROY {
1099 my ($self) = @_; 1194 my ($self) = @_;
1100 1195
1196 delete $self->{term}{_destroy}{$self};
1101 $self->{term}->ungrab; 1197 $self->{term}->ungrab;
1102} 1198}
1103 1199
1104=head2 The C<urxvt::timer> Class 1200=head2 The C<urxvt::timer> Class
1105 1201
1209This variable controls the verbosity level of the perl extension. Higher 1305This variable controls the verbosity level of the perl extension. Higher
1210numbers indicate more verbose output. 1306numbers indicate more verbose output.
1211 1307
1212=over 4 1308=over 4
1213 1309
1214=item =0 - only fatal messages 1310=item == 0 - fatal messages
1215 1311
1216=item =3 - script loading and management 1312=item >= 3 - script loading and management
1217 1313
1218=item =10 - all events received 1314=item >=10 - all events received
1219 1315
1220=back 1316=back
1221 1317
1222=head1 AUTHOR 1318=head1 AUTHOR
1223 1319

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines