ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/urxvt.pm
(Generate patch)

Comparing rxvt-unicode/src/urxvt.pm (file contents):
Revision 1.5 by root, Mon Jan 2 17:20:00 2006 UTC vs.
Revision 1.6 by root, Mon Jan 2 18:20:23 2006 UTC

3rxvtperl - rxvt-unicode's embedded perl interpreter 3rxvtperl - 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
10globally.
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
13thus must be encoded as UTF-8. 10thus 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
21On startup, @@RXVT_NAME@@ will scan F<@@RXVT_LIBDIR@@/urxvt/perl-ext/>
22for files and will load them. Everytime a terminal object gets created,
23the directory specified by the C<perl-lib> resource will be additionally
24scanned.
25
26Each script will only ever be loaded once, even in @@RXVT_NAME@@d, where
27scripts will be shared for all terminals.
28
29Hooks in scripts specified by C<perl-lib> will only be called for the
30terminals created with that specific option value.
31
32=head2 General API Considerations
33
34All objects (such as terminals, time watchers etc.) are typical
35reference-to-hash objects. The hash can be used to store anything you
36like. The only reserved member is C<_ptr>, which must not be changed.
37
38When objects are destroyed on the C++ side, the perl object hashes are
39emptied, so its best to store related objects such as time watchers and
40the like inside the terminal object so they get destroyed as soon as the
41terminal is destroyed.
42
24=head2 Hooks 43=head2 Hooks
25 44
26The following subroutines can be declared in loaded scripts, and will be called 45The following subroutines can be declared in loaded scripts, and will be called
27whenever the relevant event happens. 46whenever the relevant event happens.
28 47
120costs! The only time this is acceptable is when the terminal process 139costs! The only time this is acceptable is when the terminal process
121starts up. 140starts up.
122 141
123=item urxvt::warn $string 142=item urxvt::warn $string
124 143
125Calls C<rxvt_warn> witht eh given string which should not include a 144Calls C<rxvt_warn> with the given string which should not include a
126newline. The module also overwrites the C<warn> builtin with a function 145newline. The module also overwrites the C<warn> builtin with a function
127that calls this function. 146that calls this function.
128 147
129Using this function has the advantage that its output ends up in the 148Using this function has the advantage that its output ends up in the
130correct place, e.g. on stderr of the connecting urxvtc client. 149correct place, e.g. on stderr of the connecting urxvtc client.
131
132=item $cellwidth = urxvt::wcswidth $string
133
134Returns the number of screen-cells this string would need. Correctly
135accounts for wide and combining characters.
136 150
137=item $time = urxvt::NOW 151=item $time = urxvt::NOW
138 152
139Returns the "current time" (as per the event loop). 153Returns the "current time" (as per the event loop).
140 154
225 239
226 $pkg 240 $pkg
227 }; 241 };
228} 242}
229 243
230load_script $_ for grep -f $_, <$LIBDIR/perl-ext/*>; 244sub 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
254sub on_init {
255 my ($term) = @_;
256
257 my $libdir = $term->resource ("perl_lib");
258
259 load_scripts $libdir
260 if defined $libdir;
261}
262
263register_package __PACKAGE__;
264load_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
274sub urxvt::term::resource($$;$) { 308sub 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;
332position. 366position.
333 367
334=item $term->scr_overlay_set ($x, $y, $text) 368=item $term->scr_overlay_set ($x, $y, $text)
335 369
336Write a string at the given position into the overlay. 370Write a string at the given position into the overlay.
371
372=item $cellwidth = $term->strwidth $string
373
374Returns the number of screen-cells this string would need. Correctly
375accounts for wide and combining characters.
376
377=item $octets = $term->locale_encode $string
378
379Convert the given text string into the corresponding locale encoding.
380
381=item $string = $term->locale_decode $octets
382
383Convert the given locale-encoded octets into a perl string.
384
385=item $term->tt_write ($octets)
386
387Write the octets given in C<$data> to the tty (i.e. as program input). To
388pass characters instead of octets, you should convetr you strings first to
389the 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines