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.254 by sf-exg, Tue Mar 17 09:23:08 2015 UTC vs.
Revision 1.265 by root, Sat Jul 24 09:48:43 2021 UTC

4 4
5urxvtperl - rxvt-unicode's embedded perl interpreter 5urxvtperl - rxvt-unicode's embedded perl interpreter
6 6
7=head1 SYNOPSIS 7=head1 SYNOPSIS
8 8
9 # create a file grab_test in $HOME: 9 # create a file grab_test in some directory:
10 10
11 sub on_sel_grab { 11 sub on_sel_grab {
12 warn "you selected ", $_[0]->selection; 12 warn "you selected ", $_[0]->selection;
13 () 13 ()
14 } 14 }
15 15
16 # start a urxvt using it: 16 # start a urxvt instance using it:
17 17
18 urxvt --perl-lib $HOME -pe grab_test 18 urxvt --perl-lib path/to/somedirectory -pe grab_test
19 19
20=head1 DESCRIPTION 20=head1 DESCRIPTION
21 21
22Every time a terminal object gets created, extension scripts specified via 22Every time a terminal object gets created, extension scripts specified via
23the C<perl> resource are loaded and associated with it. 23the C<perl> resource are loaded and associated with it.
70terminal is destroyed. 70terminal is destroyed.
71 71
72Argument names also often indicate the type of a parameter. Here are some 72Argument names also often indicate the type of a parameter. Here are some
73hints on what they mean: 73hints on what they mean:
74 74
75=over 4 75=over
76 76
77=item $text 77=item $text
78 78
79Rxvt-unicode's special way of encoding text, where one "unicode" character 79Rxvt-unicode's special way of encoding text, where one "unicode" character
80always represents one screen cell. See L<ROW_t> for a discussion of this format. 80always represents one screen cell. See L<ROW_t> for a discussion of this format.
115the C<urxvt::extension> section below. 115the C<urxvt::extension> section below.
116 116
117=head2 META comments 117=head2 META comments
118 118
119Rxvt-unicode recognizes special meta comments in extensions that define 119Rxvt-unicode recognizes special meta comments in extensions that define
120different types of metadata. 120different types of metadata. These comments are scanned whenever a
121terminal is created and are typically used to autoload extensions when
122their resources or command line parameters are used.
121 123
122Currently, it recognises only one such comment: 124Currently, it recognises only one such comment:
123 125
124=over 4 126=over
125 127
126=item #:META:RESOURCE:name:type:desc 128=item #:META:RESOURCE:name:type:desc
127 129
128The RESOURCE comment defines a resource used by the extension, where 130The RESOURCE comment defines a resource used by the extension, where
129C<name> is the resource name, C<type> is the resource type, C<boolean> 131C<name> is the resource name, C<type> is the resource type, C<boolean>
130or C<string>, and C<desc> is the resource description. 132or C<string>, and C<desc> is the resource description.
131 133
134The extension will be autoloaded when this resource is specified or used
135as a command line parameter.
136
132=back 137=back
133 138
134=head2 Hooks 139=head2 Hooks
135 140
136The following subroutines can be declared in extension files, and will be 141The following subroutines can be declared in extension files, and will be
143hooks returns true, then the event counts as being I<consumed>, and the 148hooks returns true, then the event counts as being I<consumed>, and the
144relevant action might not be carried out by the C++ code. 149relevant action might not be carried out by the C++ code.
145 150
146I<< When in doubt, return a false value (preferably C<()>). >> 151I<< When in doubt, return a false value (preferably C<()>). >>
147 152
148=over 4 153=over
149 154
150=item on_init $term 155=item on_init $term
151 156
152Called after a new terminal object has been initialized, but before 157Called after a new terminal object has been initialized, but before
153windows are created or the command gets run. Most methods are unsafe to 158windows are created or the command gets run. Most methods are unsafe to
417 422
418our $NOCHAR = chr 0xffff; 423our $NOCHAR = chr 0xffff;
419 424
420=head2 Variables in the C<urxvt> Package 425=head2 Variables in the C<urxvt> Package
421 426
422=over 4 427=over
423 428
424=item $urxvt::LIBDIR 429=item $urxvt::LIBDIR
425 430
426The rxvt-unicode library directory, where, among other things, the perl 431The rxvt-unicode library directory, where, among other things, the perl
427modules and scripts are stored. 432modules and scripts are stored.
457 462
458=back 463=back
459 464
460=head2 Functions in the C<urxvt> Package 465=head2 Functions in the C<urxvt> Package
461 466
462=over 4 467=over
463 468
464=item urxvt::fatal $errormessage 469=item urxvt::fatal $errormessage
465 470
466Fatally aborts execution with the given error message (which should 471Fatally aborts execution with the given error message (which should
467include a trailing newline). Avoid at all costs! The only time this 472include a trailing newline). Avoid at all costs! The only time this
512CirculateRequest, PropertyNotify, SelectionClear, SelectionRequest, 517CirculateRequest, PropertyNotify, SelectionClear, SelectionRequest,
513SelectionNotify, ColormapNotify, ClientMessage, MappingNotify 518SelectionNotify, ColormapNotify, ClientMessage, MappingNotify
514 519
515Various constants for use in X calls and event processing. 520Various constants for use in X calls and event processing.
516 521
522=item urxvt::PrivMode_132, PrivMode_132OK, PrivMode_rVideo, PrivMode_relOrigin,
523PrivMode_Screen, PrivMode_Autowrap, PrivMode_aplCUR, PrivMode_aplKP,
524PrivMode_HaveBackSpace, PrivMode_BackSpace, PrivMode_ShiftKeys,
525PrivMode_VisibleCursor, PrivMode_MouseX10, PrivMode_MouseX11,
526PrivMode_scrollBar, PrivMode_TtyOutputInh, PrivMode_Keypress,
527PrivMode_smoothScroll, PrivMode_vt52, PrivMode_LFNL, PrivMode_MouseBtnEvent,
528PrivMode_MouseAnyEvent, PrivMode_BracketPaste, PrivMode_ExtMouseUTF8,
529PrivMode_ExtMouseUrxvt, PrivMode_BlinkingCursor, PrivMode_mouse_report,
530PrivMode_Default
531
532Constants for checking DEC private modes.
533
517=back 534=back
518 535
519=head2 RENDITION 536=head2 RENDITION
520 537
521Rendition bitsets contain information about colour, font, font styles and 538Rendition bitsets contain information about colour, font, font styles and
524The following "macros" deal with changes in rendition sets. You should 541The following "macros" deal with changes in rendition sets. You should
525never just create a bitset, you should always modify an existing one, 542never just create a bitset, you should always modify an existing one,
526as they contain important information required for correct operation of 543as they contain important information required for correct operation of
527rxvt-unicode. 544rxvt-unicode.
528 545
529=over 4 546=over
530 547
531=item $rend = urxvt::DEFAULT_RSTYLE 548=item $rend = urxvt::DEFAULT_RSTYLE
532 549
533Returns the default rendition, as used when the terminal is starting up or 550Returns the default rendition, as used when the terminal is starting up or
534being reset. Useful as a base to start when creating renditions. 551being reset. Useful as a base to start when creating renditions.
588sub parse_resource { 605sub parse_resource {
589 my ($term, $name, $isarg, $longopt, $flag, $value) = @_; 606 my ($term, $name, $isarg, $longopt, $flag, $value) = @_;
590 607
591 $term->scan_extensions; 608 $term->scan_extensions;
592 609
610 # iterating over all resources has quadratic time overhead
611 # overall, maybe this could be optimised?
593 my $r = $term->{meta}{resource}; 612 my $r = $term->{meta}{resource};
594 keys %$r; # reset iterator 613 keys %$r; # reset iterator
595 while (my ($k, $v) = each %$r) { 614 while (my ($k, $v) = each %$r) {
596 my $pattern = $k; 615 my $pattern = $k;
597 $pattern =~ y/./-/ if $isarg; 616 $pattern =~ y/./-/ if $isarg;
604 if ($pattern eq $prefix) { 623 if ($pattern eq $prefix) {
605 $name = "$urxvt::RESCLASS.$k$suffix"; 624 $name = "$urxvt::RESCLASS.$k$suffix";
606 625
607 push @{ $term->{perl_ext_3} }, $v->[0]; 626 push @{ $term->{perl_ext_3} }, $v->[0];
608 627
628 return 1 unless $isarg;
629
609 if ($v->[1] eq "boolean") { 630 if ($v->[1] eq "boolean") {
610 $term->put_option_db ($name, $flag ? "true" : "false"); 631 $term->put_option_db ($name, $flag ? "true" : "false");
611 return 1; 632 return 1;
612 } else { 633 } else {
613 $term->put_option_db ($name, $value); 634 $term->put_option_db ($name, $value);
708 @TERM_EXT = (); 729 @TERM_EXT = ();
709 $TERM->register_package ($_) for @pkg; 730 $TERM->register_package ($_) for @pkg;
710 } 731 }
711 732
712 for ( 733 for (
734 @{ delete $TERM->{perl_ext_3} },
713 (grep $_, map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2), 735 (grep $_, map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2),
714 @{ delete $TERM->{perl_ext_3} }
715 ) { 736 ) {
716 if ($_ eq "default") { 737 if ($_ eq "default") {
717 738
718 $ext_arg{$_} = [] 739 $ext_arg{$_} = []
719 for qw(selection option-popup selection-popup readline searchable-scrollback); 740 for qw(selection option-popup selection-popup readline searchable-scrollback confirm-paste);
720 741
721 for ($TERM->_keysym_resources) { 742 for ($TERM->_keysym_resources) {
722 next if /^(?:string|command|builtin|builtin-string|perl)/; 743 next if /^(?:string|command|builtin|builtin-string|perl)/;
723 next unless /^([A-Za-z0-9_\-]+):/; 744 next unless /^([A-Za-z0-9_\-]+):/;
724 745
837 858
838The methods (And data members) documented below can be called on extension 859The methods (And data members) documented below can be called on extension
839objects, in addition to call methods documented for the <urxvt::term> 860objects, in addition to call methods documented for the <urxvt::term>
840class. 861class.
841 862
842=over 4 863=over
843 864
844=item $urxvt_term = $self->{term} 865=item $urxvt_term = $self->{term}
845 866
846Returns the C<urxvt::term> object associated with this instance of the 867Returns the C<urxvt::term> object associated with this instance of the
847extension. This member I<must not> be changed in any way. 868extension. This member I<must not> be changed in any way.
1088 1109
1089package urxvt::term; 1110package urxvt::term;
1090 1111
1091=head2 The C<urxvt::term> Class 1112=head2 The C<urxvt::term> Class
1092 1113
1093=over 4 1114=over
1094 1115
1095=cut 1116=cut
1096 1117
1097# find on_xxx subs in the package and register them 1118# find on_xxx subs in the package and register them
1098# as hooks 1119# as hooks
1263 insecure intensityStyles iso14755 iso14755_52 jumpScroll loginShell 1284 insecure intensityStyles iso14755 iso14755_52 jumpScroll loginShell
1264 mapAlert meta8 mouseWheelScrollPage override_redirect pastableTabs 1285 mapAlert meta8 mouseWheelScrollPage override_redirect pastableTabs
1265 pointerBlank reverseVideo scrollBar scrollBar_floating scrollBar_right 1286 pointerBlank reverseVideo scrollBar scrollBar_floating scrollBar_right
1266 scrollTtyKeypress scrollTtyOutput scrollWithBuffer secondaryScreen 1287 scrollTtyKeypress scrollTtyOutput scrollWithBuffer secondaryScreen
1267 secondaryScroll skipBuiltinGlyphs skipScroll transparent tripleclickwords 1288 secondaryScroll skipBuiltinGlyphs skipScroll transparent tripleclickwords
1268 urgentOnBell utmpInhibit visualBell 1289 urgentOnBell utmpInhibit visualBell disablePasteBrackets
1269 1290
1270=item $value = $term->resource ($name[, $newval]) 1291=item $value = $term->resource ($name[, $newval])
1271 1292
1272Returns the current resource value associated with a given name and 1293Returns the current resource value associated with a given name and
1273optionally sets a new value. Setting values is most useful in the C<init> 1294optionally sets a new value. Setting values is most useful in the C<init>
1299 preeditType print_pipe pty_fd reverseVideo saveLines scrollBar 1320 preeditType print_pipe pty_fd reverseVideo saveLines scrollBar
1300 scrollBar_align scrollBar_floating scrollBar_right scrollBar_thickness 1321 scrollBar_align scrollBar_floating scrollBar_right scrollBar_thickness
1301 scrollTtyKeypress scrollTtyOutput scrollWithBuffer scrollstyle 1322 scrollTtyKeypress scrollTtyOutput scrollWithBuffer scrollstyle
1302 secondaryScreen secondaryScroll shade skipBuiltinGlyphs skipScroll 1323 secondaryScreen secondaryScroll shade skipBuiltinGlyphs skipScroll
1303 term_name title transient_for transparent tripleclickwords urgentOnBell 1324 term_name title transient_for transparent tripleclickwords urgentOnBell
1304 utmpInhibit visualBell 1325 utmpInhibit visualBell rewrapMode disablePasteBrackets
1305 1326
1306=cut 1327=cut
1307 1328
1308sub resource($$;$) { 1329sub resource($$;$) {
1309 my ($self, $name) = (shift, shift); 1330 my ($self, $name) = (shift, shift);
1456This method returns an urxvt::overlay object. The overlay will be visible 1477This method returns an urxvt::overlay object. The overlay will be visible
1457as long as the perl object is referenced. 1478as long as the perl object is referenced.
1458 1479
1459The methods currently supported on C<urxvt::overlay> objects are: 1480The methods currently supported on C<urxvt::overlay> objects are:
1460 1481
1461=over 4 1482=over
1462 1483
1463=item $overlay->set ($x, $y, $text[, $rend]) 1484=item $overlay->set ($x, $y, $text[, $rend])
1464 1485
1465Similar to C<< $term->ROW_t >> and C<< $term->ROW_r >> in that it puts 1486Similar to C<< $term->ROW_t >> and C<< $term->ROW_r >> in that it puts
1466text in rxvt-unicode's special encoding and an array of rendition values 1487text in rxvt-unicode's special encoding and an array of rendition values
1617 1638
1618=item $term->key_release ($state, $keycode[, $time]) 1639=item $term->key_release ($state, $keycode[, $time])
1619 1640
1620Deliver various fake events to to terminal. 1641Deliver various fake events to to terminal.
1621 1642
1622=item $window_width = $term->width 1643=item $window_width = $term->width ([$new_value])
1623 1644
1624=item $window_height = $term->height 1645=item $window_height = $term->height ([$new_value])
1625 1646
1626=item $font_width = $term->fwidth 1647=item $font_width = $term->fwidth ([$new_value])
1627 1648
1628=item $font_height = $term->fheight 1649=item $font_height = $term->fheight ([$new_value])
1629 1650
1630=item $font_ascent = $term->fbase 1651=item $font_ascent = $term->fbase ([$new_value])
1631 1652
1632=item $terminal_rows = $term->nrow 1653=item $terminal_rows = $term->nrow ([$new_value])
1633 1654
1634=item $terminal_columns = $term->ncol 1655=item $terminal_columns = $term->ncol ([$new_value])
1635 1656
1636=item $has_focus = $term->focus 1657=item $has_focus = $term->focus ([$new_value])
1637 1658
1638=item $is_mapped = $term->mapped 1659=item $is_mapped = $term->mapped ([$new_value])
1639 1660
1640=item $max_scrollback = $term->saveLines 1661=item $max_scrollback = $term->saveLines ([$new_value])
1641 1662
1642=item $nrow_plus_saveLines = $term->total_rows 1663=item $nrow_plus_saveLines = $term->total_rows ([$new_value])
1643 1664
1644=item $topmost_scrollback_row = $term->top_row 1665=item $topmost_scrollback_row = $term->top_row ([$new_value])
1645 1666
1646Return various integers describing terminal characteristics. 1667Return various integers describing terminal characteristics. If an
1668argument is given, changes the value and returns the previous one.
1647 1669
1648=item $x_display = $term->display_id 1670=item $x_display = $term->display_id
1649 1671
1650Return the DISPLAY used by rxvt-unicode. 1672Return the DISPLAY used by rxvt-unicode.
1651 1673
1688 1710
1689=item $cursor_is_hidden = $term->hidden_cursor 1711=item $cursor_is_hidden = $term->hidden_cursor
1690 1712
1691Returns whether the cursor is currently hidden or not. 1713Returns whether the cursor is currently hidden or not.
1692 1714
1715=item $priv_modes = $term->priv_modes
1716
1717Returns a bitset with the state of DEC private modes.
1718
1719Example:
1720
1721 if ($term->priv_modes & urxvt::PrivMode_mouse_report) {
1722 # mouse reporting is turned on
1723 }
1724
1693=item $view_start = $term->view_start ([$newvalue]) 1725=item $view_start = $term->view_start ([$newvalue])
1694 1726
1695Returns the row number of the topmost displayed line. Maximum value is 1727Returns the row number of the topmost displayed line and changes it,
1696C<0>, which displays the normal terminal contents. Lower values scroll 1728if an argument is given. Values greater than or equal to C<0> display
1697this many lines into the scrollback buffer. 1729the terminal contents. Lower values scroll this many lines into the
1730scrollback buffer.
1698 1731
1699=item $term->want_refresh 1732=item $term->want_refresh
1700 1733
1701Requests a screen refresh. At the next opportunity, rxvt-unicode will 1734Requests a screen refresh. At the next opportunity, rxvt-unicode will
1702compare the on-screen display with its stored representation. If they 1735compare the on-screen display with its stored representation. If they
1760 1793
1761Create and return a new C<urxvt::line> object that stores information 1794Create and return a new C<urxvt::line> object that stores information
1762about the logical line that row C<$row_number> is part of. It supports the 1795about the logical line that row C<$row_number> is part of. It supports the
1763following methods: 1796following methods:
1764 1797
1765=over 4 1798=over
1766 1799
1767=item $text = $line->t ([$new_text]) 1800=item $text = $line->t ([$new_text])
1768 1801
1769Returns or replaces the full text of the line, similar to C<ROW_t> 1802Returns or replaces the full text of the line, similar to C<ROW_t>
1770 1803
1950 1983
1951package urxvt::popup; 1984package urxvt::popup;
1952 1985
1953=head2 The C<urxvt::popup> Class 1986=head2 The C<urxvt::popup> Class
1954 1987
1955=over 4 1988=over
1956 1989
1957=cut 1990=cut
1958 1991
1959sub add_item { 1992sub add_item {
1960 my ($self, $item) = @_; 1993 my ($self, $item) = @_;
2096 ->cb (sub { 2129 ->cb (sub {
2097 $term->{overlay}->set (0, 0, 2130 $term->{overlay}->set (0, 0,
2098 sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2,1,0]); 2131 sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2,1,0]);
2099 }); 2132 });
2100 2133
2101=over 4 2134=over
2102 2135
2103=item $timer = new urxvt::timer 2136=item $timer = new urxvt::timer
2104 2137
2105Create a new timer object in started state. It is scheduled to fire 2138Create a new timer object in started state. It is scheduled to fire
2106immediately. 2139immediately.
2155 sysread $term->{socket}, my $buf, 8192 2188 sysread $term->{socket}, my $buf, 8192
2156 or end-of-file; 2189 or end-of-file;
2157 }); 2190 });
2158 2191
2159 2192
2160=over 4 2193=over
2161 2194
2162=item $iow = new urxvt::iow 2195=item $iow = new urxvt::iow
2163 2196
2164Create a new io watcher object in stopped state. 2197Create a new io watcher object in stopped state.
2165 2198
2192 2225
2193This class implements idle watchers, that get called automatically when 2226This class implements idle watchers, that get called automatically when
2194the process is idle. They should return as fast as possible, after doing 2227the process is idle. They should return as fast as possible, after doing
2195some useful work. 2228some useful work.
2196 2229
2197=over 4 2230=over
2198 2231
2199=item $iw = new urxvt::iw 2232=item $iw = new urxvt::iw
2200 2233
2201Create a new idle watcher object in stopped state. 2234Create a new idle watcher object in stopped state.
2202 2235
2227 ->cb (sub { 2260 ->cb (sub {
2228 my ($pw, $exit_status) = @_; 2261 my ($pw, $exit_status) = @_;
2229 ... 2262 ...
2230 }); 2263 });
2231 2264
2232=over 4 2265=over
2233 2266
2234=item $pw = new urxvt::pw 2267=item $pw = new urxvt::pw
2235 2268
2236Create a new process watcher in stopped state. 2269Create a new process watcher in stopped state.
2237 2270
2254=head2 URXVT_PERL_VERBOSITY 2287=head2 URXVT_PERL_VERBOSITY
2255 2288
2256This variable controls the verbosity level of the perl extension. Higher 2289This variable controls the verbosity level of the perl extension. Higher
2257numbers indicate more verbose output. 2290numbers indicate more verbose output.
2258 2291
2259=over 4 2292=over
2260 2293
2261=item == 0 - fatal messages 2294=item == 0 - fatal messages
2262 2295
2263=item >= 3 - script loading and management 2296=item >= 3 - script loading and management
2264 2297

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines