… | |
… | |
20 | =head1 DESCRIPTION |
20 | =head1 DESCRIPTION |
21 | |
21 | |
22 | Every time a terminal object gets created, extension scripts specified via |
22 | Every time a terminal object gets created, extension scripts specified via |
23 | the C<perl> resource are loaded and associated with it. |
23 | the C<perl> resource are loaded and associated with it. |
24 | |
24 | |
25 | Scripts are compiled in a 'use strict' and 'use utf8' environment, and |
25 | Scripts are compiled in a 'use strict "vars"' and 'use utf8' environment, and |
26 | thus must be encoded as UTF-8. |
26 | thus must be encoded as UTF-8. |
27 | |
27 | |
28 | Each script will only ever be loaded once, even in @@RXVT_NAME@@d, where |
28 | Each script will only ever be loaded once, even in @@RXVT_NAME@@d, where |
29 | scripts will be shared (but not enabled) for all terminals. |
29 | scripts will be shared (but not enabled) for all terminals. |
30 | |
30 | |
… | |
… | |
755 | =cut |
755 | =cut |
756 | |
756 | |
757 | package urxvt; |
757 | package urxvt; |
758 | |
758 | |
759 | use utf8; |
759 | use utf8; |
760 | use strict; |
760 | use strict 'vars'; |
761 | use Carp (); |
761 | use Carp (); |
762 | use Scalar::Util (); |
762 | use Scalar::Util (); |
763 | use List::Util (); |
763 | use List::Util (); |
764 | |
764 | |
765 | our $VERSION = 1; |
765 | our $VERSION = 1; |
… | |
… | |
946 | no warnings 'utf8'; |
946 | no warnings 'utf8'; |
947 | |
947 | |
948 | sub parse_resource { |
948 | sub 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 =~ /\.$/ |
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 { |
… | |
… | |
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 | |
|
|
1152 | package urxvt::term::extension; |
1157 | package urxvt::term::extension; |
1153 | |
1158 | |
1154 | sub enable { |
1159 | sub 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 | |
1211 | sub urxvt::destroy_hook(&) { |
1216 | sub urxvt::destroy_hook(&) { |
1212 | bless \shift, urxvt::destroy_hook:: |
1217 | bless \shift, urxvt::destroy_hook:: |
|
|
1218 | } |
|
|
1219 | |
|
|
1220 | sub x_resource { |
|
|
1221 | my ($self, $name) = @_; |
|
|
1222 | $name =~ s/^%(\.|$)/$_[0]{_name}$1/; |
|
|
1223 | $self->{term}->x_resource ($name) |
|
|
1224 | } |
|
|
1225 | |
|
|
1226 | sub x_resource_boolean { |
|
|
1227 | my ($self, $name) = @_; |
|
|
1228 | $name =~ s/^%(\.|$)/$_[0]{_name}$1/; |
|
|
1229 | $self->{term}->x_resource_boolean ($name) |
1213 | } |
1230 | } |
1214 | |
1231 | |
1215 | package urxvt::anyevent; |
1232 | package 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*(?:#|$)/) { |
… | |
… | |
1497 | Returns the X-Resource for the given pattern, excluding the program or |
1515 | Returns the X-Resource for the given pattern, excluding the program or |
1498 | class name, i.e. C<< $term->x_resource ("boldFont") >> should return the |
1516 | class name, i.e. C<< $term->x_resource ("boldFont") >> should return the |
1499 | same value as used by this instance of rxvt-unicode. Returns C<undef> if no |
1517 | same value as used by this instance of rxvt-unicode. Returns C<undef> if no |
1500 | resource with that pattern exists. |
1518 | resource with that pattern exists. |
1501 | |
1519 | |
|
|
1520 | Extensions that define extra resource or command line arguments also need |
|
|
1521 | to call this method to access their values. |
|
|
1522 | |
|
|
1523 | If the method is called on an extension object (basically, from an |
|
|
1524 | extension), then the special prefix C<%.> will be replaced by the name of |
|
|
1525 | the extension and a dot, and the lone string C<%> will be replcaed by the |
|
|
1526 | extension name itself. This makes it possible to code extensions so you |
|
|
1527 | can rename them and get a new set of commandline switches and resources |
|
|
1528 | without having to change the actual code. |
|
|
1529 | |
1502 | This method should only be called during the C<on_start> hook, as there is |
1530 | This method should only be called during the C<on_start> hook, as there is |
1503 | only one resource database per display, and later invocations might return |
1531 | only one resource database per display, and later invocations might return |
1504 | the wrong resources. |
1532 | the wrong resources. |
1505 | |
1533 | |
1506 | =item $value = $term->x_resource_boolean ($pattern) |
1534 | =item $value = $term->x_resource_boolean ($pattern) |