… | |
… | |
65 | =item example-refresh-hooks |
65 | =item example-refresh-hooks |
66 | |
66 | |
67 | Displays a very simple digital clock in the upper right corner of the |
67 | Displays a very simple digital clock in the upper right corner of the |
68 | window. Illustrates overwriting the refresh callbacks to create your own |
68 | window. Illustrates overwriting the refresh callbacks to create your own |
69 | overlays or changes. |
69 | overlays or changes. |
|
|
70 | |
|
|
71 | =item mark-urls |
|
|
72 | |
|
|
73 | A not very useful example of filtering all text output to the terminal, by |
|
|
74 | underlining all urls that matches a certain regex (i.e. some urls :). It |
|
|
75 | is not very useful because urls that are output in multiple steps (e.g. |
|
|
76 | when typing them) do not get marked. |
70 | |
77 | |
71 | =back |
78 | =back |
72 | |
79 | |
73 | =head2 General API Considerations |
80 | =head2 General API Considerations |
74 | |
81 | |
… | |
… | |
81 | When objects are destroyed on the C++ side, the perl object hashes are |
88 | When objects are destroyed on the C++ side, the perl object hashes are |
82 | emptied, so its best to store related objects such as time watchers and |
89 | emptied, so its best to store related objects such as time watchers and |
83 | the like inside the terminal object so they get destroyed as soon as the |
90 | the like inside the terminal object so they get destroyed as soon as the |
84 | terminal is destroyed. |
91 | terminal is destroyed. |
85 | |
92 | |
|
|
93 | Argument names also often indicate the type of a parameter. Here are some |
|
|
94 | hints on what they mean: |
|
|
95 | |
|
|
96 | =over 4 |
|
|
97 | |
|
|
98 | =item $text |
|
|
99 | |
|
|
100 | Rxvt-unicodes special way of encoding text, where one "unicode" character |
|
|
101 | always represents one screen cell. See L<row_t> for a discussion of this format. |
|
|
102 | |
|
|
103 | =item $string |
|
|
104 | |
|
|
105 | A perl text string, with an emphasis on I<text>. It can store all unicode |
|
|
106 | characters and is to be distinguished with text encoded in a specific |
|
|
107 | encoding (often locale-specific) and binary data. |
|
|
108 | |
|
|
109 | =item $octets |
|
|
110 | |
|
|
111 | Either binary data or - more common - a text string encoded in a |
|
|
112 | locale-specific way. |
|
|
113 | |
|
|
114 | =back |
|
|
115 | |
86 | =head2 Hooks |
116 | =head2 Hooks |
87 | |
117 | |
88 | The following subroutines can be declared in loaded scripts, and will be |
118 | The following subroutines can be declared in loaded scripts, and will be |
89 | called whenever the relevant event happens. |
119 | called whenever the relevant event happens. |
90 | |
120 | |
… | |
… | |
174 | |
204 | |
175 | Called whenever the program(s) running in the urxvt window send output. |
205 | Called whenever the program(s) running in the urxvt window send output. |
176 | |
206 | |
177 | =item on_osc_seq $term, $string |
207 | =item on_osc_seq $term, $string |
178 | |
208 | |
179 | Called whenever the B<ESC ] 777 ; string ST> command sequence is |
209 | Called whenever the B<ESC ] 777 ; string ST> command sequence (OSC = |
180 | processed. Cursor position and other state information is up-to-date when |
210 | operating system command) is processed. Cursor position and other state |
181 | this happens. For interoperability, the string should start with the |
211 | information is up-to-date when this happens. For interoperability, the |
182 | extension name and a colon, to distinguish it from commands for other |
212 | string should start with the extension name and a colon, to distinguish |
183 | extensions, and this might be enforced in the future. |
213 | it from commands for other extensions, and this might be enforced in the |
|
|
214 | future. |
|
|
215 | |
|
|
216 | Be careful not ever to trust (in a security sense) the data you receive, |
|
|
217 | as its source can not easily be controleld (e-mail content, messages from |
|
|
218 | other users on the same system etc.). |
|
|
219 | |
|
|
220 | =item on_add_lines $term, $string |
|
|
221 | |
|
|
222 | Called whenever text is about to be output, with the text as argument. You |
|
|
223 | can filter/change and output the text yourself by returning a true value |
|
|
224 | and calling C<< $term->scr_add_lines >> yourself. Please note that this |
|
|
225 | might be very slow, however, as your hook is called for B<all> text being |
|
|
226 | output. |
184 | |
227 | |
185 | =item on_refresh_begin $term |
228 | =item on_refresh_begin $term |
186 | |
229 | |
187 | Called just before the screen gets redrawn. Can be used for overlay |
230 | Called just before the screen gets redrawn. Can be used for overlay |
188 | or similar effects by modify terminal contents in refresh_begin, and |
231 | or similar effects by modify terminal contents in refresh_begin, and |
… | |
… | |
361 | |
404 | |
362 | $pkg |
405 | $pkg |
363 | } |
406 | } |
364 | } |
407 | } |
365 | |
408 | |
|
|
409 | our $retval; # return value for urxvt |
|
|
410 | |
366 | # called by the rxvt core |
411 | # called by the rxvt core |
367 | sub invoke { |
412 | sub invoke { |
368 | local $TERM = shift; |
413 | local $TERM = shift; |
369 | my $htype = shift; |
414 | my $htype = shift; |
370 | |
415 | |
371 | if ($htype == 0) { # INIT |
416 | if ($htype == 0) { # INIT |
372 | my @dirs = ((split /:/, $TERM->resource ("perl_lib")), "$LIBDIR/perl"); |
417 | my @dirs = ((split /:/, $TERM->resource ("perl_lib")), "$LIBDIR/perl"); |
373 | |
418 | |
374 | for my $ext (split /:/, $TERM->resource ("perl_ext")) { |
419 | for my $ext (map { split /:/, $TERM->resource ("perl_ext_$_") } 1, 2) { |
375 | my @files = grep -f $_, map "$_/$ext", @dirs; |
420 | my @files = grep -f $_, map "$_/$ext", @dirs; |
376 | |
421 | |
377 | if (@files) { |
422 | if (@files) { |
378 | register_package script_package $files[0]; |
423 | register_package script_package $files[0]; |
379 | } else { |
424 | } else { |
380 | warn "perl extension '$ext' not found in perl library search path\n"; |
425 | warn "perl extension '$ext' not found in perl library search path\n"; |
381 | } |
426 | } |
382 | } |
427 | } |
|
|
428 | } |
383 | |
429 | |
|
|
430 | $retval = undef; |
|
|
431 | |
|
|
432 | if (my $cb = $TERM->{_hook}[$htype]) { |
|
|
433 | verbose 10, "$HOOKNAME[$htype] (" . (join ", ", $TERM, @_) . ")" |
|
|
434 | if $verbosity >= 10; |
|
|
435 | |
|
|
436 | keys %$cb; |
|
|
437 | |
|
|
438 | while (my ($pkg, $cb) = each %$cb) { |
|
|
439 | $retval = $cb->( |
|
|
440 | $TERM->{_pkg}{$pkg} ||= do { |
|
|
441 | my $proxy = bless { }, urxvt::term::proxy::; |
|
|
442 | Scalar::Util::weaken ($proxy->{term} = $TERM); |
|
|
443 | $proxy |
|
|
444 | }, |
|
|
445 | @_, |
|
|
446 | ) and last; |
|
|
447 | } |
|
|
448 | } |
|
|
449 | |
384 | } elsif ($htype == 1) { # DESTROY |
450 | if ($htype == 1) { # DESTROY |
|
|
451 | # remove hooks if unused |
385 | if (my $hook = $TERM->{_hook}) { |
452 | if (my $hook = $TERM->{_hook}) { |
386 | for my $htype (0..$#$hook) { |
453 | for my $htype (0..$#$hook) { |
387 | $hook_count[$htype] -= scalar keys %{ $hook->[$htype] || {} } |
454 | $hook_count[$htype] -= scalar keys %{ $hook->[$htype] || {} } |
388 | or set_should_invoke $htype, 0; |
455 | or set_should_invoke $htype, 0; |
389 | } |
456 | } |
390 | } |
457 | } |
|
|
458 | |
|
|
459 | # clear package objects |
|
|
460 | %$_ = () for values %{ $TERM->{_pkg} }; |
|
|
461 | |
|
|
462 | # clear package |
|
|
463 | %$TERM = (); |
391 | } |
464 | } |
392 | |
465 | |
393 | my $cb = $TERM->{_hook}[$htype] |
466 | $retval |
394 | or return; |
|
|
395 | |
|
|
396 | verbose 10, "$HOOKNAME[$htype] (" . (join ", ", $TERM, @_) . ")" |
|
|
397 | if $verbosity >= 10; |
|
|
398 | |
|
|
399 | keys %$cb; |
|
|
400 | |
|
|
401 | while (my ($pkg, $cb) = each %$cb) { |
|
|
402 | return 1 |
|
|
403 | if $cb->( |
|
|
404 | $TERM->{$pkg} ||= do { |
|
|
405 | my $proxy = bless { }, urxvt::term::proxy::; |
|
|
406 | Scalar::Util::weaken ($proxy->{term} = $TERM); |
|
|
407 | $proxy |
|
|
408 | }, |
|
|
409 | @_, |
|
|
410 | ); |
|
|
411 | } |
|
|
412 | |
|
|
413 | 0 |
|
|
414 | } |
467 | } |
415 | |
468 | |
416 | sub urxvt::term::proxy::AUTOLOAD { |
469 | sub urxvt::term::proxy::AUTOLOAD { |
417 | $urxvt::term::proxy::AUTOLOAD =~ /:([^:]+)$/ |
470 | $urxvt::term::proxy::AUTOLOAD =~ /:([^:]+)$/ |
418 | or die "FATAL: \$AUTOLOAD '$urxvt::term::proxy::AUTOLOAD' unparsable"; |
471 | or die "FATAL: \$AUTOLOAD '$urxvt::term::proxy::AUTOLOAD' unparsable"; |
… | |
… | |
456 | answerbackstring backgroundPixmap backspace_key boldFont boldItalicFont |
509 | answerbackstring backgroundPixmap backspace_key boldFont boldItalicFont |
457 | borderLess color cursorBlink cursorUnderline cutchars delete_key |
510 | borderLess color cursorBlink cursorUnderline cutchars delete_key |
458 | display_name embed ext_bwidth fade font geometry hold iconName |
511 | display_name embed ext_bwidth fade font geometry hold iconName |
459 | imFont imLocale inputMethod insecure int_bwidth intensityStyles |
512 | imFont imLocale inputMethod insecure int_bwidth intensityStyles |
460 | italicFont jumpScroll lineSpace loginShell mapAlert menu meta8 modifier |
513 | italicFont jumpScroll lineSpace loginShell mapAlert menu meta8 modifier |
461 | mouseWheelScrollPage name pastableTabs path perl_eval perl_ext |
514 | mouseWheelScrollPage name pastableTabs path perl_eval perl_ext_1 perl_ext_2 |
462 | perl_lib pointerBlank pointerBlankDelay preeditType print_pipe pty_fd |
515 | perl_lib pointerBlank pointerBlankDelay preeditType print_pipe pty_fd |
463 | reverseVideo saveLines scrollBar scrollBar_align scrollBar_floating |
516 | reverseVideo saveLines scrollBar scrollBar_align scrollBar_floating |
464 | scrollBar_right scrollBar_thickness scrollTtyKeypress scrollTtyOutput |
517 | scrollBar_right scrollBar_thickness scrollTtyKeypress scrollTtyOutput |
465 | scrollWithBuffer scrollstyle secondaryScreen secondaryScroll selectstyle |
518 | scrollWithBuffer scrollstyle secondaryScreen secondaryScroll selectstyle |
466 | shade term_name title transparent transparent_all tripleclickwords |
519 | shade term_name title transparent transparent_all tripleclickwords |
… | |
… | |
472 | my ($self, $name) = (shift, shift); |
525 | my ($self, $name) = (shift, shift); |
473 | unshift @_, $self, $name, ($name =~ s/\s*\+\s*(\d+)$// ? $1 : 0); |
526 | unshift @_, $self, $name, ($name =~ s/\s*\+\s*(\d+)$// ? $1 : 0); |
474 | goto &urxvt::term::_resource; |
527 | goto &urxvt::term::_resource; |
475 | } |
528 | } |
476 | |
529 | |
|
|
530 | =item $rend = $term->rstyle ([$new_rstyle]) |
|
|
531 | |
|
|
532 | Return and optionally change the current rendition. Text that is output by |
|
|
533 | the terminal application will use this style. |
|
|
534 | |
|
|
535 | =item ($row, $col) = $term->screen_cur ([$row, $col]) |
|
|
536 | |
|
|
537 | Return the current coordinates of the text cursor position and optionally |
|
|
538 | set it (which is usually bad as applications don't expect that). |
|
|
539 | |
477 | =item ($row, $col) = $term->selection_mark ([$row, $col]) |
540 | =item ($row, $col) = $term->selection_mark ([$row, $col]) |
478 | |
541 | |
479 | =item ($row, $col) = $term->selection_beg ([$row, $col]) |
542 | =item ($row, $col) = $term->selection_beg ([$row, $col]) |
480 | |
543 | |
481 | =item ($row, $col) = $term->selection_end ([$row, $col]) |
544 | =item ($row, $col) = $term->selection_end ([$row, $col]) |
… | |
… | |
495 | #=item $term->overlay ($x, $y, $text) |
558 | #=item $term->overlay ($x, $y, $text) |
496 | # |
559 | # |
497 | #Create a simple multi-line overlay box. See the next method for details. |
560 | #Create a simple multi-line overlay box. See the next method for details. |
498 | # |
561 | # |
499 | #=cut |
562 | #=cut |
500 | |
563 | # |
501 | sub urxvt::term::scr_overlay { |
564 | #sub urxvt::term::scr_overlay { |
502 | die; |
|
|
503 | my ($self, $x, $y, $text) = @_; |
565 | # my ($self, $x, $y, $text) = @_; |
504 | |
566 | # |
505 | my @lines = split /\n/, $text; |
567 | # my @lines = split /\n/, $text; |
506 | |
568 | # |
507 | my $w = 0; |
569 | # my $w = 0; |
508 | for (map $self->strwidth ($_), @lines) { |
570 | # for (map $self->strwidth ($_), @lines) { |
509 | $w = $_ if $w < $_; |
571 | # $w = $_ if $w < $_; |
510 | } |
572 | # } |
511 | |
573 | # |
512 | $self->scr_overlay_new ($x, $y, $w, scalar @lines); |
574 | # $self->scr_overlay_new ($x, $y, $w, scalar @lines); |
513 | $self->scr_overlay_set (0, $_, $lines[$_]) for 0.. $#lines; |
575 | # $self->scr_overlay_set (0, $_, $lines[$_]) for 0.. $#lines; |
514 | } |
576 | #} |
515 | |
577 | |
516 | =item $term->overlay ($x, $y, $width, $height[, $rstyle[, $border]]) |
578 | =item $term->overlay ($x, $y, $width, $height[, $rstyle[, $border]]) |
517 | |
579 | |
518 | Create a new (empty) overlay at the given position with the given |
580 | Create a new (empty) overlay at the given position with the given |
519 | width/height. C<$rstyle> defines the initial rendition style |
581 | width/height. C<$rstyle> defines the initial rendition style |
… | |
… | |
559 | |
621 | |
560 | =item $string = $term->locale_decode $octets |
622 | =item $string = $term->locale_decode $octets |
561 | |
623 | |
562 | Convert the given locale-encoded octets into a perl string. |
624 | Convert the given locale-encoded octets into a perl string. |
563 | |
625 | |
|
|
626 | =item $term->scr_add_lines ($string) |
|
|
627 | |
|
|
628 | Write the given text string to the screen, as if output by the application |
|
|
629 | running inside the terminal. It may not contain command sequences (escape |
|
|
630 | codes), but is free to use line feeds, carriage returns and tabs. The |
|
|
631 | string is a normal text string, not in locale-dependent encoding. |
|
|
632 | |
|
|
633 | Normally its not a good idea to use this function, as programs might be |
|
|
634 | confused by changes in cursor position or scrolling. Its useful inside a |
|
|
635 | C<on_add_lines> hook, though. |
|
|
636 | |
564 | =item $term->tt_write ($octets) |
637 | =item $term->tt_write ($octets) |
565 | |
638 | |
566 | Write the octets given in C<$data> to the tty (i.e. as program input). To |
639 | Write the octets given in C<$data> to the tty (i.e. as program input). To |
567 | pass characters instead of octets, you should convert your strings first |
640 | pass characters instead of octets, you should convert your strings first |
568 | to the locale-specific encoding using C<< $term->locale_encode >>. |
641 | to the locale-specific encoding using C<< $term->locale_encode >>. |
569 | |
642 | |
|
|
643 | =item $window_width = $term->width |
|
|
644 | |
|
|
645 | =item $window_height = $term->height |
|
|
646 | |
|
|
647 | =item $font_width = $term->fwidth |
|
|
648 | |
|
|
649 | =item $font_height = $term->fheight |
|
|
650 | |
|
|
651 | =item $font_ascent = $term->fbase |
|
|
652 | |
570 | =item $nrow = $term->nrow |
653 | =item $terminal_rows = $term->nrow |
571 | |
654 | |
572 | =item $ncol = $term->ncol |
655 | =item $terminal_columns = $term->ncol |
573 | |
656 | |
574 | Return the number of rows/columns of the terminal window (i.e. as |
657 | =item $has_focus = $term->focus |
575 | specified by C<-geometry>, excluding any scrollback). |
|
|
576 | |
658 | |
577 | =item $nsaved = $term->nsaved |
659 | =item $is_mapped = $term->mapped |
578 | |
660 | |
579 | Returns the number of lines in the scrollback buffer. |
661 | =item $max_scrollback = $term->saveLines |
|
|
662 | |
|
|
663 | =item $nrow_plus_saveLines = $term->total_rows |
|
|
664 | |
|
|
665 | =item $lines_in_scrollback = $term->nsaved |
|
|
666 | |
|
|
667 | Return various integers describing terminal characteristics. |
580 | |
668 | |
581 | =item $view_start = $term->view_start ([$newvalue]) |
669 | =item $view_start = $term->view_start ([$newvalue]) |
582 | |
670 | |
583 | Returns the negative row number of the topmost line. Minimum value is |
671 | Returns the negative row number of the topmost line. Minimum value is |
584 | C<0>, which displays the normal terminal contents. Larger values scroll |
672 | C<0>, which displays the normal terminal contents. Larger values scroll |
… | |
… | |
692 | |
780 | |
693 | bless { |
781 | bless { |
694 | term => $self, |
782 | term => $self, |
695 | beg => $beg, |
783 | beg => $beg, |
696 | end => $end, |
784 | end => $end, |
|
|
785 | ncol => $self->ncol, |
697 | len => ($end - $beg) * $self->ncol + $self->ROW_l ($end), |
786 | len => ($end - $beg) * $self->ncol + $self->ROW_l ($end), |
698 | }, urxvt::line:: |
787 | }, urxvt::line:: |
699 | } |
788 | } |
700 | |
789 | |
701 | sub urxvt::line::t { |
790 | sub urxvt::line::t { |
702 | my ($self) = @_; |
791 | my ($self) = @_; |
703 | |
792 | |
|
|
793 | if (@_ > 1) |
|
|
794 | { |
|
|
795 | $self->{term}->ROW_t ($_, $_[1], 0, ($_ - $self->{beg}) * $self->{ncol}, $self->{ncol}) |
|
|
796 | for $self->{beg} .. $self->{end}; |
|
|
797 | } |
|
|
798 | |
|
|
799 | defined wantarray && |
704 | substr +(join "", map $self->{term}->ROW_t ($_), $self->{beg} .. $self->{end}), |
800 | substr +(join "", map $self->{term}->ROW_t ($_), $self->{beg} .. $self->{end}), |
705 | 0, $self->{len} |
801 | 0, $self->{len} |
706 | } |
802 | } |
707 | |
803 | |
708 | sub urxvt::line::r { |
804 | sub urxvt::line::r { |
709 | my ($self) = @_; |
805 | my ($self) = @_; |
710 | |
806 | |
|
|
807 | if (@_ > 1) |
|
|
808 | { |
|
|
809 | $self->{term}->ROW_r ($_, $_[1], 0, ($_ - $self->{beg}) * $self->{ncol}, $self->{ncol}) |
|
|
810 | for $self->{beg} .. $self->{end}; |
|
|
811 | } |
|
|
812 | |
|
|
813 | if (defined wantarray) { |
711 | my $rend = [ |
814 | my $rend = [ |
712 | map @{ $self->{term}->ROW_r ($_) }, $self->{beg} .. $self->{end} |
815 | map @{ $self->{term}->ROW_r ($_) }, $self->{beg} .. $self->{end} |
713 | ]; |
816 | ]; |
714 | $#$rend = $self->{len} - 1; |
817 | $#$rend = $self->{len} - 1; |
715 | $rend |
818 | return $rend; |
|
|
819 | } |
|
|
820 | |
|
|
821 | () |
716 | } |
822 | } |
717 | |
823 | |
718 | sub urxvt::line::beg { $_[0]{beg} } |
824 | sub urxvt::line::beg { $_[0]{beg} } |
719 | sub urxvt::line::end { $_[0]{end} } |
825 | sub urxvt::line::end { $_[0]{end} } |
720 | sub urxvt::line::l { $_[0]{len} } |
826 | sub urxvt::line::l { $_[0]{len} } |
721 | |
827 | |
722 | sub urxvt::line::offset_of { |
828 | sub urxvt::line::offset_of { |
723 | my ($self, $row, $col) = @_; |
829 | my ($self, $row, $col) = @_; |
724 | |
830 | |
725 | ($row - $self->{beg}) * $self->{term}->ncol + $col |
831 | ($row - $self->{beg}) * $self->{ncol} + $col |
726 | } |
832 | } |
727 | |
833 | |
728 | sub urxvt::line::coord_of { |
834 | sub urxvt::line::coord_of { |
729 | my ($self, $offset) = @_; |
835 | my ($self, $offset) = @_; |
730 | |
836 | |
731 | use integer; |
837 | use integer; |
732 | |
838 | |
733 | ( |
839 | ( |
734 | $offset / $self->{term}->ncol + $self->{beg}, |
840 | $offset / $self->{ncol} + $self->{beg}, |
735 | $offset % $self->{term}->ncol |
841 | $offset % $self->{ncol} |
736 | ) |
842 | ) |
737 | } |
843 | } |
738 | |
844 | |
739 | =item ($row, $col) = $line->coord_of ($offset) |
845 | =item ($row, $col) = $line->coord_of ($offset) |
740 | =item $text = $term->special_encode $string |
846 | =item $text = $term->special_encode $string |