… | |
… | |
943 | }; |
943 | }; |
944 | } |
944 | } |
945 | |
945 | |
946 | no warnings 'utf8'; |
946 | no warnings 'utf8'; |
947 | |
947 | |
|
|
948 | sub resource { |
|
|
949 | my ($term, $name, $isarg, $flag, $value) = @_; |
|
|
950 | |
|
|
951 | $term->scan_meta; |
|
|
952 | |
|
|
953 | warn "resourece<@_>\n";#d# |
|
|
954 | |
|
|
955 | 0 |
|
|
956 | } |
|
|
957 | |
|
|
958 | sub usage { |
|
|
959 | my ($term, $usage_type) = @_; |
|
|
960 | |
|
|
961 | $term->scan_meta; |
|
|
962 | |
|
|
963 | my $r = $term->{meta}{resource}; |
|
|
964 | |
|
|
965 | for my $regex (sort keys %$r) { |
|
|
966 | my ($ext, $type, $desc) = @{ $r->{$regex} }; |
|
|
967 | |
|
|
968 | $desc .= " (-pe $ext)"; |
|
|
969 | |
|
|
970 | if ($usage_type == 1) { |
|
|
971 | if ($type eq "boolean") { |
|
|
972 | urxvt::log sprintf " -%-20.20s %s\n", "/+$regex", $desc; |
|
|
973 | } else { |
|
|
974 | urxvt::log sprintf " -%-20.20s %s\n", "$regex $type", $desc; |
|
|
975 | } |
|
|
976 | } else { |
|
|
977 | urxvt::log sprintf " %-19.19s %s\n", "$regex:", $type; |
|
|
978 | } |
|
|
979 | } |
|
|
980 | } |
|
|
981 | |
948 | my $verbosity = $ENV{URXVT_PERL_VERBOSITY}; |
982 | my $verbosity = $ENV{URXVT_PERL_VERBOSITY}; |
949 | |
983 | |
950 | sub verbose { |
984 | sub verbose { |
951 | my ($level, $msg) = @_; |
985 | my ($level, $msg) = @_; |
952 | warn "$msg\n" if $level <= $verbosity; |
986 | warn "$msg\n" if $level <= $verbosity; |
… | |
… | |
988 | sub invoke { |
1022 | sub invoke { |
989 | local $TERM = shift; |
1023 | local $TERM = shift; |
990 | my $htype = shift; |
1024 | my $htype = shift; |
991 | |
1025 | |
992 | if ($htype == 0) { # INIT |
1026 | if ($htype == 0) { # INIT |
993 | my @dirs = ((split /:/, $TERM->resource ("perl_lib")), "$ENV{HOME}/.urxvt/ext", "$LIBDIR/perl"); |
1027 | my @dirs = $TERM->perl_libdirs; |
994 | |
1028 | |
995 | my %ext_arg; |
1029 | my %ext_arg; |
996 | |
1030 | |
997 | { |
1031 | { |
998 | my @init = @TERM_INIT; |
1032 | my @init = @TERM_INIT; |
… | |
… | |
1100 | while (my ($name, $cb) = each %hook) { |
1134 | while (my ($name, $cb) = each %hook) { |
1101 | my $htype = $HOOKTYPE{uc $name}; |
1135 | my $htype = $HOOKTYPE{uc $name}; |
1102 | defined $htype |
1136 | defined $htype |
1103 | or Carp::croak "unsupported hook type '$name'"; |
1137 | or Carp::croak "unsupported hook type '$name'"; |
1104 | |
1138 | |
1105 | $self->modify_should_invoke_count ($htype, +1) |
1139 | $self->set_should_invoke ($htype, +1) |
1106 | unless exists $self->{term}{_hook}[$htype]{$pkg}; |
1140 | unless exists $self->{term}{_hook}[$htype]{$pkg}; |
1107 | |
1141 | |
1108 | $self->{term}{_hook}[$htype]{$pkg} = $cb; |
1142 | $self->{term}{_hook}[$htype]{$pkg} = $cb; |
1109 | } |
1143 | } |
1110 | } |
1144 | } |
… | |
… | |
1116 | for my $name (@hook) { |
1150 | for my $name (@hook) { |
1117 | my $htype = $HOOKTYPE{uc $name}; |
1151 | my $htype = $HOOKTYPE{uc $name}; |
1118 | defined $htype |
1152 | defined $htype |
1119 | or Carp::croak "unsupported hook type '$name'"; |
1153 | or Carp::croak "unsupported hook type '$name'"; |
1120 | |
1154 | |
1121 | $self->modify_should_invoke_count ($htype, -1) |
1155 | $self->set_should_invoke ($htype, -1) |
1122 | if delete $self->{term}{_hook}[$htype]{$pkg}; |
1156 | if delete $self->{term}{_hook}[$htype]{$pkg}; |
1123 | } |
1157 | } |
1124 | } |
1158 | } |
1125 | |
1159 | |
1126 | our $AUTOLOAD; |
1160 | our $AUTOLOAD; |
… | |
… | |
1159 | =head2 The C<urxvt::anyevent> Class |
1193 | =head2 The C<urxvt::anyevent> Class |
1160 | |
1194 | |
1161 | The sole purpose of this class is to deliver an interface to the |
1195 | The sole purpose of this class is to deliver an interface to the |
1162 | C<AnyEvent> module - any module using it will work inside urxvt without |
1196 | C<AnyEvent> module - any module using it will work inside urxvt without |
1163 | further programming. The only exception is that you cannot wait on |
1197 | further programming. The only exception is that you cannot wait on |
1164 | condition variables, but non-blocking condvar use is ok. What this means |
1198 | condition variables, but non-blocking condvar use is ok. |
1165 | is that you cannot use blocking APIs, but the non-blocking variant should |
1199 | |
1166 | work. |
1200 | In practical terms this means is that you cannot use blocking APIs, but |
|
|
1201 | the non-blocking variant should work. |
1167 | |
1202 | |
1168 | =cut |
1203 | =cut |
1169 | |
1204 | |
1170 | our $VERSION = '5.23'; |
1205 | our $VERSION = '5.23'; |
1171 | |
1206 | |
… | |
… | |
1265 | $self->{_pkg}{$pkg} = $proxy; |
1300 | $self->{_pkg}{$pkg} = $proxy; |
1266 | |
1301 | |
1267 | for my $name (@HOOKNAME) { |
1302 | for my $name (@HOOKNAME) { |
1268 | if (my $ref = $pkg->can ("on_" . lc $name)) { |
1303 | if (my $ref = $pkg->can ("on_" . lc $name)) { |
1269 | $proxy->enable ($name => $ref); |
1304 | $proxy->enable ($name => $ref); |
|
|
1305 | } |
|
|
1306 | } |
|
|
1307 | } |
|
|
1308 | |
|
|
1309 | sub perl_libdirs { |
|
|
1310 | map { split /:/ } |
|
|
1311 | $_[0]->resource ("perl_lib"), |
|
|
1312 | $ENV{URXVT_PERL_LIB}, |
|
|
1313 | "$ENV{HOME}/.urxvt/ext", |
|
|
1314 | "$LIBDIR/perl" |
|
|
1315 | } |
|
|
1316 | |
|
|
1317 | sub scan_meta { |
|
|
1318 | my ($self) = @_; |
|
|
1319 | my @libdirs = perl_libdirs $self; |
|
|
1320 | |
|
|
1321 | return if $self->{meta_libdirs} eq join "\x00", @libdirs; |
|
|
1322 | |
|
|
1323 | my %meta; |
|
|
1324 | |
|
|
1325 | $self->{meta_libdirs} = join "\x00", @libdirs; |
|
|
1326 | $self->{meta} = \%meta; |
|
|
1327 | |
|
|
1328 | for my $dir (reverse @libdirs) { |
|
|
1329 | opendir my $fh, $dir |
|
|
1330 | or next; |
|
|
1331 | for my $ext (readdir $fh) { |
|
|
1332 | $ext ne "." |
|
|
1333 | and $ext ne ".." |
|
|
1334 | and open my $fh, "<", "$dir/$ext" |
|
|
1335 | or next; |
|
|
1336 | |
|
|
1337 | while (<$fh>) { |
|
|
1338 | if (/^#:META:RESOURCE:(.*)/) { |
|
|
1339 | my ($regex, $type, $desc) = split /:/, $1; |
|
|
1340 | $regex =~ s/\$\$/$ext/g; # $$ in regex == extension name |
|
|
1341 | $meta{resource}{$regex} = [$ext, $type, $desc]; |
|
|
1342 | } elsif (/^\s*(?:#|$)/) { |
|
|
1343 | # skip other comments and empty lines |
|
|
1344 | } else { |
|
|
1345 | last; # stop parsing on first non-empty non-comment line |
|
|
1346 | } |
|
|
1347 | } |
1270 | } |
1348 | } |
1271 | } |
1349 | } |
1272 | } |
1350 | } |
1273 | |
1351 | |
1274 | =item $term = new urxvt::term $envhashref, $rxvtname, [arg...] |
1352 | =item $term = new urxvt::term $envhashref, $rxvtname, [arg...] |