--- rxvt-unicode/src/urxvt.pm 2006/01/10 19:46:28 1.76 +++ rxvt-unicode/src/urxvt.pm 2006/01/12 01:30:53 1.82 @@ -86,7 +86,9 @@ =item mark-urls -Uses per-line display filtering (C) to underline urls. +Uses per-line display filtering (C) to underline urls and +make them clickable. When clicked, the program specified in the resource +C (default C) will be started. =item block-graphics-to-ascii @@ -125,7 +127,7 @@ =item $text Rxvt-unicodes special way of encoding text, where one "unicode" character -always represents one screen cell. See L for a discussion of this format. +always represents one screen cell. See L for a discussion of this format. =item $string @@ -345,6 +347,27 @@ =back +=cut + +package urxvt; + +use utf8; +use strict; +use Carp (); +use Scalar::Util (); +use List::Util (); + +our $VERSION = 1; +our $TERM; +our @HOOKNAME; +our %HOOKTYPE = map +($HOOKNAME[$_] => $_), 0..$#HOOKNAME; +our %OPTION; + +our $LIBDIR; +our $RESNAME; +our $RESCLASS; +our $RXVTNAME; + =head2 Variables in the C Package =over 4 @@ -367,22 +390,12 @@ The current terminal. This variable stores the current C object, whenever a callback/hook is executing. -=item - =back =head2 Functions in the C Package =over 4 -=item $term = new urxvt [arg...] - -Creates a new terminal, very similar as if you had started it with -C. Croaks (and probably outputs an error message) -if the new instance couldn't be created. Returns C if the new -instance didn't initialise perl, and the terminal object otherwise. The -C and C hooks will be called during the call. - =item urxvt::fatal $errormessage Fatally aborts execution with the given error message. Avoid at all @@ -398,6 +411,8 @@ Using this function has the advantage that its output ends up in the correct place, e.g. on stderr of the connecting urxvtc client. +Messages have a size limit of 1023 bytes currently. + =item $is_safe = urxvt::safe Returns true when it is safe to do potentially unsafe things, such as @@ -472,25 +487,6 @@ =cut -package urxvt; - -use utf8; -use strict; -use Carp (); -use Scalar::Util (); -use List::Util (); - -our $VERSION = 1; -our $TERM; -our @HOOKNAME; -our %HOOKTYPE = map +($HOOKNAME[$_] => $_), 0..$#HOOKNAME; -our %OPTION; - -our $LIBDIR; -our $RESNAME; -our $RESCLASS; -our $RXVTNAME; - BEGIN { urxvt->bootstrap; @@ -502,6 +498,7 @@ urxvt::warn ($msg); }; + # %ENV is the original startup environment delete $ENV{IFS}; delete $ENV{CDPATH}; delete $ENV{BASH_ENV}; @@ -785,6 +782,25 @@ } } +=item $term = new urxvt::term $envhashref, $rxvtname, [arg...] + +Creates a new terminal, very similar as if you had started it with system +C<$rxvtname, arg...>. C<$envhashref> must be a reference to a C<%ENV>-like +hash which defines the environment of the new terminal. + +Croaks (and probably outputs an error message) if the new instance +couldn't be created. Returns C if the new instance didn't +initialise perl, and the terminal object otherwise. The C and +C hooks will be called during this call. + +=cut + +sub new { + my ($class, $env, @args) = @_; + + _new ([ map "$_=$env->{$_}", keys %$env ], @args); +} + =item $term->destroy Destroy the terminal object (close the window, free resources @@ -849,6 +865,17 @@ &urxvt::term::_resource } +=item $value = $term->x_resource ($pattern) + +Returns the X-Resource for the given pattern, excluding the program or +class name, i.e. C<< $term->x_resource ("boldFont") >> should return the +same value as used by this instance of rxvt-unicode. Returns C if no +resource with that pattern exists. + +This method should only be called during the C hook, as there is +only one resource database per display, and later invocations might return +the wrong resources. + =item $success = $term->parse_keysym ($keysym_spec, $command_string) Adds a keymap translation exactly as specified via a resource. See the @@ -1057,13 +1084,28 @@ Return various integers describing terminal characteristics. +=item $x_display = $term->display_id + +Return the DISPLAY used by rxvt-unicode. + =item $lc_ctype = $term->locale Returns the LC_CTYPE category string used by this rxvt-unicode. -=item $x_display = $term->display_id +=item $env = $term->env -Return the DISPLAY used by rxvt-unicode. +Returns a copy of the environment in effect for the terminal as a hashref +similar to C<\%ENV>. + +=cut + +sub env { + if (my $env = $_[0]->_env) { + +{ map /^([^=]+)(?:=(.*))?$/s && ($1 => $2), @$env } + } else { + +{ %ENV } + } +} =item $modifiermask = $term->ModLevel3Mask @@ -1394,12 +1436,16 @@ local $urxvt::popup::self = $self; - local $ENV{LC_ALL} = $self->{term}->locale; - - urxvt->new ("--perl-lib" => "", "--perl-ext-common" => "", "-pty-fd" => -1, "-sl" => 0, "-b" => 0, - "--transient-for" => $self->{term}->parent, - "-display" => $self->{term}->display_id, - "-pe" => "urxvt-popup") + my $env = $self->{term}->env; + # we can't hope to reproduce the locale algorithm, so nuke LC_ALL and set LC_CTYPE. + delete $env->{LC_ALL}; + $env->{LC_CTYPE} = $self->{term}->locale; + + urxvt::term->new ($env, $self->{term}->resource ("name"), + "--perl-lib" => "", "--perl-ext-common" => "", "-pty-fd" => -1, "-sl" => 0, "-b" => 0, + "--transient-for" => $self->{term}->parent, + "-display" => $self->{term}->display_id, + "-pe" => "urxvt-popup") or die "unable to create popup window\n"; } @@ -1410,6 +1456,8 @@ $self->{term}->ungrab; } +=back + =head2 The C Class This class implements timer watchers/events. Time is represented as a