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.58 by root, Sun Jan 8 22:58:13 2006 UTC

342 342
343=item urxvt::ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, 343=item urxvt::ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask,
344Mod3Mask, Mod4Mask, Mod5Mask, Button1Mask, Button2Mask, Button3Mask, 344Mod3Mask, Mod4Mask, Mod5Mask, Button1Mask, Button2Mask, Button3Mask,
345Button4Mask, Button5Mask, AnyModifier 345Button4Mask, Button5Mask, AnyModifier
346 346
347Various constants for use in X events. 347Various constants for use in X calls and event processing.
348 348
349=back 349=back
350 350
351=head2 RENDITION 351=head2 RENDITION
352 352
407use utf8; 407use utf8;
408use strict; 408use strict;
409use Scalar::Util (); 409use Scalar::Util ();
410use List::Util (); 410use List::Util ();
411 411
412our $VERSION = 1;
412our $TERM; 413our $TERM;
413our @HOOKNAME; 414our @HOOKNAME;
414our %OPTION; 415our %OPTION;
415our $LIBDIR; 416our $LIBDIR;
416 417
469 my $source = "package $pkg; use strict; use utf8;\n" 470 my $source = "package $pkg; use strict; use utf8;\n"
470 . "use base urxvt::term::proxy::;\n" 471 . "use base urxvt::term::proxy::;\n"
471 . "#line 1 \"$path\"\n{\n" 472 . "#line 1 \"$path\"\n{\n"
472 . (do { local $/; <$fh> }) 473 . (do { local $/; <$fh> })
473 . "\n};\n1"; 474 . "\n};\n1";
475
476 $source =~ /(.*)/s and $source = $1; # untaint
474 477
475 eval $source or die "$path: $@"; 478 eval $source or die "$path: $@";
476 479
477 $pkg 480 $pkg
478 } 481 }
507 register_package extension_package $files[0]; 510 register_package extension_package $files[0];
508 } else { 511 } else {
509 warn "perl extension '$ext' not found in perl library search path\n"; 512 warn "perl extension '$ext' not found in perl library search path\n";
510 } 513 }
511 } 514 }
515
516 eval "#line 1 \"--perl-eval resource/argument\"\n" . $TERM->resource ("perl_eval");
517 warn $@ if $@;
512 } 518 }
513 519
514 $retval = undef; 520 $retval = undef;
515 521
516 if (my $cb = $TERM->{_hook}[$htype]) { 522 if (my $cb = $TERM->{_hook}[$htype]) {
528 $proxy 534 $proxy
529 }, 535 },
530 @_, 536 @_,
531 ) and last; 537 ) and last;
532 }; 538 };
533 warn $@ if $@;#d# 539 if ($@) {
540 $TERM->ungrab; # better to lose the grab than the session
541 warn $@;
542 }
534 } 543 }
535 } 544 }
536 545
537 if ($htype == 1) { # DESTROY 546 if ($htype == 1) { # DESTROY
538 # remove hooks if unused 547 # remove hooks if unused
551 } 560 }
552 561
553 $retval 562 $retval
554} 563}
555 564
565# urxvt::term::proxy
566
556sub urxvt::term::proxy::AUTOLOAD { 567sub urxvt::term::proxy::AUTOLOAD {
557 $urxvt::term::proxy::AUTOLOAD =~ /:([^:]+)$/ 568 $urxvt::term::proxy::AUTOLOAD =~ /:([^:]+)$/
558 or die "FATAL: \$AUTOLOAD '$urxvt::term::proxy::AUTOLOAD' unparsable"; 569 or die "FATAL: \$AUTOLOAD '$urxvt::term::proxy::AUTOLOAD' unparsable";
559 570
560 eval qq{ 571 eval qq{
566 } or die "FATAL: unable to compile method forwarder: $@"; 577 } or die "FATAL: unable to compile method forwarder: $@";
567 578
568 goto &$urxvt::term::proxy::AUTOLOAD; 579 goto &$urxvt::term::proxy::AUTOLOAD;
569} 580}
570 581
582sub urxvt::term::proxy::DESTROY {
583 # nop
584}
585
586# urxvt::destroy_hook
587
571sub urxvt::destroy_hook::DESTROY { 588sub urxvt::destroy_hook::DESTROY {
572 ${$_[0]}->(); 589 ${$_[0]}->();
573} 590}
574 591
575sub urxvt::destroy_hook(&) { 592sub urxvt::destroy_hook(&) {
576 bless \shift, urxvt::destroy_hook:: 593 bless \shift, urxvt::destroy_hook::
577} 594}
595
596package urxvt::anyevent;
597
598=head2 The C<urxvt::anyevent> Class
599
600The sole purpose of this class is to deliver an interface to the
601C<AnyEvent> module - any module using it will work inside urxvt without
602further work. The only exception is that you cannot wait on condition
603variables, but non-blocking condvar use is ok. What this means is that you
604cannot use blocking APIs, but the non-blocking variant should work.
605
606=cut
607
608our $VERSION = 1;
609
610$INC{"urxvt/anyevent.pm"} = 1; # mark us as there
611push @AnyEvent::REGISTRY, [urxvt => urxvt::anyevent::];
612
613sub timer {
614 my ($class, %arg) = @_;
615
616 my $cb = $arg{cb};
617
618 urxvt::timer
619 ->new
620 ->start (urxvt::NOW + $arg{after})
621 ->cb (sub {
622 $_[0]->stop; # need to cancel manually
623 $cb->();
624 })
625}
626
627sub io {
628 my ($class, %arg) = @_;
629
630 my $cb = $arg{cb};
631
632 bless [$arg{fh}, urxvt::iow
633 ->new
634 ->fd (fileno $arg{fh})
635 ->events (($arg{poll} =~ /r/ ? 1 : 0)
636 | ($arg{poll} =~ /w/ ? 2 : 0))
637 ->start
638 ->cb (sub {
639 $cb->(($_[1] & 1 ? 'r' : '')
640 . ($_[1] & 2 ? 'w' : ''));
641 })],
642 urxvt::anyevent::
643}
644
645sub DESTROY {
646 $_[0][1]->stop;
647}
648
649sub condvar {
650 bless \my $flag, urxvt::anyevent::condvar::
651}
652
653sub urxvt::anyevent::condvar::broadcast {
654 ${$_[0]}++;
655}
656
657sub urxvt::anyevent::condvar::wait {
658 unless (${$_[0]}) {
659 require Carp;
660 Carp::croak ("AnyEvent->condvar blocking wait unsupported in urxvt, use a non-blocking API");
661 }
662}
663
664package urxvt::term;
578 665
579=head2 The C<urxvt::term> Class 666=head2 The C<urxvt::term> Class
580 667
581=over 4 668=over 4
582 669
634 shade term_name title transparent transparent_all tripleclickwords 721 shade term_name title transparent transparent_all tripleclickwords
635 utmpInhibit visualBell 722 utmpInhibit visualBell
636 723
637=cut 724=cut
638 725
639sub urxvt::term::resource($$;$) { 726sub resource($$;$) {
640 my ($self, $name) = (shift, shift); 727 my ($self, $name) = (shift, shift);
641 unshift @_, $self, $name, ($name =~ s/\s*\+\s*(\d+)$// ? $1 : 0); 728 unshift @_, $self, $name, ($name =~ s/\s*\+\s*(\d+)$// ? $1 : 0);
642 &urxvt::term::_resource 729 &urxvt::term::_resource
643} 730}
644 731
731C<$event> I<must> be the event causing the menu to pop up (a button event, 818C<$event> I<must> be the event causing the menu to pop up (a button event,
732currently). 819currently).
733 820
734=cut 821=cut
735 822
736sub urxvt::term::popup { 823sub popup {
737 my ($self, $event) = @_; 824 my ($self, $event) = @_;
738 825
739 $self->grab ($event->{time}, 1) 826 $self->grab ($event->{time}, 1)
740 or return; 827 or return;
741 828
931 1018
932=back 1019=back
933 1020
934=cut 1021=cut
935 1022
936sub urxvt::term::line { 1023sub line {
937 my ($self, $row) = @_; 1024 my ($self, $row) = @_;
938 1025
939 my $maxrow = $self->nrow - 1; 1026 my $maxrow = $self->nrow - 1;
940 1027
941 my ($beg, $end) = ($row, $row); 1028 my ($beg, $end) = ($row, $row);
1019Converts rxvt-unicodes text reprsentation into a perl string. See 1106Converts rxvt-unicodes text reprsentation into a perl string. See
1020C<< $term->ROW_t >> for details. 1107C<< $term->ROW_t >> for details.
1021 1108
1022=back 1109=back
1023 1110
1111=cut
1112
1113package urxvt::popup;
1114
1024=head2 The C<urxvt::popup> Class 1115=head2 The C<urxvt::popup> Class
1025 1116
1026=over 4 1117=over 4
1027 1118
1028=cut 1119=cut
1029
1030package urxvt::popup;
1031 1120
1032sub add_item { 1121sub add_item {
1033 my ($self, $item) = @_; 1122 my ($self, $item) = @_;
1034 1123
1035 $item->{rend}{normal} = "\x1b[0;30;47m" unless exists $item->{rend}{normal}; 1124 $item->{rend}{normal} = "\x1b[0;30;47m" unless exists $item->{rend}{normal};
1075 1164
1076 my $item; $item = { 1165 my $item; $item = {
1077 type => "button", 1166 type => "button",
1078 text => " $text", 1167 text => " $text",
1079 value => $value, 1168 value => $value,
1080 render => sub { ($item->{value} ? "* " : " ") . $text }, 1169 render => sub { ($_[0]{value} ? "* " : " ") . $text },
1081 activate => sub { $cb->($item->{value} = !$item->{value}); }, 1170 activate => sub { $cb->($_[0]{value} = !$_[0]{value}); },
1082 }; 1171 };
1083 1172
1084 $self->add_item ($item); 1173 $self->add_item ($item);
1085} 1174}
1086 1175
1096} 1185}
1097 1186
1098sub DESTROY { 1187sub DESTROY {
1099 my ($self) = @_; 1188 my ($self) = @_;
1100 1189
1190 delete $self->{term}{_destroy}{$self};
1101 $self->{term}->ungrab; 1191 $self->{term}->ungrab;
1102} 1192}
1103 1193
1104=head2 The C<urxvt::timer> Class 1194=head2 The C<urxvt::timer> Class
1105 1195
1209This variable controls the verbosity level of the perl extension. Higher 1299This variable controls the verbosity level of the perl extension. Higher
1210numbers indicate more verbose output. 1300numbers indicate more verbose output.
1211 1301
1212=over 4 1302=over 4
1213 1303
1214=item =0 - only fatal messages 1304=item == 0 - fatal messages
1215 1305
1216=item =3 - script loading and management 1306=item >= 3 - script loading and management
1217 1307
1218=item =10 - all events received 1308=item >=10 - all events received
1219 1309
1220=back 1310=back
1221 1311
1222=head1 AUTHOR 1312=head1 AUTHOR
1223 1313

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines