ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/doc/rxvtperl.3.txt
Revision: 1.12
Committed: Sat Jan 7 04:19:43 2006 UTC (18 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.11: +125 -30 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 NAME
2 rxvtperl - rxvt-unicode's embedded perl interpreter
3
4 SYNOPSIS
5 # create a file grab_test in $HOME:
6
7 sub on_sel_grab {
8 warn "you selected ", $_[0]->selection;
9 ()
10 }
11
12 # start a rxvt using it:
13
14 rxvt --perl-lib $HOME -pe grab_test
15
16 DESCRIPTION
17 Everytime a terminal object gets created, scripts specified via the
18 "perl" resource are loaded and associated with it.
19
20 Scripts are compiled in a 'use strict' and 'use utf8' environment, and
21 thus must be encoded as UTF-8.
22
23 Each script will only ever be loaded once, even in rxvtd, where scripts
24 will be shared (but not enabled) for all terminals.
25
26 Prepackaged Extensions
27 This section describes the extensiosn delivered with this version. You
28 can find them in /opt/rxvt/lib/urxvt/perl/.
29
30 You can activate them like this:
31
32 rxvt -pe <extensionname>
33
34 selection
35 Intelligent selection. This extension tries to be more intelligent
36 when the user extends selections (double-click). Right now, it tries
37 to select urls and complete shell-quoted arguments, which is very
38 convenient, too, if your ls supports "--quoting-style=shell".
39
40 It also offers the following bindable event:
41
42 rot13
43 Rot-13 the selection when activated. Used via keyboard trigger:
44
45 URxvt.keysym.C-M-r: perl:selection:rot13
46
47 digital-clock
48 Displays a digital clock using the built-in overlay.
49
50 mark-urls
51 Uses per-line display filtering ("on_line_update") to underline
52 urls.
53
54 block-graphics-to-ascii
55 A not very useful example of filtering all text output to the
56 terminal, by replacing all line-drawing characters (U+2500 ..
57 U+259F) by a similar-looking ascii character.
58
59 example-refresh-hooks
60 Displays a very simple digital clock in the upper right corner of
61 the window. Illustrates overwriting the refresh callbacks to create
62 your own overlays or changes.
63
64 General API Considerations
65 All objects (such as terminals, time watchers etc.) are typical
66 reference-to-hash objects. The hash can be used to store anything you
67 like. All members starting with an underscore (such as "_ptr" or
68 "_hook") are reserved for internal uses and MUST NOT be accessed or
69 modified).
70
71 When objects are destroyed on the C++ side, the perl object hashes are
72 emptied, so its best to store related objects such as time watchers and
73 the like inside the terminal object so they get destroyed as soon as the
74 terminal is destroyed.
75
76 Argument names also often indicate the type of a parameter. Here are
77 some hints on what they mean:
78
79 $text
80 Rxvt-unicodes special way of encoding text, where one "unicode"
81 character always represents one screen cell. See row_t for a
82 discussion of this format.
83
84 $string
85 A perl text string, with an emphasis on *text*. It can store all
86 unicode characters and is to be distinguished with text encoded in a
87 specific encoding (often locale-specific) and binary data.
88
89 $octets
90 Either binary data or - more common - a text string encoded in a
91 locale-specific way.
92
93 Hooks
94 The following subroutines can be declared in extension files, and will
95 be called whenever the relevant event happens.
96
97 The first argument passed to them is an object private to each terminal
98 and extension package. You can call all "urxvt::term" methods on it, but
99 its not a real "urxvt::term" object. Instead, the real "urxvt::term"
100 object that is shared between all packages is stored in the "term"
101 member.
102
103 All of them must return a boolean value. If it is true, then the event
104 counts as being *consumed*, and the invocation of other hooks is
105 skipped, and the relevant action might not be carried out by the C++
106 code.
107
108 When in doubt, return a false value (preferably "()").
109
110 on_init $term
111 Called after a new terminal object has been initialized, but before
112 windows are created or the command gets run. Most methods are unsafe
113 to call or deliver senseless data, as terminal size and other
114 characteristics have not yet been determined. You can safely query
115 and change resources, though.
116
117 on_reset $term
118 Called after the screen is "reset" for any reason, such as resizing
119 or control sequences. Here is where you can react on changes to
120 size-related variables.
121
122 on_start $term
123 Called at the very end of initialisation of a new terminal, just
124 before returning to the mainloop.
125
126 on_sel_make $term, $eventtime
127 Called whenever a selection has been made by the user, but before
128 the selection text is copied, so changes to the beginning, end or
129 type of the selection will be honored.
130
131 Returning a true value aborts selection making by urxvt, in which
132 case you have to make a selection yourself by calling
133 "$term->selection_grab".
134
135 on_sel_grab $term, $eventtime
136 Called whenever a selection has been copied, but before the
137 selection is requested from the server. The selection text can be
138 queried and changed by calling "$term->selection".
139
140 Returning a true value aborts selection grabbing. It will still be
141 hilighted.
142
143 on_sel_extend $term
144 Called whenever the user tries to extend the selection (e.g. with a
145 double click) and is either supposed to return false (normal
146 operation), or should extend the selection itelf and return true to
147 suppress the built-in processing.
148
149 See the selection example extension.
150
151 on_focus_in $term
152 Called whenever the window gets the keyboard focus, before urxvt
153 does focus in processing.
154
155 on_focus_out $term
156 Called wheneever the window loses keyboard focus, before urxvt does
157 focus out processing.
158
159 on_view_change $term, $offset
160 Called whenever the view offset changes, i..e the user or program
161 scrolls. Offset 0 means display the normal terminal, positive values
162 show this many lines of scrollback.
163
164 on_scroll_back $term, $lines, $saved
165 Called whenever lines scroll out of the terminal area into the
166 scrollback buffer. $lines is the number of lines scrolled out and
167 may be larger than the scroll back buffer or the terminal.
168
169 It is called before lines are scrolled out (so rows 0 .. min ($lines
170 - 1, $nrow - 1) represent the lines to be scrolled out). $saved is
171 the total number of lines that will be in the scrollback buffer.
172
173 on_tty_activity $term *NYI*
174 Called whenever the program(s) running in the urxvt window send
175 output.
176
177 on_osc_seq $term, $string
178 Called whenever the ESC ] 777 ; string ST command sequence (OSC =
179 operating system command) is processed. Cursor position and other
180 state information is up-to-date when this happens. For
181 interoperability, the string should start with the extension name
182 and a colon, to distinguish it from commands for other extensions,
183 and this might be enforced in the future.
184
185 Be careful not ever to trust (in a security sense) the data you
186 receive, as its source can not easily be controleld (e-mail content,
187 messages from other users on the same system etc.).
188
189 on_add_lines $term, $string
190 Called whenever text is about to be output, with the text as
191 argument. You can filter/change and output the text yourself by
192 returning a true value and calling "$term->scr_add_lines" yourself.
193 Please note that this might be very slow, however, as your hook is
194 called for all text being output.
195
196 on_line_update $term, $row
197 Called whenever a line was updated or changed. Can be used to filter
198 screen output (e.g. underline urls or other useless stuff). Only
199 lines that are being shown will be filtered, and, due to performance
200 reasons, not always immediately.
201
202 The row number is always the topmost row of the line if the line
203 spans multiple rows.
204
205 Please note that, if you change the line, then the hook might get
206 called later with the already-modified line (e.g. if unrelated parts
207 change), so you cannot just toggle rendition bits, but only set
208 them.
209
210 on_refresh_begin $term
211 Called just before the screen gets redrawn. Can be used for overlay
212 or similar effects by modify terminal contents in refresh_begin, and
213 restoring them in refresh_end. The built-in overlay and selection
214 display code is run after this hook, and takes precedence.
215
216 on_refresh_end $term
217 Called just after the screen gets redrawn. See "on_refresh_begin".
218
219 on_keyboard_command $term, $string
220 Called whenever the user presses a key combination that has a
221 "perl:string" action bound to it (see description of the keysym
222 resource in the rxvt(1) manpage).
223
224 on_key_press $term, $event, $octets
225 on_key_release $term, $event
226 on_button_press $term, $event
227 on_button_release $term, $event
228 on_motion_notify $term, $event
229 Called whenever the corresponding X event is received for the
230 terminal If the hook returns true, then the even will be ignored by
231 rxvt-unicode.
232
233 The event is a hash with most values as named by Xlib (see the
234 XEvent manpage), with the additional members "row" and "col", which
235 are the row and column under the mouse cursor.
236
237 "on_key_press" additionally receives the string rxvt-unicode would
238 output, if any, in locale-specific encoding.
239
240 subwindow.
241
242 Variables in the "urxvt" Package
243 $urxvt::TERM
244 The current terminal. This variable stores the current "urxvt::term"
245 object, whenever a callback/hook is executing.
246
247 Functions in the "urxvt" Package
248 $term = new urxvt [arg...]
249 Creates a new terminal, very similar as if you had started it with
250 "system $binfile, arg...". Croaks (and probably outputs an error
251 message) if the new instance couldn't be created. Returns "undef" if
252 the new instance didn't initialise perl, and the terminal object
253 otherwise. The "init" and "start" hooks will be called during the
254 call.
255
256 urxvt::fatal $errormessage
257 Fatally aborts execution with the given error message. Avoid at all
258 costs! The only time this is acceptable is when the terminal process
259 starts up.
260
261 urxvt::warn $string
262 Calls "rxvt_warn" with the given string which should not include a
263 newline. The module also overwrites the "warn" builtin with a
264 function that calls this function.
265
266 Using this function has the advantage that its output ends up in the
267 correct place, e.g. on stderr of the connecting urxvtc client.
268
269 $time = urxvt::NOW
270 Returns the "current time" (as per the event loop).
271
272 RENDITION
273 Rendition bitsets contain information about colour, font, font styles
274 and similar information for each screen cell.
275
276 The following "macros" deal with changes in rendition sets. You should
277 never just create a bitset, you should always modify an existing one, as
278 they contain important information required for correct operation of
279 rxvt-unicode.
280
281 $rend = urxvt::DEFAULT_RSTYLE
282 Returns the default rendition, as used when the terminal is starting
283 up or being reset. Useful as a base to start when creating
284 renditions.
285
286 $rend = urxvt::OVERLAY_RSTYLE
287 Return the rendition mask used for overlays by default.
288
289 $rendbit = urxvt::RS_Bold, RS_Italic, RS_Blink, RS_RVid, RS_Uline
290 Return the bit that enabled bold, italic, blink, reverse-video and
291 underline, respectively. To enable such a style, just logically OR
292 it into the bitset.
293
294 $foreground = urxvt::GET_BASEFG $rend
295 $background = urxvt::GET_BASEBG $rend
296 Return the foreground/background colour index, respectively.
297
298 $rend = urxvt::SET_FGCOLOR ($rend, $new_colour)
299 $rend = urxvt::SET_BGCOLOR ($rend, $new_colour)
300 Replace the foreground/background colour in the rendition mask with
301 the specified one.
302
303 $value = urxvt::GET_CUSTOM ($rend)
304 Return the "custom" value: Every rendition has 5 bits for use by
305 extensions. They can be set and changed as you like and are
306 initially zero.
307
308 $rend = urxvt::SET_CUSTOM ($rend, $new_value)
309 Change the custom value.
310
311 The "urxvt::term" Class
312 $term->destroy
313 Destroy the terminal object (close the window, free resources etc.).
314
315 $value = $term->resource ($name[, $newval])
316 Returns the current resource value associated with a given name and
317 optionally sets a new value. Setting values is most useful in the
318 "init" hook. Unset resources are returned and accepted as "undef".
319
320 The new value must be properly encoded to a suitable character
321 encoding before passing it to this method. Similarly, the returned
322 value may need to be converted from the used encoding to text.
323
324 Resource names are as defined in src/rsinc.h. Colours can be
325 specified as resource names of the form "color+<index>", e.g.
326 "color+5". (will likely change).
327
328 Please note that resource strings will currently only be freed when
329 the terminal is destroyed, so changing options frequently will eat
330 memory.
331
332 Here is a a likely non-exhaustive list of resource names, not all of
333 which are supported in every build, please see the source to see the
334 actual list:
335
336 answerbackstring backgroundPixmap backspace_key boldFont boldItalicFont
337 borderLess color cursorBlink cursorUnderline cutchars delete_key
338 display_name embed ext_bwidth fade font geometry hold iconName
339 imFont imLocale inputMethod insecure int_bwidth intensityStyles
340 italicFont jumpScroll lineSpace loginShell mapAlert menu meta8 modifier
341 mouseWheelScrollPage name pastableTabs path perl_eval perl_ext_1 perl_ext_2
342 perl_lib pointerBlank pointerBlankDelay preeditType print_pipe pty_fd
343 reverseVideo saveLines scrollBar scrollBar_align scrollBar_floating
344 scrollBar_right scrollBar_thickness scrollTtyKeypress scrollTtyOutput
345 scrollWithBuffer scrollstyle secondaryScreen secondaryScroll selectstyle
346 shade term_name title transparent transparent_all tripleclickwords
347 utmpInhibit visualBell
348
349 $rend = $term->rstyle ([$new_rstyle])
350 Return and optionally change the current rendition. Text that is
351 output by the terminal application will use this style.
352
353 ($row, $col) = $term->screen_cur ([$row, $col])
354 Return the current coordinates of the text cursor position and
355 optionally set it (which is usually bad as applications don't expect
356 that).
357
358 ($row, $col) = $term->selection_mark ([$row, $col])
359 ($row, $col) = $term->selection_beg ([$row, $col])
360 ($row, $col) = $term->selection_end ([$row, $col])
361 Return the current values of the selection mark, begin or end
362 positions, and optionally set them to new values.
363
364 $success = $term->selection_grab ($eventtime)
365 Try to request the primary selection from the server (for example,
366 as set by the next method).
367
368 $oldtext = $term->selection ([$newtext])
369 Return the current selection text and optionally replace it by
370 $newtext.
371
372 #=item $term->overlay ($x, $y, $text) # #Create a simple multi-line
373 overlay box. See the next method for details. # #=cut # #sub
374 urxvt::term::scr_overlay { # my ($self, $x, $y, $text) = @_; # # my
375 @lines = split /\n/, $text; # # my $w = 0; # for (map
376 $self->strwidth ($_), @lines) { # $w = $_ if $w < $_; # } # #
377 $self->scr_overlay_new ($x, $y, $w, scalar @lines); #
378 $self->scr_overlay_set (0, $_, $lines[$_]) for 0.. $#lines; #}
379
380 $term->overlay ($x, $y, $width, $height[, $rstyle[, $border]])
381 Create a new (empty) overlay at the given position with the given
382 width/height. $rstyle defines the initial rendition style (default:
383 "OVERLAY_RSTYLE").
384
385 If $border is 2 (default), then a decorative border will be put
386 around the box.
387
388 If either $x or $y is negative, then this is counted from the
389 right/bottom side, respectively.
390
391 This method returns an urxvt::overlay object. The overlay will be
392 visible as long as the perl object is referenced.
393
394 The methods currently supported on "urxvt::overlay" objects are:
395
396 $overlay->set ($x, $y, $text, $rend)
397 Similar to "$term->ROW_t" and "$term->ROW_r" in that it puts
398 text in rxvt-unicode's special encoding and an array of
399 rendition values at a specific position inside the overlay.
400
401 $overlay->hide
402 If visible, hide the overlay, but do not destroy it.
403
404 $overlay->show
405 If hidden, display the overlay again.
406
407 $cellwidth = $term->strwidth ($string)
408 Returns the number of screen-cells this string would need. Correctly
409 accounts for wide and combining characters.
410
411 $octets = $term->locale_encode ($string)
412 Convert the given text string into the corresponding locale
413 encoding.
414
415 $string = $term->locale_decode ($octets)
416 Convert the given locale-encoded octets into a perl string.
417
418 $term->scr_add_lines ($string)
419 Write the given text string to the screen, as if output by the
420 application running inside the terminal. It may not contain command
421 sequences (escape codes), but is free to use line feeds, carriage
422 returns and tabs. The string is a normal text string, not in
423 locale-dependent encoding.
424
425 Normally its not a good idea to use this function, as programs might
426 be confused by changes in cursor position or scrolling. Its useful
427 inside a "on_add_lines" hook, though.
428
429 $term->cmd_parse ($octets)
430 Similar to "scr_add_lines", but the argument must be in the
431 locale-specific encoding of the terminal and can contain command
432 sequences (escape codes) that will be interpreted.
433
434 $term->tt_write ($octets)
435 Write the octets given in $data to the tty (i.e. as program input).
436 To pass characters instead of octets, you should convert your
437 strings first to the locale-specific encoding using
438 "$term->locale_encode".
439
440 $windowid = $term->parent
441 Return the window id of the toplevel window.
442
443 $windowid = $term->vt
444 Return the window id of the terminal window.
445
446 $window_width = $term->width
447 $window_height = $term->height
448 $font_width = $term->fwidth
449 $font_height = $term->fheight
450 $font_ascent = $term->fbase
451 $terminal_rows = $term->nrow
452 $terminal_columns = $term->ncol
453 $has_focus = $term->focus
454 $is_mapped = $term->mapped
455 $max_scrollback = $term->saveLines
456 $nrow_plus_saveLines = $term->total_rows
457 $lines_in_scrollback = $term->nsaved
458 Return various integers describing terminal characteristics.
459
460 $view_start = $term->view_start ([$newvalue])
461 Returns the negative row number of the topmost line. Minimum value
462 is 0, which displays the normal terminal contents. Larger values
463 scroll this many lines into the scrollback buffer.
464
465 $term->want_refresh
466 Requests a screen refresh. At the next opportunity, rxvt-unicode
467 will compare the on-screen display with its stored representation.
468 If they differ, it redraws the differences.
469
470 Used after changing terminal contents to display them.
471
472 $text = $term->ROW_t ($row_number[, $new_text[, $start_col]])
473 Returns the text of the entire row with number $row_number. Row 0 is
474 the topmost terminal line, row "$term->$ncol-1" is the bottommost
475 terminal line. The scrollback buffer starts at line -1 and extends
476 to line "-$term->nsaved". Nothing will be returned if a nonexistent
477 line is requested.
478
479 If $new_text is specified, it will replace characters in the current
480 line, starting at column $start_col (default 0), which is useful to
481 replace only parts of a line. The font index in the rendition will
482 automatically be updated.
483
484 $text is in a special encoding: tabs and wide characters that use
485 more than one cell when displayed are padded with urxvt::NOCHAR
486 characters ("chr 65535"). Characters with combining characters and
487 other characters that do not fit into the normal tetx encoding will
488 be replaced with characters in the private use area.
489
490 You have to obey this encoding when changing text. The advantage is
491 that "substr" and similar functions work on screen cells and not on
492 characters.
493
494 The methods "$term->special_encode" and "$term->special_decode" can
495 be used to convert normal strings into this encoding and vice versa.
496
497 $rend = $term->ROW_r ($row_number[, $new_rend[, $start_col]])
498 Like "$term->ROW_t", but returns an arrayref with rendition bitsets.
499 Rendition bitsets contain information about colour, font, font
500 styles and similar information. See also "$term->ROW_t".
501
502 When setting rendition, the font mask will be ignored.
503
504 See the section on RENDITION, above.
505
506 $length = $term->ROW_l ($row_number[, $new_length])
507 Returns the number of screen cells that are in use ("the line
508 length"). Unlike the urxvt core, this returns "$term->ncol" if the
509 line is joined with the following one.
510
511 $bool = $term->is_longer ($row_number)
512 Returns true if the row is part of a multiple-row logical "line"
513 (i.e. joined with the following row), which means all characters are
514 in use and it is continued on the next row (and possibly a
515 continuation of the previous row(s)).
516
517 $line = $term->line ($row_number)
518 Create and return a new "urxvt::line" object that stores information
519 about the logical line that row $row_number is part of. It supports
520 the following methods:
521
522 $text = $line->t ([$new_text])
523 Returns or replaces the full text of the line, similar to
524 "ROW_t"
525
526 $rend = $line->r ([$new_rend])
527 Returns or replaces the full rendition array of the line,
528 similar to "ROW_r"
529
530 $length = $line->l
531 Returns the length of the line in cells, similar to "ROW_l".
532
533 $rownum = $line->beg
534 $rownum = $line->end
535 Return the row number of the first/last row of the line,
536 respectively.
537
538 $offset = $line->offset_of ($row, $col)
539 Returns the character offset of the given row|col pair within
540 the logical line.
541
542 ($row, $col) = $line->coord_of ($offset)
543 Translates a string offset into terminal coordinates again.
544
545 ($row, $col) = $line->coord_of ($offset) =item $text =
546 $term->special_encode $string
547 Converts a perl string into the special encoding used by
548 rxvt-unicode, where one character corresponds to one screen cell.
549 See "$term->ROW_t" for details.
550
551 $string = $term->special_decode $text
552 Converts rxvt-unicodes text reprsentation into a perl string. See
553 "$term->ROW_t" for details.
554
555 The "urxvt::timer" Class
556 This class implements timer watchers/events. Time is represented as a
557 fractional number of seconds since the epoch. Example:
558
559 $term->{overlay} = $term->overlay (-1, 0, 8, 1, urxvt::OVERLAY_RSTYLE, 0);
560 $term->{timer} = urxvt::timer
561 ->new
562 ->interval (1)
563 ->cb (sub {
564 $term->{overlay}->set (0, 0,
565 sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2,1,0]);
566 });
567
568 $timer = new urxvt::timer
569 Create a new timer object in started state. It is scheduled to fire
570 immediately.
571
572 $timer = $timer->cb (sub { my ($timer) = @_; ... })
573 Set the callback to be called when the timer triggers.
574
575 $tstamp = $timer->at
576 Return the time this watcher will fire next.
577
578 $timer = $timer->set ($tstamp)
579 Set the time the event is generated to $tstamp.
580
581 $timer = $timer->interval ($interval)
582 Normally (and when $interval is 0), the timer will automatically
583 stop after it has fired once. If $interval is non-zero, then the
584 timer is automatically rescheduled at the given intervals.
585
586 $timer = $timer->start
587 Start the timer.
588
589 $timer = $timer->start ($tstamp)
590 Set the event trigger time to $tstamp and start the timer.
591
592 $timer = $timer->stop
593 Stop the timer.
594
595 The "urxvt::iow" Class
596 This class implements io watchers/events. Example:
597
598 $term->{socket} = ...
599 $term->{iow} = urxvt::iow
600 ->new
601 ->fd (fileno $term->{socket})
602 ->events (1) # wait for read data
603 ->start
604 ->cb (sub {
605 my ($iow, $revents) = @_;
606 # $revents must be 1 here, no need to check
607 sysread $term->{socket}, my $buf, 8192
608 or end-of-file;
609 });
610
611 $iow = new urxvt::iow
612 Create a new io watcher object in stopped state.
613
614 $iow = $iow->cb (sub { my ($iow, $reventmask) = @_; ... })
615 Set the callback to be called when io events are triggered.
616 $reventmask is a bitset as described in the "events" method.
617
618 $iow = $iow->fd ($fd)
619 Set the filedescriptor (not handle) to watch.
620
621 $iow = $iow->events ($eventmask)
622 Set the event mask to watch. Bit #0 (value 1) enables watching for
623 read data, Bit #1 (value 2) enables watching for write data.
624
625 $iow = $iow->start
626 Start watching for requested events on the given handle.
627
628 $iow = $iow->stop
629 Stop watching for events on the given filehandle.
630
631 ENVIRONMENT
632 URXVT_PERL_VERBOSITY
633 This variable controls the verbosity level of the perl extension. Higher
634 numbers indicate more verbose output.
635
636 =0 - only fatal messages
637 =3 - script loading and management
638 =10 - all events received
639
640 AUTHOR
641 Marc Lehmann <pcg@goof.com>
642 http://software.schmorp.de/pkg/rxvt-unicode
643