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 |
PACKAGED 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 |
Miscellaneous selection modifications. |
36 |
|
37 |
rot13 |
38 |
Rot-13 the selection when activated. Used via keyboard trigger: |
39 |
|
40 |
URxvt.keysym.C-M-r: perl:selection:rot13 |
41 |
|
42 |
digital-clock |
43 |
Displays a very simple digital clock in the upper right corner of |
44 |
the window. Illustrates overwriting the refresh callbacks to create |
45 |
your own overlays or changes. |
46 |
|
47 |
simple-overlay-clock |
48 |
Displays a digital clock using the built-in overlay (colorful, |
49 |
useless). |
50 |
|
51 |
General API Considerations |
52 |
All objects (such as terminals, time watchers etc.) are typical |
53 |
reference-to-hash objects. The hash can be used to store anything you |
54 |
like. All members starting with an underscore (such as "_ptr" or |
55 |
"_hook") are reserved for internal uses and must not be accessed or |
56 |
modified). |
57 |
|
58 |
When objects are destroyed on the C++ side, the perl object hashes are |
59 |
emptied, so its best to store related objects such as time watchers and |
60 |
the like inside the terminal object so they get destroyed as soon as the |
61 |
terminal is destroyed. |
62 |
|
63 |
Hooks |
64 |
The following subroutines can be declared in loaded scripts, and will be |
65 |
called whenever the relevant event happens. |
66 |
|
67 |
All of them must return a boolean value. If it is true, then the event |
68 |
counts as being *consumed*, and the invocation of other hooks is |
69 |
skipped, and the relevant action might not be carried out by the C++ |
70 |
code. |
71 |
|
72 |
When in doubt, return a false value (preferably "()"). |
73 |
|
74 |
on_init $term |
75 |
Called after a new terminal object has been initialized, but before |
76 |
windows are created or the command gets run. |
77 |
|
78 |
on_reset $term |
79 |
Called after the screen is "reset" for any reason, such as resizing |
80 |
or control sequences. Here is where you can react on changes to |
81 |
size-related variables. |
82 |
|
83 |
on_start $term |
84 |
Called at the very end of initialisation of a new terminal, just |
85 |
before returning to the mainloop. |
86 |
|
87 |
on_sel_make $term, $eventtime |
88 |
Called whenever a selection has been made by the user, but before |
89 |
the selection text is copied, so changes to the beginning, end or |
90 |
type of the selection will be honored. |
91 |
|
92 |
Returning a true value aborts selection making by urxvt, in which |
93 |
case you have to make a selection yourself by calling |
94 |
"$term->selection_grab". |
95 |
|
96 |
on_sel_grab $term, $eventtime |
97 |
Called whenever a selection has been copied, but before the |
98 |
selection is requested from the server. The selection text can be |
99 |
queried and changed by calling "$term->selection". |
100 |
|
101 |
Returning a true value aborts selection grabbing. It will still be |
102 |
hilighted. |
103 |
|
104 |
on_focus_in $term |
105 |
Called whenever the window gets the keyboard focus, before urxvt |
106 |
does focus in processing. |
107 |
|
108 |
on_focus_out $term |
109 |
Called wheneever the window loses keyboard focus, before urxvt does |
110 |
focus out processing. |
111 |
|
112 |
on_view_change $term, $offset |
113 |
Called whenever the view offset changes, i..e the user or program |
114 |
scrolls. Offset 0 means display the normal terminal, positive values |
115 |
show this many lines of scrollback. |
116 |
|
117 |
on_scroll_back $term, $lines, $saved |
118 |
Called whenever lines scroll out of the terminal area into the |
119 |
scrollback buffer. $lines is the number of lines scrolled out and |
120 |
may be larger than the scroll back buffer or the terminal. |
121 |
|
122 |
It is called before lines are scrolled out (so rows 0 .. min ($lines |
123 |
- 1, $nrow - 1) represent the lines to be scrolled out). $saved is |
124 |
the total number of lines that will be in the scrollback buffer. |
125 |
|
126 |
on_tty_activity $term *NYI* |
127 |
Called whenever the program(s) running in the urxvt window send |
128 |
output. |
129 |
|
130 |
on_refresh_begin $term |
131 |
Called just before the screen gets redrawn. Can be used for overlay |
132 |
or similar effects by modify terminal contents in refresh_begin, and |
133 |
restoring them in refresh_end. The built-in overlay and selection |
134 |
display code is run after this hook, and takes precedence. |
135 |
|
136 |
on_refresh_end $term |
137 |
Called just after the screen gets redrawn. See "on_refresh_begin". |
138 |
|
139 |
on_keyboard_command $term, $string |
140 |
Called whenever the user presses a key combination that has a |
141 |
"perl:string" action bound to it (see description of the keysym |
142 |
resource in the rxvt(1) manpage). |
143 |
|
144 |
Functions in the "urxvt" Package |
145 |
urxvt::fatal $errormessage |
146 |
Fatally aborts execution with the given error message. Avoid at all |
147 |
costs! The only time this is acceptable is when the terminal process |
148 |
starts up. |
149 |
|
150 |
urxvt::warn $string |
151 |
Calls "rxvt_warn" with the given string which should not include a |
152 |
newline. The module also overwrites the "warn" builtin with a |
153 |
function that calls this function. |
154 |
|
155 |
Using this function has the advantage that its output ends up in the |
156 |
correct place, e.g. on stderr of the connecting urxvtc client. |
157 |
|
158 |
$time = urxvt::NOW |
159 |
Returns the "current time" (as per the event loop). |
160 |
|
161 |
The "urxvt::term" Class |
162 |
$value = $term->resource ($name[, $newval]) |
163 |
Returns the current resource value associated with a given name and |
164 |
optionally sets a new value. Setting values is most useful in the |
165 |
"init" hook. Unset resources are returned and accepted as "undef". |
166 |
|
167 |
The new value must be properly encoded to a suitable character |
168 |
encoding before passing it to this method. Similarly, the returned |
169 |
value may need to be converted from the used encoding to text. |
170 |
|
171 |
Resource names are as defined in src/rsinc.h. Colours can be |
172 |
specified as resource names of the form "color+<index>", e.g. |
173 |
"color+5". (will likely change). |
174 |
|
175 |
Please note that resource strings will currently only be freed when |
176 |
the terminal is destroyed, so changing options frequently will eat |
177 |
memory. |
178 |
|
179 |
Here is a a likely non-exhaustive list of resource names, not all of |
180 |
which are supported in every build, please see the source to see the |
181 |
actual list: |
182 |
|
183 |
answerbackstring backgroundPixmap backspace_key boldFont boldItalicFont |
184 |
borderLess color cursorBlink cursorUnderline cutchars delete_key |
185 |
display_name embed ext_bwidth fade font geometry hold iconName |
186 |
imFont imLocale inputMethod insecure int_bwidth intensityStyles |
187 |
italicFont jumpScroll lineSpace loginShell mapAlert menu meta8 modifier |
188 |
mouseWheelScrollPage name pastableTabs path perl_eval perl_ext |
189 |
perl_lib pointerBlank pointerBlankDelay preeditType print_pipe pty_fd |
190 |
reverseVideo saveLines scrollBar scrollBar_align scrollBar_floating |
191 |
scrollBar_right scrollBar_thickness scrollTtyKeypress scrollTtyOutput |
192 |
scrollWithBuffer scrollstyle secondaryScreen secondaryScroll selectstyle |
193 |
shade term_name title transparent transparent_all tripleclickwords |
194 |
utmpInhibit visualBell |
195 |
|
196 |
($row, $col) = $term->selection_mark ([$row, $col]) |
197 |
($row, $col) = $term->selection_beg ([$row, $col]) |
198 |
($row, $col) = $term->selection_end ([$row, $col]) |
199 |
Return the current values of the selection mark, begin or end |
200 |
positions, and optionally set them to new values. |
201 |
|
202 |
$success = $term->selection_grab ($eventtime) |
203 |
Try to request the primary selection from the server (for example, |
204 |
as set by the next method). |
205 |
|
206 |
$oldtext = $term->selection ([$newtext]) |
207 |
Return the current selection text and optionally replace it by |
208 |
$newtext. |
209 |
|
210 |
$term->scr_overlay ($x, $y, $text) |
211 |
Create a simple multi-line overlay box. See the next method for |
212 |
details. |
213 |
|
214 |
$term->scr_overlay_new ($x, $y, $width, $height) |
215 |
Create a new (empty) overlay at the given position with the given |
216 |
width/height. A border will be put around the box. If either $x or |
217 |
$y is negative, then this is counted from the right/bottom side, |
218 |
respectively. |
219 |
|
220 |
$term->scr_overlay_off |
221 |
Switch the overlay off again. |
222 |
|
223 |
$term->scr_overlay_set_char ($x, $y, $char, $rend = OVERLAY_RSTYLE) |
224 |
Put a single character (specified numerically) at the given overlay |
225 |
position. |
226 |
|
227 |
$term->scr_overlay_set ($x, $y, $text) |
228 |
Write a string at the given position into the overlay. |
229 |
|
230 |
$cellwidth = $term->strwidth $string |
231 |
Returns the number of screen-cells this string would need. Correctly |
232 |
accounts for wide and combining characters. |
233 |
|
234 |
$octets = $term->locale_encode $string |
235 |
Convert the given text string into the corresponding locale |
236 |
encoding. |
237 |
|
238 |
$string = $term->locale_decode $octets |
239 |
Convert the given locale-encoded octets into a perl string. |
240 |
|
241 |
$term->tt_write ($octets) |
242 |
Write the octets given in $data to the tty (i.e. as program input). |
243 |
To pass characters instead of octets, you should convert your |
244 |
strings first to the locale-specific encoding using |
245 |
"$term->locale_encode". |
246 |
|
247 |
$nrow = $term->nrow |
248 |
$ncol = $term->ncol |
249 |
Return the number of rows/columns of the terminal window (i.e. as |
250 |
specified by "-geometry", excluding any scrollback). |
251 |
|
252 |
$nsaved = $term->nsaved |
253 |
Returns the number of lines in the scrollback buffer. |
254 |
|
255 |
$view_start = $term->view_start ([$newvalue]) |
256 |
Returns the negative row number of the topmost line. Minimum value |
257 |
is 0, which displays the normal terminal contents. Larger values |
258 |
scroll this many lines into the scrollback buffer. |
259 |
|
260 |
$term->want_refresh |
261 |
Requests a screen refresh. At the next opportunity, rxvt-unicode |
262 |
will compare the on-screen display with its stored representation. |
263 |
If they differ, it redraws the differences. |
264 |
|
265 |
Used after changing terminal contents to display them. |
266 |
|
267 |
$text = $term->ROW_t ($row_number[, $new_text[, $start_col]]) |
268 |
Returns the text of the entire row with number $row_number. Row 0 is |
269 |
the topmost terminal line, row "$term->$ncol-1" is the bottommost |
270 |
terminal line. The scrollback buffer starts at line -1 and extends |
271 |
to line "-$term->nsaved". |
272 |
|
273 |
If $new_text is specified, it will replace characters in the current |
274 |
line, starting at column $start_col (default 0), which is useful to |
275 |
replace only parts of a line. The font iindex in the rendition will |
276 |
automatically be updated. |
277 |
|
278 |
$text is in a special encoding: tabs and wide characters that use |
279 |
more than one cell when displayed are padded with urxvt::NOCHAR |
280 |
characters ("chr 65535"). Characters with combining characters and |
281 |
other characters that do not fit into the normal tetx encoding will |
282 |
be replaced with characters in the private use area. |
283 |
|
284 |
You have to obey this encoding when changing text. The advantage is |
285 |
that "substr" and similar functions work on screen cells and not on |
286 |
characters. |
287 |
|
288 |
The methods "$term->special_encode" and "$term->special_decode" can |
289 |
be used to convert normal strings into this encoding and vice versa. |
290 |
|
291 |
$rend = $term->ROW_r ($row_number[, $new_rend[, $start_col]]) |
292 |
Like "$term->ROW_t", but returns an arrayref with rendition bitsets. |
293 |
Rendition bitsets contain information about colour, font, font |
294 |
styles and similar information. See also "$term->ROW_t". |
295 |
|
296 |
When setting rendition, the font mask will be ignored. |
297 |
|
298 |
See the section on RENDITION, below. |
299 |
|
300 |
$length = $term->ROW_l ($row_number[, $new_length]) |
301 |
Returns the number of screen cells that are in use ("the line |
302 |
length"). If it is -1, then the line is part of a multiple-row |
303 |
logical "line", which means all characters are in use and it is |
304 |
continued on the next row. |
305 |
|
306 |
$text = $term->special_encode $string |
307 |
Converts a perl string into the special encoding used by |
308 |
rxvt-unicode, where one character corresponds to one screen cell. |
309 |
See "$term->ROW_t" for details. |
310 |
|
311 |
$string = $term->special_decode $text |
312 |
Converts rxvt-unicodes text reprsentation into a perl string. See |
313 |
"$term->ROW_t" for details. |
314 |
|
315 |
RENDITION |
316 |
Rendition bitsets contain information about colour, font, font styles |
317 |
and similar information for each screen cell. |
318 |
|
319 |
The following "macros" deal with changes in rendition sets. You should |
320 |
never just create a bitset, you should always modify an existing one, as |
321 |
they contain important information required for correct operation of |
322 |
rxvt-unicode. |
323 |
|
324 |
$rend = urxvt::DEFAULT_RSTYLE |
325 |
Returns the default rendition, as used when the terminal is starting |
326 |
up or being reset. Useful as a base |
327 |
|
328 |
The "urxvt::timer" Class |
329 |
This class implements timer watchers/events. Time is represented as a |
330 |
fractional number of seconds since the epoch. Example: |
331 |
|
332 |
# create a digital clock display in upper right corner |
333 |
$term->{timer} = urxvt::timer |
334 |
->new |
335 |
->start (urxvt::NOW) |
336 |
->cb (sub { |
337 |
my ($timer) = @_; |
338 |
my $time = $timer->at; |
339 |
$timer->start ($time + 1); |
340 |
$self->scr_overlay (-1, 0, |
341 |
POSIX::strftime "%H:%M:%S", localtime $time); |
342 |
}); |
343 |
|
344 |
$timer = new urxvt::timer |
345 |
Create a new timer object in stopped state. |
346 |
|
347 |
$timer = $timer->cb (sub { my ($timer) = @_; ... }) |
348 |
Set the callback to be called when the timer triggers. |
349 |
|
350 |
$tstamp = $timer->at |
351 |
Return the time this watcher will fire next. |
352 |
|
353 |
$timer = $timer->set ($tstamp) |
354 |
Set the time the event is generated to $tstamp. |
355 |
|
356 |
$timer = $timer->start |
357 |
Start the timer. |
358 |
|
359 |
$timer = $timer->start ($tstamp) |
360 |
Set the event trigger time to $tstamp and start the timer. |
361 |
|
362 |
$timer = $timer->stop |
363 |
Stop the timer. |
364 |
|
365 |
The "urxvt::iow" Class |
366 |
This class implements io watchers/events. Example: |
367 |
|
368 |
$term->{socket} = ... |
369 |
$term->{iow} = urxvt::iow |
370 |
->new |
371 |
->fd (fileno $term->{socket}) |
372 |
->events (1) # wait for read data |
373 |
->start |
374 |
->cb (sub { |
375 |
my ($iow, $revents) = @_; |
376 |
# $revents must be 1 here, no need to check |
377 |
sysread $term->{socket}, my $buf, 8192 |
378 |
or end-of-file; |
379 |
}); |
380 |
|
381 |
$iow = new urxvt::iow |
382 |
Create a new io watcher object in stopped state. |
383 |
|
384 |
$iow = $iow->cb (sub { my ($iow, $reventmask) = @_; ... }) |
385 |
Set the callback to be called when io events are triggered. |
386 |
$reventmask is a bitset as described in the "events" method. |
387 |
|
388 |
$iow = $iow->fd ($fd) |
389 |
Set the filedescriptor (not handle) to watch. |
390 |
|
391 |
$iow = $iow->events ($eventmask) |
392 |
Set the event mask to watch. Bit #0 (value 1) enables watching for |
393 |
read data, Bit #1 (value 2) enables watching for write data. |
394 |
|
395 |
$iow = $iow->start |
396 |
Start watching for requested events on the given handle. |
397 |
|
398 |
$iow = $iow->stop |
399 |
Stop watching for events on the given filehandle. |
400 |
|
401 |
ENVIRONMENT |
402 |
URXVT_PERL_VERBOSITY |
403 |
This variable controls the verbosity level of the perl extension. Higher |
404 |
numbers indicate more verbose output. |
405 |
|
406 |
0 - only fatal messages |
407 |
3 - script loading and management |
408 |
10 - all events received |
409 |
|
410 |
AUTHOR |
411 |
Marc Lehmann <pcg@goof.com> |
412 |
http://software.schmorp.de/pkg/rxvt-unicode |
413 |
|