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