… | |
… | |
445 | sub verbose { |
445 | sub verbose { |
446 | my ($level, $msg) = @_; |
446 | my ($level, $msg) = @_; |
447 | warn "$msg\n" if $level <= $verbosity; |
447 | warn "$msg\n" if $level <= $verbosity; |
448 | } |
448 | } |
449 | |
449 | |
450 | # find on_xxx subs in the package and register them |
|
|
451 | # as hooks |
|
|
452 | sub register_package($) { |
|
|
453 | my ($pkg) = @_; |
|
|
454 | |
|
|
455 | for my $htype (0.. $#HOOKNAME) { |
|
|
456 | my $name = $HOOKNAME[$htype]; |
|
|
457 | |
|
|
458 | my $ref = $pkg->can ("on_" . lc $name) |
|
|
459 | or next; |
|
|
460 | |
|
|
461 | $TERM->{_hook}[$htype]{$pkg} = $ref; |
|
|
462 | $hook_count[$htype]++ |
|
|
463 | or set_should_invoke $htype, 1; |
|
|
464 | } |
|
|
465 | } |
|
|
466 | |
|
|
467 | my $extension_pkg = "extension0000"; |
450 | my $extension_pkg = "extension0000"; |
468 | my %extension_pkg; |
451 | my %extension_pkg; |
469 | |
452 | |
470 | # load a single script into its own package, once only |
453 | # load a single script into its own package, once only |
471 | sub extension_package($) { |
454 | sub extension_package($) { |
… | |
… | |
499 | my $htype = shift; |
482 | my $htype = shift; |
500 | |
483 | |
501 | if ($htype == 0) { # INIT |
484 | if ($htype == 0) { # INIT |
502 | my @dirs = ((split /:/, $TERM->resource ("perl_lib")), "$LIBDIR/perl"); |
485 | my @dirs = ((split /:/, $TERM->resource ("perl_lib")), "$LIBDIR/perl"); |
503 | |
486 | |
504 | my %want_ext; |
487 | my %ext_arg; |
505 | |
488 | |
506 | for (map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2) { |
489 | for (map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2) { |
507 | if ($_ eq "default") { |
490 | if ($_ eq "default") { |
508 | $want_ext{$_}++ for qw(selection option-popup selection-popup); |
491 | $ext_arg{$_} ||= [] for qw(selection option-popup selection-popup); |
509 | } elsif (/^-(.*)$/) { |
492 | } elsif (/^-(.*)$/) { |
510 | delete $want_ext{$1}; |
493 | delete $ext_arg{$1}; |
|
|
494 | } elsif (/^([^<]+)<(.*)>$/) { |
|
|
495 | push @{ $ext_arg{$1} }, $2; |
511 | } else { |
496 | } else { |
512 | $want_ext{$_}++; |
497 | $ext_arg{$_} ||= []; |
513 | } |
498 | } |
514 | } |
499 | } |
515 | |
500 | |
516 | for my $ext (keys %want_ext) { |
501 | while (my ($ext, $argv) = each %ext_arg) { |
517 | my @files = grep -f $_, map "$_/$ext", @dirs; |
502 | my @files = grep -f $_, map "$_/$ext", @dirs; |
518 | |
503 | |
519 | if (@files) { |
504 | if (@files) { |
520 | register_package extension_package $files[0]; |
505 | $TERM->register_package (extension_package $files[0], $argv); |
521 | } else { |
506 | } else { |
522 | warn "perl extension '$ext' not found in perl library search path\n"; |
507 | warn "perl extension '$ext' not found in perl library search path\n"; |
523 | } |
508 | } |
524 | } |
509 | } |
525 | |
510 | |
… | |
… | |
534 | if $verbosity >= 10; |
519 | if $verbosity >= 10; |
535 | |
520 | |
536 | keys %$cb; |
521 | keys %$cb; |
537 | |
522 | |
538 | while (my ($pkg, $cb) = each %$cb) { |
523 | while (my ($pkg, $cb) = each %$cb) { |
539 | eval { |
524 | $retval = eval { $cb->($TERM->{_pkg}{$pkg}, @_) } |
540 | $retval = $cb->( |
|
|
541 | $TERM->{_pkg}{$pkg} ||= do { |
|
|
542 | my $proxy = bless { }, $pkg; |
|
|
543 | Scalar::Util::weaken ($proxy->{term} = $TERM); |
|
|
544 | $proxy |
|
|
545 | }, |
|
|
546 | @_, |
|
|
547 | ) and last; |
525 | and last; |
548 | }; |
526 | |
549 | if ($@) { |
527 | if ($@) { |
550 | $TERM->ungrab; # better to lose the grab than the session |
528 | $TERM->ungrab; # better to lose the grab than the session |
551 | warn $@; |
529 | warn $@; |
552 | } |
530 | } |
553 | } |
531 | } |
… | |
… | |
674 | package urxvt::term; |
652 | package urxvt::term; |
675 | |
653 | |
676 | =head2 The C<urxvt::term> Class |
654 | =head2 The C<urxvt::term> Class |
677 | |
655 | |
678 | =over 4 |
656 | =over 4 |
|
|
657 | |
|
|
658 | =cut |
|
|
659 | |
|
|
660 | # find on_xxx subs in the package and register them |
|
|
661 | # as hooks |
|
|
662 | sub register_package { |
|
|
663 | my ($self, $pkg, $argv) = @_; |
|
|
664 | |
|
|
665 | my $proxy = bless { argv => $argv }, $pkg; |
|
|
666 | Scalar::Util::weaken ($proxy->{term} = $TERM); |
|
|
667 | |
|
|
668 | $self->{_pkg}{$pkg} = $proxy; |
|
|
669 | |
|
|
670 | for my $htype (0.. $#HOOKNAME) { |
|
|
671 | my $name = $HOOKNAME[$htype]; |
|
|
672 | |
|
|
673 | my $ref = $pkg->can ("on_" . lc $name) |
|
|
674 | or next; |
|
|
675 | |
|
|
676 | $self->{_hook}[$htype]{$pkg} = $ref; |
|
|
677 | $hook_count[$htype]++ |
|
|
678 | or urxvt::set_should_invoke $htype, 1; |
|
|
679 | } |
|
|
680 | } |
679 | |
681 | |
680 | =item $term->destroy |
682 | =item $term->destroy |
681 | |
683 | |
682 | Destroy the terminal object (close the window, free resources etc.). |
684 | Destroy the terminal object (close the window, free resources etc.). |
683 | |
685 | |
… | |
… | |
917 | |
919 | |
918 | =item $lines_in_scrollback = $term->nsaved |
920 | =item $lines_in_scrollback = $term->nsaved |
919 | |
921 | |
920 | Return various integers describing terminal characteristics. |
922 | Return various integers describing terminal characteristics. |
921 | |
923 | |
|
|
924 | =item $lc_ctype = $term->locale |
|
|
925 | |
|
|
926 | Returns the LC_CTYPE category string used by this rxvt-unicode. |
|
|
927 | |
|
|
928 | =item $x_display = $term->display_id |
|
|
929 | |
|
|
930 | Return the DISPLAY used by rxvt-unicode. |
|
|
931 | |
922 | =item $modifiermask = $term->ModLevel3Mask |
932 | =item $modifiermask = $term->ModLevel3Mask |
923 | |
933 | |
924 | =item $modifiermask = $term->ModMetaMask |
934 | =item $modifiermask = $term->ModMetaMask |
925 | |
935 | |
926 | =item $modifiermask = $term->ModNumLockMask |
936 | =item $modifiermask = $term->ModNumLockMask |
… | |
… | |
1168 | } |
1178 | } |
1169 | |
1179 | |
1170 | sub add_separator { |
1180 | sub add_separator { |
1171 | my ($self, $sep) = @_; |
1181 | my ($self, $sep) = @_; |
1172 | |
1182 | |
1173 | $sep ||= "═"; |
1183 | $sep ||= "="; |
1174 | |
1184 | |
1175 | $self->add_item ({ |
1185 | $self->add_item ({ |
1176 | rend => { normal => "\x1b[0;30;47m", hover => "\x1b[0;30;47m", active => "\x1b[0;30;47m" }, |
1186 | rend => { normal => "\x1b[0;30;47m", hover => "\x1b[0;30;47m", active => "\x1b[0;30;47m" }, |
1177 | text => "", |
1187 | text => "", |
1178 | render => sub { $sep x $self->{term}->ncol }, |
1188 | render => sub { $sep x $self->{term}->ncol }, |