--- rxvt-unicode/src/urxvt.pm 2006/01/21 08:07:38 1.122 +++ rxvt-unicode/src/urxvt.pm 2006/02/06 06:14:08 1.133 @@ -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. @@ -129,6 +153,31 @@ additionally stores the first match in the current line into the primary selection. +=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 +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). + +To avoid too many false positives, this is only done when: + +=over 4 + +=item - the tty is in ICANON state. + +=item - the text cursor is visible. + +=item - the primary screen is currently being displayed. + +=item - the mouse is on the same (multi-row-) line as the text cursor. + +=back + +The normal selection mechanism isn't disabled, so quick successive clicks +might interfere with selection creation in harmless ways. + =item selection-autotransform This selection allows you to do automatic transforms on a selection @@ -164,29 +213,6 @@ every error message as a selection pattern, and the second line transforms the message into vi commands to load the file. -=item readline - -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 -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). - -To avoid too many false positives, this is only done when: - -=over 4 - -=item - the mouse is on the same (multi-row-) line as the text cursor. - -=item - the primary screen is currently being displayed. - -=item - the text cursor is visible. - -=back - -The normal selection mechanism isn't disabled, so quick successive clicks -might interfere with selection creation in harmless ways. - =item tabbed This transforms the terminal into a tabbar with additional terminals, that @@ -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,6 +243,18 @@ 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 @@ -223,11 +273,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 +322,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 @@ -363,9 +433,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 @@ -477,12 +546,15 @@ 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_x_event $term, $event Called on every X event received on the vt window (and possibly other @@ -563,7 +635,7 @@ our $RESCLASS; our $RXVTNAME; -our $NOCHAR = chr 0xfffe; +our $NOCHAR = chr 0xffff; =head2 Variables in the C Package @@ -626,6 +698,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 +772,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 +801,8 @@ }; } +no warnings 'utf8'; + my $verbosity = $ENV{URXVT_PERL_VERBOSITY}; sub verbose { @@ -745,7 +828,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"; @@ -780,7 +863,7 @@ for (grep $_, map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2) { if ($_ eq "default") { - $ext_arg{$_} ||= [] for qw(selection option-popup selection-popup searchable-scrollback); + $ext_arg{$_} ||= [] for qw(selection option-popup selection-popup searchable-scrollback readline); } elsif (/^-(.*)$/) { delete $ext_arg{$1}; } elsif (/^([^<]+)<(.*)>$/) { @@ -790,11 +873,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"; } @@ -837,6 +920,10 @@ $retval } +sub SET_COLOR($$$) { + SET_BGCOLOR (SET_FGCOLOR ($_[0], $_[1]), $_[2]) +} + # urxvt::term::extension package urxvt::term::extension; @@ -1013,14 +1100,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 +1401,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 +1421,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 @@ -1418,8 +1524,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 +1685,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 +1818,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",