… | |
… | |
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 | |
… | |
… | |
80 | |
87 | |
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. |
|
|
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 |
85 | |
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. |
… | |
… | |
184 | future. |
214 | future. |
185 | |
215 | |
186 | Be careful not ever to trust (in a security sense) the data you receive, |
216 | Be careful not ever to trust (in a security sense) the data you receive, |
187 | as its source can not easily be controleld (e-mail content, messages from |
217 | as its source can not easily be controleld (e-mail content, messages from |
188 | other users on the same system etc.). |
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. |
189 | |
227 | |
190 | =item on_refresh_begin $term |
228 | =item on_refresh_begin $term |
191 | |
229 | |
192 | 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 |
193 | or similar effects by modify terminal contents in refresh_begin, and |
231 | or similar effects by modify terminal contents in refresh_begin, and |
… | |
… | |
487 | my ($self, $name) = (shift, shift); |
525 | my ($self, $name) = (shift, shift); |
488 | unshift @_, $self, $name, ($name =~ s/\s*\+\s*(\d+)$// ? $1 : 0); |
526 | unshift @_, $self, $name, ($name =~ s/\s*\+\s*(\d+)$// ? $1 : 0); |
489 | goto &urxvt::term::_resource; |
527 | goto &urxvt::term::_resource; |
490 | } |
528 | } |
491 | |
529 | |
492 | =item $rend = $term->screen_rstyle ([$new_rstyle]) |
530 | =item $rend = $term->rstyle ([$new_rstyle]) |
493 | |
531 | |
494 | Return and optionally change the current rendition. Text thta is output by |
532 | Return and optionally change the current rendition. Text that is output by |
495 | the temrianl application will use this style. |
533 | the terminal application will use this style. |
496 | |
534 | |
497 | =item ($row, $col) = $term->screen_cur ([$row, $col]) |
535 | =item ($row, $col) = $term->screen_cur ([$row, $col]) |
498 | |
536 | |
499 | Return the current coordinates of the text cursor position and optionally |
537 | Return the current coordinates of the text cursor position and optionally |
500 | set it (which is usually bad as applications don't expect that). |
538 | set it (which is usually bad as applications don't expect that). |
… | |
… | |
520 | #=item $term->overlay ($x, $y, $text) |
558 | #=item $term->overlay ($x, $y, $text) |
521 | # |
559 | # |
522 | #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. |
523 | # |
561 | # |
524 | #=cut |
562 | #=cut |
525 | |
563 | # |
526 | sub urxvt::term::scr_overlay { |
564 | #sub urxvt::term::scr_overlay { |
527 | die; |
|
|
528 | my ($self, $x, $y, $text) = @_; |
565 | # my ($self, $x, $y, $text) = @_; |
529 | |
566 | # |
530 | my @lines = split /\n/, $text; |
567 | # my @lines = split /\n/, $text; |
531 | |
568 | # |
532 | my $w = 0; |
569 | # my $w = 0; |
533 | for (map $self->strwidth ($_), @lines) { |
570 | # for (map $self->strwidth ($_), @lines) { |
534 | $w = $_ if $w < $_; |
571 | # $w = $_ if $w < $_; |
535 | } |
572 | # } |
536 | |
573 | # |
537 | $self->scr_overlay_new ($x, $y, $w, scalar @lines); |
574 | # $self->scr_overlay_new ($x, $y, $w, scalar @lines); |
538 | $self->scr_overlay_set (0, $_, $lines[$_]) for 0.. $#lines; |
575 | # $self->scr_overlay_set (0, $_, $lines[$_]) for 0.. $#lines; |
539 | } |
576 | #} |
540 | |
577 | |
541 | =item $term->overlay ($x, $y, $width, $height[, $rstyle[, $border]]) |
578 | =item $term->overlay ($x, $y, $width, $height[, $rstyle[, $border]]) |
542 | |
579 | |
543 | 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 |
544 | width/height. C<$rstyle> defines the initial rendition style |
581 | width/height. C<$rstyle> defines the initial rendition style |
… | |
… | |
583 | Convert the given text string into the corresponding locale encoding. |
620 | Convert the given text string into the corresponding locale encoding. |
584 | |
621 | |
585 | =item $string = $term->locale_decode $octets |
622 | =item $string = $term->locale_decode $octets |
586 | |
623 | |
587 | Convert the given locale-encoded octets into a perl string. |
624 | Convert the given locale-encoded octets into a perl string. |
|
|
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. |
588 | |
636 | |
589 | =item $term->tt_write ($octets) |
637 | =item $term->tt_write ($octets) |
590 | |
638 | |
591 | 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 |
592 | pass characters instead of octets, you should convert your strings first |
640 | pass characters instead of octets, you should convert your strings first |
… | |
… | |
732 | |
780 | |
733 | bless { |
781 | bless { |
734 | term => $self, |
782 | term => $self, |
735 | beg => $beg, |
783 | beg => $beg, |
736 | end => $end, |
784 | end => $end, |
|
|
785 | ncol => $self->ncol, |
737 | len => ($end - $beg) * $self->ncol + $self->ROW_l ($end), |
786 | len => ($end - $beg) * $self->ncol + $self->ROW_l ($end), |
738 | }, urxvt::line:: |
787 | }, urxvt::line:: |
739 | } |
788 | } |
740 | |
789 | |
741 | sub urxvt::line::t { |
790 | sub urxvt::line::t { |
742 | my ($self) = @_; |
791 | my ($self) = @_; |
743 | |
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 && |
744 | substr +(join "", map $self->{term}->ROW_t ($_), $self->{beg} .. $self->{end}), |
800 | substr +(join "", map $self->{term}->ROW_t ($_), $self->{beg} .. $self->{end}), |
745 | 0, $self->{len} |
801 | 0, $self->{len} |
746 | } |
802 | } |
747 | |
803 | |
748 | sub urxvt::line::r { |
804 | sub urxvt::line::r { |
749 | my ($self) = @_; |
805 | my ($self) = @_; |
750 | |
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) { |
751 | my $rend = [ |
814 | my $rend = [ |
752 | map @{ $self->{term}->ROW_r ($_) }, $self->{beg} .. $self->{end} |
815 | map @{ $self->{term}->ROW_r ($_) }, $self->{beg} .. $self->{end} |
753 | ]; |
816 | ]; |
754 | $#$rend = $self->{len} - 1; |
817 | $#$rend = $self->{len} - 1; |
755 | $rend |
818 | return $rend; |
|
|
819 | } |
|
|
820 | |
|
|
821 | () |
756 | } |
822 | } |
757 | |
823 | |
758 | sub urxvt::line::beg { $_[0]{beg} } |
824 | sub urxvt::line::beg { $_[0]{beg} } |
759 | sub urxvt::line::end { $_[0]{end} } |
825 | sub urxvt::line::end { $_[0]{end} } |
760 | sub urxvt::line::l { $_[0]{len} } |
826 | sub urxvt::line::l { $_[0]{len} } |
761 | |
827 | |
762 | sub urxvt::line::offset_of { |
828 | sub urxvt::line::offset_of { |
763 | my ($self, $row, $col) = @_; |
829 | my ($self, $row, $col) = @_; |
764 | |
830 | |
765 | ($row - $self->{beg}) * $self->{term}->ncol + $col |
831 | ($row - $self->{beg}) * $self->{ncol} + $col |
766 | } |
832 | } |
767 | |
833 | |
768 | sub urxvt::line::coord_of { |
834 | sub urxvt::line::coord_of { |
769 | my ($self, $offset) = @_; |
835 | my ($self, $offset) = @_; |
770 | |
836 | |
771 | use integer; |
837 | use integer; |
772 | |
838 | |
773 | ( |
839 | ( |
774 | $offset / $self->{term}->ncol + $self->{beg}, |
840 | $offset / $self->{ncol} + $self->{beg}, |
775 | $offset % $self->{term}->ncol |
841 | $offset % $self->{ncol} |
776 | ) |
842 | ) |
777 | } |
843 | } |
778 | |
844 | |
779 | =item ($row, $col) = $line->coord_of ($offset) |
845 | =item ($row, $col) = $line->coord_of ($offset) |
780 | =item $text = $term->special_encode $string |
846 | =item $text = $term->special_encode $string |