--- rxvt-unicode/src/urxvt.pm 2012/06/05 19:32:29 1.205 +++ rxvt-unicode/src/urxvt.pm 2012/06/06 15:26:32 1.214 @@ -764,8 +764,8 @@ our $VERSION = 1; our $TERM; -our @TERM_INIT; -our @TERM_EXT; +our @TERM_INIT; # should go, prevents async I/O etc. +our @TERM_EXT; # should go, prevents async I/O etc. our @HOOKNAME; our %HOOKTYPE = map +($HOOKNAME[$_] => $_), 0..$#HOOKNAME; our %OPTION; @@ -945,6 +945,65 @@ no warnings 'utf8'; +sub parse_resource { + my ($term, $name, $isarg, $longopt, $flag, $value) = @_; + + $term->scan_meta; + + my $r = $term->{meta}{resource}; + while (my ($pattern, $v) = each %$r) { + $name =~ y/-/./ if $isarg; + + if ( + $pattern =~ /\.$/ + ? $pattern eq substr $name, 0, length $pattern + : $pattern eq $name + ) { + $name = "$urxvt::RESCLASS.$name"; + + push @TERM_EXT, $v->[0]; + + if ($v->[1] eq "boolean") { + $term->put_option_db ($name, $flag ? "true" : "false"); + return 1; + } else { + $term->put_option_db ($name, $value); + return 1 + 2; + } + } + } + + 0 +} + +sub usage { + my ($term, $usage_type) = @_; + + $term->scan_meta; + + my $r = $term->{meta}{resource}; + + for my $pattern (sort keys %$r) { + my ($ext, $type, $desc) = @{ $r->{$pattern} }; + + $desc .= " (-pe $ext)"; + + if ($usage_type == 1) { + $pattern =~ y/./-/; + $pattern =~ s/-$/-.../g; + + if ($type eq "boolean") { + urxvt::log sprintf " -%-30s %s\n", "/+$pattern", $desc; + } else { + urxvt::log sprintf " -%-30s %s\n", "$pattern $type", $desc; + } + } else { + $pattern =~ s/\.$/.*/g; + urxvt::log sprintf " %-31s %s\n", "$pattern:", $type; + } + } +} + my $verbosity = $ENV{URXVT_PERL_VERBOSITY}; sub verbose { @@ -990,7 +1049,7 @@ my $htype = shift; if ($htype == 0) { # INIT - my @dirs = ((split /:/, $TERM->resource ("perl_lib")), "$ENV{HOME}/.urxvt/ext", "$LIBDIR/perl"); + my @dirs = $TERM->perl_libdirs; my %ext_arg; @@ -1102,7 +1161,7 @@ defined $htype or Carp::croak "unsupported hook type '$name'"; - $self->modify_should_invoke_count ($htype, +1) + $self->set_should_invoke ($htype, +1) unless exists $self->{term}{_hook}[$htype]{$pkg}; $self->{term}{_hook}[$htype]{$pkg} = $cb; @@ -1118,7 +1177,7 @@ defined $htype or Carp::croak "unsupported hook type '$name'"; - $self->modify_should_invoke_count ($htype, -1) + $self->set_should_invoke ($htype, -1) if delete $self->{term}{_hook}[$htype]{$pkg}; } } @@ -1161,9 +1220,10 @@ The sole purpose of this class is to deliver an interface to the C module - any module using it will work inside urxvt without further programming. The only exception is that you cannot wait on -condition variables, but non-blocking condvar use is ok. What this means -is that you cannot use blocking APIs, but the non-blocking variant should -work. +condition variables, but non-blocking condvar use is ok. + +In practical terms this means is that you cannot use blocking APIs, but +the non-blocking variant should work. =cut @@ -1271,6 +1331,53 @@ } } +sub perl_libdirs { + map { split /:/ } + $_[0]->resource ("perl_lib"), + $ENV{URXVT_PERL_LIB}, + "$ENV{HOME}/.urxvt/ext", + "$LIBDIR/perl" +} + +sub scan_meta { + my ($self) = @_; + my @libdirs = perl_libdirs $self; + + return if $self->{meta_libdirs} eq join "\x00", @libdirs; + + my %meta; + + $self->{meta_libdirs} = join "\x00", @libdirs; + $self->{meta} = \%meta; + + for my $dir (reverse @libdirs) { + opendir my $fh, $dir + or next; + for my $ext (readdir $fh) { + $ext ne "." + and $ext ne ".." + and open my $fh, "<", "$dir/$ext" + or next; + + while (<$fh>) { + if (/^#:META:X_RESOURCE:(.*)/) { + my ($pattern, $type, $desc) = split /:/, $1; + $pattern =~ s/^%(\.|$)/$ext$1/g; # % in pattern == extension name + if ($pattern =~ /[^a-zA-Z0-9\-\.]/) { + warn "$dir/$ext: meta resource '$pattern' contains illegal characters (not alphanumeric nor . nor *)\n"; + } else { + $meta{resource}{$pattern} = [$ext, $type, $desc]; + } + } elsif (/^\s*(?:#|$)/) { + # skip other comments and empty lines + } else { + last; # stop parsing on first non-empty non-comment line + } + } + } + } +} + =item $term = new urxvt::term $envhashref, $rxvtname, [arg...] Creates a new terminal, very similar as if you had started it with system @@ -1397,6 +1504,22 @@ only one resource database per display, and later invocations might return the wrong resources. +=item $value = $term->x_resource_boolean ($pattern) + +Like C, above, but interprets the string value as a boolean +and returns C<1> for true values, C<0> for false values and C if +the resource or option isn't specified. + +You should always use this method to parse boolean resources. + +=cut + +sub x_resource_boolean { + my $res = &x_resource; + + $res =~ /^\s*(?:true|yes|on|1)\s*$/i ? 1 : defined $res && 0 +} + =item $success = $term->parse_keysym ($key, $octets) Adds a key binding exactly as specified via a resource. See the