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.211 by root, Wed Jun 6 14:34:03 2012 UTC vs.
Revision 1.217 by root, Sun Jun 10 13:58:05 2012 UTC

20=head1 DESCRIPTION 20=head1 DESCRIPTION
21 21
22Every time a terminal object gets created, extension scripts specified via 22Every time a terminal object gets created, extension scripts specified via
23the C<perl> resource are loaded and associated with it. 23the C<perl> resource are loaded and associated with it.
24 24
25Scripts are compiled in a 'use strict' and 'use utf8' environment, and 25Scripts are compiled in a 'use strict "vars"' and 'use utf8' environment, and
26thus must be encoded as UTF-8. 26thus must be encoded as UTF-8.
27 27
28Each script will only ever be loaded once, even in @@RXVT_NAME@@d, where 28Each script will only ever be loaded once, even in @@RXVT_NAME@@d, where
29scripts will be shared (but not enabled) for all terminals. 29scripts will be shared (but not enabled) for all terminals.
30 30
755=cut 755=cut
756 756
757package urxvt; 757package urxvt;
758 758
759use utf8; 759use utf8;
760use strict; 760use strict 'vars';
761use Carp (); 761use Carp ();
762use Scalar::Util (); 762use Scalar::Util ();
763use List::Util (); 763use List::Util ();
764 764
765our $VERSION = 1; 765our $VERSION = 1;
946no warnings 'utf8'; 946no warnings 'utf8';
947 947
948sub parse_resource { 948sub parse_resource {
949 my ($term, $name, $isarg, $longopt, $flag, $value) = @_; 949 my ($term, $name, $isarg, $longopt, $flag, $value) = @_;
950 950
951 $name =~ y/-/./ if $isarg;
952
951 $term->scan_meta; 953 $term->scan_meta;
952 954
953 my $r = $term->{meta}{resource}; 955 my $r = $term->{meta}{resource};
956 keys %$r; # reste iterator
954 while (my ($pattern, $v) = each %$r) { 957 while (my ($pattern, $v) = each %$r) {
955 $name =~ y/-/./ if $isarg;
956
957 if ( 958 if (
958 $pattern =~ s/\*$// 959 $pattern =~ /\.$/
959 ? $pattern eq substr $name, 0, length $pattern 960 ? $pattern eq substr $name, 0, length $pattern
960 : $pattern eq $name 961 : $pattern eq $name
961 ) { 962 ) {
962 $name = "$urxvt::RESCLASS.$name"; 963 $name = "$urxvt::RESCLASS.$name";
963 964
964 push @TERM_EXT, $v->[0]; 965 push @{ $term->{perl_ext_3} }, $v->[0];
965 966
966 if ($v->[1] eq "boolean") { 967 if ($v->[1] eq "boolean") {
967 $term->put_option_db ($name, $flag ? "true" : "false"); 968 $term->put_option_db ($name, $flag ? "true" : "false");
968 return 1; 969 return 1;
969 } else { 970 } else {
988 989
989 $desc .= " (-pe $ext)"; 990 $desc .= " (-pe $ext)";
990 991
991 if ($usage_type == 1) { 992 if ($usage_type == 1) {
992 $pattern =~ y/./-/; 993 $pattern =~ y/./-/;
993 $pattern =~ s/\*/.../g; 994 $pattern =~ s/-$/-.../g;
994 995
995 if ($type eq "boolean") { 996 if ($type eq "boolean") {
996 urxvt::log sprintf " -%-30s %s\n", "/+$pattern", $desc; 997 urxvt::log sprintf " -%-30s %s\n", "/+$pattern", $desc;
997 } else { 998 } else {
998 urxvt::log sprintf " -%-30s %s\n", "$pattern $type", $desc; 999 urxvt::log sprintf " -%-30s %s\n", "$pattern $type", $desc;
999 } 1000 }
1000 } else { 1001 } else {
1002 $pattern =~ s/\.$/.*/g;
1001 urxvt::log sprintf " %-31s %s\n", "$pattern:", $type; 1003 urxvt::log sprintf " %-31s %s\n", "$pattern:", $type;
1002 } 1004 }
1003 } 1005 }
1004} 1006}
1005 1007
1022 $pkg =~ s/[^[:word:]]/_/g; 1024 $pkg =~ s/[^[:word:]]/_/g;
1023 $pkg = "urxvt::ext::$pkg"; 1025 $pkg = "urxvt::ext::$pkg";
1024 1026
1025 verbose 3, "loading extension '$path' into package '$pkg'"; 1027 verbose 3, "loading extension '$path' into package '$pkg'";
1026 1028
1029 (${"$pkg\::_NAME"} = $path) =~ s/^.*[\\\/]//; # hackish
1030
1027 open my $fh, "<:raw", $path 1031 open my $fh, "<:raw", $path
1028 or die "$path: $!"; 1032 or die "$path: $!";
1029 1033
1030 my $source = 1034 my $source =
1031 "package $pkg; use strict; use utf8; no warnings 'utf8';\n" 1035 "package $pkg; use strict 'vars'; use utf8; no warnings 'utf8';\n"
1032 . "#line 1 \"$path\"\n{\n" 1036 . "#line 1 \"$path\"\n{\n"
1033 . (do { local $/; <$fh> }) 1037 . (do { local $/; <$fh> })
1034 . "\n};\n1"; 1038 . "\n};\n1";
1035 1039
1036 eval $source 1040 eval $source
1059 my @pkg = @TERM_EXT; 1063 my @pkg = @TERM_EXT;
1060 @TERM_EXT = (); 1064 @TERM_EXT = ();
1061 $TERM->register_package ($_) for @pkg; 1065 $TERM->register_package ($_) for @pkg;
1062 } 1066 }
1063 1067
1068 for (
1069 @{ delete $TERM->{perl_ext_3} },
1064 for (grep $_, map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2) { 1070 grep $_, map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2
1071 ) {
1065 if ($_ eq "default") { 1072 if ($_ eq "default") {
1066 $ext_arg{$_} ||= [] for qw(selection option-popup selection-popup searchable-scrollback readline); 1073 $ext_arg{$_} ||= [] for qw(selection option-popup selection-popup searchable-scrollback readline);
1067 } elsif (/^-(.*)$/) { 1074 } elsif (/^-(.*)$/) {
1068 delete $ext_arg{$1}; 1075 delete $ext_arg{$1};
1069 } elsif (/^([^<]+)<(.*)>$/) { 1076 } elsif (/^([^<]+)<(.*)>$/) {
1145 } 1152 }
1146 } 1153 }
1147 ($mask, @color{qw(fg bg)}, \@failed) 1154 ($mask, @color{qw(fg bg)}, \@failed)
1148} 1155}
1149 1156
1150# urxvt::term::extension
1151
1152package urxvt::term::extension; 1157package urxvt::term::extension;
1153 1158
1154sub enable { 1159sub enable {
1155 my ($self, %hook) = @_; 1160 my ($self, %hook) = @_;
1156 my $pkg = $self->{_pkg}; 1161 my $pkg = $self->{_pkg};
1208 ${$_[0]}->(); 1213 ${$_[0]}->();
1209} 1214}
1210 1215
1211sub urxvt::destroy_hook(&) { 1216sub urxvt::destroy_hook(&) {
1212 bless \shift, urxvt::destroy_hook:: 1217 bless \shift, urxvt::destroy_hook::
1218}
1219
1220sub x_resource {
1221 my ($self, $name) = @_;
1222 $name =~ s/^%(\.|$)/$_[0]{_name}$1/;
1223 $self->{term}->x_resource ($name)
1224}
1225
1226sub x_resource_boolean {
1227 my ($self, $name) = @_;
1228 $name =~ s/^%(\.|$)/$_[0]{_name}$1/;
1229 $self->{term}->x_resource_boolean ($name)
1213} 1230}
1214 1231
1215package urxvt::anyevent; 1232package urxvt::anyevent;
1216 1233
1217=head2 The C<urxvt::anyevent> Class 1234=head2 The C<urxvt::anyevent> Class
1314 urxvt::verbose 6, "register package $pkg to $self"; 1331 urxvt::verbose 6, "register package $pkg to $self";
1315 1332
1316 @{"$pkg\::ISA"} = urxvt::term::extension::; 1333 @{"$pkg\::ISA"} = urxvt::term::extension::;
1317 1334
1318 my $proxy = bless { 1335 my $proxy = bless {
1319 _pkg => $pkg, 1336 _pkg => $pkg,
1337 _name => ${"$pkg\::_NAME"}, # hackish
1320 argv => $argv, 1338 argv => $argv,
1321 }, $pkg; 1339 }, $pkg;
1322 Scalar::Util::weaken ($proxy->{term} = $self); 1340 Scalar::Util::weaken ($proxy->{term} = $self);
1323 1341
1324 $self->{_pkg}{$pkg} = $proxy; 1342 $self->{_pkg}{$pkg} = $proxy;
1325 1343
1359 or next; 1377 or next;
1360 1378
1361 while (<$fh>) { 1379 while (<$fh>) {
1362 if (/^#:META:X_RESOURCE:(.*)/) { 1380 if (/^#:META:X_RESOURCE:(.*)/) {
1363 my ($pattern, $type, $desc) = split /:/, $1; 1381 my ($pattern, $type, $desc) = split /:/, $1;
1364 $pattern =~ s/^%\./$ext./g; # $$ in pattern == extension name 1382 $pattern =~ s/^%(\.|$)/$ext$1/g; # % in pattern == extension name
1365 if ($pattern =~ /[^a-zA-Z\*\.]/) { 1383 if ($pattern =~ /[^a-zA-Z0-9\-\.]/) {
1366 warn "$dir/$ext: meta resource '$pattern' contains illegal characters (not alphanumeric nor . nor *)\n"; 1384 warn "$dir/$ext: meta resource '$pattern' contains illegal characters (not alphanumeric nor . nor *)\n";
1367 } else { 1385 } else {
1368 $meta{resource}{$pattern} = [$ext, $type, $desc]; 1386 $meta{resource}{$pattern} = [$ext, $type, $desc];
1369 } 1387 }
1370 } elsif (/^\s*(?:#|$)/) { 1388 } elsif (/^\s*(?:#|$)/) {
1497Returns the X-Resource for the given pattern, excluding the program or 1515Returns the X-Resource for the given pattern, excluding the program or
1498class name, i.e. C<< $term->x_resource ("boldFont") >> should return the 1516class name, i.e. C<< $term->x_resource ("boldFont") >> should return the
1499same value as used by this instance of rxvt-unicode. Returns C<undef> if no 1517same value as used by this instance of rxvt-unicode. Returns C<undef> if no
1500resource with that pattern exists. 1518resource with that pattern exists.
1501 1519
1520Extensions that define extra resource or command line arguments also need
1521to call this method to access their values.
1522
1523If the method is called on an extension object (basically, from an
1524extension), then the special prefix C<%.> will be replaced by the name of
1525the extension and a dot, and the lone string C<%> will be replcaed by the
1526extension name itself. This makes it possible to code extensions so you
1527can rename them and get a new set of commandline switches and resources
1528without having to change the actual code.
1529
1502This method should only be called during the C<on_start> hook, as there is 1530This method should only be called during the C<on_start> hook, as there is
1503only one resource database per display, and later invocations might return 1531only one resource database per display, and later invocations might return
1504the wrong resources. 1532the wrong resources.
1505 1533
1506=item $value = $term->x_resource_boolean ($pattern) 1534=item $value = $term->x_resource_boolean ($pattern)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines