Nlib - weechat perl library with helper functions for infolists and to map screen coordinates
To use this library in a weechat perl script,
put the library file in either the weechat perl directory or in the same place as the script file you use in the /perl load
command.
Then,
add the following preamble to your script,
replacing YOUR_SCRIPT_NAME_HERE
with the name of your script and the call to weechat::register
with the appropriate data:
use constant SCRIPT_NAME => 'YOUR_SCRIPT_NAME_HERE'; weechat::register(SCRIPT_NAME, 'Author <address>', '9.99', 'License', 'Script description', 'stop_script_function', 'parameters'); sub SCRIPT_FILE() { my $infolistptr = weechat::infolist_get('perl_script', '', SCRIPT_NAME); my $filename = weechat::infolist_string($infolistptr, 'filename') if weechat::infolist_next($infolistptr); weechat::infolist_free($infolistptr); return $filename unless @_; my $sep = weechat::info_get('dir_separator', ''); my @path = split $sep, $filename; my $link = readlink $filename; my @lpath = split $sep, $link if defined $link; (join '/', @path[0..$#path-1]), ($path[-2] eq 'autoload' ? join '/', @path[0..$#path-2] : ()), (@lpath ? join '/', ($lpath[0] ne '' ? @path[0..$#path-1] : ''), @lpath[0..$#lpath-1] : ()), (join '/', (split $sep, weechat::info_get('weechat_dir', '')), 'perl') } require lib; lib->import(&SCRIPT_FILE(1)); require Nlib;
To use the functions provided herein, call them with Nlib::function_name parameters...
for full pod documentation, filter this script with
perl -pE' (s/^## (.*?) -- (.*)/=head2 $1\n\n$2\n\n=over\n/ and $o=1) or s/^## (.*?) - (.*)/=item I<$1>\n\n$2\n/ or (s/^## (.*)/=back\n\n$1\n\n=cut\n/ and $o=0,1) or ($o and $o=0,1 and s/^sub /=back\n\n=cut\n\nsub /)'
copy weechat infolist content into perl hash
name of the infolist in weechat
pointer argument (infolist dependend)
arguments to the infolist (list dependend)
string of ref type "fields" if only certain keys are needed (optional)
returns perl list with perl hashes for each infolist entry
hdata helper
arg pointer or hdata list name
hdata name
hdata variable name
hashref with key/value to update (optional)
returns value of hdata, and hdata name in list ctx, or number of variables updated
copy weechat list into perl list
weechat list pointer
if true, clear weechat list
returns perl list
find the bar window where the coordinates belong to
row
column
returns bar window infolist and bar infolist in a array ref if found
check if given coordinates are in a window
row
column
infolist of window to check
returns true if in window
check if given coordinates are in the chat part of a window
row
column
infolist of window to check
returns true if in chat part of window
some constants for "true"
value string
returns true if string looks like a true thing
some constants for "false"
value string
returns true if string looks like a false thing
weechat::hook something and store hook reference
hook type (e.g. modifier)
event type to hook (depends on $hook_call)
subroutine name to install
parameters
weechat::unhook something where hook reference has been stored with hook_dynamic
event type that was hooked
subroutine name that was installed
get current filling according to position
info about bar (from find_bar_window)
returns filling as an integer number
get max item length for column based filling
info about bar (from find_bar_window)
returns max item length
get position of an item in a bar structure
instance and general info about bar (from find_bar_window)
search pattern for item name
returns (outer position, inner position, true if found)
apply linebreak for horizontal bar filling
reference to column counter
reference to row counter
info about bar (from find_bar_window)
count lines in column layout
info about bar (from find_bar_window)
returns lines needed for columns_horizontal layout
skip several bar items on search for subitem position
info about bar (from find_bar_window)
patter of item to skip to
pointer column
pointer row
extract subitem from a bar item at given coords
info about bar
search pattern for item whose subitems to get
pointer column
pointer row
returns error message, subitem index, subitem text
gets item and subitem at position
info about bar
pointer column
pointer row
returns generic item, error if outside subitem, index of subitem and text of subitem
return setting description from pod documentation
filename with pod
name of setting
returns description as text
retrieve all settings in settings section of pod
file with pod
returns list of all settings
turn man output into weechat codes
list of grotty lines that should be turned into weechat attributes
returns modified lines and modifies lines in-place
read a man page in weechat window
file with pod
buffer name