--- rxvt-unicode/src/urxvt.pm 2006/08/17 21:56:11 1.146 +++ rxvt-unicode/src/urxvt.pm 2010/12/18 15:37:10 1.189 @@ -28,6 +28,9 @@ Each script will only ever be loaded once, even in @@RXVT_NAME@@d, where scripts will be shared (but not enabled) for all terminals. +You can disable the embedded perl interpreter by setting both "perl-ext" +and "perl-ext-common" resources to the empty string. + =head1 PREPACKAGED EXTENSIONS This section describes the extensions delivered with this release. You can @@ -39,7 +42,7 @@ Or by adding them to the resource for extensions loaded by default: - URxvt.perl-ext-common: default,automove-background,selection-autotransform + URxvt.perl-ext-common: default,selection-autotransform =over 4 @@ -100,14 +103,14 @@ 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 +Its 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}>: +C<< $self->{myoption} >>: push @{ $self->{term}{option_popup_hook} }, sub { ("my option" => $myoption, sub { $self->{myoption} = $_[0] }) @@ -123,7 +126,7 @@ 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 +Its sole argument is the popup menu, which can be modified. The selection is in C<$_>, which can be used to decide whether to add something or not. It should either return nothing or a string and a code reference. The string will be used as button text and the code reference will be called @@ -134,7 +137,7 @@ Cs: push @{ $self->{term}{selection_popup_hook} }, sub { - /a/ ? ("a to be" => sub { s/a/b/g } + /a/ ? ("a to b" => sub { s/a/b/g } : () }; @@ -151,7 +154,7 @@ bottom. C leaves search mode and returns to the point where search was started, while C or C stay at the current position and additionally stores the first match in the current line into the primary -selection. +selection if the C modifier is active. The regex defaults to "(?i)", resulting in a case-insensitive search. To get a case-sensitive search you can delete this prefix using C @@ -164,7 +167,7 @@ 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 +cursor-left or cursor-right keypresses as required (this only works for programs that correctly support wide characters). To avoid too many false positives, this is only done when: @@ -242,18 +245,40 @@ See I in the @@RXVT_NAME@@(1) manpage for valid indices. -=item mark-urls +=item matcher -Uses per-line display filtering (C) to underline urls and -make them clickable. When middle-clicked, the program specified in the -resource C (default C) will be started with -the URL as first argument. +Uses per-line display filtering (C) to underline text +matching a certain pattern and make it clickable. When clicked with the +mouse button specified in the C resource (default 2, or +middle), the program specified in the C resource +(default, the C resource, C) will be started +with the matched text as first argument. The default configuration is +suitable for matching URLs and launching a web browser, like the +former "mark-urls" extension. + +The default pattern to match URLs can be overridden with the +C resource, and additional patterns can be specified +with numbered patterns, in a manner similar to the "selection" extension. +The launcher can also be overridden on a per-pattern basis. + +It is possible to activate the most recently seen match from the keyboard. +Simply bind a keysym to "perl:matcher" as seen in the example below. + +Example configuration: + + URxvt.perl-ext: default,matcher + URxvt.urlLauncher: sensible-browser + URxvt.keysym.C-Delete: perl:matcher + URxvt.matcher.button: 1 + URxvt.matcher.pattern.1: \\bwww\\.[\\w-]+\\.[\\w./?&@#-]*[\\w/-] + URxvt.matcher.pattern.2: \\B(/\\S+?):(\\d+)(?=:|$) + URxvt.matcher.launcher.2: gvim +$2 $1 =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 +OnTheSpot editing in general, but it seems to work at least for SCIM and kinput2. You enable it by specifying this extension and a preedit style of @@ -271,7 +296,7 @@ Initially, the window will not be shown when using this extension. -This is useful if you need a single terminal thats not using any desktop +This is useful if you need a single terminal that is not using any desktop space most of the time but is quickly available at the press of a key. The accelerator key is grabbed regardless of any modifiers, so this @@ -280,14 +305,11 @@ If you want a quake-like animation, tell your window manager to do so (fvwm can do it). -=item automove-background - -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. Example: +=item overlay-osc - @@RXVT_NAME@@ -pixmap background.xpm -pe automove-background +This extension implements some OSC commands to display timed popups on the +screen - useful for status displays from within scripts. You have to read +the sources for more info. =item block-graphics-to-ascii @@ -302,7 +324,7 @@ =item remote-clipboard 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 popup that allows one to run external commands to store the selection somewhere and fetch it again. We use it to implement a "distributed selection mechanism", which just @@ -321,7 +343,7 @@ =item selection-pastebin -This is a little rarely useful extension that Uploads the selection as +This is a little rarely useful extension that uploads the selection as textfile to a remote site (or does other things). (The implementation is not currently secure for use in a multiuser environment as it writes to F directly.). @@ -350,15 +372,34 @@ I xrdb uses the C preprocessor, which might interpret the double C characters as comment start. Use C<\057\057> instead, -which works regardless of wether xrdb is used to parse the resource file +which works regardless of whether xrdb is used to parse the resource file or not. +=item macosx-clipboard and macosx-clipboard-native + +These two modules implement an extended clipboard for Mac OS X. They are +used like this: + + URxvt.perl-ext-common: default,macosx-clipboard + URxvt.keysym.M-c: perl:macosx-clipboard:copy + URxvt.keysym.M-v: perl:macosx-clipboard:paste + +The difference between them is that the native variant requires a +perl from apple's devkit or so, and C requires the +C module, works with other perls, has fewer bugs, is +simpler etc. etc. + =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. +=item confirm-paste + +Displays a confirmation dialog when a paste containing at least a full +line is detected. + =back =head1 API DOCUMENTATION @@ -383,7 +424,7 @@ =item $text -Rxvt-unicodes special way of encoding text, where one "unicode" character +Rxvt-unicode's special way of encoding text, where one "unicode" character always represents one screen cell. See L for a discussion of this format. =item $string @@ -527,29 +568,42 @@ $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, $op, $args +=item on_osc_seq $term, $op, $args, $resp 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 +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 +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 +=item on_osc_seq_perl $term, $args, $resp Called whenever the B command sequence (OSC = operating system command) is processed. Cursor position and other state information is up-to-date when this happens. For interoperability, the -string should start with the extension name and a colon, to distinguish -it from commands for other extensions, and this might be enforced in the -future. +string should start with the extension name (sans -osc) and a semicolon, +to distinguish it from commands for other extensions, and this might be +enforced in the future. + +For example, C uses this: + + sub on_osc_seq_perl { + my ($self, $osc, $resp) = @_; + + return unless $osc =~ s/^overlay;//; + + ... process remaining $osc string + } Be careful not ever to trust (in a security sense) the data you receive, as its source can not easily be controlled (e-mail content, messages from other users on the same system etc.). +For responses, C<$resp> contains the end-of-args separator used by the +sender. + =item on_add_lines $term, $string Called whenever text is about to be output, with the text as argument. You @@ -563,6 +617,13 @@ Called whenever some data is written to the tty/pty and can be used to suppress or filter tty input. +=item on_tt_paste $term, $octets + +Called whenever text is about to be pasted, with the text as argument. You +can filter/change and paste the text yourself by returning a true value +and calling C<< $term->tt_paste >> yourself. C<$octets> is +locale-encoded. + =item on_line_update $term, $row Called whenever a line was updated or changed. Can be used to filter @@ -579,8 +640,8 @@ =item on_refresh_begin $term -Called just before the screen gets redrawn. Can be used for overlay -or similar effects by modify terminal contents in refresh_begin, and +Called just before the screen gets redrawn. Can be used for overlay or +similar effects by modifying the terminal contents in refresh_begin, and restoring them in refresh_end. The built-in overlay and selection display code is run after this hook, and takes precedence. @@ -597,7 +658,7 @@ 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 +=item on_resize_all_windows $term, $new_width, $new_height Called just after the new window size has been calculated, but before windows are actually being resized or hints are being set. If this hook @@ -641,8 +702,8 @@ =item on_unmap_notify $term, $event -Called whenever the corresponding X event is received for the terminal If -the hook returns true, then the even will be ignored by rxvt-unicode. +Called whenever the corresponding X event is received for the terminal. If +the hook returns true, then the event will be ignored by rxvt-unicode. The event is a hash with most values as named by Xlib (see the XEvent manpage), with the additional members C and C, which are the @@ -662,6 +723,10 @@ Called when various types of ClientMessage events are received (all with format=32, WM_PROTOCOLS or WM_PROTOCOLS:WM_DELETE_WINDOW). +=item on_bell $term + +Called on receipt of a bell character. + =back =cut @@ -808,7 +873,8 @@ Return the rendition mask used for overlays by default. -=item $rendbit = urxvt::RS_Bold, RS_Italic, RS_Blink, RS_RVid, RS_Uline +=item $rendbit = urxvt::RS_Bold, urxvt::RS_Italic, urxvt::RS_Blink, +urxvt::RS_RVid, urxvt::RS_Uline Return the bit that enabled bold, italic, blink, reverse-video and underline, respectively. To enable such a style, just logically OR it into @@ -901,7 +967,7 @@ if ($htype == 0) { # INIT my @dirs = ((split /:/, $TERM->resource ("perl_lib")), "$LIBDIR/perl"); - + my %ext_arg; { @@ -974,6 +1040,31 @@ SET_BGCOLOR (SET_FGCOLOR ($_[0], $_[1]), $_[2]) } +sub rend2mask { + no strict 'refs'; + my ($str, $mask) = (@_, 0); + my %color = ( fg => undef, bg => undef ); + my @failed; + for my $spec ( split /\s+/, $str ) { + if ( $spec =~ /^([fb]g)[_:-]?(\d+)/i ) { + $color{lc($1)} = $2; + } else { + my $neg = $spec =~ s/^[-^]//; + unless ( exists &{"RS_$spec"} ) { + push @failed, $spec; + next; + } + my $cur = &{"RS_$spec"}; + if ( $neg ) { + $mask &= ~$cur; + } else { + $mask |= $cur; + } + } + } + ($mask, @color{qw(fg bg)}, \@failed) +} + # urxvt::term::extension package urxvt::term::extension; @@ -1052,7 +1143,7 @@ =cut -our $VERSION = 1; +our $VERSION = '5.23'; $INC{"urxvt/anyevent.pm"} = 1; # mark us as there push @AnyEvent::REGISTRY, [urxvt => urxvt::anyevent::]; @@ -1064,8 +1155,8 @@ urxvt::timer ->new - ->start (urxvt::NOW + $arg{after}) - ->cb (sub { + ->after ($arg{after}, $arg{interval}) + ->cb ($arg{interval} ? $cb : sub { $_[0]->stop; # need to cancel manually $cb->(); }) @@ -1075,36 +1166,50 @@ my ($class, %arg) = @_; my $cb = $arg{cb}; + my $fd = fileno $arg{fh}; + defined $fd or $fd = $arg{fh}; bless [$arg{fh}, urxvt::iow ->new - ->fd (fileno $arg{fh}) + ->fd ($fd) ->events (($arg{poll} =~ /r/ ? 1 : 0) | ($arg{poll} =~ /w/ ? 2 : 0)) ->start - ->cb (sub { - $cb->(($_[1] & 1 ? 'r' : '') - . ($_[1] & 2 ? 'w' : '')); - })], - urxvt::anyevent:: + ->cb ($cb) + ], urxvt::anyevent:: } -sub DESTROY { - $_[0][1]->stop; +sub idle { + my ($class, %arg) = @_; + + my $cb = $arg{cb}; + + urxvt::iw + ->new + ->start + ->cb ($cb) } -sub condvar { - bless \my $flag, urxvt::anyevent::condvar:: +sub child { + my ($class, %arg) = @_; + + my $cb = $arg{cb}; + + urxvt::pw + ->new + ->start ($arg{pid}) + ->cb (sub { + $_[0]->stop; # need to cancel manually + $cb->($_[0]->rpid, $_[0]->rstatus); + }) } -sub urxvt::anyevent::condvar::broadcast { - ${$_[0]}++; +sub DESTROY { + $_[0][1]->stop; } -sub urxvt::anyevent::condvar::wait { - unless (${$_[0]}) { - Carp::croak "AnyEvent->condvar blocking wait unsupported in urxvt, use a non-blocking API"; - } +sub one_event { + Carp::croak "AnyEvent->one_event blocking wait unsupported in urxvt, use a non-blocking API"; } package urxvt::term; @@ -1233,16 +1338,16 @@ to see the actual list: answerbackstring backgroundPixmap backspace_key boldFont boldItalicFont - borderLess color cursorBlink cursorUnderline cutchars delete_key + borderLess chdir color cursorBlink cursorUnderline cutchars delete_key display_name embed ext_bwidth fade font geometry hold iconName imFont imLocale inputMethod insecure int_bwidth intensityStyles - italicFont jumpScroll lineSpace loginShell mapAlert meta8 modifier - mouseWheelScrollPage name override_redirect pastableTabs path perl_eval - perl_ext_1 perl_ext_2 perl_lib pointerBlank pointerBlankDelay + italicFont jumpScroll lineSpace letterSpace loginShell mapAlert meta8 + modifier mouseWheelScrollPage name override_redirect pastableTabs path + perl_eval perl_ext_1 perl_ext_2 perl_lib pointerBlank pointerBlankDelay preeditType print_pipe pty_fd reverseVideo saveLines scrollBar scrollBar_align scrollBar_floating scrollBar_right scrollBar_thickness scrollTtyKeypress scrollTtyOutput scrollWithBuffer scrollstyle - secondaryScreen secondaryScroll selectstyle shade term_name title + secondaryScreen secondaryScroll shade term_name title transient_for transparent transparent_all tripleclickwords utmpInhibit visualBell @@ -1251,7 +1356,7 @@ sub resource($$;$) { my ($self, $name) = (shift, shift); unshift @_, $self, $name, ($name =~ s/\s*\+\s*(\d+)$// ? $1 : 0); - &urxvt::term::_resource + goto &urxvt::term::_resource } =item $value = $term->x_resource ($pattern) @@ -1286,25 +1391,38 @@ =item ($row, $col) = $term->selection_end ([$row, $col]) -Return the current values of the selection mark, begin or end positions, -and optionally set them to new values. +Return the current values of the selection mark, begin or end positions. + +When arguments are given, then the selection coordinates are set to +C<$row> and C<$col>, and the selection screen is set to the current +screen. + +=item $screen = $term->selection_screen ([$screen]) + +Returns the current selection screen, and then optionally sets it. =item $term->selection_make ($eventtime[, $rectangular]) Tries to make a selection as set by C and C. If C<$rectangular> is true (default: false), a -rectangular selection will be made. This is the prefered function to make +rectangular selection will be made. This is the preferred function to make a selection. -=item $success = $term->selection_grab ($eventtime) +=item $success = $term->selection_grab ($eventtime[, $clipboard]) -Try to request the primary selection text from the server (for example, as -set by the next method). No visual feedback will be given. This function +Try to acquire ownership of the primary (clipboard if C<$clipboard> is +true) selection from the server. The corresponding text can be set +with the next method. No visual feedback will be given. This function is mostly useful from within C hooks. -=item $oldtext = $term->selection ([$newtext]) +=item $oldtext = $term->selection ([$newtext, $clipboard]) + +Return the current selection (clipboard if C<$clipboard> is true) text +and optionally replace it by C<$newtext>. -Return the current selection text and optionally replace it by C<$newtext>. +=item $term->selection_clear ([$clipboard]) + +Revoke ownership of the primary (clipboard if C<$clipboard> is true) selection. =item $term->overlay_simple ($x, $y, $text) @@ -1344,12 +1462,14 @@ =over 4 -=item $overlay->set ($x, $y, $text, $rend) +=item $overlay->set ($x, $y, $text[, $rend]) Similar to C<< $term->ROW_t >> and C<< $term->ROW_r >> in that it puts text in rxvt-unicode's special encoding and an array of rendition values at a specific position inside the overlay. +If C<$rend> is missing, then the rendition will not be changed. + =item $overlay->hide If visible, hide the overlay, but do not destroy it. @@ -1440,10 +1560,16 @@ =item $term->tt_write ($octets) -Write the octets given in C<$data> to the tty (i.e. as program input). To +Write the octets given in C<$octets> to the tty (i.e. as program input). To pass characters instead of octets, you should convert your strings first to the locale-specific encoding using C<< $term->locale_encode >>. +=item $term->tt_paste ($octets) + +Write the octets given in C<$octets> to the tty as a paste, converting NL to +CR and bracketing the data with control sequences if bracketed paste mode +is set. + =item $old_events = $term->pty_ev_events ([$new_events]) Replaces the event mask of the pty watcher by the given event mask. Can @@ -1568,10 +1694,9 @@ =item $text = $term->ROW_t ($row_number[, $new_text[, $start_col]]) -Returns the text of the entire row with number C<$row_number>. Row C<0> -is the topmost terminal line, row C<< $term->$ncol-1 >> is the bottommost -terminal line. The scrollback buffer starts at line C<-1> and extends to -line C<< -$term->nsaved >>. Nothing will be returned if a nonexistent line +Returns the text of the entire row with number C<$row_number>. Row C<< $term->top_row >> +is the topmost terminal line, row C<< $term->nrow-1 >> is the bottommost +terminal line. Nothing will be returned if a nonexistent line is requested. If C<$new_text> is specified, it will replace characters in the current @@ -1582,7 +1707,7 @@ 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 +do not fit into the normal text encoding will be replaced with characters in the private use area. You have to obey this encoding when changing text. The advantage is @@ -1767,7 +1892,7 @@ =item $term->ungrab -Calls XUngrab for the most recent grab. Is called automatically on +Calls XUngrabPointer and XUngrabKeyboard for the most recent grab. Is called automatically on evaluation errors, as it is better to lose the grab in the error case as the session. @@ -1779,7 +1904,7 @@ =item ($type,$format,$octets) = $term->XGetWindowProperty ($window, $property) -=item $term->XChangeWindowProperty ($window, $property, $type, $format, $octets) +=item $term->XChangeProperty ($window, $property, $type, $format, $octets) =item $term->XDeleteProperty ($window, $property) @@ -1799,7 +1924,7 @@ Various X or X-related functions. The C<$term> object only serves as the source of the display, otherwise those functions map more-or-less -directory onto the X functions of the same name. +directly onto the X functions of the same name. =back @@ -1911,14 +2036,21 @@ delete $env->{LC_ALL}; $env->{LC_CTYPE} = $self->{term}->locale; - urxvt::term->new ($env, "popup", - "--perl-lib" => "", "--perl-ext-common" => "", - "-pty-fd" => -1, "-sl" => 0, - "-b" => 1, "-bd" => "grey80", "-bl", "-override-redirect", - "--transient-for" => $self->{term}->parent, - "-display" => $self->{term}->display_id, - "-pe" => "urxvt-popup") - or die "unable to create popup window\n"; + my $term = urxvt::term->new ( + $env, "popup", + "--perl-lib" => "", "--perl-ext-common" => "", + "-pty-fd" => -1, "-sl" => 0, + "-b" => 1, "-bd" => "grey80", "-bl", "-override-redirect", + "--transient-for" => $self->{term}->parent, + "-display" => $self->{term}->display_id, + "-pe" => "urxvt-popup", + ) or die "unable to create popup window\n"; + + unless (delete $term->{urxvt_popup_init_done}) { + $term->ungrab; + $term->destroy; + die "unable to initialise popup window\n"; + } } sub DESTROY { @@ -1934,11 +2066,6 @@ package urxvt::watcher; -@urxvt::timer::ISA = __PACKAGE__; -@urxvt::iow::ISA = __PACKAGE__; -@urxvt::pw::ISA = __PACKAGE__; -@urxvt::iw::ISA = __PACKAGE__; - =head2 The C Class This class implements timer watchers/events. Time is represented as a @@ -1951,7 +2078,7 @@ ->cb (sub { $term->{overlay}->set (0, 0, sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2,1,0]); - }); + }); =over 4 @@ -1964,17 +2091,14 @@ Set the callback to be called when the timer triggers. -=item $tstamp = $timer->at +=item $timer = $timer->set ($tstamp[, $interval]) -Return the time this watcher will fire next. - -=item $timer = $timer->set ($tstamp) - -Set the time the event is generated to $tstamp. +Set the time the event is generated to $tstamp (and optionally specifies a +new $interval). =item $timer = $timer->interval ($interval) -Normally (and when C<$interval> is C<0>), the timer will automatically +By default (and when C<$interval> is C<0>), the timer will automatically stop after it has fired once. If C<$interval> is non-zero, then the timer is automatically rescheduled at the given intervals. @@ -1982,11 +2106,12 @@ Start the timer. -=item $timer = $timer->start ($tstamp) +=item $timer = $timer->start ($tstamp[, $interval]) -Set the event trigger time to C<$tstamp> and start the timer. +Set the event trigger time to C<$tstamp> and start the timer. Optionally +also replaces the interval. -=item $timer = $timer->after ($delay) +=item $timer = $timer->after ($delay[, $interval]) Like C, but sets the expiry timer to c. @@ -2004,7 +2129,7 @@ $term->{iow} = urxvt::iow ->new ->fd (fileno $term->{socket}) - ->events (urxvt::EVENT_READ) + ->events (urxvt::EV_READ) ->start ->cb (sub { my ($iow, $revents) = @_; @@ -2032,8 +2157,8 @@ =item $iow = $iow->events ($eventmask) Set the event mask to watch. The only allowed values are -C and C, which might be ORed -together, or C. +C and C, which might be ORed +together, or C. =item $iow = $iow->start @@ -2084,7 +2209,7 @@ ->cb (sub { my ($pw, $exit_status) = @_; ... - }); + }); =over 4 @@ -2133,3 +2258,5 @@ =cut 1 + +# vim: sw=3: