ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/doc/rxvtperl.3.html
Revision: 1.3
Committed: Mon Jan 2 19:36:07 2006 UTC (18 years, 6 months ago) by root
Content type: text/html
Branch: MAIN
Changes since 1.2: +56 -17 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2     <html xmlns="http://www.w3.org/1999/xhtml">
3     <head>
4     <title>rxvtperl - rxvt-unicode's embedded perl interpreter</title>
5     <link rev="made" href="mailto:perl-binary@plan9.de" />
6     </head>
7    
8     <body style="background-color: white">
9    
10     <p><a name="__index__"></a></p>
11     <!-- INDEX BEGIN -->
12    
13     <ul>
14    
15     <li><a href="#name">NAME</a></li>
16     <li><a href="#synopsis">SYNOPSIS</a></li>
17     <li><a href="#description">DESCRIPTION</a></li>
18     <ul>
19    
20 root 1.3 <li><a href="#general_api_considerations">General API Considerations</a></li>
21 root 1.1 <li><a href="#hooks">Hooks</a></li>
22     <li><a href="#functions_in_the_urxvt_package">Functions in the <code>urxvt</code> Package</a></li>
23     <li><a href="#the_urxvt__term_class">The <code>urxvt::term</code> Class</a></li>
24     <li><a href="#the_urxvt__timer_class">The <code>urxvt::timer</code> Class</a></li>
25     <li><a href="#the_urxvt__iow_class">The <code>urxvt::iow</code> Class</a></li>
26     </ul>
27    
28 root 1.2 <li><a href="#environment">ENVIRONMENT</a></li>
29     <ul>
30    
31     <li><a href="#urxvt_perl_verbosity">URXVT_PERL_VERBOSITY</a></li>
32     </ul>
33    
34 root 1.1 <li><a href="#author">AUTHOR</a></li>
35     </ul>
36     <!-- INDEX END -->
37    
38     <hr />
39     <p>
40     </p>
41     <h1><a name="name">NAME</a></h1>
42     <p>rxvtperl - rxvt-unicode's embedded perl interpreter</p>
43     <p>
44     </p>
45     <hr />
46     <h1><a name="synopsis">SYNOPSIS</a></h1>
47     <p>* Put your scripts into <em>/opt/rxvt/lib/urxvt/perl-ext/</em>, they will be loaded automatically.</p>
48     <p>* Scripts are evaluated in a 'use strict' and 'use utf8' environment, and
49     thus must be encoded as UTF-8.</p>
50     <pre>
51     sub on_sel_grab {
52     warn &quot;you selected &quot;, $_[0]-&gt;selection;
53     ()
54     }</pre>
55     <pre>
56     1</pre>
57     <p>
58     </p>
59     <hr />
60     <h1><a name="description">DESCRIPTION</a></h1>
61 root 1.3 <p>On startup, rxvt will scan <em>/opt/rxvt/lib/urxvt/perl-ext/</em>
62     for files and will load them. Everytime a terminal object gets created,
63     the directory specified by the <code>perl-lib</code> resource will be additionally
64     scanned.</p>
65     <p>Each script will only ever be loaded once, even in rxvtd, where
66     scripts will be shared for all terminals.</p>
67     <p>Hooks in scripts specified by <code>perl-lib</code> will only be called for the
68     terminals created with that specific option value.</p>
69     <p>
70     </p>
71     <h2><a name="general_api_considerations">General API Considerations</a></h2>
72     <p>All objects (such as terminals, time watchers etc.) are typical
73     reference-to-hash objects. The hash can be used to store anything you
74     like. All members starting with an underscore (such as <code>_ptr</code> or
75     <code>_hook</code>) are reserved for internal uses and must not be accessed or
76     modified).</p>
77     <p>When objects are destroyed on the C++ side, the perl object hashes are
78     emptied, so its best to store related objects such as time watchers and
79     the like inside the terminal object so they get destroyed as soon as the
80     terminal is destroyed.</p>
81 root 1.1 <p>
82     </p>
83     <h2><a name="hooks">Hooks</a></h2>
84     <p>The following subroutines can be declared in loaded scripts, and will be called
85     whenever the relevant event happens.</p>
86     <p>All of them must return a boolean value. If it is true, then the event
87     counts as being <em>consumed</em>, and the invocation of other hooks is skipped,
88     and the relevant action might not be carried out by the C++ code.</p>
89     <p>When in doubt, return a false value (preferably <code>()</code>).</p>
90     <dl>
91     <dt><strong><a name="item_on_init__24term">on_init $term</a></strong><br />
92     </dt>
93     <dd>
94     Called after a new terminal object has been initialized, but before
95     windows are created or the command gets run.
96     </dd>
97     <p></p>
98     <dt><strong><a name="item_on_reset__24term">on_reset $term</a></strong><br />
99     </dt>
100     <dd>
101     Called after the screen is ``reset'' for any reason, such as resizing or
102     control sequences. Here is where you can react on changes to size-related
103     variables.
104     </dd>
105     <p></p>
106     <dt><strong><a name="item_on_start__24term">on_start $term</a></strong><br />
107     </dt>
108     <dd>
109     Called at the very end of initialisation of a new terminal, just before
110     returning to the mainloop.
111     </dd>
112     <p></p>
113     <dt><strong><a name="item_on_sel_make__24term_2c__24eventtime">on_sel_make $term, $eventtime</a></strong><br />
114     </dt>
115     <dd>
116     Called whenever a selection has been made by the user, but before the
117     selection text is copied, so changes to the beginning, end or type of the
118     selection will be honored.
119     </dd>
120     <dd>
121     <p>Returning a true value aborts selection making by urxvt, in which case you
122     have to make a selection yourself by calling <a href="#item_selection_grab"><code>$term-&gt;selection_grab</code></a>.</p>
123     </dd>
124     <p></p>
125     <dt><strong><a name="item_on_sel_grab__24term_2c__24eventtime">on_sel_grab $term, $eventtime</a></strong><br />
126     </dt>
127     <dd>
128     Called whenever a selection has been copied, but before the selection is
129     requested from the server. The selection text can be queried and changed
130     by calling <a href="#item_selection"><code>$term-&gt;selection</code></a>.
131     </dd>
132     <dd>
133     <p>Returning a true value aborts selection grabbing. It will still be hilighted.</p>
134     </dd>
135     <p></p>
136     <dt><strong><a name="item_on_focus_in__24term">on_focus_in $term</a></strong><br />
137     </dt>
138     <dd>
139     Called whenever the window gets the keyboard focus, before urxvt does
140     focus in processing.
141     </dd>
142     <p></p>
143     <dt><strong><a name="item_on_focus_out__24term">on_focus_out $term</a></strong><br />
144     </dt>
145     <dd>
146     Called wheneever the window loses keyboard focus, before urxvt does focus
147     out processing.
148     </dd>
149     <p></p>
150     <dt><strong><a name="item_on_view_change__24term_2c__24offset">on_view_change $term, $offset</a></strong><br />
151     </dt>
152     <dd>
153     Called whenever the view offset changes, i..e the user or program
154     scrolls. Offset <code>0</code> means display the normal terminal, positive values
155     show this many lines of scrollback.
156     </dd>
157     <p></p>
158     <dt><strong><a name="item_on_scroll_back__24term_2c__24lines_2c__24saved">on_scroll_back $term, $lines, $saved</a></strong><br />
159     </dt>
160     <dd>
161     Called whenever lines scroll out of the terminal area into the scrollback
162     buffer. <code>$lines</code> is the number of lines scrolled out and may be larger
163     than the scroll back buffer or the terminal.
164     </dd>
165     <dd>
166     <p>It is called before lines are scrolled out (so rows 0 .. min ($lines - 1,
167     $nrow - 1) represent the lines to be scrolled out). <code>$saved</code> is the total
168     number of lines that will be in the scrollback buffer.</p>
169     </dd>
170     <p></p>
171     <dt><strong><a name="item_on_tty_activity__24term__2anyi_2a">on_tty_activity $term *NYI*</a></strong><br />
172     </dt>
173     <dd>
174     Called whenever the <code>program(s)</code> running in the urxvt window send output.
175     </dd>
176     <p></p>
177     <dt><strong><a name="item_on_refresh_begin__24term">on_refresh_begin $term</a></strong><br />
178     </dt>
179     <dd>
180     Called just before the screen gets redrawn. Can be used for overlay
181     or similar effects by modify terminal contents in refresh_begin, and
182     restoring them in refresh_end. The built-in overlay and selection display
183     code is run after this hook, and takes precedence.
184     </dd>
185     <p></p>
186     <dt><strong><a name="item_on_refresh_end__24term">on_refresh_end $term</a></strong><br />
187     </dt>
188     <dd>
189     Called just after the screen gets redrawn. See <code>on_refresh_begin</code>.
190     </dd>
191     <p></p></dl>
192     <p>
193     </p>
194     <h2><a name="functions_in_the_urxvt_package">Functions in the <code>urxvt</code> Package</a></h2>
195     <dl>
196     <dt><strong><a name="item_urxvt_3a_3afatal__24errormessage">urxvt::fatal $errormessage</a></strong><br />
197     </dt>
198     <dd>
199     Fatally aborts execution with the given error message. Avoid at all
200     costs! The only time this is acceptable is when the terminal process
201     starts up.
202     </dd>
203     <p></p>
204     <dt><strong><a name="item_urxvt_3a_3awarn__24string">urxvt::warn $string</a></strong><br />
205     </dt>
206     <dd>
207 root 1.3 Calls <code>rxvt_warn</code> with the given string which should not include a
208 root 1.1 newline. The module also overwrites the <code>warn</code> builtin with a function
209     that calls this function.
210     </dd>
211     <dd>
212     <p>Using this function has the advantage that its output ends up in the
213     correct place, e.g. on stderr of the connecting urxvtc client.</p>
214     </dd>
215     <p></p>
216     <dt><strong><a name="item__24time__3d_urxvt_3a_3anow">$time = urxvt::NOW</a></strong><br />
217     </dt>
218     <dd>
219     Returns the ``current time'' (as per the event loop).
220     </dd>
221     <p></p></dl>
222     <p>
223     </p>
224     <h2><a name="the_urxvt__term_class">The <code>urxvt::term</code> Class</a></h2>
225     <dl>
226 root 1.2 <dt><strong><a name="item_resource">$value = $term-&gt;resource ($name[, $newval])</a></strong><br />
227     </dt>
228     <dd>
229     Returns the current resource value associated with a given name and
230     optionally sets a new value. Setting values is most useful in the <code>init</code>
231     hook. Unset resources are returned and accepted as <code>undef</code>.
232     </dd>
233     <dd>
234     <p>The new value must be properly encoded to a suitable character encoding
235     before passing it to this method. Similarly, the returned value may need
236     to be converted from the used encoding to text.</p>
237     </dd>
238     <dd>
239     <p>Resource names are as defined in <em>src/rsinc.h</em>. Colours can be specified
240     as resource names of the form <code>color+&lt;index&gt;</code>, e.g. <code>color+5</code>. (will
241     likely change).</p>
242     </dd>
243     <dd>
244     <p>Please note that resource strings will currently only be freed when the
245     terminal is destroyed, so changing options frequently will eat memory.</p>
246     </dd>
247     <dd>
248     <p>Here is a a likely non-exhaustive list of resource names, not all of which
249     are supported in every build, please see the source to see the actual
250     list:</p>
251     </dd>
252     <dd>
253     <pre>
254     answerbackstring backgroundPixmap backspace_key boldFont boldItalicFont
255     borderLess color cursorBlink cursorUnderline cutchars delete_key
256     display_name embed ext_bwidth fade font geometry hold iconName
257     imFont imLocale inputMethod insecure int_bwidth intensityStyles
258     italicFont jumpScroll lineSpace loginShell mapAlert menu meta8
259 root 1.3 modifier mouseWheelScrollPage name pastableTabs path perl perl_eval
260     perl_lib pointerBlank pointerBlankDelay preeditType print_pipe pty_fd
261     reverseVideo saveLines scrollBar scrollBar_align scrollBar_floating
262     scrollBar_right scrollBar_thickness scrollTtyKeypress scrollTtyOutput
263     scrollWithBuffer scrollstyle secondaryScreen secondaryScroll selectstyle
264     shade term_name title transparent transparent_all tripleclickwords
265     utmpInhibit visualBell</pre>
266 root 1.2 </dd>
267     <p></p>
268 root 1.1 <dt><strong><a name="item_selection_mark">($row, $col) = $term-&gt;selection_mark ([$row, $col])</a></strong><br />
269     </dt>
270     <dt><strong><a name="item_selection_beg">($row, $col) = $term-&gt;selection_beg ([$row, $col])</a></strong><br />
271     </dt>
272     <dt><strong><a name="item_selection_end">($row, $col) = $term-&gt;selection_end ([$row, $col])</a></strong><br />
273     </dt>
274     <dd>
275     Return the current values of the selection mark, begin or end positions,
276     and optionally set them to new values.
277     </dd>
278     <p></p>
279     <dt><strong><a name="item_selection_grab">$success = $term-&gt;selection_grab ($eventtime)</a></strong><br />
280     </dt>
281     <dd>
282     Try to request the primary selection from the server (for example, as set
283     by the next method).
284     </dd>
285     <p></p>
286     <dt><strong><a name="item_selection">$oldtext = $term-&gt;selection ([$newtext])</a></strong><br />
287     </dt>
288     <dd>
289     Return the current selection text and optionally replace it by <code>$newtext</code>.
290     </dd>
291     <p></p>
292     <dt><strong><a name="item_scr_overlay">$term-&gt;scr_overlay ($x, $y, $text)</a></strong><br />
293     </dt>
294     <dd>
295     Create a simple multi-line overlay box. See the next method for details.
296     </dd>
297     <p></p>
298     <dt><strong><a name="item_scr_overlay_new">$term-&gt;scr_overlay_new ($x, $y, $width, $height)</a></strong><br />
299     </dt>
300     <dd>
301     Create a new (empty) overlay at the given position with the given
302     width/height. A border will be put around the box. If either <code>$x</code> or
303     <code>$y</code> is negative, then this is counted from the right/bottom side,
304     respectively.
305     </dd>
306     <p></p>
307     <dt><strong><a name="item_scr_overlay_off">$term-&gt;scr_overlay_off</a></strong><br />
308     </dt>
309     <dd>
310     Switch the overlay off again.
311     </dd>
312     <p></p>
313     <dt><strong><a name="item_scr_overlay_set_char">$term-&gt;scr_overlay_set_char ($x, $y, $char, $rend = OVERLAY_RSTYLE)</a></strong><br />
314     </dt>
315     <dd>
316     Put a single character (specified numerically) at the given overlay
317     position.
318     </dd>
319     <p></p>
320     <dt><strong><a name="item_scr_overlay_set">$term-&gt;scr_overlay_set ($x, $y, $text)</a></strong><br />
321     </dt>
322     <dd>
323     Write a string at the given position into the overlay.
324     </dd>
325 root 1.3 <p></p>
326     <dt><strong><a name="item_strwidth">$cellwidth = $term-&gt;strwidth $string</a></strong><br />
327     </dt>
328     <dd>
329     Returns the number of screen-cells this string would need. Correctly
330     accounts for wide and combining characters.
331     </dd>
332     <p></p>
333     <dt><strong><a name="item_locale_encode">$octets = $term-&gt;locale_encode $string</a></strong><br />
334     </dt>
335     <dd>
336     Convert the given text string into the corresponding locale encoding.
337     </dd>
338     <p></p>
339     <dt><strong><a name="item_locale_decode">$string = $term-&gt;locale_decode $octets</a></strong><br />
340     </dt>
341     <dd>
342     Convert the given locale-encoded octets into a perl string.
343     </dd>
344     <p></p>
345     <dt><strong><a name="item_tt_write">$term-&gt;tt_write ($octets)</a></strong><br />
346     </dt>
347     <dd>
348     Write the octets given in <code>$data</code> to the tty (i.e. as program input). To
349     pass characters instead of octets, you should convetr you strings first to
350     the locale-specific encoding using <a href="#item_locale_encode"><code>$term-&gt;locale_encode</code></a>.
351     </dd>
352 root 1.1 <p></p></dl>
353     <p>
354     </p>
355     <h2><a name="the_urxvt__timer_class">The <code>urxvt::timer</code> Class</a></h2>
356     <p>This class implements timer watchers/events. Time is represented as a
357     fractional number of seconds since the epoch. Example:</p>
358     <pre>
359     # create a digital clock display in upper right corner
360     $term-&gt;{timer} = urxvt::timer
361     -&gt;new
362     -&gt;start (urxvt::NOW)
363     -&gt;cb (sub {
364     my ($timer) = @_;
365     my $time = $timer-&gt;at;
366     $timer-&gt;start ($time + 1);
367     $self-&gt;scr_overlay (-1, 0,
368     POSIX::strftime &quot;%H:%M:%S&quot;, localtime $time);
369     });</pre>
370     <dl>
371     <dt><strong><a name="item__24timer__3d_new_urxvt_3a_3atimer">$timer = new urxvt::timer</a></strong><br />
372     </dt>
373     <dd>
374     Create a new timer object in stopped state.
375     </dd>
376     <p></p>
377     <dt><strong><a name="item_cb">$timer = $timer-&gt;cb (sub { my ($timer) = @_; ... })</a></strong><br />
378     </dt>
379     <dd>
380     Set the callback to be called when the timer triggers.
381     </dd>
382     <p></p>
383     <dt><strong><a name="item_at">$tstamp = $timer-&gt;at</a></strong><br />
384     </dt>
385     <dd>
386     Return the time this watcher will fire next.
387     </dd>
388     <p></p>
389     <dt><strong><a name="item_set">$timer = $timer-&gt;set ($tstamp)</a></strong><br />
390     </dt>
391     <dd>
392     Set the time the event is generated to $tstamp.
393     </dd>
394     <p></p>
395     <dt><strong><a name="item_start">$timer = $timer-&gt;start</a></strong><br />
396     </dt>
397     <dd>
398     Start the timer.
399     </dd>
400     <p></p>
401     <dt><strong>$timer = $timer-&gt;start ($tstamp)</strong><br />
402     </dt>
403     <dd>
404     Set the event trigger time to <code>$tstamp</code> and start the timer.
405     </dd>
406     <p></p>
407     <dt><strong><a name="item_stop">$timer = $timer-&gt;stop</a></strong><br />
408     </dt>
409     <dd>
410     Stop the timer.
411     </dd>
412     <p></p></dl>
413     <p>
414     </p>
415     <h2><a name="the_urxvt__iow_class">The <code>urxvt::iow</code> Class</a></h2>
416     <p>This class implements io watchers/events. Example:</p>
417     <pre>
418     $term-&gt;{socket} = ...
419     $term-&gt;{iow} = urxvt::iow
420     -&gt;new
421     -&gt;fd (fileno $term-&gt;{socket})
422     -&gt;events (1) # wait for read data
423     -&gt;start
424     -&gt;cb (sub {
425     my ($iow, $revents) = @_;
426     # $revents must be 1 here, no need to check
427     sysread $term-&gt;{socket}, my $buf, 8192
428     or end-of-file;
429     });</pre>
430     <dl>
431     <dt><strong><a name="item__24iow__3d_new_urxvt_3a_3aiow">$iow = new urxvt::iow</a></strong><br />
432     </dt>
433     <dd>
434     Create a new io watcher object in stopped state.
435     </dd>
436     <p></p>
437     <dt><strong>$iow = $iow-&gt;cb (sub { my ($iow, $reventmask) = @_; ... })</strong><br />
438     </dt>
439     <dd>
440     Set the callback to be called when io events are triggered. <code>$reventmask</code>
441     is a bitset as described in the <a href="#item_events"><code>events</code></a> method.
442     </dd>
443     <p></p>
444     <dt><strong><a name="item_fd">$iow = $iow-&gt;fd ($fd)</a></strong><br />
445     </dt>
446     <dd>
447     Set the filedescriptor (not handle) to watch.
448     </dd>
449     <p></p>
450     <dt><strong><a name="item_events">$iow = $iow-&gt;events ($eventmask)</a></strong><br />
451     </dt>
452     <dd>
453     Set the event mask to watch. Bit #0 (value <code>1</code>) enables watching for read
454     data, Bit #1 (value <code>2</code>) enables watching for write data.
455     </dd>
456     <p></p>
457     <dt><strong>$iow = $iow-&gt;start</strong><br />
458     </dt>
459     <dd>
460     Start watching for requested events on the given handle.
461     </dd>
462     <p></p>
463     <dt><strong>$iow = $iow-&gt;stop</strong><br />
464     </dt>
465     <dd>
466     Stop watching for events on the given filehandle.
467     </dd>
468     <p></p></dl>
469     <p>
470     </p>
471     <hr />
472 root 1.2 <h1><a name="environment">ENVIRONMENT</a></h1>
473     <p>
474     </p>
475     <h2><a name="urxvt_perl_verbosity">URXVT_PERL_VERBOSITY</a></h2>
476     <p>This variable controls the verbosity level of the perl extension. Higher
477     numbers indicate more verbose output.</p>
478     <ol>
479     <li><strong><a name="item__2d_only_fatal_messages">- only fatal messages</a></strong><br />
480     </li>
481     <li><strong><a name="item__2d_script_loading_and_management">- script loading and management</a></strong><br />
482     </li>
483     <li><strong><a name="item__2d_all_events_received">- all events received</a></strong><br />
484     </li>
485     </ol>
486     <p>
487     </p>
488     <hr />
489 root 1.1 <h1><a name="author">AUTHOR</a></h1>
490     <pre>
491     Marc Lehmann &lt;pcg@goof.com&gt;
492     <a href="http://software.schmorp.de/pkg/rxvt-unicode">http://software.schmorp.de/pkg/rxvt-unicode</a></pre>
493    
494     </body>
495    
496     </html>