… | |
… | |
3 | rxvtperl - rxvt-unicode's embedded perl interpreter |
3 | rxvtperl - rxvt-unicode's embedded perl interpreter |
4 | |
4 | |
5 | =head1 SYNOPSIS |
5 | =head1 SYNOPSIS |
6 | |
6 | |
7 | * Put your scripts into F<@@RXVT_LIBDIR@@/urxvt/perl-ext/>, they will be loaded automatically. |
7 | * Put your scripts into F<@@RXVT_LIBDIR@@/urxvt/perl-ext/>, they will be loaded automatically. |
8 | |
|
|
9 | * Each script will only be loaded once, even in urxvtd, and will be valid |
|
|
10 | globally. |
|
|
11 | |
8 | |
12 | * Scripts are evaluated in a 'use strict' and 'use utf8' environment, and |
9 | * Scripts are evaluated in a 'use strict' and 'use utf8' environment, and |
13 | thus must be encoded as UTF-8. |
10 | thus must be encoded as UTF-8. |
14 | |
11 | |
15 | sub on_sel_grab { |
12 | sub on_sel_grab { |
… | |
… | |
19 | |
16 | |
20 | 1 |
17 | 1 |
21 | |
18 | |
22 | =head1 DESCRIPTION |
19 | =head1 DESCRIPTION |
23 | |
20 | |
|
|
21 | On startup, @@RXVT_NAME@@ will scan F<@@RXVT_LIBDIR@@/urxvt/perl-ext/> |
|
|
22 | for files and will load them. Everytime a terminal object gets created, |
|
|
23 | the directory specified by the C<perl-lib> resource will be additionally |
|
|
24 | scanned. |
|
|
25 | |
|
|
26 | Each script will only ever be loaded once, even in @@RXVT_NAME@@d, where |
|
|
27 | scripts will be shared for all terminals. |
|
|
28 | |
|
|
29 | Hooks in scripts specified by C<perl-lib> will only be called for the |
|
|
30 | terminals created with that specific option value. |
|
|
31 | |
|
|
32 | =head2 General API Considerations |
|
|
33 | |
|
|
34 | All objects (such as terminals, time watchers etc.) are typical |
|
|
35 | reference-to-hash objects. The hash can be used to store anything you |
|
|
36 | like. The only reserved member is C<_ptr>, which must not be changed. |
|
|
37 | |
|
|
38 | When objects are destroyed on the C++ side, the perl object hashes are |
|
|
39 | emptied, so its best to store related objects such as time watchers and |
|
|
40 | the like inside the terminal object so they get destroyed as soon as the |
|
|
41 | terminal is destroyed. |
|
|
42 | |
24 | =head2 Hooks |
43 | =head2 Hooks |
25 | |
44 | |
26 | The following subroutines can be declared in loaded scripts, and will be called |
45 | The following subroutines can be declared in loaded scripts, and will be called |
27 | whenever the relevant event happens. |
46 | whenever the relevant event happens. |
28 | |
47 | |
… | |
… | |
120 | costs! The only time this is acceptable is when the terminal process |
139 | costs! The only time this is acceptable is when the terminal process |
121 | starts up. |
140 | starts up. |
122 | |
141 | |
123 | =item urxvt::warn $string |
142 | =item urxvt::warn $string |
124 | |
143 | |
125 | Calls C<rxvt_warn> witht eh given string which should not include a |
144 | Calls C<rxvt_warn> with the given string which should not include a |
126 | newline. The module also overwrites the C<warn> builtin with a function |
145 | newline. The module also overwrites the C<warn> builtin with a function |
127 | that calls this function. |
146 | that calls this function. |
128 | |
147 | |
129 | Using this function has the advantage that its output ends up in the |
148 | Using this function has the advantage that its output ends up in the |
130 | correct place, e.g. on stderr of the connecting urxvtc client. |
149 | correct place, e.g. on stderr of the connecting urxvtc client. |
131 | |
|
|
132 | =item $cellwidth = urxvt::wcswidth $string |
|
|
133 | |
|
|
134 | Returns the number of screen-cells this string would need. Correctly |
|
|
135 | accounts for wide and combining characters. |
|
|
136 | |
150 | |
137 | =item $time = urxvt::NOW |
151 | =item $time = urxvt::NOW |
138 | |
152 | |
139 | Returns the "current time" (as per the event loop). |
153 | Returns the "current time" (as per the event loop). |
140 | |
154 | |
… | |
… | |
225 | |
239 | |
226 | $pkg |
240 | $pkg |
227 | }; |
241 | }; |
228 | } |
242 | } |
229 | |
243 | |
230 | load_script $_ for grep -f $_, <$LIBDIR/perl-ext/*>; |
244 | sub load_scripts($) { |
|
|
245 | my ($dir) = @_; |
|
|
246 | |
|
|
247 | verbose 3, "loading scripts from '$dir'"; |
|
|
248 | |
|
|
249 | load_script $_ |
|
|
250 | for grep -f $_, |
|
|
251 | <$dir/perl-ext/*>; |
|
|
252 | } |
|
|
253 | |
|
|
254 | sub on_init { |
|
|
255 | my ($term) = @_; |
|
|
256 | |
|
|
257 | my $libdir = $term->resource ("perl_lib"); |
|
|
258 | |
|
|
259 | load_scripts $libdir |
|
|
260 | if defined $libdir; |
|
|
261 | } |
|
|
262 | |
|
|
263 | register_package __PACKAGE__; |
|
|
264 | load_scripts $LIBDIR; |
231 | |
265 | |
232 | =back |
266 | =back |
233 | |
267 | |
234 | =head2 The C<urxvt::term> Class |
268 | =head2 The C<urxvt::term> Class |
235 | |
269 | |
… | |
… | |
259 | answerbackstring backgroundPixmap backspace_key boldFont boldItalicFont |
293 | answerbackstring backgroundPixmap backspace_key boldFont boldItalicFont |
260 | borderLess color cursorBlink cursorUnderline cutchars delete_key |
294 | borderLess color cursorBlink cursorUnderline cutchars delete_key |
261 | display_name embed ext_bwidth fade font geometry hold iconName |
295 | display_name embed ext_bwidth fade font geometry hold iconName |
262 | imFont imLocale inputMethod insecure int_bwidth intensityStyles |
296 | imFont imLocale inputMethod insecure int_bwidth intensityStyles |
263 | italicFont jumpScroll lineSpace loginShell mapAlert menu meta8 |
297 | italicFont jumpScroll lineSpace loginShell mapAlert menu meta8 |
264 | modifier mouseWheelScrollPage name pastableTabs path pointerBlank |
298 | modifier mouseWheelScrollPage name pastableTabs path perl perl_eval |
265 | pointerBlankDelay preeditType print_pipe pty_fd reverseVideo saveLines |
299 | perl_lib pointerBlank pointerBlankDelay preeditType print_pipe pty_fd |
266 | scrollBar scrollBar_align scrollBar_floating scrollBar_right |
300 | reverseVideo saveLines scrollBar scrollBar_align scrollBar_floating |
267 | scrollBar_thickness scrollTtyKeypress scrollTtyOutput scrollWithBuffer |
301 | scrollBar_right scrollBar_thickness scrollTtyKeypress scrollTtyOutput |
268 | scrollstyle secondaryScreen secondaryScroll selectstyle shade term_name |
302 | scrollWithBuffer scrollstyle secondaryScreen secondaryScroll selectstyle |
269 | title transparent transparent_all tripleclickwords utmpInhibit |
303 | shade term_name title transparent transparent_all tripleclickwords |
270 | visualBell |
304 | utmpInhibit visualBell |
271 | |
305 | |
272 | =cut |
306 | =cut |
273 | |
307 | |
274 | sub urxvt::term::resource($$;$) { |
308 | sub urxvt::term::resource($$;$) { |
275 | my ($self, $name) = (shift, shift); |
309 | my ($self, $name) = (shift, shift); |
… | |
… | |
305 | my ($self, $x, $y, $text) = @_; |
339 | my ($self, $x, $y, $text) = @_; |
306 | |
340 | |
307 | my @lines = split /\n/, $text; |
341 | my @lines = split /\n/, $text; |
308 | |
342 | |
309 | my $w = 0; |
343 | my $w = 0; |
310 | for (map urxvt::wcswidth $_, @lines) { |
344 | for (map $self->strwidth ($_), @lines) { |
311 | $w = $_ if $w < $_; |
345 | $w = $_ if $w < $_; |
312 | } |
346 | } |
313 | |
347 | |
314 | $self->scr_overlay_new ($x, $y, $w, scalar @lines); |
348 | $self->scr_overlay_new ($x, $y, $w, scalar @lines); |
315 | $self->scr_overlay_set (0, $_, $lines[$_]) for 0.. $#lines; |
349 | $self->scr_overlay_set (0, $_, $lines[$_]) for 0.. $#lines; |
… | |
… | |
332 | position. |
366 | position. |
333 | |
367 | |
334 | =item $term->scr_overlay_set ($x, $y, $text) |
368 | =item $term->scr_overlay_set ($x, $y, $text) |
335 | |
369 | |
336 | Write a string at the given position into the overlay. |
370 | Write a string at the given position into the overlay. |
|
|
371 | |
|
|
372 | =item $cellwidth = $term->strwidth $string |
|
|
373 | |
|
|
374 | Returns the number of screen-cells this string would need. Correctly |
|
|
375 | accounts for wide and combining characters. |
|
|
376 | |
|
|
377 | =item $octets = $term->locale_encode $string |
|
|
378 | |
|
|
379 | Convert the given text string into the corresponding locale encoding. |
|
|
380 | |
|
|
381 | =item $string = $term->locale_decode $octets |
|
|
382 | |
|
|
383 | Convert the given locale-encoded octets into a perl string. |
|
|
384 | |
|
|
385 | =item $term->tt_write ($octets) |
|
|
386 | |
|
|
387 | Write the octets given in C<$data> to the tty (i.e. as program input). To |
|
|
388 | pass characters instead of octets, you should convetr you strings first to |
|
|
389 | the locale-specific encoding using C<< $term->locale_encode >>. |
337 | |
390 | |
338 | =back |
391 | =back |
339 | |
392 | |
340 | =head2 The C<urxvt::timer> Class |
393 | =head2 The C<urxvt::timer> Class |
341 | |
394 | |