--- rxvt-unicode/src/urxvt.pm 2006/01/21 14:49:18 1.123 +++ rxvt-unicode/src/urxvt.pm 2006/07/03 19:11:41 1.141 @@ -69,6 +69,13 @@ URxvt.selection.pattern-0: \\|([^|]+)\\| +Another example: Programs I use often output "absolute path: " at the +beginning of a line when they process multiple files. The following +pattern matches the filename (note, there is a single space at the very +end): + + URxvt.selection.pattern-0: ^(/[^:]+):\ + You can look at the source of the selection extension to see more interesting uses, such as parsing a line from beginning to end. @@ -89,6 +96,23 @@ Binds a popup menu to Ctrl-Button2 that lets you toggle (some) options at runtime. +Other extensions can extend this popup menu by pushing a code reference +onto C<@{ $term->{option_popup_hook} }>, which gets called whenever the +popup is being displayed. + +It's sole argument is the popup menu, which can be modified. It should +either return nothing or a string, the initial boolean value and a code +reference. The string will be used as button text and the code reference +will be called when the toggle changes, with the new boolean value as +first argument. + +The following will add an entry C that changes +C<$self->{myoption}>: + + push @{ $self->{term}{option_popup_hook} }, sub { + ("my option" => $myoption, sub { $self->{myoption} = $_[0] }) + }; + =item selection-popup (enabled by default) Binds a popup menu to Ctrl-Button3 that lets you convert the selection @@ -96,8 +120,8 @@ evaluation, web-browser starting etc.), depending on content. Other extensions can extend this popup menu by pushing a code reference -onto C<@{ $term->{selection_popup_hook} }>, that is called whenever the -popup is displayed. +onto C<@{ $term->{selection_popup_hook} }>, which gets called whenever the +popup is being displayed. It's sole argument is the popup menu, which can be modified. The selection is in C<$_>, which can be used to decide wether to add something or not. @@ -131,8 +155,8 @@ =item readline (enabled by default) -A support package that tries to make editing with readline easier. At the -moment, it reacts to clicking with the left mouse button by trying to +A support package that tries to make editing with readline easier. At +the moment, it reacts to clicking shift-left mouse button by trying to move the text cursor to this position. It does so by generating as many cursor-left or cursor-right keypresses as required (the this only works for programs that correctly support wide characters). @@ -141,11 +165,13 @@ =over 4 -=item - the mouse is on the same (multi-row-) line as the text cursor. +=item - the tty is in ICANON state. + +=item - the text cursor is visible. =item - the primary screen is currently being displayed. -=item - the text cursor is visible. +=item - the mouse is on the same (multi-row-) line as the text cursor. =back @@ -198,6 +224,18 @@ B will switch to the tab left or right of the current one, while B creates a new tab. +The tabbar itself can be configured similarly to a normal terminal, but +with a resource class of C. In addition, it supports the +following four resources (shown with defaults): + + URxvt.tabbed.tabbar-fg: + URxvt.tabbed.tabbar-bg: + URxvt.tabbed.tab-fg: + URxvt.tabbed.tab-bg: + +See I in the @@RXVT_NAME@@(1) manpage for valid +indices. + =item mark-urls Uses per-line display filtering (C) to underline urls and @@ -205,17 +243,30 @@ resource C (default C) will be started with the URL as first argument. +=item xim-onthespot + +This (experimental) perl extension implements OnTheSpot editing. It does +not work perfectly, and some input methods don't seem to work well with +OnTheSpot editing in general, but it seems to work at leats for SCIM and +kinput2. + +You enable it by specifying this extension and a preedit style of +C, i.e.: + + @@RXVT_NAME@@ -pt OnTheSpot -pe xim-onthespot + =item automove-background -This is basically a one-line extension that dynamically changes the background pixmap offset -to the window position, in effect creating the same effect as pseudo transparency with -a custom pixmap. No scaling is supported in this mode. Exmaple: +This is basically a very small extension that dynamically changes the +background pixmap offset to the window position, in effect creating the +same effect as pseudo transparency with a custom pixmap. No scaling is +supported in this mode. Exmaple: @@RXVT_NAME@@ -pixmap background.xpm -pe automove-background =item block-graphics-to-ascii -A not very useful example of filtering all text output to the terminal, +A not very useful example of filtering all text output to the terminal by replacing all line-drawing characters (U+2500 .. U+259F) by a similar-looking ascii character. @@ -223,11 +274,25 @@ Displays a digital clock using the built-in overlay. -=item example-refresh-hooks +=item remote-clipboard -Displays a very simple digital clock in the upper right corner of the -window. Illustrates overwriting the refresh callbacks to create your own -overlays or changes. +Somewhat of a misnomer, this extension adds two menu entries to the +selection popup that allows one ti run external commands to store the +selection somewhere and fetch it again. + +We use it to implement a "distributed selection mechanism", which just +means that one command uploads the file to a remote server, and another +reads it. + +The commands can be set using the C and +C resources. The first should read the +selection to store from STDIN (always in UTF-8), the second should provide +the selection data on STDOUT (also in UTF-8). + +The defaults (which are likely useless to you) use rsh and cat: + + URxvt.remote-selection.store: rsh ruth 'cat >/tmp/distributed-selection' + URxvt.remote-selection.fetch: rsh ruth 'cat /tmp/distributed-selection' =item selection-pastebin @@ -258,6 +323,12 @@ URxvt.selection-pastebin.url: http://www.ta-sa.org/files/txt/% +=item example-refresh-hooks + +Displays a very simple digital clock in the upper right corner of the +window. Illustrates overwriting the refresh callbacks to create your own +overlays or changes. + =back =head1 API DOCUMENTATION @@ -300,7 +371,7 @@ =head2 Extension Objects -Very perl extension is a perl class. A separate perl object is created +Every perl extension is a perl class. A separate perl object is created for each terminal and each extension and passed as the first parameter to hooks. So extensions can use their C<$self> object without having to think about other extensions, with the exception of methods and members that @@ -363,9 +434,8 @@ =item on_destroy $term -Called whenever something tries to destroy terminal, before doing anything -yet. If this hook returns true, then destruction is skipped, but this is -rarely a good idea. +Called whenever something tries to destroy terminal, when the terminal is +still fully functional (not for long, though). =item on_reset $term @@ -426,7 +496,17 @@ $nrow - 1) represent the lines to be scrolled out). C<$saved> is the total number of lines that will be in the scrollback buffer. -=item on_osc_seq $term, $string +=item on_osc_seq $term, $op, $args + +Called on every OSC sequence and can be used to suppress it or modify its +behaviour. The default should be to return an empty list. A true value +suppresses execution of the request completely. Make sure you don't get +confused by recursive invocations when you output an osc sequence within +this callback. + +C should be used for new behaviour. + +=item on_osc_seq_perl $term, $string Called whenever the B command sequence (OSC = operating system command) is processed. Cursor position and other state @@ -477,12 +557,21 @@ Called just after the screen gets redrawn. See C. -=item on_keyboard_command $term, $string +=item on_user_command $term, $string -Called whenever the user presses a key combination that has a -C action bound to it (see description of the B +Called whenever the a user-configured event is being activated (e.g. via +a C action bound to a key, see description of the B resource in the @@RXVT_NAME@@(1) manpage). +The event is simply the action string. This interface is assumed to change +slightly in the future. + +=item on_resize_all_windows $tern, $new_width, $new_height + +Called just after the new window size has been calculcated, but before +windows are actually being resized or hints are being set. If this hook +returns TRUE, setting of the window hints is being skipped. + =item on_x_event $term, $event Called on every X event received on the vt window (and possibly other @@ -563,7 +652,7 @@ our $RESCLASS; our $RXVTNAME; -our $NOCHAR = chr 0xfffe; +our $NOCHAR = chr 0xffff; =head2 Variables in the C Package @@ -626,6 +715,13 @@ Messages have a size limit of 1023 bytes currently. +=item @terms = urxvt::termlist + +Returns all urxvt::term objects that exist in this process, regardless of +wether they are started, being destroyed etc., so be careful. Only term +objects that have perl extensions attached will be returned (because there +is no urxvt::term objet associated with others). + =item $time = urxvt::NOW Returns the "current time" (as per the event loop). @@ -693,6 +789,8 @@ =item $rend = urxvt::SET_BGCOLOR $rend, $new_colour +=item $rend = urxvt::SET_COLOR $rend, $new_fg, $new_bg + Replace the foreground/background colour in the rendition mask with the specified one. @@ -720,6 +818,8 @@ }; } +no warnings 'utf8'; + my $verbosity = $ENV{URXVT_PERL_VERBOSITY}; sub verbose { @@ -745,7 +845,7 @@ or die "$path: $!"; my $source = - "package $pkg; use strict; use utf8;\n" + "package $pkg; use strict; use utf8; no warnings 'utf8';\n" . "#line 1 \"$path\"\n{\n" . (do { local $/; <$fh> }) . "\n};\n1"; @@ -790,11 +890,11 @@ } } - while (my ($ext, $argv) = each %ext_arg) { + for my $ext (sort keys %ext_arg) { my @files = grep -f $_, map "$_/$ext", @dirs; if (@files) { - $TERM->register_package (extension_package $files[0], $argv); + $TERM->register_package (extension_package $files[0], $ext_arg{$ext}); } else { warn "perl extension '$ext' not found in perl library search path\n"; } @@ -810,10 +910,8 @@ verbose 10, "$HOOKNAME[$htype] (" . (join ", ", $TERM, @_) . ")" if $verbosity >= 10; - keys %$cb; - - while (my ($pkg, $cb) = each %$cb) { - my $retval_ = eval { $cb->($TERM->{_pkg}{$pkg}, @_) }; + for my $pkg (keys %$cb) { + my $retval_ = eval { $cb->{$pkg}->($TERM->{_pkg}{$pkg}, @_) }; $retval ||= $retval_; if ($@) { @@ -837,6 +935,10 @@ $retval } +sub SET_COLOR($$$) { + SET_BGCOLOR (SET_FGCOLOR ($_[0], $_[1]), $_[2]) +} + # urxvt::term::extension package urxvt::term::extension; @@ -1013,14 +1115,18 @@ 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. +C hooks will be called before this call returns, and are free to +refer to global data (which is race free). =cut sub new { my ($class, $env, @args) = @_; - _new ([ map "$_=$env->{$_}", keys %$env ], @args); + $env or Carp::croak "environment hash missing in call to urxvt::term->new"; + @args or Carp::croak "name argument missing in call to urxvt::term->new"; + + _new ([ map "$_=$env->{$_}", keys %$env ], \@args); } =item $term->destroy @@ -1310,6 +1416,11 @@ description of C<< urxvt::timer->events >>. Make sure to always restore the previous value. +=item $fd = $term->pty_fd + +Returns the master file descriptor for the pty in use, or C<-1> if no pty +is used. + =item $windowid = $term->parent Return the window id of the toplevel window. @@ -1325,6 +1436,16 @@ $term->vt_emask_add (urxvt::PointerMotionMask); +=item $term->focus_in + +=item $term->focus_out + +=item $term->key_press ($state, $keycode[, $time]) + +=item $term->key_release ($state, $keycode[, $time]) + +Deliver various fake events to to terminal. + =item $window_width = $term->width =item $window_height = $term->height @@ -1364,14 +1485,19 @@ Returns a copy of the environment in effect for the terminal as a hashref similar to C<\%ENV>. +=item @envv = $term->envv + +Returns the environment as array of strings of the form C. + +=item @argv = $term->argv + +Return the argument vector as this terminal, similar to @ARGV, but +includes the program name as first element. + =cut sub env { - if (my $env = $_[0]->_env) { - +{ map /^([^=]+)(?:=(.*))?$/s && ($1 => $2), @$env } - } else { - +{ %ENV } - } + +{ map /^([^=]+)(?:=(.*))?$/s && ($1 => $2), $_[0]->envv } } =item $modifiermask = $term->ModLevel3Mask @@ -1418,8 +1544,8 @@ to replace only parts of a line. The font index in the rendition will automatically be updated. -C<$text> is in a special encoding: tabs and wide characters that use -more than one cell when displayed are padded with C<$urxvt::NOCHAR> +C<$text> is in a special encoding: tabs and wide characters that use more +than one cell when displayed are padded with C<$urxvt::NOCHAR> (chr 65535) characters. Characters with combining characters and other characters that do not fit into the normal tetx encoding will be replaced with characters in the private use area. @@ -1579,9 +1705,12 @@ Converts rxvt-unicodes text reprsentation into a perl string. See C<< $term->ROW_t >> for details. -=item $success = $term->grab_button ($button, $modifiermask) +=item $success = $term->grab_button ($button, $modifiermask[, $window = $term->vt]) + +=item $term->ungrab_button ($button, $modifiermask[, $window = $term->vt]) -Registers a synchronous button grab. See the XGrabButton manpage. +Register/unregister a synchronous button grab. See the XGrabButton +manpage. =item $success = $term->grab ($eventtime[, $sync]) @@ -1709,16 +1838,16 @@ $self->add_item ({ type => "button", text => $text, activate => $cb}); } -=item $popup->add_toggle ($text, $cb, $initial_value) +=item $popup->add_toggle ($text, $initial_value, $cb) -Adds a toggle/checkbox item to the popup. Teh callback gets called -whenever it gets toggled, with a boolean indicating its value as its first -argument. +Adds a toggle/checkbox item to the popup. The callback gets called +whenever it gets toggled, with a boolean indicating its new value as its +first argument. =cut sub add_toggle { - my ($self, $text, $cb, $value) = @_; + my ($self, $text, $value, $cb) = @_; my $item; $item = { type => "button",