urxvtperl(3)
๐ NAME ๐
urxvtperl โ bestie, it's rxvt-unicode's embedded perl interpreter! ๐ that's the whole vibe. (And yeah, you're reading the urxvtperl(3) page from the RXVT-UNICODE manual, in case you needed the receipts. ๐งพ)
๐ซถ SYNOPSIS ๐ซถ
okay so the classic move is: you drop a little file somewhere, and then you point urxvt at it. watch this:
# create a file grab_test in some directory:
sub on_sel_grab {
warn "you selected ", $_[0]->selection;
()
}
# start a urxvt instance using it:
urxvt --perl-lib path/to/somedirectory -pe grab_test
that's it. that's the whole ritual. ๐ฅ
๐ธ DESCRIPTION ๐ธ
okay so real talk โ every single time a terminal object gets created, all the extension scripts you specified via the perl resource get loaded and associated with it. like, instantly. ๐ซ
Scripts are compiled inside a 'use strict qw(vars subs)' and 'use utf8' environment โ which means, yeah, they must be encoded as UTF-8. no exceptions, no cap. ๐ค
And listen: each script will only ever be loaded once. even in urxvtd, where scripts will be shared (but not enabled) for all terminals. one load, shared across the whole little family. ๐ซถ
wanna shut the embedded perl interpreter all the way off? set bothperl-extandperl-ext-commonresources to the empty string. that's the off switch. ๐
๐ PREPACKAGED EXTENSIONS ๐
A number of extensions are delivered with this release. you can find them chillin' in <libdir>/urxvt/perl/, and the documentation can be viewed using man urxvt-<EXTENSIONNAME>. every one's got receipts. ๐
You can activate them like this:
urxvt -pe <extensionname>
Or by adding them to the resource for extensions loaded by default:
URxvt.perl-ext-common: default,selection-autotransform
Extensions may add additional resources and "actions" โ i.e., methods which can be bound to a key and invoked by the user. ๐ An extension can define the resources it supports using so called META comments, described below, iykyk. And similarly to builtin resources, extension resources can also be specified on the command line as long options (with . replaced by -), in which case the corresponding extension is loaded automatically. ๐ช For this to work the extension must define META comments for its resources โ so no META comments, no magic. ๐
๐ง API DOCUMENTATION ๐ง
๐ General API Considerations ๐
All objects (such as terminals, time watchers etc.) are typical reference-to-hash objects. the hash is yours โ use it to store literally anything you like. ๐ But all members starting with an underscore (such as _ptr or _hook) are reserved for internal uses and MUST NOT be accessed or modified. hands off, bestie. ๐
When objects are destroyed on the C++ side, the perl object hashes are emptied โ so it's best to store related objects such as time watchers and the like inside the terminal object, so they get destroyed as soon as the terminal is destroyed. nesting = self-cleaning, we love to see it. โจ
Argument names also often indicate the type of a parameter. here are some hints on what they mean:
$textโ rxvt-unicode's special way of encoding text, where one "unicode" character always represents one screen cell. seeROW_tfor a discussion of this format.$stringโ a perl text string, with an emphasis on text. it can store all unicode characters, and is to be distinguished with text encoded in a specific encoding (often locale-specific) and binary data.$octetsโ either binary data or โ more common โ a text string encoded in a locale-specific way.$keysymโ an integer that is a valid X11 keysym code. you can convert a string into a keysym and viceversa by usingXStringToKeysymandXKeysymToString.
๐ฆ Extension Objects ๐ฆ
Every perl extension is a perl class. ๐
A separate perl object is created for each terminal, and each terminal has its own set of extension objects, which are passed as the first parameter to hooks. so extensions can use their $self object without having to think about clashes with other extensions or other terminals โ with the exception of methods and members that begin with an underscore character _: those are reserved for internal use. ๐
Although it isn't a urxvt::term object, you can call all methods of the urxvt::term class on this object. iconic behaviour, honestly. ๐
Additional methods only supported for extension objects are described in the urxvt::extension section below. ๐
๐งพ META comments ๐งพ
Rxvt-unicode recognises special meta comments in extensions that define different types of metadata. these comments are scanned whenever a terminal is created, and are typically used to autoload extensions when their resources or command line parameters are used. ๐
Currently, it recognises these comments below. individual components are separated by colons (:), and should not contain colons themselves โ there is also currently no escaping mechanism provided for this. so like, plan accordingly. ๐
๐ #:META:RESOURCE:name:type:desc
The RESOURCE comment defines a resource used by the extension, where name is the resource name, type is the resource type โ boolean or string โ and desc is the resource description.
The extension will be autoloaded when this resource is specified or used as a command line parameter. ๐ช
Example: matcher provides the matcher.launcher resource by having this comment:
#:META:RESOURCE:%.launcher:string:default launcher command
Example: load this extension when the -tr command line option or resource name is used:
#:META:RESOURCE:tr:boolean:set root pixmap as background
๐ #:META:OSC:number:desc
The OSC comment specifies an OSC sequence, where number is the numerical OSC code and desc is a short description that is currently unused.
This will cause the extension to be autoloaded when the OSC sequence is used for the first time.
โ ๏ธ Note that autoloading carries some extra responsibilities with it: although the terminal cannot really protect itself against malicious sources of command sequences โ therefore relying on the programs running inside to sanitize data that they output โ it is very common for programs to emit command sequences from untrusted sources. While this means that extensions should, as a defense-in-depth mechanism, always consider whether OSC sequences are safe, autoloading automatically exposes any autoloaded extension in all terminal windows, so extra care should be taken. ๐ฅ
Example: the background extension registers OSC 20 like this:
#:META:OSC:20:change/query background image
๐ #:META:OSC_PERL:prefix:desc
The same as the OSC comment, but for the Perl OSC sequence (777). the prefix should be unique among extensions, of course โ most easily arranged by using the extension name, although this is not required.
Example: the overlay-osc extension registers its Perl OSC like this:
#:META:OSC_PERL:overlay:man overlay-osc
๐ Hooks ๐
The following subroutines can be declared in extension files, and will be called whenever the relevant event happens. ๐
The first argument passed to them is an extension object as described in the "Extension Objects" section.
All of these hooks must return a boolean value. If any of the called hooks returns true, then the event counts as being consumed, and the relevant action might not be carried out by the C++ code. ๐ฌ
When in doubt, return a false value (preferably ()). ๐ซถ
โญ on_attach $term
Called when an extension package is attached to a running terminal instance. Must return true in all cases, and runs with the same limitations as on_init.
Unlike on_init or on_start, this is called when the extension is attached to a terminal, regardless of whether the extension is loaded before or after the terminal is started. Extensions that need to do something before they work can do it in this callback โ as opposed to, e.g., on_init, which might not be called. ๐ก
โญ on_init $term
Called after a new terminal object has been initialized, but before windows are created or the command gets run. most methods are unsafe to call or deliver senseless data, as terminal size and other characteristics have not yet been determined. you can safely query and change resources and options, though. For many purposes the on_start hook is a better place. ๐
โญ on_start $term
Called at the very end of initialisation of a new terminal โ just before trying to map (display) the toplevel and returning to the main loop. the final boss of startup, basically. ๐
โญ on_destroy $term
Called whenever something tries to destroy terminal, when the terminal is still fully functional (not for long, though ๐ญ).
โญ on_reset $term
Called after the screen is "reset" for any reason, such as resizing or control sequences. this is where you can react on changes to size-related variables. ๐
โญ on_child_start $term, $pid
Called just after the child process has been forked. ๐ด
โญ on_child_exit $term, $status
Called just after the child process has exited. $status is the status from waitpid. ๐ซก
โญ on_sel_make $term, $eventtime
Called whenever a selection has been made by the user, but before the selection text is copied โ so changes to the beginning, end or type of the selection will be honored. ๐
Returning a true value aborts selection making by urxvt, in which case you have to make a selection yourself by calling $term->selection_grab. (congrats, you're the main character now ๐)
โญ on_sel_grab $term, $eventtime
Called whenever a selection has been copied, but before the selection is requested from the server. the selection text can be queried and changed by calling $term->selection.
Returning a true value aborts selection grabbing. it will still be highlighted, though. โจ
โญ on_sel_extend $term
Called whenever the user tries to extend the selection (e.g. with a double click) and is either supposed to return false (normal operation), or should extend the selection itself and return true to suppress the built-in processing. this can happen multiple times โ as long as the callback returns true, it will be called on every further click by the user and is supposed to enlarge the selection more and more, if possible. ๐ฑ๏ธ
See the selection example extension. ๐
โญ on_view_change $term, $offset
Called whenever the view offset changes โ i.e. the user or program scrolls. Offset 0 means display the normal terminal; positive values show this many lines of scrollback. ๐
โญ on_scroll_back $term, $lines, $saved
Called whenever lines scroll out of the terminal area into the scrollback buffer. $lines is the number of lines scrolled out and may be larger than the scroll back buffer or the terminal.
It is called before lines are scrolled out (so rows 0 .. min ($lines - 1, $nrow - 1) represent the lines to be scrolled out). $saved is the total number of lines that will be in the scrollback buffer. ๐งฎ
on_osc_seq $term, $op, $args, $resp
okay so this one fires on every single OSC sequence, and it's your moment to suppress it or change how it behaves. โจ The default vibe should be returning an empty list. If you return a true value, execution of the request gets suppressed completely โ like, gone gone. Justโฆ be careful you don't get tangled up in recursive invocations when you output an OSC sequence from inside this callback, bestie. ๐ญ That's a whole loop situation.
Heads up: on_osc_seq_perl should be used for new behaviour. This one's the old way, iykyk.
on_osc_seq_perl $term, $args, $resp
Called whenever the ESC ] 777 ; prefix ; string ST command sequence gets processed (OSC = operating system command, for the uninitiated ๐
). The cute part? Cursor position and other state info are already up-to-date when this happens. ๐
For interoperability, your argument should start with the extension name (sans -osc) or some other suitable prefix, plus a semicolon, so it doesn't get confused with commands meant for other extensions. Like, stay in your lane bestie.
For example, overlay-osc uses this:
sub on_osc_seq_perl {
my ($self, $osc, $resp) = @_;
return unless $osc =~ s/^overlay;//;
... process remaining $osc string
}
๐ฅ Security moment, no cap: be careful to never trust the data you receive in a security sense โ its source can't easily be controlled (e-mail content, messages from other users on the same system, etc.). Like, don't let strangers into the group chat.
For responses, $resp contains the end-of-args separator used by the sender. ๐ซถ
on_add_lines $term, $string
Called whenever text is about to be output, with the text as the argument. You can filter/change it and output the text yourself by returning a true value and calling $term->scr_add_lines yourself. ๐
โ ๏ธ But please note this might be very slow, because your hook gets called for all the text being output. Every single bit. ๐ญ
on_tt_write $term, $octets
Called whenever some data is written to the tty/pty. Use it to suppress or filter tty input. Clean and simple, we love her. โจ
on_tt_paste $term, $octets
Called whenever text is about to be pasted, with the text as the argument. You can filter/change it and paste the text yourself by returning a true value and calling $term->tt_paste yourself. ๐ Note that $octets is locale-encoded โ keep that in mind!
on_line_update $term, $row
Called whenever a line was updated or changed. Perfect for filtering screen output (e.g. underlining urls or other useless stuff ๐). Only lines that are actually being shown get filtered, and โ for performance reasons โ not always immediately.
The row number is always the topmost row of the line if the line spans multiple rows.
๐จ Real talk: if you change the line, the hook might get called later with the already-modified line (like, if unrelated parts change), so you can't just toggle rendition bits โ you can only set them. No take-backsies.
on_refresh_begin $term
Called just before the screen gets redrawn. Slay for overlay or similar effects โ modify the terminal contents in refresh_begin and restore them in refresh_end. ๐ฆ
Note: the built-in overlay and selection display code runs after this hook, and takes precedence. So it's giving main character energy and will absolutely steal your spotlight.
on_refresh_end $term
Called just after the screen gets redrawn. See on_refresh_begin above โ they're a matching set, periodt. ๐
on_action $term, $string
Called whenever an action is invoked for the corresponding extension (e.g. via an extension:string builtin action bound to a key โ see the description of the keysym resource in the urxvt(1) manpage). The event is simply the action string. Note that an action event is always associated to a single extension. ๐ธ
on_user_command $term, $string DEPRECATED
Called whenever a user-configured event is being activated (e.g. via a perl:string action bound to a key โ see the description of the keysym resource in the urxvt(1) manpage). The event is simply the action string.
๐ This interface is going away in preference to the on_action hook. She's retiring, let her go gracefully.
on_resize_all_windows $term, $new_width, $new_height
Called just after the new window size has been calculated, but before windows are actually being resized or hints are being set. If this hook returns a true value, setting of the window hints gets skipped. ๐ชโจ
on_x_event $term, $event
Called on every X event received on the vt window (and possibly other windows). Should only be used as a last resort โ most event structure members are not passed. ๐
on_root_event $term, $event
Like on_x_event, but it's called for events on the root window. ๐
on_focus_in $term
Called whenever the window gets the keyboard focus, before rxvt-unicode does focus in processing. ๐
on_focus_out $term
Called whenever the window loses keyboard focus, before rxvt-unicode does focus out processing. ๐ฅฒ
on_configure_notify $term, $event
on_property_notify $term, $event
on_key_press $term, $event, $keysym, $octets
on_key_release $term, $event, $keysym
on_button_press $term, $event
on_button_release $term, $event
on_motion_notify $term, $event
on_map_notify $term, $event
on_unmap_notify $term, $event
Called whenever the corresponding X event is received for the terminal. If the hook returns true, then the event gets ignored by rxvt-unicode. โจ
The $event is a hash with most values as named by Xlib (see the XEvent manpage), with the additional members row and col, which are the (real, not screen-based) row and column under the mouse cursor. ๐ฑ๏ธ๐
on_key_press additionally receives the string rxvt-unicode would output, if any, in locale-specific encoding.
on_client_message $term, $event
on_wm_protocols $term, $event
on_wm_delete_window $term, $event
Called when various types of ClientMessage events are received (all with format=32, WM_PROTOCOLS or WM_PROTOCOLS:WM_DELETE_WINDOW).
on_bell $term
Called on receipt of a bell character. ๐ Ding ding, bestie.
๐ซถ Variables in the urxvt Package
$urxvt::LIBDIR
The rxvt-unicode library directory, where โ among other things โ the perl modules and scripts are stored. ๐
$urxvt::RESCLASS, $urxvt::RESCLASS
The resource class and name rxvt-unicode uses to look up X resources.
$urxvt::RXVTNAME
The basename of the installed binaries, usually urxvt. ๐
$urxvt::TERM
The current terminal. This variable stores the current urxvt::term object whenever a callback/hook is executing. Like a little "you are here" map. ๐
@urxvt::TERM_INIT
All code references in this array get called as methods of the next newly created urxvt::term object (during the on_init phase). The array gets cleared before the code references that were in it are being executed, so references can push themselves onto it again if they so desire. โจ
This complements the perl-eval command line option, but it gets executed first.
@urxvt::TERM_EXT
Works similar to @TERM_INIT, but contains perl package/class names, which get registered as normal extensions after calling the hooks in @TERM_INIT but before other extensions. Gets cleared just like @TERM_INIT. ๐ธ
๐ Functions in the urxvt Package
urxvt::fatal $errormessage
Fatally aborts execution with the given error message (which should include a trailing newline โ don't forget it!).
๐จ Avoid at all costs! The only time this is acceptable (and useful) is in the init hook, where it prevents the terminal from starting up. That's it. That's the one use case. Fr fr.
urxvt::warn $string
Calls rxvt_warn with the given string, which should include a trailing newline. The module also overwrites the warn builtin with a function that calls this function. ๐
Using this function has the advantage that its output ends up in the correct place, e.g. on stderr of the connecting urxvtc client. ๐ฏ
Messages have a size limit of 1023 bytes currently. Keep it snappy, bestie.
@terms = urxvt::termlist
Returns all urxvt::term objects that exist in this process โ regardless of whether they are started, being destroyed, etc., so be careful. ๐ Only term objects that have perl extensions attached will be returned (because there is no urxvt::term object associated with the others).
$time = urxvt::NOW
Returns the "current time" (as per the event loop). โฐ
X constants โจ
urxvt::CurrentTime
urxvt::ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask, Button1Mask, Button2Mask, Button3Mask, Button4Mask, Button5Mask, AnyModifier
urxvt::NoEventMask, KeyPressMask, KeyReleaseMask, ButtonPressMask, ButtonReleaseMask, EnterWindowMask, LeaveWindowMask, PointerMotionMask, PointerMotionHintMask, Button1MotionMask, Button2MotionMask, Button3MotionMask, Button4MotionMask, Button5MotionMask, ButtonMotionMask, KeymapStateMask, ExposureMask, VisibilityChangeMask, StructureNotifyMask, ResizeRedirectMask, SubstructureNotifyMask, SubstructureRedirectMask, FocusChangeMask, PropertyChangeMask, ColormapChangeMask, OwnerGrabButtonMask
urxvt::KeyPress, KeyRelease, ButtonPress, ButtonRelease, MotionNotify, EnterNotify, LeaveNotify, FocusIn, FocusOut, KeymapNotify, Expose, GraphicsExpose, NoExpose, VisibilityNotify, CreateNotify, DestroyNotify, UnmapNotify, MapNotify, MapRequest, ReparentNotify, ConfigureNotify, ConfigureRequest, GravityNotify, ResizeRequest, CirculateNotify, CirculateRequest, PropertyNotify, SelectionClear, SelectionRequest, SelectionNotify, ColormapNotify, ClientMessage, MappingNotify
Various constants for use in X calls and event processing. ๐ฆ
DEC private mode constants ๐
urxvt::PrivMode_132, PrivMode_132OK, PrivMode_rVideo, PrivMode_relOrigin, PrivMode_Screen, PrivMode_Autowrap, PrivMode_aplCUR, PrivMode_aplKP, PrivMode_HaveBackSpace, PrivMode_BackSpace, PrivMode_ShiftKeys, PrivMode_VisibleCursor, PrivMode_MouseX10, PrivMode_MouseX11, PrivMode_scrollBar, PrivMode_TtyOutputInh, PrivMode_Keypress, PrivMode_smoothScroll, PrivMode_vt52, PrivMode_LFNL, PrivMode_MouseBtnEvent, PrivMode_MouseAnyEvent, PrivMode_BracketPaste, PrivMode_ExtMouseUTF8, PrivMode_ExtMouseUrxvt, PrivMode_BlinkingCursor, PrivMode_mouse_report, PrivMode_Default
Constants for checking DEC private modes. ๐
๐จ RENDITION
Rendition bitsets contain information about colour, font, font styles and similar information for each screen cell. ๐๏ธโจ
โ ๏ธ The following "macros" deal with changes in rendition sets. You should never just create a bitset โ you should always modify an existing one, as they contain important information required for correct operation of rxvt-unicode. Like, do not cook from scratch here, bestie. Fr fr.
$rend = urxvt::DEFAULT_RSTYLE
Returns the default rendition, as used when the terminal is starting up or being reset. Useful as a base to start from when creating renditions. ๐
$rend = urxvt::OVERLAY_RSTYLE
Returns the rendition mask used for overlays by default. ๐
$rendbit = urxvt::RS_Bold, urxvt::RS_Italic, urxvt::RS_Blink, urxvt::RS_RVid, urxvt::RS_Ulineโ hands you the bit that turns on bold, italic, blink, reverse-video and underline respectively ๐ and to actually enable one of those styles you just logically OR it into the bitset. slay.$foreground = urxvt::GET_BASEFG $rendand$background = urxvt::GET_BASEBG $rendโ grab the foreground / background colour index respectively, no cap.$rend = urxvt::SET_FGCOLOR $rend, $new_colourโ swap the foreground colour in the rendition mask for the one you picked.$rend = urxvt::SET_BGCOLOR $rend, $new_colourโ same vibe, but for the background colour.$rend = urxvt::SET_COLOR $rend, $new_fg, $new_bgโ do both at once, foreground and background, in a single glow-up โจ$value = urxvt::GET_CUSTOM $rendโ returns the "custom" value. so every single rendition has 5 bits reserved just for extensions ๐ you can set them and change them however you want, and they start out at zero.$rend = urxvt::SET_CUSTOM $rend, $new_valueโ change that custom value. go off.
๐ The urxvt::term::extension class
okay so every extension that gets attached to a terminal object is represented by a urxvt::term::extension object. icon behavior.
you can absolutely use these objects โ they get passed to all the callbacks โ to stash any state related to the terminal and the extension instance ๐ซถ
the methods (and data members!!) documented down below can be called on extension objects, on top of the methods documented for the <urxvt::term> class. two-for-one.
$urxvt_term = $self->{term}โ returns theurxvt::termobject associated with this instance of the extension. โ ๏ธ this member must not be changed in any way โ hands off bestie, it's load-bearing.$self->enable ($hook_name => $cb[, $hook_name => $cb..])โ dynamically enables the given hooks (named without theon_prefix) for this extension, replacing any hook previously installed viaenablein this extension. so useful when you wanna overwrite time-critical hooks only temporarily ๐$self->disable ($hook_name[, $hook_name..])โ dynamically disables the given hooks. bye felicia.$guard = $self->on ($hook_name => $cb[, $hook_name => $cb..])โ same energy asenable, except it adds callbacks for the given hook(s) instead of replacing what's already there, and it returns a guard object. when that guard object gets destroyed, the callbacks get disabled again ๐ฆ very set-it-and-forget-it of it.$self->bind_action ($hotkey, $action),$self->x_resource ($pattern),$self->x_resource_boolean ($pattern)โ these all support an extra"%"prefix for$actionor$patternwhen you call them on an extension object, compared to theurxvt::termmethods of the same name ๐ธ head to the description of those methods in theurxvt::termclass for the deets.
๐ง The urxvt::anyevent Class
the whole entire purpose of this class is to serve up an interface to the AnyEvent module โ meaning any module that uses it will just work inside urxvt with no further programming required ๐ the only exception is that you cannot wait on condition variables, but non-blocking condvar use is totally fine.
in practical terms that means you can't use blocking APIs, but the non-blocking variant should work. simple as.
๐ The urxvt::term Class
$term = new urxvt::term $envhashref, $rxvtname, [arg...]โ creates a brand-new terminal, basically identical to if you'd started it with"$rxvtname, arg...".$envhashrefmust be a reference to a%ENV-like hash that defines the environment of the new terminal.
it croaks (and probably prints an error message) if the new instance couldn't be created ๐ญ and it returns undef if the new instance didn't initialise perl, otherwise you get the terminal object. the init and start hooks will be called before this call returns, and they're free to refer to global data (which is race free). iconic.
$term->destroyโ destroys the terminal object (closes the window, frees resources, all that). โ ๏ธ but please note: urxvt will not exit as long as any event watchers (timers, io watchers) are still active. so like, clean those up too bestie.$term->exec_async ($cmd[, @args])โ works like a combo of thefork/execbuiltins, i.e. it executes ("starts") programs in the background. this function takes care of setting the user environment before exec'ing the command (likePATH) and honestly you should prefer it over explicitly callingexecorsystem๐
it also sets the URXVT_EXT_WINDOWID environment variable to the window ID of the terminal ($self->parent), similar to the WINDOWID variable that gets set for the process spawned inside the terminal.
returns the pid of the subprocess, or undef on error.
$isset = $term->option ($optval[, $set])โ returns true if the option specified by$optvalis enabled, and optionally changes it. all option values are stored by name in the hash%urxvt::OPTION๐ options that aren't enabled in this binary just aren't in the hash, sorry not sorry.
here's a likely non-exhaustive list of option names โ see the source file /src/optinc.h for the actual list:
borderLess buffered console cursorBlink cursorUnderline hold iconic
insecure intensityStyles iso14755 iso14755_52 jumpScroll loginShell
mapAlert meta8 mouseWheelScrollPage override_redirect pastableTabs
pointerBlank reverseVideo scrollBar scrollBar_floating scrollBar_right
scrollTtyKeypress scrollTtyOutput scrollWithBuffer secondaryScreen
secondaryScroll skipBuiltinGlyphs skipScroll transparent tripleclickwords
urgentOnBell utmpInhibit visualBell disablePasteBrackets
$value = $term->resource ($name[, $newval])โ returns the current resource value for a given name, and optionally sets a new value. setting values is most useful in theinithook โจ unset resources are returned and accepted asundef.
the new value must be properly encoded to a suitable character encoding before you pass it to this method. same deal on the way out โ the returned value may need converting from the used encoding to text.
resource names are as defined in src/rsinc.h. colours can be specified as resource names of the form "color+<index>", e.g. "color+5". (will likely change).
๐จ heads up: resource strings will currently only be freed when the terminal is destroyed, so changing options frequently will eat memory. fr fr, mind that.
here's a likely non-exhaustive list of resource names, not all of which are supported in every build โ see the source file /src/rsinc.h for the actual list:
answerbackstring backgroundPixmap backspace_key blurradius
boldFont boldItalicFont borderLess buffered chdir color cursorBlink
cursorUnderline cutchars delete_key depth display_name embed ext_bwidth
fade font geometry hold iconName iconfile imFont imLocale inputMethod
insecure int_bwidth intensityStyles iso14755 iso14755_52 italicFont
jumpScroll letterSpace lineSpace loginShell mapAlert meta8 modifier
mouseWheelScrollPage name override_redirect pastableTabs path perl_eval
perl_ext_1 perl_ext_2 perl_lib pointerBlank pointerBlankDelay
preeditType print_pipe pty_fd reverseVideo saveLines scrollBar
scrollBar_align scrollBar_floating scrollBar_right scrollBar_thickness
scrollTtyKeypress scrollTtyOutput scrollWithBuffer scrollstyle
secondaryScreen secondaryScroll shade skipBuiltinGlyphs skipScroll
term_name title transient_for transparent tripleclickwords urgentOnBell
utmpInhibit visualBell rewrapMode disablePasteBrackets
$value = $term->x_resource ($pattern)โ returns the X-Resource for the given pattern, excluding the program or class name. so like"$term->x_resource ("boldFont")"should return the same value that this instance of rxvt-unicode actually used ๐ฆ returnsundefif no resource with that pattern exists.
extensions that define extra resources also need to call this method to get at their values, iykyk.
if you call the method on an extension object (basically, from inside an extension), then the special prefix "%." gets replaced by the name of the extension plus a dot, and a lone string "%" gets replaced by the extension name itself ๐ this is what makes it possible to write extensions so you can rename them and get a whole new set of resources without touching the actual code. obsessed.
โญ this method should only be called during the on_start hook, because there's only one resource database per display, and later invocations might hand you the wrong resources.
$value = $term->x_resource_boolean ($pattern)โ likex_resourceabove, but it interprets the string value as a boolean and returns1for true values,0for false values, andundefif the resource or option isn't specified. you should always use this method to parse boolean resources ๐ no exceptions.$action = $term->lookup_keysym ($keysym, $state)โ returns the action bound to the key combination"($keysym, $state)"if a binding for it exists, andundefotherwise.$success = $term->bind_action ($key, $action)โ adds a key binding exactly as specified via akeysymresource. check thekeysymresource in the urxvt(1) manpage for that โจ
to add default bindings for actions, an extension should call ->bind_action in its init hook for every such binding. doing it in the init hook means users can override or remove the binding again later โ very considerate of them ๐
example: the searchable-scrollback by default binds itself on Meta-s, using $self->bind_action, which calls $term->bind_action:
sub init {
my ($self) = @_;
$self->bind_action ("M-s" => "%:start");
}
$rend = $term->rstyle ([$new_rstyle])โ returns and optionally changes the current rendition. text output by the terminal application will use this style. main character energy for your text.($row, $col) = $term->screen_cur ([$row, $col])โ returns the current coordinates of the text cursor position, and optionally sets it. โ ๏ธ setting it is usually a bad idea because applications don't expect that โ you'll freak them out.($row, $col) = $term->selection_mark ([$row, $col])โ returns the current value of the selection mark position.($row, $col) = $term->selection_beg ([$row, $col])โ same thing but for the selection begin position.($row, $col) = $term->selection_end ([$row, $col])โ and this one's the selection end position.
when arguments are given to any of these three, the selection coordinates get set to $row and $col, and the selection screen gets set to the current screen ๐ซถ
$screen = $term->selection_screen ([$screen])โ returns the current selection screen, and then optionally sets it.$term->selection_make ($eventtime[, $rectangular])โ tries to make a selection as set byselection_begandselection_end. if$rectangularis true (default: false), a rectangular selection gets made ๐ this is the preferred function for making a selection, so use this one bestie, not the others.$success = $term->selection_grab ($eventtime[, $clipboard])โ okay so this one tries to snag ownership of the primary selection from the server (or the clipboard instead, if$clipboardis true ๐). The actual text gets set with the next method. Heads up: no visual feedback whatsoever, so don't go looking for a cute highlight, it's not coming. This is mostly useful from insideon_sel_grabhooks.$oldtext = $term->selection ([$newtext, $clipboard])โ returns the current selection text (clipboard if$clipboardis true, you know the drill) and, if you feel like it, swaps it out for$newtextโจ.$term->selection_clear ([$clipboard])โ revokes ownership of the primary selection (or the clipboard if$clipboardis true). Bye bestie ๐.$term->overlay_simple ($x, $y, $text)โ makes a simple multi-line overlay box. See the next method for the deets.$term->overlay ($x, $y, $width, $height[, $rstyle[, $border]])โ creates a brand new (empty!) overlay at the position you give it, with the width/height you give it.$rstylesets the initial rendition style (default:"OVERLAY_RSTYLE").
If $border is 2 (that's the default), a decorative border goes around the box ๐.
If either $x or $y is negative, it gets counted from the right/bottom side respectively โ iconique.
This method returns an urxvt::overlay object. The overlay stays visible for as long as the perl object is referenced (so like, keep a reference, bestie).
The methods currently supported on urxvt::overlay objects are:
$overlay->set ($x, $y, $text[, $rend])โ similar to$term->ROW_tand$term->ROW_rin that it puts text in rxvt-unicode's special encoding plus an array of rendition values at a specific position inside the overlay.
If $rend is missing, the rendition will not be changed.
$overlay->hideโ if it's visible, hide the overlay, but don't destroy it.$overlay->showโ if it's hidden, display the overlay again ๐ธ.
$popup = $term->popup ($event)โ creates a newurxvt::popupobject that implements a popup menu. The$eventmust be the event causing the menu to pop up (a button event, currently).$cellwidth = $term->strwidth ($string)โ returns the number of screen-cells this string would need. Correctly accounts for wide and combining characters, no cap ๐ .$octets = $term->locale_encode ($string)โ converts the given text string into the corresponding locale encoding. Returnsundefif$stringisundef.$string = $term->locale_decode ($octets)โ converts the given locale-encoded octets into a perl string. Returnsundefif$octetsisundef.$term->scr_xor_span ($beg_row, $beg_col, $end_row, $end_col[, $rstyle])โ XORs the rendition values in the given span with the provided value (default:RS_RVid), which MUST NOT contain font styles. Useful in refresh hooks to pull off effects similar to the selection โจ.$term->scr_xor_rect ($beg_row, $beg_col, $end_row, $end_col[, $rstyle1[, $rstyle2]])โ similar toscr_xor_span, but xors a rectangle instead. Trailing whitespace also gets xored with$rstyle2, which defaults toRS_RVid | RS_Ulineโ that removes reverse video again and underlines it instead. Both styles MUST NOT contain font styles.$term->scr_bellโ Ring the bell! ๐ That's it. That's the whole thing.$term->scr_add_lines ($string)โ writes the given text string to the screen, as if the app running inside the terminal output it. It may not contain command sequences (escape codes โ seecmd_parsefor that), but it's free to use line feeds, carriage returns and tabs. The string is a normal text string, not in locale-dependent encoding.
Normally it's not a good idea to use this function, because programs might get confused by changes in cursor position or scrolling ๐. It is useful inside an on_add_lines hook, though.
$term->scr_change_screen ($screen)โ switches to the given screen:0primary,1secondary.$term->cmd_parse ($octets)โ likescr_add_lines, but the argument must be in the locale-specific encoding of the terminal and it can contain command sequences (escape codes) that will be interpreted ๐ฆ.$term->tt_write ($octets)โ writes the octets given in$octetsto the tty (i.e. as user input to the program โ seecmd_parsefor the opposite direction). If you want to pass characters instead of octets, convert your strings first to the locale-specific encoding using$term->locale_encode.$term->tt_write_user_input ($octets)โ likett_write, but this one should be used when writing strings in response to the user pressing a key, so the additional actions requested by the user for that case actually get invoked (tt_writedoesn't do that ๐). The typical use case is insideon_actionhooks.$term->tt_paste ($octets)โ writes the octets given in$octetsto the tty as a paste, converting NL to CR and bracketing the data with control sequences if bracketed paste mode is set ๐.$old_events = $term->pty_ev_events ([$new_events])โ replaces the event mask of the pty watcher with the given event mask. Can be used to suppress input and output handling to the pty/tty. See the description ofurxvt::timer->events. Make sure to always restore the previous value, okay? No leaving it broken ๐ญ.$fd = $term->pty_fdโ returns the master file descriptor for the pty in use, or-1if no pty is used.$windowid = $term->parentโ returns the window id of the toplevel window.$windowid = $term->vtโ returns the window id of the terminal window.$term->vt_emask_add ($x_event_mask)โ adds the specified events to the vt event mask. Useful e.g. when you want to receive pointer events all the times:
$term->vt_emask_add (urxvt::PointerMotionMask);
$term->set_urgency ($set)โ enable/disable the urgency hint on the toplevel window.$term->focus_in$term->focus_out$term->key_press ($state, $keycode[, $time])$term->key_release ($state, $keycode[, $time])โ delivers various fake events to the terminal ๐ซถ.$window_width = $term->width ([$new_value])$window_height = $term->height ([$new_value])$font_width = $term->fwidth ([$new_value])$font_height = $term->fheight ([$new_value])$font_ascent = $term->fbase ([$new_value])$terminal_rows = $term->nrow ([$new_value])$terminal_columns = $term->ncol ([$new_value])$has_focus = $term->focus ([$new_value])$is_mapped = $term->mapped ([$new_value])$max_scrollback = $term->saveLines ([$new_value])$nrow_plus_saveLines = $term->total_rows ([$new_value])$topmost_scrollback_row = $term->top_row ([$new_value])โ all of these return various integers describing terminal characteristics. And if you pass an argument, it changes the value and returns the previous one. Sneaky but slay ๐ฅ.$x_display = $term->display_idโ returns theDISPLAYused by rxvt-unicode.$lc_ctype = $term->localeโ returns theLC_CTYPEcategory string used by this rxvt-unicode.$env = $term->envโ returns a copy of the environment in effect for the terminal as a hashref, similar to\%ENV.@envv = $term->envvโ returns the environment as an array of strings of the formVAR=VALUE.@argv = $term->argvโ returns the argument vector as this terminal, similar to@ARGV, but it includes the program name as the first element ๐.$modifiermask = $term->ModLevel3Mask$modifiermask = $term->ModMetaMask$modifiermask = $term->ModNumLockMaskโ these return the modifier masks corresponding to the "ISO Level 3 Shift" (often AltGr), the meta key (often Alt) and the num lock key, if applicable.$screen = $term->current_screenโ returns the currently displayed screen (0primary,1secondary).$cursor_is_hidden = $term->hidden_cursorโ tells you whether the cursor is currently hidden or not. Peekaboo ๐.$priv_modes = $term->priv_modesโ returns a bitset with the state of DEC private modes.
Example:
if ($term->priv_modes & urxvt::PrivMode_mouse_report) {
# mouse reporting is turned on
}
$view_start = $term->view_start ([$newvalue])โ returns the row number of the topmost displayed line, and changes it if an argument is given. Values greater than or equal to0display the terminal contents. Lower values scroll this many lines into the scrollback buffer ๐.$term->want_refreshโ requests a screen refresh. At the next opportunity, rxvt-unicode will compare the on-screen display with its stored representation, and if they differ, it redraws the differences. Use this after changing terminal contents so they actually show up, bestie โจ.$term->refresh_checkโ checks if a refresh has been requested and, if so, schedules one.$text = $term->ROW_t ($row_number[, $new_text[, $start_col]])โ returns the text of the entire row with number$row_number. Row$term->top_rowis the topmost terminal line, row$term->nrow-1is the bottommost terminal line. Nothing gets returned if you ask for a nonexistent line (fair enough ๐ ).
If $new_text is specified, it replaces characters in the current line, starting at column $start_col (default 0), which is super useful when you only wanna replace parts of a line. The font index in the rendition will automatically be updated.
$text is in a special encoding: tabs and wide characters that use more than one cell when displayed are padded with $urxvt::NOCHAR (chr 65535) characters. Characters with combining characters, and other characters that don't fit into the normal text encoding, get replaced with characters in the private use area ๐ฆ.
You have to obey this encoding when changing text. The upside is that substr and similar functions then work on screen cells and not on characters โ which is genuinely iconic.
The methods $term->special_encode and $term->special_decode can be used to convert normal strings into this encoding and vice versa.
$rend = $term->ROW_r ($row_number[, $new_rend[, $start_col]])โ like$term->ROW_t, but returns an arrayref with rendition bitsets. Rendition bitsets contain information about colour, font, font styles and similar info. See also$term->ROW_t.
When setting rendition, the font mask will be ignored ๐.
See the section on RENDITION, above.
$length = $term->ROW_l ($row_number[, $new_length])โ returns the number of screen cells that are in use ("the line length"). Unlike the urxvt core, this returns$term->ncolif the line is joined with the following one. Note the difference, okay? That's the whole point ๐.$bool = $term->is_longer ($row_number)โ returns true if the row is part of a multiple-row logical "line" (i.e. joined with the following row), which means all characters are in use and it's continued on the next row (and possibly a continuation of the previous row(s)) ๐ง.
$line = $term->line ($row_number) โ ok bestie, this creates and returns a brand-new urxvt::line object that stores info about the logical line that row $row_number is part of. Itโs giving line-detective energy ๐ and it supports these methods:
$text = $line->t ([$new_text])โ returns or replaces the full text of the line, similar toROW_t.$rend = $line->r ([$new_rend])โ returns or replaces the full rendition array of the line, similar toROW_r.$length = $line->lโ returns the length of the line in cells, similar toROW_l.$rownum = $line->beg$rownum = $line->endโ these two return the row number of the first/last row of the line, respectively.$offset = $line->offset_of ($row, $col)โ returns the character offset of the given row|col pair within the logical line. Works for rows outside the line too, and returns corresponding offsets outside the string.($row, $col) = $line->coord_of ($offset)โ translates a string offset back into terminal coordinates again.
$text = $term->special_encode ($string) โ converts a perl string into the special encoding used by rxvt-unicode, where one character corresponds to one screen cell. See $term->ROW_t for details.
$string = $term->special_decode ($text) โ converts rxvt-unicodeโs text representation back into a perl string. See $term->ROW_t for details.
$success = $term->grab_button ($button, $modifiermask[, $window = $term->vt]) $term->ungrab_button ($button, $modifiermask[, $window = $term->vt]) โ registers/unregisters a synchronous button grab. See the XGrabButton manpage.
$success = $term->grab ($eventtime[, $sync]) โ calls XGrabPointer and XGrabKeyboard in asynchronous mode (the default) or synchronous mode ($sync is true). Also remembers the grab timestamp.
$term->allow_events_async โ calls XAllowEvents with AsyncBoth for the most recent grab.
$term->allow_events_sync โ calls XAllowEvents with SyncBoth for the most recent grab.
$term->allow_events_replay โ calls XAllowEvents with both ReplayPointer and ReplayKeyboard for the most recent grab.
$term->ungrab โ calls XUngrabPointer and XUngrabKeyboard for the most recent grab. Itโs called automatically on evaluation errors, because losing the grab in the error case is better than losing the whole session ๐.
$atom = $term->XInternAtom ($atom_name[, $only_if_exists])
$atom_name = $term->XGetAtomName ($atom)
@atoms = $term->XListProperties ($window)
($type,$format,$octets) = $term->XGetWindowProperty ($window, $property)
$term->XChangeProperty ($window, $property, $type, $format, $octets)
$term->XDeleteProperty ($window, $property)
$window = $term->DefaultRootWindow
$term->XReparentWindow ($window, $parent, [$x, $y])
$term->XMapWindow ($window)
$term->XUnmapWindow ($window)
$term->XMoveResizeWindow ($window, $x, $y, $width, $height)
($x, $y, $child_window) = $term->XTranslateCoordinates ($src, $dst, $x, $y)
$term->XChangeInput ($window, $add_events[, $del_events])
$keysym = $term->XStringToKeysym ($string)
$string = $term->XKeysymToString ($keysym)
Various X or X-related functions. The $term object only serves as the source of the display โ otherwise those functions map more-or-less directly onto the X functions of the same name.
๐ The urxvt::popup Class ๐
$popup->add_title ($title) โ adds a non-clickable title to the popup. Very demure, very mindful โจ.
$popup->add_separator ([$sepchr]) โ creates a separator, optionally using the character given as $sepchr.
$popup->add_button ($text, $cb) โ adds a clickable button to the popup. $cb is called whenever it is selected.
$popup->add_toggle ($text, $initial_value, $cb) โ adds a toggle/checkbox item to the popup. The callback gets called whenever it gets toggled, with a boolean indicating its new value as its first argument.
$popup->show โ displays the popup (which is initially hidden).
โฐ The urxvt::timer Class โฐ
This class implements timer watchers/events. Time is represented as a fractional number of seconds since the epoch. Example:
$term->{overlay} = $term->overlay (-1, 0, 8, 1, urxvt::OVERLAY_RSTYLE, 0);
$term->{timer} = urxvt::timer
->new
->interval (1)
->cb (sub {
$term->{overlay}->set (0, 0,
sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2,1,0]);
});
$timer = new urxvt::timer โ create a new timer object in started state. It is scheduled to fire immediately.
$timer = $timer->cb (sub { my ($timer) = @_; ... }) โ set the callback to be called when the timer triggers.
$timer = $timer->set ($tstamp[, $interval]) โ set the time the event is generated to $tstamp (and optionally specifies a new $interval).
$timer = $timer->interval ($interval) โ by default (and when $interval is 0), the timer will automatically stop after it has fired once. If $interval is non-zero, then the timer is automatically rescheduled at the given intervals.
$timer = $timer->start โ start the timer.
$timer = $timer->start ($tstamp[, $interval]) โ set the event trigger time to $tstamp and start the timer. Optionally also replaces the interval.
$timer = $timer->after ($delay[, $interval]) โ like start, but sets the expiry timer to urxvt::NOW + $delay.
$timer = $timer->stop โ stop the timer.
๐ฆ The urxvt::iow Class ๐ฆ
This class implements io watchers/events. Example:
$term->{socket} = ...
$term->{iow} = urxvt::iow
->new
->fd (fileno $term->{socket})
->events (urxvt::EV_READ)
->start
->cb (sub {
my ($iow, $revents) = @_;
# $revents must be 1 here, no need to check
sysread $term->{socket}, my $buf, 8192
or end-of-file;
});
$iow = new urxvt::iow โ create a new io watcher object in stopped state.
$iow = $iow->cb (sub { my ($iow, $reventmask) = @_; ... }) โ set the callback to be called when io events are triggered. $reventmask is a bitset as described in the events method.
$iow = $iow->fd ($fd) โ set the file descriptor (not handle) to watch.
$iow = $iow->events ($eventmask) โ set the event mask to watch. The only allowed values are urxvt::EV_READ and urxvt::EV_WRITE, which might be ORed together, or urxvt::EV_NONE.
$iow = $iow->start โ start watching for requested events on the given handle.
$iow = $iow->stop โ stop watching for events on the given file handle.
๐ธ The urxvt::iw Class ๐ธ
This class implements idle watchers, that get called automatically when the process is idle. They should return as fast as possible, after doing some useful work.
$iw = new urxvt::iw โ create a new idle watcher object in stopped state.
$iw = $iw->cb (sub { my ($iw) = @_; ... }) โ set the callback to be called when the watcher triggers.
$timer = $timer->start โ start the watcher. (Yep, the page literally says $timer here โ we donโt make the rules ๐ญ.)
$timer = $timer->stop โ stop the watcher. (Again with the $timer, iconic copy-paste energy ๐.)
๐ The urxvt::pw Class ๐
This class implements process watchers. They create an event whenever a process exits, after which they stop automatically.
my $pid = fork;
...
$term->{pw} = urxvt::pw
->new
->start ($pid)
->cb (sub {
my ($pw, $exit_status) = @_;
...
});
$pw = new urxvt::pw โ create a new process watcher in stopped state.
$pw = $pw->cb (sub { my ($pw, $exit_status) = @_; ... }) โ set the callback to be called when the timer triggers.
$pw = $timer->start ($pid) โ tells the watcher to start watching for process $pid.
$pw = $pw->stop โ stop the watcher.
๐ฑ ENVIRONMENT ๐ฑ
URXVT_PERL_VERBOSITY
This variable controls the verbosity level of the perl extension. Higher numbers indicate more verbose output.
== 0โ fatal messages only>= 2โ general warnings (default level)>= 3โ script loading and management>=10โ all called hooks>=11โ hook return values
๐ AUTHOR ๐
Marc Lehmann <schmorp@schmorp.de> http://software.schmorp.de/pkg/rxvt-unicode
Thatโs the whole vibe from urxvtperl(3) โ version 9.31, dated 2023-12-02. Go forth and slay your terminal extensions, bestie ๐ซถ๐
โจ
๐ฆ where this page comes from
- opensuse-leap 16.0: rxvt-unicode 9.31-bp160.1.13 ยท GPL-3.0-or-later
- opensuse-leap 16.0: rxvt-unicode 9.31-bp160.1.13 ยท GPL-3.0-or-later
- opensuse-leap 16.0: rxvt-unicode 9.31-bp160.1.13 ยท GPL-3.0-or-later
- opensuse-leap 16.0: rxvt-unicode 9.31-bp160.1.13 ยท GPL-3.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms