Translators:

Questo manuale documenta il client di chat WeeChat, ed è parte del programma stesso.

Latest version of this document can be found on this page .

1. Introduzione

WeeChat (Wee Enhanced Environment for Chat) è un client di chat libero, veloce e leggero, realizzato per molti sistemi operativi.

Questo manuale documenta le API per i plugin di WeeChat, utilizzate dai plugin C per interagire con il core di WeeChat.

2. Plugin in WeeChat

Un plugin è un programma C che può richiamare le funzioni di WeeChat definite in un’interfaccia.

Questo programma C non richiede i sorgenti di WeeChat per essere compilato e può essere caricato dinamicamente in WeeChat con il comano /plugin.

Il plugin deve essere una libreria dinamica, per essere caricato dinamicamente dal del sistema operativo. In GNU/Linux, il file ha estensione ".so", ".dll" in Windows.

Il plugin deve includere il file "weechat-plugin.h" (disponibile nel codice sorgente di WeeChat). Il file definisce strutture e tipi utilizzati per comunicare con WeeChat.

In order to call WeeChat functions in the format displayed in Plugin API, the following global pointer must be declared and initialized in the function weechat_plugin_init:

struct t_weechat_plugin *weechat_plugin;

2.1. Macro

Il plugin deve utilizzare alcune macro (per definire alcune variabili):

WEECHAT_PLUGIN_NAME("nome")

nome del plugin

WEECHAT_PLUGIN_DESCRIPTION("descrizione")

breve descrizione del plugin

WEECHAT_PLUGIN_AUTHOR("author")

the author name

WEECHAT_PLUGIN_VERSION("1.0")

versione del plugin

WEECHAT_PLUGIN_LICENSE("GPL3")

licenza del plugin

WEECHAT_PLUGIN_PRIORITY(1000)

the plugin priority (optional, see below)

2.2. Funzioni principali

Il plugin deve usare due funzioni:

  • weechat_plugin_init

  • weechat_plugin_end

weechat_plugin_init

Questa funzione viene chiamata quando il plugin è caricato. da WeeChat.

Prototipo:

int weechat_plugin_init (struct t_weechat_plugin *plugin,
                         int argc, char *argv[]);

Argomenti:

  • plugin: puntatore alla struttura del plugin di WeeChat, used to initialize the convenience global pointer weechat_plugin

  • argc: numero di argomenti per il plugin

  • argv: argomenti per il plugin (see below)

Valori restituiti:

  • WEECHAT_RC_OK se l’operazione ha successo (il plugin verrà caricato)

  • WEECHAT_RC_ERROR se c’è un errore (il plugin NON verrà caricato)

Plugin arguments

When the plugin is loaded by WeeChat, it receives the list of arguments in parameter argv and the number of arguments in argc.

The arguments can be:

  • command line arguments when running the WeeChat binary,

  • arguments given to the command /plugin load xxx, when the plugin is manually loaded by the user.

When the arguments come from the command line, only these arguments are sent to the plugin:

-a, --no-connect

Disabilita la connessione automatica ai server all’avvio di WeeChat.

-s, --no-script

Disabilita il caricamento automatico dei script.

plugin:option

Option for a plugin: only the plugin-related options are sent, for example only the options starting with irc: are sent to the plugin called "irc".

Plugin priority

When plugins are auto-loaded (for example on startup), WeeChat first loads all plugins, and then calls the init functions, using the priority defined in each plugin. A high priority means that the init function is called first.

Default priority is 1000 (with such priority, the plugin is loaded after all default plugins).

The default WeeChat plugins are initialized in this order:

Rank Plugin Priority

1

charset

16000

2

logger

15000

3

exec

14000

4

trigger

13000

5

spell

12000

6

alias

11000

7

buflist

10000

8

fifo

9000

9

typing

8000

10

xfer

7000

11

irc

6000

12

relay

5000

13

guile

4070

14

lua

4050

15

perl

4040

16

php

4030

17

python

4020

18

ruby

4010

19

tcl

4000

20

script

3000

21

fset

2000

weechat_plugin_end

Questa funzione viene chiamata quando il plugin viene scaricato da WeeChat.

Prototipo:

int weechat_plugin_end (struct t_weechat_plugin *plugin);

Argomenti:

  • plugin: puntatore alla struttura plugin di WeeChat

Valori restituiti:

  • WEECHAT_RC_OK se l’operazione ha successo

  • WEECHAT_RC_ERROR se c’è un errore

2.3. Compilazione del plugin

La compilazione non richiede i sorgenti di WeeChat, è richiesto solo il file weechat-plugin.h.

Per compilare un plugin che ha un file "tizio.c" (in GNU/Linux):

$ gcc -fPIC -Wall -c tizio.c
$ gcc -shared -fPIC -o tizio.so tizio.o

2.4. Caricamento del plugin

Copiare il file tizio.so nella cartella plugin di sistema (ad esempio /usr/local/lib/weechat/plugins) oppure nella cartella plugin dell’utente (ad esempio /home/user/.local/share/weechat/plugins).

In WeeChat:

/plugin load tizio

2.5. Plugin di esempio

Un esempio completo di plugin, che aggiunge un comando /double: visualizza due volte gli argomenti nel buffer corrente, oppure esegue un comando due volte (ok, non sarà molto utile, ma è solo un esempio!):

#include <stdlib.h>

#include "weechat-plugin.h"

WEECHAT_PLUGIN_NAME("double");
WEECHAT_PLUGIN_DESCRIPTION("Test plugin for WeeChat");
WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu <flashcode@flashtux.org>");
WEECHAT_PLUGIN_VERSION("0.1");
WEECHAT_PLUGIN_LICENSE("GPL3");

struct t_weechat_plugin *weechat_plugin = NULL;


/* callback per il comando "/double" */

int
command_double_cb (const void *pointer, void *data,
                   struct t_gui_buffer *buffer,
                   int argc, char **argv, char **argv_eol)
{
    /* fa felice il compilatore C */
    (void) pointer;
    (void) data;
    (void) buffer;
    (void) argv;

    if (argc > 1)
    {
        weechat_command (NULL, argv_eol[1]);
        weechat_command (NULL, argv_eol[1]);
    }

    return WEECHAT_RC_OK;
}

int
weechat_plugin_init (struct t_weechat_plugin *plugin,
                     int argc, char *argv[])
{
    weechat_plugin = plugin;

    weechat_hook_command ("double",
                          "Visualizza due volte un messaggio "
                          "oppure esegue un comando due volte",
                          "messaggio | comando",
                          "messaggio: messaggio da visualizzare due volte\n"
                          "comando: comando da eseguire due volte",
                          NULL,
                          &command_double_cb, NULL, NULL);

    return WEECHAT_RC_OK;
}

int
weechat_plugin_end (struct t_weechat_plugin *plugin)
{
    /* fa felice il compilatore C */
    (void) plugin;

    return WEECHAT_RC_OK;
}

3. Plugin API

I capitoli seguenti descrivono le funzioni nelle API, organizzate in categorie.

Per ogni funzione, viene fornita:

  • descrizione della funzione,

  • prototipo C,

  • dettaglio degli argomenti,

  • valore restituito,

  • esempio C,

  • esempio nello script Python (la sintassi è simile per gli altri linguaggi di scripting).

3.1. Registering

Functions to register a script: used only by scripting API, not the C API.

register

Register the script.

For more information, see the WeeChat scripting guide .

Script (Python):

# prototipo
def register(name: str, author: str, version: str, license: str, description: str, shutdown_function: str, charset: str) -> int: ...
This function is not available in the C API.

3.2. Plugin

Funzioni per ottenere informazioni sui plugin.

plugin_get_name

Ottiene il nome del plugin.

Prototipo:

const char *weechat_plugin_get_name (struct t_weechat_plugin *plugin);

Argomenti:

  • plugin: puntatore alla struttura plugin di WeeChat (può essere NULL)

Valore restituito:

  • nome del plugin, "core" per il core di WeeChat (se il puntatore al plugin è NULL)

Esempio in C:

const char *name = weechat_plugin_get_name (plugin);

Script (Python):

# prototipo
def plugin_get_name(plugin: str) -> str: ...

# esempio
plugin = weechat.buffer_get_pointer(weechat.current_buffer(), "plugin")
name = weechat.plugin_get_name(plugin)

3.3. Stringhe

Molte delle funzioni stringa che seguono sono già disponibili tramite funzioni standard in C, ma si raccomanda di utilizzare le funzioni in questa API perché compatibili con UTF-8 e il locale.

charset_set

Imposta il nuovo set caratteri del nuovo plugin (il set caratteri predefinito è UTF-8, così se il plugin usa UTF-8 non è necessario chiamare questa funzione).

Prototipo:

void weechat_charset_set (const char *charset);

Argomenti:

  • charset: nuovo set caratteri da usare

Esempio in C:

weechat_charset_set ("iso-8859-1");

Script (Python):

# prototipo
def charset_set(charset: str) -> int: ...

# esempio
weechat.charset_set("iso-8859-1")

iconv_to_internal

Converte le stringhe per il set caratteri interno di WeeChat (UTF-8).

Prototipo:

char *weechat_iconv_to_internal (const char *charset, const char *string);

Argomenti:

  • charset: set caratteri da convertire

  • string: stringa da convertire

Valore restituito:

  • la stringa convertita (deve essere liberata richiamando "free" dopo l’utilizzo)

Esempio in C:

char *str = weechat_iconv_to_internal ("iso-8859-1", "iso string: é à");
/* ... */
free (str);

Script (Python):

# prototipo
def iconv_to_internal(charset: str, string: str) -> str: ...

# esempio
str = weechat.iconv_to_internal("iso-8859-1", "iso string: é à")

iconv_from_internal

Converte la stringa dal set caratteri interno di WeeChat (UTF-8) in un’altra.

Prototipo:

char *weechat_iconv_from_internal (const char *charset, const char *string);

Argomenti:

  • charset: set caratteri in uscita

  • string: stringa da convertire

Valore restituito:

  • la stringa convertita (deve essere liberata richiamando "free" dopo l’utilizzo

Esempio in C:

char *str = weechat_iconv_from_internal ("iso-8859-1", "utf-8 string: é à");
/* ... */
free (str);

Script (Python):

# prototipo
def iconv_from_internal(charset: str, string: str) -> str: ...

# esempio
str = weechat.iconv_from_internal("iso-8859-1", "utf-8 string: é à")

gettext

Restituisce la stringa tradotta (dipende dalla lingua).

Prototipo:

const char *weechat_gettext (const char *string);

Argomenti:

  • string: stringa da tradurre

Valore restituito:

  • translated string or string if there is no translation available in local language

Esempio in C:

char *str = weechat_gettext ("hello");

Script (Python):

# prototipo
def gettext(string: str) -> str: ...

# esempio
str = weechat.gettext("hello")

ngettext

Restituisce la stringa tradotta, utilizzando il singolare o il plurale, in base all’argomento count (contatore).

Prototipo:

const char *weechat_ngettext (const char *string, const char *plural,
                              int count);

Argomenti:

  • string: stringa da tradurre, singolare

  • plural: stringa da tradurre, plurale

  • count: utilizzato per scegliere tra singolare e plurale (la scelta viene fatta in base alla lingua locale)

Valore restituito:

  • translated string or string / plural if there is no translation available in local language

Esempio in C:

char *str = weechat_ngettext ("file", "files", num_files);

Script (Python):

# prototipo
def ngettext(string: str, plural: str, count: int) -> str: ...

# esempio
num_files = 2
str = weechat.ngettext("file", "files", num_files)

strndup

Return duplicated string, with a max number of bytes.

Prototipo:

char *weechat_strndup (const char *string, int bytes);

Argomenti:

  • string: stringa da duplicare

  • bytes: max bytes to duplicate

Valore restituito:

  • stringa duplicata (deve essere liberata chiamando "free" dopo l’utilizzo)

Esempio in C:

char *str = weechat_strndup ("abcdef", 3);  /* result: "abc" */
/* ... */
free (str);
Questa funzione non è disponibile nelle API per lo scripting.

string_cut

WeeChat ≥ 3.3.

Cut a string after a given number of chars, add an optional suffix after the string if it is cut.

Prototipo:

char *weechat_string_cut (const char *string, int length, int count_suffix, int screen, const char *cut_suffix);

Argomenti:

  • string: string to cut

  • length: max chars

  • count_suffix: if 1, the length of suffix is counter in the max length

  • screen: if 1, the cut is based on width of chars displayed

  • cut_suffix: the suffix added after the string if it is cut

Valore restituito:

  • cut string (must be freed by calling "free" after use)

Esempio in C:

char *str = weechat_string_cut ("this is a test", 5, 1, 1, "…");  /* result: "this…" */
/* ... */
free (str);
Questa funzione non è disponibile nelle API per lo scripting.

string_tolower

Updated in 3.8.

Return a string with uppercase letters converted to lowercase.

Behavior has changed in version 3.8: now all uppercase letters are properly converted to lowercase (by calling function towlower), in addition to the range A to Z.
Moreover, a newly allocated string is returned and must be freed after use.

Prototipo:

char *weechat_string_tolower (const char *string);

Argomenti:

  • string: stringa da convertire

Valore restituito:

  • string with lowercase letters (must be freed by calling "free" after use)

Esempio in C:

char *str = weechat_string_tolower ("ABCD_É");  /* result: "abcd_é" */
/* ... */
free (str);
Questa funzione non è disponibile nelle API per lo scripting.

string_toupper

Updated in 3.8.

Return a string with lowercase letters converted to uppercase.

Behavior has changed in version 3.8: now all lowercase letters are properly converted to uppercase (by calling function towupper), in addition to the range a to z.
Moreover, a newly allocated string is returned and must be freed after use.

Prototipo:

char *weechat_string_toupper (const char *string);

Argomenti:

  • string: stringa da convertire

Valore restituito:

  • string with uppercase letters (must be freed by calling "free" after use)

Esempio in C:

char *str = weechat_string_toupper ("abcd_é");  /* result: "ABCD_É" */
/* ... */
free (str);
Questa funzione non è disponibile nelle API per lo scripting.

string_charcmp

Updated in 1.0, 3.8.

Confronta due caratteri.

Prototipo:

int weechat_string_charcmp (const char *string1, const char *string2);

Argomenti:

  • string1: prima stringa da comparare

  • string2: seconda stringa da comparare

Return value:

  • arithmetic result of subtracting the first UTF-8 char in string2 from the first UTF-8 char in string1:

    • < 0 if char1 < char2

    • 0 if char1 == char2

    • > 0 if char1 > char2

Esempio in C:

int diff = weechat_string_charcmp ("aaa", "ccc");  /* == -2 */
Questa funzione non è disponibile nelle API per lo scripting.

string_charcasecmp

Updated in 1.0, 3.8.

Confronta due caratteri, ignorando la sensibilità alle maiuscole.

Behavior has changed in version 3.8: now all uppercase letters are properly converted to lowercase (by calling function towlower), in addition to the range A to Z.

Prototipo:

int weechat_string_charcasecmp (const char *string1, const char *string2);

Argomenti:

  • string1: prima stringa da comparare

  • string2: seconda stringa da comparare

Return value:

  • arithmetic result of subtracting the first UTF-8 char in string2 (converted to lowercase) from the first UTF-8 char in string1 (converted to lowercase):

    • < 0 if char1 < char2

    • 0 if char1 == char2

    • > 0 if char1 > char2

Esempio in C:

int diff = weechat_string_charcasecmp ("aaa", "CCC");  /* == -2 */
Questa funzione non è disponibile nelle API per lo scripting.

strcmp

WeeChat ≥ 3.8.

Case sensitive string comparison.

Prototipo:

int weechat_strcmp (const char *string1, const char *string2);

Argomenti:

  • string1: prima stringa da comparare

  • string2: seconda stringa da comparare

Return value:

  • arithmetic result of subtracting the last compared UTF-8 char in string2 from the last compared UTF-8 char in string1:

    • < 0 if string1 < string2

    • 0 if string1 == string2

    • > 0 if string1 > string2

Esempio in C:

int diff = weechat_strcmp ("aaa", "ccc");  /* == -2 */
Questa funzione non è disponibile nelle API per lo scripting.

strncmp

WeeChat ≥ 3.8.

Case sensitive string comparison, for max chars.

Prototipo:

int weechat_strncmp (const char *string1, const char *string2, int max);

Argomenti:

  • string1: prima stringa da comparare

  • string2: seconda stringa da comparare

  • max: numero massimo di caratteri da comparare

Return value:

  • arithmetic result of subtracting the last compared UTF-8 char in string2 from the last compared UTF-8 char in string1:

    • < 0 if string1 < string2

    • 0 if string1 == string2

    • > 0 if string1 > string2

Esempio in C:

int diff = weechat_strncmp ("aabb", "aacc", 2);  /* == 0 */
Questa funzione non è disponibile nelle API per lo scripting.

strcasecmp

Updated in 1.0, 3.8.

Case insensitive string comparison.

Behavior has changed in version 3.8: now all uppercase letters are properly converted to lowercase (by calling function towlower), in addition to the range A to Z.

Prototipo:

int weechat_strcasecmp (const char *string1, const char *string2);

Argomenti:

  • string1: prima stringa da comparare

  • string2: seconda stringa da comparare

Return value:

  • arithmetic result of subtracting the last compared UTF-8 char in string2 (converted to lowercase) from the last compared UTF-8 char in string1 (converted to lowercase):

    • < 0 if string1 < string2

    • 0 if string1 == string2

    • > 0 if string1 > string2

Esempio in C:

int diff;
diff = weechat_strcasecmp ("aaa", "CCC");    /* == -2 */
diff = weechat_strcasecmp ("noël", "NOËL");  /* == 0  */
Questa funzione non è disponibile nelle API per lo scripting.

strcasecmp_range

WeeChat ≥ 0.3.7, updated in 1.0, 3.8.

Confronta stringa non sensibile alle maiuscole e alla localizzazione, usando una serie per il confronto.

Prototipo:

int weechat_strcasecmp_range (const char *string1, const char *string2, int range);

Argomenti:

  • string1: prima stringa da comparare

  • string2: seconda stringa da comparare

  • range: numero di caratteri nel confronto maiuscole/minuscole, ad esempio:

    • 26: A-Z vengono ridotti ad a-z

    • 29: A-Z [ \ ] vengono ridotti ad a-z { | }

    • 30: A-Z [ \ ] ^ vengono ridotti ad a-z { | } ~

I valori 29 e 30 vengono usati da alcuni protocolli come IRC.

Return value:

  • arithmetic result of subtracting the last compared UTF-8 char in string2 (converted to lowercase) from the last compared UTF-8 char in string1 (converted to lowercase):

    • < 0 if string1 < string2

    • 0 if string1 == string2

    • > 0 if string1 > string2

Esempio in C:

int diff = weechat_strcasecmp_range ("nick{away}", "NICK[away]", 29);  /* == 0 */
Questa funzione non è disponibile nelle API per lo scripting.

strncasecmp

Updated in 1.0, 3.8.

Case insensitive string comparison, for max chars.

Behavior has changed in version 3.8: now all uppercase letters are properly converted to lowercase (by calling function towlower), in addition to the range A to Z.

Prototipo:

int weechat_strncasecmp (const char *string1, const char *string2, int max);

Argomenti:

  • string1: prima stringa da comparare

  • string2: seconda stringa da comparare

  • max: numero massimo di caratteri da comparare

Return value:

  • arithmetic result of subtracting the last compared UTF-8 char in string2 (converted to lowercase) from the last compared UTF-8 char in string1 (converted to lowercase):

    • < 0 if string1 < string2

    • 0 if string1 == string2

    • > 0 if string1 > string2

Esempio in C:

int diff = weechat_strncasecmp ("aabb", "AACC", 2);  /* == 0 */
Questa funzione non è disponibile nelle API per lo scripting.

strncasecmp_range

WeeChat ≥ 0.3.7, updated in 1.0, 3.8.

Confronta una stringa non sensibile alle maiuscole e alla localizzazione, per un numero max di caratteri, usando una serie per il confronto.

Prototipo:

int weechat_strncasecmp_range (const char *string1, const char *string2, int max, int range);

Argomenti:

  • string1: prima stringa da comparare

  • string2: seconda stringa da comparare

  • max: numero massimo di caratteri da comparare

  • range: numero di caratteri nel confronto maiuscole/minuscole, ad esempio:

    • 26: A-Z vengono ridotti ad a-z

    • 29: A-Z [ \ ] vengono ridotti ad a-z { | }

    • 30: A-Z [ \ ] ^ vengono ridotti ad a-z { | } ~

I valori 29 e 30 vengono usati da alcuni protocolli come IRC.

Return value:

  • arithmetic result of subtracting the last compared UTF-8 char in string2 (converted to lowercase) from the last compared UTF-8 char in string1 (converted to lowercase):

    • < 0 if string1 < string2

    • 0 if string1 == string2

    • > 0 if string1 > string2

Esempio in C:

int diff = weechat_strncasecmp_range ("nick{away}", "NICK[away]", 6, 29);  /* == 0 */
Questa funzione non è disponibile nelle API per lo scripting.

strcmp_ignore_chars

Updated in 1.0, 3.8.

String comparison ignoring some chars.

Prototipo:

int weechat_strcmp_ignore_chars (const char *string1, const char *string2,
                                 const char *chars_ignored,
                                 int case_sensitive);

Argomenti:

  • string1: prima stringa per il confronto

  • string2: seconda stringa per il confronto

  • chars_ignored: stringa con caratteri da ignorare

  • case_sensitive: 1 per il confronto sensibile alle maiuscole, altrimenti 0

Behavior has changed in version 3.8 when case_sensitive is set to 0: now all uppercase letters are properly converted to lowercase (by calling function towlower), in addition to the range A to Z.

Return value:

  • arithmetic result of subtracting the last compared UTF-8 char in string2 (converted to lowercase if case_sentitive is set to 0) from the last compared UTF-8 char in string1 (converted to lowercase if case_sensitive is set to 0):

    • < 0 if string1 < string2

    • 0 if string1 == string2

    • > 0 if string1 > string2

Esempio in C:

int diff = weechat_strcmp_ignore_chars ("a-b", "--a-e", "-", 1);  /* == -3 */
Questa funzione non è disponibile nelle API per lo scripting.

strcasestr

Updated in 1.3, 3.8.

Case insensitive string search.

Behavior has changed in version 3.8: now all uppercase letters are properly converted to lowercase (by calling function towlower), in addition to the range A to Z.

Prototipo:

const char *weechat_strcasestr (const char *string, const char *search);

Argomenti:

  • string: stringa

  • search: stringa da cercare in string

Valore restituito:

  • puntatore alla stringa trovata, o NULL se non trovata (WeeChat ≥ 1.3: pointer returned is a const char * instead of char *)

Esempio in C:

const char *pos = weechat_strcasestr ("aBcDeF", "de");  /* risultato: puntatore a "DeF" */
Questa funzione non è disponibile nelle API per lo scripting.

strlen_screen

WeeChat ≥ 0.4.2, updated in 3.8.

Return number of chars needed on screen to display UTF-8 string.

WeeChat color codes are skipped and don’t count in the result (this is the only difference with the function utf8_strlen_screen).

Prototipo:

int weechat_strlen_screen (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • numero di caratteri necessari per visualizzare la stringa UTF-8 su schermo

Esempio in C:

int length_on_screen = weechat_strlen_screen ("é");  /* == 1 */

Script (Python):

# prototipo
def strlen_screen(string: str) -> int: ...

# esempio
length = weechat.strlen_screen("é")  # 1

string_match

Updated in 1.0, 3.8.

Verifica se una stringa coincide ad una mask.

Prototipo:

int weechat_string_match (const char *string, const char *mask,
                          int case_sensitive);

Argomenti:

  • string: stringa

  • mask: mask with wildcards (*), each wildcard matches 0 or more chars in the string

  • case_sensitive: 1 per il confronto sensibile alle maiuscole, altrimenti 0

Since version 1.0, wildcards are allowed inside the mask (not only beginning/end of mask).
Behavior has changed in version 3.8 when case_sensitive is set to 0: now all uppercase letters are properly converted to lowercase (by calling function towlower), in addition to the range A to Z.

Valore restituito:

  • 1 se la stringa coincide alla mask, altrimenti 0

Esempio in C:

int match1 = weechat_string_match ("abcdef", "abc*", 0);   /* == 1 */
int match2 = weechat_string_match ("abcdef", "*dd*", 0);   /* == 0 */
int match3 = weechat_string_match ("abcdef", "*def", 0);   /* == 1 */
int match4 = weechat_string_match ("abcdef", "*de*", 0);   /* == 1 */
int match5 = weechat_string_match ("abcdef", "*b*d*", 0);  /* == 1 */

Script (Python):

# prototipo
def string_match(string: str, mask: str, case_sensitive: int) -> int: ...

# esempio
match1 = weechat.string_match("abcdef", "abc*", 0)   # == 1
match2 = weechat.string_match("abcdef", "*dd*", 0)   # == 0
match3 = weechat.string_match("abcdef", "*def", 0)   # == 1
match4 = weechat.string_match("abcdef", "*de*", 0)   # == 1
match5 = weechat.string_match("abcdef", "*b*d*", 0)  # == 1

string_match_list

WeeChat ≥ 2.5, updated in 3.8.

Check if a string matches a list of masks where negative mask is allowed with the format "!word". A negative mask has higher priority than a standard mask.

Prototipo:

int weechat_string_match_list (const char *string, const char **masks,
                               int case_sensitive);

Argomenti:

  • string: string

  • masks: list of masks, with a NULL after the last mask in list; each mask is compared to the string with the function string_match

  • case_sensitive: 1 for case sensitive comparison, otherwise 0

Behavior has changed in version 3.8 when case_sensitive is set to 0: now all uppercase letters are properly converted to lowercase (by calling function towlower), in addition to the range A to Z.

Valore restituito:

  • 1 if string matches list of masks (at least one mask matches and no negative mask matches), otherwise 0

Esempio in C:

const char *masks[3] = { "*", "!abc*", NULL };
int match1 = weechat_string_match_list ("abc", masks, 0);     /* == 0 */
int match2 = weechat_string_match_list ("abcdef", masks, 0);  /* == 0 */
int match3 = weechat_string_match_list ("def", masks, 0);     /* == 1 */

Script (Python):

# prototipo
def string_match_list(string: str, masks: str, case_sensitive: int) -> int: ...

# esempio
match1 = weechat.string_match("abc", "*,!abc*", 0)     # == 0
match2 = weechat.string_match("abcdef", "*,!abc*", 0)  # == 0
match3 = weechat.string_match("def", "*,!abc*", 0)     # == 1

string_expand_home

WeeChat ≥ 0.3.3.

Sostituisce la ~ iniziale con la stringa con la cartella home. Se la stringa non inizia con ~, viene restituita la stessa stringa.

Prototipo:

char *weechat_string_expand_home (const char *path);

Argomenti:

  • path: percorso

Valore restituito:

  • percorso con la ~ iniziale sostituita dalla cartella home (deve essere liberata chiamando "free" dopo l’uso)

Esempio in C:

char *str = weechat_string_expand_home ("~/file.txt");
/* result: "/home/user/file.txt" */
/* ... */
free (str);
Questa funzione non è disponibile nelle API per lo scripting.

string_eval_path_home

WeeChat ≥ 1.3, updated in 3.2.

Evaluate a path in 3 steps:

  1. replace leading %h by a WeeChat directory (data by default),

  2. replace leading ~ by user home directory (call to string_expand_home),

  3. evaluate variables (see string_eval_expression).

Prototipo:

char *weechat_string_eval_path_home (const char *path,
                                     struct t_hashtable *pointers,
                                     struct t_hashtable *extra_vars,
                                     struct t_hashtable *options);

Argomenti:

  • path: path

  • pointers: hashtable for call to function string_eval_expression

  • extra_vars: hashtable for call to function string_eval_expression

  • options: hashtable for call to function string_eval_expression, with one extra key supported:

    • directory: WeeChat directory to use when replacing %h, one of:

      • config

      • data (default)

      • cache

      • runtime

Valore restituito:

  • evaluated path (must be freed by calling "free" after use)

Esempio in C:

char *str = weechat_string_eval_path_home ("${weechat_config_dir}/test.conf", NULL, NULL, NULL);
/* result: "/home/user/.config/weechat/test.conf" */
/* ... */
free (str);

Script (Python):

# prototipo
def string_eval_path_home(path: str, pointers: Dict[str, str], extra_vars: Dict[str, str], options: Dict[str, str]) -> str: ...

# esempio
path = weechat.string_eval_path_home("${weechat_config_dir}/test.conf", {}, {}, {})
# path == "/home/user/.config/weechat/test.conf"

string_remove_quotes

Rimuove le virgolette all’inizio e alla fine della stringa (ignora gli spazi se presenti prima delle prime virgolette o dopo le ultime virgolette).

Prototipo:

char *weechat_string_remove_quotes (const char *string, const char *quotes);

Argomenti:

  • string: stringa

  • quotes: stringa con elenco di virgolette

Valore restituito:

  • stringa senza virgolette all’inizio/fine (deve essere liberata chiamando "free" dopo l’uso)

Esempio in C:

char *str = weechat_string_remove_quotes (string, " 'Non posso' ", "'");
/* risultato: "Non posso" */
/* ... */
free (str);
Questa funzione non è disponibile nelle API per lo scripting.

string_strip

Rimuove i caratteri ad inizio/fine della stringa.

Prototipo:

char *weechat_string_strip (const char *string, int left, int right,
                            const char *chars);

Argomenti:

  • string: stringa

  • left: rimuove i caratteri a sinistra se diversi da 0

  • right: rimuove i caratteri a destra se diversi da 0

  • chars: stringa con i caratteri da rimuovere

Valore restituito:

  • stringa corretta (deve essere liberata chiamando "free" dopo l’uso)

Esempio in C:

char *str = weechat_string_strip (".abc -", 0, 1, "- .");  /* risultato: ".abc" */
/* ... */
free (str);
Questa funzione non è disponibile nelle API per lo scripting.

string_convert_escaped_chars

WeeChat ≥ 1.0.

Convert escaped chars to their value:

  • \": double quote

  • \\: backslash

  • \a: alert (BEL)

  • \b: backspace

  • \e: escape

  • \f: form feed

  • \n: new line

  • \r: carriage return

  • \t: horizontal tab

  • \v: vertical tab

  • \0ooo: char as octal value (ooo is 0 to 3 digits)

  • \xhh: char as hexadecimal value (hh is 1 to 2 digits)

  • \uhhhh: unicode char as hexadecimal value (hhhh is 1 to 4 digits)

  • \Uhhhhhhhh: unicode char as hexadecimal value (hhhhhhhh is 1 to 8 digits)

Prototipo:

char *weechat_string_convert_escaped_chars (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • string with escaped chars replaced by their value (deve essere liberata chiamando "free" dopo l’uso)

Esempio in C:

char *str = weechat_string_convert_escaped_chars ("snowman: \\u2603");
/* str == "snowman: ☃" */
/* ... */
free (str);
Questa funzione non è disponibile nelle API per lo scripting.

string_mask_to_regex

Restituisce una espressione regolare con una mask, dove l’unico carattere speciale è *. Tutti gli altri caratteri speciali per le espressioni regolari non vengono riconosciuti.

Prototipo:

char *weechat_string_mask_to_regex (const char *mask);

Argomenti:

  • mask: mask

Valore restituito:

  • espressione regolare, come stringa (deve essere liberata chiamando "free" dopo l’uso)

Esempio in C:

char *str_regex = weechat_string_mask_to_regex ("test*mask");
/* result: "test.*mask" */
/* ... */
free (str_regex);

Script (Python):

# prototipo
def string_mask_to_regex(mask: str) -> str: ...

# esempio
regex = weechat.string_mask_to_regex("test*mask")  # "test.*mask"

string_regex_flags

WeeChat ≥ 0.3.7.

Restituisce sia il puntatore sulla stringa dopo le flag che la mask con le flag per compilare l’espressione regolare.

Prototipo:

const char *weechat_string_regex_flags (const char *regex, int default_flags, int *flags)

Argomenti:

  • regex: POSIX extended regular expression

  • default_flags: combinazione dei seguenti valori (consultare man regcomp):

    • REG_EXTENDED

    • REG_ICASE

    • REG_NEWLINE

    • REG_NOSUB

  • flags: pointer value is set with flags used in regular expression (default flags + flags set in regular expression)

Flags must be at beginning of regular expression. Format is: "(?eins-eins)string".

Allowed flags are:

  • e: POSIX extended regular expression (REG_EXTENDED)

  • i: case insensitive (REG_ICASE)

  • n: match-any-character operators don_t match a newline (REG_NEWLINE)

  • s: support for substring addressing of matches is not required (REG_NOSUB)

Valore restituito:

  • pointer in regex, after flags

Esempio in C:

const char *regex = "(?i)test";
int flags;
const char *ptr_regex = weechat_string_regex_flags (regex, REG_EXTENDED, &flags);
/* ptr_regex == "test", flags == REG_EXTENDED | REG_ICASE */
Questa funzione non è disponibile nelle API per lo scripting.

string_regcomp

WeeChat ≥ 0.3.7.

Compile a POSIX extended regular expression using optional flags at beginning of string (for format of flags, see string_regex_flags).

Prototipo:

int weechat_string_regcomp (void *preg, const char *regex, int default_flags)

Argomenti:

  • preg: pointer to regex_t structure

  • regex: POSIX extended regular expression

  • default_flags: combination of following values (see man regcomp):

    • REG_EXTENDED

    • REG_ICASE

    • REG_NEWLINE

    • REG_NOSUB

Valore restituito:

  • same return code as function regcomp (0 if ok, other value for error, see man regcomp)

Regular expression preg must be cleaned by calling "regfree" after use, if the function returned 0 (OK).

Esempio in C:

regex_t my_regex;
if (weechat_string_regcomp (&my_regex, "(?i)test", REG_EXTENDED) == 0)
{
    /* OK */
    /* ... */
    regfree (&my_regex);
}
else
{
    /* error */
    /* ... */
}
Questa funzione non è disponibile nelle API per lo scripting.

string_has_highlight

Controlla se una stringa ha uno o più eventi, usando la lista di parole per gli eventi.

Prototipo:

int weechat_string_has_highlight (const char *string,
                                  const char highlight_words);

Argomenti:

  • string: stringa

  • highlight_words: lista di parole per gli eventi, separate da virgole

Valore restituito:

  • 1 se la stringa ha uno o più eventi, altrimenti 0

Esempio in C:

int hl = weechat_string_has_highlight ("my test string", "test,word2");  /* == 1 */

Script (Python):

# prototipo
def string_has_highlight(string: str, highlight_words: str) -> int: ...

# esempio
highlight = weechat.string_has_highlight("my test string", "test,word2")  # 1

string_has_highlight_regex

WeeChat ≥ 0.3.4.

Check if a string has one or more highlights, using a POSIX extended regular expression.
For at least one match of regular expression on string, it must be surrounded by delimiters (chars different from: alphanumeric, -, _ and |).

Prototipo:

int weechat_string_has_highlight_regex (const char *string, const char *regex);

Argomenti:

  • string: stringa

  • regex: POSIX extended regular expression

Valore restituito:

  • 1 se la stringa ha uno o più eventi, altrimenti 0

Esempio in C:

int hl = weechat_string_has_highlight_regex ("my test string", "test|word2");  /* == 1 */

Script (Python):

# prototipo
def string_has_highlight_regex(string: str, regex: str) -> int: ...

# esempio
highlight = weechat.string_has_highlight_regex("my test string", "test|word2")  # 1

string_replace

Sostituisce tutte le ricorrenze di una stringa con un’altra.

Prototipo:

char *weechat_string_replace (const char *string, const char *search,
                              const char *replace);

Argomenti:

  • string: stringa

  • search: stringa da sostituire

  • replace: sostituzione per la stringa search

Valore restituito:

  • la stringa dopo search sostituita da replace (deve essere liberata chiamando "free" dopo l’uso)

Esempio in C:

char *str = weechat_string_replace ("test", "s", "x");  /* result: "text" */
/* ... */
free (str);
Questa funzione non è disponibile nelle API per lo scripting.

string_replace_regex

WeeChat ≥ 1.0.

Replace text in a string using a regular expression, replacement text and optional callback.

Prototipo:

char *weechat_string_replace_regex (const char *string, void *regex,
                                    const char *replace, const char reference_char,
                                    char *(*callback)(void *data, const char *text),
                                    void *callback_data);

Argomenti:

  • string: string

  • regex: pointer to a regular expression (regex_t structure) compiled with WeeChat function string_regcomp or regcomp (see man regcomp)

  • replace: replacement text, where following references are allowed:

    • $0 to $99: match 0 to 99 in regular expression (0 is the whole match, 1 to 99 are groups captured between parentheses)

    • $+: the last match (with highest number)

    • $.*N: match N (can be + or 0 to 99), with all chars replaced by * (the * char can be any char between space (32) and ~ (126))

  • reference_char: the char used for reference to match (commonly $)

  • callback: an optional callback called for each reference in replace (except for matches replaced by a char); the callback must return:

    • newly allocated string: it is used as replacement text (it is freed after use)

    • NULL: the text received in callback is used as replacement text (without changes)

  • callback_data: pointer given to callback when it is called

Valore restituito:

  • string with text replaced, NULL if problem (must be freed by calling "free" after use)

Esempio in C:

regex_t my_regex;
char *string;
if (weechat_string_regcomp (&my_regex, "([0-9]{4})-([0-9]{2})-([0-9]{2})",
                            REG_EXTENDED) == 0)
{
    string = weechat_string_replace_regex ("date: 2014-02-14", &my_regex,
                                           "$3/$2/$1", '$', NULL, NULL);
    /* string == "date: 14/02/2014" */
    if (string)
        free (string);
    regfree (&my_regex);
}
Questa funzione non è disponibile nelle API per lo scripting.

string_translate_chars

WeeChat ≥ 3.8.

Translate chars in a string.

Prototipo:

char *string_translate_chars (const char *string, const char *chars1, const char *chars2);

Argomenti:

  • string: string

  • chars1: string with chars to translate

  • chars2: string with replacement chars; it must contain the same number of UTF-8 chars than chars1

Valore restituito:

  • string with translated chars, NULL if problem (must be freed by calling "free" after use)

Esempi in C:

/* "test" => "tEst" */
char *str = weechat_string_translate_chars ("test", "abcdef", "ABCDEF");

/* "clean the boat" => "CleAn the BoAt" */
char *str = weechat_string_translate_chars ("clean the boat", "abc", "ABC");
Questa funzione non è disponibile nelle API per lo scripting.

string_split

Updated in 2.5, 2.6.

Divide una stringa in base a uno o più delimitatori.

Prototipo:

char **weechat_string_split (const char *string, const char *separators,
                             const char *strip_items, int flags,
                             int num_items_max, int *num_items);

Argomenti:

  • string: stringa da dividere

  • separators: delimitatori usati per dividere

  • strip_items: chars to strip from returned items (left/right); optional, can be NULL

  • flags: combination values to change the default behavior; if the value is 0, the default behavior is used (no strip of separators at beginning/end of string, multiple separators are kept as-is so empty strings can be returned); the following flags are accepted:

    • WEECHAT_STRING_SPLIT_STRIP_LEFT: strip separators on the left (beginning of string)

    • WEECHAT_STRING_SPLIT_STRIP_RIGHT: strip separators on the right (end of string)

    • WEECHAT_STRING_SPLIT_COLLAPSE_SEPS: collapse multiple consecutive separators into a single one

    • WEECHAT_STRING_SPLIT_KEEP_EOL: keep end of line for each value

  • num_items_max: numero massimo di elementi creati (0 = nessun limite)

  • num_items: puntatore ad int che conterrà il numero di elementi creati

With WeeChat ≤ 2.4, the flags argument was called keep_eol and took other values, which must be converted like that:
keep_eol flags

0

WEECHAT_STRING_SPLIT_STRIP_LEFT | WEECHAT_STRING_SPLIT_STRIP_RIGHT | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS

1

WEECHAT_STRING_SPLIT_STRIP_LEFT | WEECHAT_STRING_SPLIT_STRIP_RIGHT | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS | WEECHAT_STRING_SPLIT_KEEP_EOL

2

WEECHAT_STRING_SPLIT_STRIP_LEFT | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS | WEECHAT_STRING_SPLIT_KEEP_EOL

Valore restituito:

  • array di stringhe, NULL se si verifica un problema (deve essere liberata chiamando string_free_split dopo l’uso)

Esempi:

char **argv;
int argc;

argv = weechat_string_split ("abc de  fghi ", " ", NULL, 0, 0, &argc);
/* result: argv[0] == "abc"
           argv[1] == "de"
           argv[2] = ""
           argv[3] == "fghi"
           argv[4] = ""
           argv[5] == NULL
           argc == 5
*/
weechat_string_free_split (argv);

argv = weechat_string_split ("abc de  fghi ", " ", NULL,
                             WEECHAT_STRING_SPLIT_STRIP_LEFT
                             | WEECHAT_STRING_SPLIT_STRIP_RIGHT
                             | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
                             0, &argc);
/* result: argv[0] == "abc"
           argv[1] == "de"
           argv[2] == "fghi"
           argv[3] == NULL
           argc == 3
*/
weechat_string_free_split (argv);

argv = weechat_string_split ("abc de  fghi ", " ", NULL,
                             WEECHAT_STRING_SPLIT_STRIP_LEFT
                             | WEECHAT_STRING_SPLIT_STRIP_RIGHT
                             | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS
                             | WEECHAT_STRING_SPLIT_KEEP_EOL,
                             0, &argc);
/* result: argv[0] == "abc de  fghi"
           argv[1] == "de  fghi"
           argv[2] == "fghi"
           argv[3] == NULL
           argc == 3
*/
weechat_string_free_split (argv);

argv = weechat_string_split ("abc de  fghi ", " ", NULL,
                             WEECHAT_STRING_SPLIT_STRIP_LEFT
                             | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS
                             | WEECHAT_STRING_SPLIT_KEEP_EOL,
                             0, &argc);
/* result: argv[0] == "abc de  fghi "
           argv[1] == "de  fghi "
           argv[2] == "fghi "
           argv[3] == NULL
           argc == 3
*/
weechat_string_free_split (argv);

argv = weechat_string_split (" abc, de,, fghi ", ",", " ",
                             WEECHAT_STRING_SPLIT_STRIP_LEFT
                             | WEECHAT_STRING_SPLIT_STRIP_RIGHT
                             | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
                             0, &argc);
/* result: argv[0] == "abc"
           argv[1] == "de"
           argv[2] == "fghi"
           argv[3] == NULL
           argc == 3
*/
weechat_string_free_split (argv);
Questa funzione non è disponibile nelle API per lo scripting.

string_split_shell

WeeChat ≥ 1.0.

Split a string like the shell does for a command with arguments.

This function is a C conversion of Python class "shlex" (file: Lib/shlex.py in Python repository), see this page .

Prototipo:

char **weechat_string_split_shell (const char *string, int *num_items);

Argomenti:

  • string: stringa da dividere

  • num_items: puntatore ad int che conterrà il numero di elementi creati

Valore restituito:

  • array di stringhe, NULL se si verifica un problema (deve essere liberata chiamando string_free_split dopo l’uso)

Esempio in C:

char **argv;
int argc;
argv = weechat_string_split_shell ("test 'first arg'  \"second arg\"", &argc);
/* result: argv[0] == "test"
           argv[1] == "first arg"
           argv[2] == "second arg"
           argv[3] == NULL
           argc == 3
*/
weechat_string_free_split (argv);
Questa funzione non è disponibile nelle API per lo scripting.

string_free_split

Libera la memoria usata per la divisione di una stringa.

Prototipo:

void weechat_string_free_split (char **split_string);

Argomenti:

Esempio in C:

char *argv;
int argc;
argv = weechat_string_split (string, " ", 0, 0, &argc);
/* ... */
weechat_string_free_split (argv);
Questa funzione non è disponibile nelle API per lo scripting.

string_rebuild_split_string

Updated in 3.7.

Rebuild a string with a split string, using optional separator and index of first/last string to use.

Prototipo:

char *weechat_string_rebuild_split_string (char **split_string,
                                           const char *separator,
                                           int index_start, int index_end);

Argomenti:

  • split_string: stringa divisa dalla funzione string_split

  • separator: string used to separate strings (can be NULL or empty string)

  • index_start: index of first string to use (≥ 0)

  • index_end: index of last string to use (must be ≥ index_start; special value -1 can be used to use all arguments until NULL is found)

Valore restituito:

  • stringa compilata con la stringa divisa (deve essere liberata chiamando "free" dopo l’uso)

Esempio in C:

char **argv;
int argc;
argv = weechat_string_split ("abc def ghi", " ", 0, 0, &argc);
char *str = weechat_string_rebuild_split_string (argv, ";", 0, -1);
/* str == "abc;def;ghi" */
/* ... */
free (str);
Questa funzione non è disponibile nelle API per lo scripting.

string_split_command

Divide una lista di comandi separata da separator (che può essere omesso aggiungendo \ nella stringa).

Prototipo:

char **weechat_string_split_command (const char *command, char separator);

Argomenti:

  • command: comando da dividere

  • separator: separatore

Valore restituito:

  • array di stringhe, NULL in caso di problemi (deve essere liberata chiamando free_split_command dopo l’uso)

Esempio in C:

char **argv = weechat_string_split_command ("/command1 arg;/command2", ';');
/* result: argv[0] == "/command1 arg"
           argv[1] == "/command2"
           argv[2] == NULL
*/
weechat_free_split_command (argv);
Questa funzione non è disponibile nelle API per lo scripting.

string_free_split_command

Libera la memoria utilizzata dalla divisione di un comando.

Prototipo:

void weechat_string_free_split_command (char **split_command);

Argomenti:

Esempio in C:

char **argv = weechat_string_split_command ("/command1 arg;/command2", ';');
/* ... */
weechat_free_split_command (argv);
Questa funzione non è disponibile nelle API per lo scripting.

string_format_size

Compila una stringa con un file di dimensione fissa ed una unità tradotta nella lingua locale.

Prototipo:

char *weechat_string_format_size (unsigned long long size);

Argomenti:

  • size: dimensione (in byte)

Valore restituito:

  • stringa formattata (deve essere liberata chiamando "free" dopo l’uso)

Esempi in C:

/* esempi in lingua inglese */

char *str = weechat_string_format_size (0);  /* str == "0 bytes" */
/* ... */
free (str);

char *str = weechat_string_format_size (1);  /* str == "1 byte" */
/* ... */
free (str);

char *str = weechat_string_format_size (200);  /* str == "200 bytes" */
/* ... */
free (str);

char *str = weechat_string_format_size (15200);  /* str == "15.2 KB" */
/* ... */
free (str);

char *str = weechat_string_format_size (2097152);  /* str == "2.10 MB" */
/* ... */
free (str);

Script (Python), WeeChat ≥ 2.2:

# prototipo
def string_format_size(size: int) -> str: ...

# esempio
str = weechat.string_format_size(15200)  # == "15.2 KB"

string_parse_size

WeeChat ≥ 3.7.

Parse a string with a size and optional unit and return the size in bytes.

Prototipo:

unsigned long long weechat_string_parse_size (const char *size);

Argomenti:

  • size: the size as string: positive integer number followed by optional spaces and optional unit (lower or upper case), which is one of:

    • b: bytes

    • k: kilobytes (1k = 1000 bytes)

    • m: megabytes (1m = 1000k = 1,000,000 bytes)

    • g: gigabytes (1g = 1000m = 1,000,000,000 bytes)

    • t: terabytes (1t = 1000g = 1,000,000,000,000 bytes)

Valore restituito:

  • size in bytes, 0 if error

Esempio in C:

unsigned long long size = weechat_parse_size ("1.34m");  /* size == 1340000 */

Script (Python):

# prototipo
def string_parse_size(size: str) -> int: ...

# esempio
size = weechat.string_parse_size("1.34m")  # 1340000

string_color_code_size

WeeChat ≥ 3.0.

Return the size (in bytes) of the WeeChat color code at the beginning of the string.

Prototipo:

int weechat_string_color_code_size (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • size (in bytes) of the WeeChat color code at the beginning of the string; if the string is NULL, empty or does not start with a color code, 0 is returned; if the string begins with multiple color codes, only the size of the first one is returned

Esempi:

int size;

size = weechat_string_color_code_size ("test");  /* size == 0 */
size = weechat_string_color_code_size (weechat_color ("bold"));  /* size == 2 */
size = weechat_string_color_code_size (weechat_color ("yellow,red"));  /* size == 7 */

Script (Python):

# prototipo
def string_color_code_size(string: str) -> int: ...

# esempio
size = weechat.string_color_code_size("test")  # size == 0
size = weechat.string_color_code_size(weechat.color("bold"))  # size == 2
size = weechat.string_color_code_size(weechat.color("yellow,red"))  # size == 7

string_remove_color

Rimuove i colori di WeeChat da una stringa.

Prototipo:

char *weechat_string_remove_color (const char *string,
                                   const char *replacement);

Argomenti:

  • string: stringa

  • replacement: se non NULL e non vuota, i codici colore di WeeChat sono sostituiti dal primo carattere di questa stringa, altrimenti i codici colori di WeeChat ed i caratteri seguenti (se correlate al colore) sono rimossi dalla stringa

Valore restituito:

  • stringa senza un colore (deve essere liberata chiamando "free" dopo l’uso)

Esempi:

/* rimuove i codici colore */
char *str = weechat_string_remove_color (my_string1, NULL);
/* ... */
free (str);

/* sostituisce i codici colore con "?" */
char *str = weechat_string_remove_color (my_string2, "?");
/* ... */
free (str);

Script (Python):

# prototipo
def string_remove_color(string: str, replacement: str) -> str: ...

# esempio
str = weechat.string_remove_color(my_string, "?")

string_base_encode

WeeChat ≥ 2.4.

Encode a string in base 16, 32, or 64.

Prototipo:

int weechat_string_base_encode (int base, const char *from, int length, char *to);

Argomenti:

  • base: 16, 32, or 64

  • from: stringa da codificare

  • length: lunghezza della stringa da codificare (ad esempio strlen(from))

  • to: puntatore alla stringa per memorizzare il risultato (deve essere sufficientemente lunga, il risultato è più lungo della stringa iniziale)

Valore restituito:

  • lunghezza della stringa memorizzata in *to (lo \0 finale non conta), -1 if error

Esempio in C:

char *string = "abcdefgh", result[128];
int length;
length = weechat_string_base_encode (16, string, strlen (string), result);
/* length == 16, result == "6162636465666768" */
length = weechat_string_base_encode (32, string, strlen (string), result);
/* length == 16, result == "MFRGGZDFMZTWQ===" */
length = weechat_string_base_encode (64, string, strlen (string), result);
/* length == 12, result == "YWJjZGVmZ2g=" */
Questa funzione non è disponibile nelle API per lo scripting.

string_base_decode

WeeChat ≥ 2.4.

Decode a string encoded in base 16, 32, or 64.

Prototipo:

int weechat_string_base_decode (int base, const char *from, char *to);

Argomenti:

  • base: 16, 32, or 64

  • from: stringa da decodificare

  • to: puntatore alla stringa per memorizzare il risultato (deve essere sufficientemente lunga, il risultato è più lungo della stringa iniziale)

Valore restituito:

  • lunghezza della stringa memorizzata in *to (lo \0 finale non conta), -1 if error

Esempio in C:

char result[128];
int length;
length = weechat_string_base_decode (16, "6162636465666768", result);
/* length == 8, result == "abcdefgh" */
length = weechat_string_base_decode (32, "MFRGGZDFMZTWQ===", result);
/* length == 8, result == "abcdefgh" */
length = weechat_string_base_decode (64, "YWJjZGVmZ2g=", result);
/* length == 8, result == "abcdefgh" */
Questa funzione non è disponibile nelle API per lo scripting.

string_hex_dump

WeeChat ≥ 1.4.

Display a dump of data as hexadecimal and ascii bytes.

Prototipo:

char *string_hex_dump (const char *data, int data_size, int bytes_per_line,
                       const char *prefix, const char *suffix);

Argomenti:

  • data: the data to dump

  • data_size: number of bytes to dump in data

  • bytes_per_line: number of bytes to display in each line

  • prefix: the prefix to display at the beginning of each line (optional, can be NULL)

  • suffix: the suffix to display at the end of each line (optional, can be NULL)

Valore restituito:

  • string with dump of data (must be freed by calling "free" after use)

Esempio in C:

char *string = "abc def-ghi";
char *dump = weechat_string_hex_dump (string, strlen (string), 8, " >> ", NULL);
/* dump == " >> 61 62 63 20 64 65 66 2D   a b c   d e f - \n"
           " >> 67 68 69                  g h i           "  */
Questa funzione non è disponibile nelle API per lo scripting.

string_is_command_char

WeeChat ≥ 0.3.2.

Verifica che il primo carattere della stringa sia un carattere comando (il comando carattere predefinito è /).

Prototipo:

int weechat_string_is_command_char (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • 1 se il primo carattere della stringa è un comando carattere, altrimenti 0

Esempi in C:

int command_char1 = weechat_string_is_command_char ("/test");  /* == 1 */
int command_char2 = weechat_string_is_command_char ("test");   /* == 0 */

Script (Python):

# prototipo
def string_is_command_char(string: str) -> int: ...

# esempi
command_char1 = weechat.string_is_command_char("/test")  # == 1
command_char2 = weechat.string_is_command_char("test")   # == 0

string_input_for_buffer

WeeChat ≥ 0.3.2.

Restituisce il puntatore al testo in input per il buffer (puntatore all’interno dell’argomento "string"), oppure NULL se è un comando.

Prototipo:

const char *weechat_string_input_for_buffer (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • puntatore all’interno di "string", oppure NULL

Esempi in C:

const char *str1 = weechat_string_input_for_buffer ("test");    /* "test"  */
const char *str2 = weechat_string_input_for_buffer ("/test");   /* NULL    */
const char *str3 = weechat_string_input_for_buffer ("//test");  /* "/test" */

Script (Python):

# prototipo
def string_input_for_buffer(string: str) -> str: ...

# esempi
str1 = weechat.string_input_for_buffer("test")    # "test"
str2 = weechat.string_input_for_buffer("/test")   # ""
str3 = weechat.string_input_for_buffer("//test")  # "/test"

string_eval_expression

WeeChat ≥ 0.4.0, updated in 0.4.2, 0.4.3, 1.0, 1.1, 1.2, 1.3, 1.6, 1.8, 2.0, 2.2, 2.3, 2.7, 2.9, 3.1, 3.2, 3.3, 3.4, 3.6, 3.8, 4.0.0, 4.2.0.

Evaluate an expression and return result as a string. Special variables with format ${variable} are expanded (see table below).

Since version 1.0, nested variables are supported, for example: ${color:${variable}}.

Prototipo:

char *weechat_string_eval_expression (const char *expr,
                                      struct t_hashtable *pointers,
                                      struct t_hashtable *extra_vars,
                                      struct t_hashtable *options);

Argomenti:

  • expr: the expression to evaluate (see conditions and variables)

  • pointers: hashtable with pointers (keys must be string, values must be pointer); pointers "window" and "buffer" are automatically added if they are not in hashtable (with pointer to current window/buffer) (can be NULL):

    • regex: pointer to a regular expression (regex_t structure) compiled with WeeChat function string_regcomp or regcomp (see man regcomp); this option is similar to regex in hashtable options (below), but is used for better performance

  • extra_vars: extra variables that will be expanded (can be NULL)

  • options: a hashtable with some options (keys and values must be string) (can be NULL):

    • type: default behavior is just to replace values in expression, other types can be selected:

      • condition: the expression is evaluated as a condition: operators and parentheses are used, result is a boolean ("0" or "1")

    • prefix: prefix before variables to replace (default: ${)

    • suffix: suffix after variables to replace (default: })

    • extra: default behavior is to just replace extra variables (extra_vars), other behavior can be selected:

      • eval: extra variables (extra_vars) are evaluated themselves before replacing (WeeChat ≥ 1.6)

    • regex: a regex used to replace text in expr (which is then not evaluated)

    • regex_replace: the replacement text to use with regex, to replace text in expr (the regex_replace is evaluated on each match of regex against expr, until no match is found)

    • debug: debug level (string with integer number ≥ 1), if enabled, a key "debug_output" is added in hashtable options:

      • 1: enable debug

      • 2: enable more verbose debug

Valore restituito:

  • evaluated expression (must be freed by calling "free" after use), or NULL if problem (invalid expression or not enough memory)

Esempi in C:

/* conditions */
struct t_hashtable *options1 = weechat_hashtable_new (8,
                                                      WEECHAT_HASHTABLE_STRING,
                                                      WEECHAT_HASHTABLE_STRING,
                                                      NULL,
                                                      NULL);
weechat_hashtable_set (options1, "type", "condition");
char *str1 = weechat_string_eval_expression ("${window.win_width} > 100", NULL, NULL, options1);  /* "1" */
char *str2 = weechat_string_eval_expression ("abc =~ def", NULL, NULL, options1);                 /* "0" */

/* simple expression */
char *str3 = weechat_string_eval_expression ("${buffer.full_name}", NULL, NULL, NULL);  /* "core.weechat" */

/* replace with regex */
struct t_hashtable *options2 = weechat_hashtable_new (8,
                                                      WEECHAT_HASHTABLE_STRING,
                                                      WEECHAT_HASHTABLE_STRING,
                                                      NULL,
                                                      NULL);
/* add brackets around URLs */
weechat_hashtable_set (options2, "regex", "[a-zA-Z0-9_]+://[^ ]+");
weechat_hashtable_set (options2, "regex_replace", "[ ${re:0} ]");
char *str4 = weechat_string_eval_expression ("test: https://weechat.org", NULL, NULL, NULL);  /* "test: [ https://weechat.org ]" */

/* hide passwords */
weechat_hashtable_set (options2, "regex", "(password=)([^ ]+)");
weechat_hashtable_set (options2, "regex_replace", "${re:1}${hide:*,${re:2}}");
char *str5 = weechat_string_eval_expression ("password=abc password=def", NULL, NULL, NULL);  /* "password=*** password=***" */

Script (Python):

# prototipo
def string_eval_expression(expr: str, pointers: Dict[str, str], extra_vars: Dict[str, str], options: Dict[str, str]) -> str: ...

# esempi

# conditions
str1 = weechat.string_eval_expression("${window.win_width} > 100", {}, {}, {"type": "condition"})  # "1"
str2 = weechat.string_eval_expression("abc =~ def", {}, {}, {"type": "condition"})                 # "0"

# simple expression
str3 = weechat.string_eval_expression("${buffer.full_name}", {}, {}, {}) # "core.weechat"

# replace with regex: add brackets around URLs
options = {
    "regex": "[a-zA-Z0-9_]+://[^ ]+",
    "regex_replace": "[ ${re:0} ]",
}
str4 = weechat.string_eval_expression("test: https://weechat.org", {}, {}, options)  # "test: [ https://weechat.org ]"

# replace with regex: hide passwords
options = {
    "regex": "(password=)([^ ]+)",
    "regex_replace": "${re:1}${hide:*,${re:2}}",
}
str5 = weechat.string_eval_expression("password=abc password=def", {}, {}, options)  # "password=*** password=***"
Conditions

List of logical operators that can be used in conditions (by order of priority, from first used to last):

Operator Min WeeChat Description Examples

&&

Logical "and"

>> 25 && 77
== 1

>> 25 && 0
== 0

||

Logical "or"

>> 25 || 0
== 1

>> 0 || 0
== 0

List of comparison operators that can be used in conditions (by order of priority, from first used to last):

Operator Min WeeChat Description Examples

=~

Is matching POSIX extended regex (optional flags are allowed, see function string_regcomp)

>> abc def =~ ab.*ef
== 1

>> abc def =~ y.*z
== 0

!~

Is NOT matching POSIX extended regex (optional flags are allowed, see function string_regcomp)

>> abc def !~ ab.*ef
== 0

>> abc def !~ y.*z
== 1

==*

2.9

Is matching mask where "*" is allowed, case sensitive (see function string_match)

>> abc def ==* a*f
== 1

>> abc def ==* y*z
== 0

!!*

2.9

Is NOT wildcard mask where "*" is allowed, case sensitive (see function string_match)

>> abc def !!* a*f
== 0

>> abc def !!* y*z
== 1

=*

1.8

Is matching mask where "*" is allowed, case insensitive (see function string_match)

>> abc def =* A*F
== 1

>> abc def =* Y*Z
== 0

!*

1.8

Is NOT wildcard mask where "*" is allowed, case insensitive (see function string_match)

>> abc def !* A*F
== 0

>> abc def !* Y*Z
== 1

==-

2.9

Is included, case sensitive

>> abc def ==- bc
== 1

>> abc def ==- xyz
== 0

!!-

2.9

Is NOT included, case sensitive

>> abc def !!- bc
== 0

>> abc def !!- xyz
== 1

=-

2.9

Is included, case insensitive

>> abc def =- BC
== 1

>> abc def =- XYZ
== 0

!-

2.9

Is NOT included, case insensitive

>> abc def !- BC
== 0

>> abc def !- XYZ
== 1

==

Equal

>> test == test
== 1

>> test == string
== 0

!=

Not equal

>> test != test
== 0

>> test != string
== 1

<=

Less or equal

>> abc <= defghi
== 1

>> abc <= abc
== 1

>> defghi <= abc
== 0

>> 15 <= 2
== 0

<

Less

>> abc < defghi
== 1

>> abc < abc
== 0

>> defghi < abc
== 0

>> 15 < 2
== 0

>=

Greater or equal

>> defghi >= abc
== 1

>> abc >= abc
== 1

>> abc >= defghi
== 0

>> 15 >= 2
== 1

>

Greater

>> defghi > abc
== 1

>> abc > abc
== 0

>> abc > defghi
== 0

>> 15 > 2
== 1

The comparison is made using floating point numbers if the two expressions are valid numbers, with one of the following formats:

  • integer (examples: 5, -7)

  • floating point number (examples: 5.2, -7.5, 2.83e-2) (WeeChat ≥ 2.0)

  • hexadecimal number (examples: 0xA3, -0xA3) (WeeChat ≥ 2.0)

To force a string comparison, you can add double quotes around each expression, for example:

  • 50 > 100 returns 0 (number comparison)

  • "50" > "100" returns 1 (string comparison)

Variables

List of variables expanded in expression (by order of priority, from first expanded to last):

Format Min WeeChat Description Examples

${raw_hl:xxx}

4.2.0

Raw string (not evaluated), with syntax highlighting (using colors).

>> ${raw_hl:${cut:1,,${rev:hello}}}
== ${cut:1,,${rev:hello}} (with colors)

${raw:xxx}

3.1

Raw string (not evaluated).

>> ${raw:${info:version}}
== ${info:version}

${hl:xxx}

4.2.0

String with syntax highlighting (using colors).

>> ${hl:${file.section.option}}
== test ${variable} (with colors)

${name}

3.4

User variable (defined with ${define:name,value}).

>> ${name}
== value

${name}

Variable name from hashtable extra_vars.

>> ${name}
== value

${weechat_xxx_dir}

3.2

A WeeChat directory: ${weechat_config_dir}, ${weechat_data_dir}, ${weechat_cache_dir} or ${weechat_runtime_dir}.

>> ${weechat_config_dir}
== /home/user/.config/weechat

>> ${weechat_data_dir}
== /home/user/.local/share/weechat

>> ${weechat_cache_dir}
== /home/user/.cache/weechat

>> ${weechat_runtime_dir}
== /run/user/1000/weechat

${eval:xxx}

1.3

String to evaluate.

>> ${eval:${date:${weechat.look.buffer_time_format}}}
== 19:02:45 (1)

(1) With colors if there are color codes in the option weechat.look.buffer_time_format

${eval_cond:xxx}

3.1

String to evaluate as condition.

>> ${eval_cond:${window.win_width} > 100}
== 1

${esc:xxx}
${\xxx}

1.0

String with escaped chars.

>> ${esc:prefix\tmessage}
== prefix<TAB>message

>> ${\ua9}
== ©

${chars:range}

3.8

String with a range of chars, where range is one of:
- digit (0123456789)
- xdigit (0123456789abcdefABCDEF)
- lower (all lower case letters)
- upper (all upper case letters)
- alpha (all letters)
- alnum (all letters and digits)
- a range of chars with format c1-c2 (c1 code point must be lower or equal to c2)

>> ${chars:digit}
== 0123456789

>> ${chars:xdigit}
== 0123456789abcdefABCDEF

>> ${chars:lower}
== abcdefghijklmnopqrstuvwxyz

>> ${chars:J-V}
== JKLMNOPQRSTUV

>> ${chars:←-↓}
== ←↑→↓

${lower:string}

3.6

String converted to lower case.

>> ${lower:TEST}
== test

${upper:string}

3.6

String converted to upper case.

>> ${upper:test}
== TEST

${hide:x,string}

1.1

String with hidden chars (all chars in string replaced x).

>> ${hide:*,password}
== ********

${cut:max,suffix,string}
${cut:+max,suffix,string}

1.8

String with max chars, and optional suffix if string is cut.
With the format +max, the suffix is counted in max length.

>> ${cut:4,…,this is a test}
== this…

>> ${cut:+4,…,this is a test}
== t…

>> ${cut:2,>>,こんにちは世界}
== こん>>

${cutscr:max,suffix,string}
${cutscr:+max,suffix,string}

1.8

String with max chars displayed on screen, and optional suffix if string is cut.
With the format +max, the suffix is counted in max length.

>> ${cutscr:4,…,this is a test}
== this…

>> ${cutscr:+4,…,this is a test}
== thi…

>> ${cutscr:2,>>,こんにちは世界}
== こ>>

${rev:xxx}

2.2

Reversed string (color codes are reversed, so the string should not contain color codes).

>> ${rev:Hello, world!}
== !dlrow ,olleH

>> ${rev:Hello, ${color:red}world!}
== !dlrow30F ,olleH (1)

(1) No color, the color code is reversed

${revscr:xxx}

2.7

Reversed string for screen, color codes are not reversed.

>> ${revscr:Hello, world!}
== !dlrow ,olleH

>> ${revscr:Hello, ${color:red}world!}
== !dlrow ,olleH (1)

(1) ,olleH in red

${repeat:count,string}

2.3

Repeated string.

>> ${repeat:5,-}
== -----

${length:xxx}

2.7

Length of string (number of UTF-8 chars), color codes are ignored.

>> ${length:test}
== 4

>> ${length:こんにちは世界}
== 7

${lengthscr:xxx}

2.7

Length of string displayed on screen, color codes are ignored.

>> ${lengthscr:test}
== 4

>> ${lengthscr:こんにちは世界}
== 14

${split:number,seps,flags,xxx}

3.3

Split string, and return, according to number:
- count: the number of items after split
- random: a random item
- integer ≥ 1: the item by index (1 = first item)
- integer ≤ -1: the item by index from the end (-1 = last item, -2 = penultimate item, etc.),
seps is a list of chars that are used as separators (if empty, a comma is used),
flags is a list of flags separated by +:
- strip_left: strip separators on the left (beginning of string)
- strip_right: strip separators on the right (end of string)
- collapse_seps: collapse multiple consecutive separators into a single one
- keep_eol: keep end of line for each value
- strip_items=xyz: strip chars x, y and z from beginning/end of items
- max_items=N: return max N items

>> ${split:1,,,abc,def,ghi}
== abc

>> ${split:-1,,,abc,def,ghi}
== ghi

>> ${split:count,,,abc,def,ghi}
== 3

>> ${split:random,,,abc,def,ghi}
== def

>> ${split:3,,collapse_seps,abc,,,def,,,ghi}
== ghi

>> ${split:3,,strip_items=-_,_-abc-_,_-def-_,_-ghi-_}
== ghi

>> ${split:2, ,,this is a test}
== is

>> ${split:2, ,strip_left+strip_right, this is a test }
== is

>> ${split:2, ,keep_eol,this is a test}
== is a test

${split_shell:number,xxx}

3.3

Split shell arguments, and return, according to number:
- count: the number of arguments after split
- random: a random argument
- integer ≥ 1: the argument by index (1 = first argument)
- integer ≤ -1: the argument by index from the end (-1 = last argument, -2 = penultimate argument, etc.)

>> ${split_shell:1,"first arg" arg2}
== first arg

>> ${split_shell:-1,"first arg" arg2}
== arg2

>> ${split_shell:count,"first arg" arg2}
== 2

>> ${split_shell:random,"first arg" arg2}
== arg2

${re:xxx}

1.1

Regex data:
0 = whole string matching,
1 to 99 = group captured,
+ = last group captured,
# = index of last group captured (WeeChat ≥ 1.8),
repl_index = index of replacement being done (starts to 1) (WeeChat ≥ 3.3).

>> ${re:0}
== test1 test2

>> ${re:1}
== test1

>> ${re:2}
== test2

>> ${re:+}
== test2

>> ${re:#}
== 2

>> ${re:repl_index}
== 1

${color:name}

0.4.2

WeeChat color code (the name of color has optional attributes), see function color for supported formats.

>> ${color:red}red text
== red text (1)

>> ${color:*214}bold orange text
== bold orange text (2)

(1) In red
(2) In bold orange

${modifier:name,data,string}

2.7

Result of a modifier, see function hook_modifier_exec.

>> ${modifier:eval_path_home,,~}
== /home/user

>> ${modifier:eval_path_home,directory=config,%h/irc.conf}
== /home/user/.config/weechat/irc.conf

${info:name}
${info:name,arguments}

0.4.3

Info from WeeChat or a plugin, see function info_get.

>> ${info:version}
== 1.0

>> ${info:nick_color_name,foo}
== lightblue

${base_encode:base,xxx}

2.9

String encoded in base 16, 32 or 64.

>> ${base_encode:16,test string}
== 7465737420737472696E67

>> ${base_encode:32,test string}
== ORSXG5BAON2HE2LOM4======

>> ${base_encode:64,test string}
== dGVzdCBzdHJpbmc=

${base_decode:base,xxx}

2.9

String decoded from base 16, 32 or 64.

>> ${base_decode:16,7465737420737472696E67}
== test string

>> ${base_decode:32,ORSXG5BAON2HE2LOM4======}
== test string

>> ${base_decode:64,dGVzdCBzdHJpbmc=}
== test string

${date}
${date:xxx}

1.3

Current date/time, with custom format (see man strftime), default format is %F %T.

>> ${date}
== 2015-06-30 19:02:45

>> ${date:%H:%M:%S}
== 19:02:45

${env:NAME}

1.2

Value of the environment variable NAME.

>> ${env:HOME}
== /home/user

${if:condition}
${if:condition?true} ${if:condition?true:false}

1.8

Ternary operator with a condition, a value if the condition is true (optional) and another value if the condition is false (optional). If values are not given, "1" or "0" are returned, according to the result of the condition.

>> ${if:${info:term_width}>80?big:small}
== big

${calc:xxx}

2.7

Result of expression, where parentheses and the following operators are supported:
+: addition
-: subtraction
*: multiplication
/: division
//: result of division without fractional part
%: remainder of division
**: power.

>> ${calc:5+2*3}
== 11

>> ${calc:(5+2)*3}
== 21

>> ${calc:10/4}
== 2.5

>> ${calc:10//4}
== 2

>> ${calc:9.2%3}
== 0.2

>> ${calc:2**16}
== 65536

${random:min,max}

3.3

Random integer number in the range from min to max (inclusive).

>> ${random:0,10}
== 3

${translate:xxx}

3.2

Translated string (depends on the language used by WeeChat to display messages).

>> ${translate:Plugin}
== Extension (1)

(1) Example in French

${define:name,value}

3.4

Define a variable name set to value, which can then be used in the same evaluated expression with ${name}.

>> ${define:len,${calc:5+3}}${len}x${len}
== 8x8

${sec.data.name}

Value of the secured data name.

>> ${sec.data.libera_pass}
== my_password

${file.section.option}

Value of the option.

>> ${weechat.look.buffer_time_format}
== %H:%M:%S

${name}

Value of local variable name in buffer.

>> ${nick}
== FlashCode

${pointer}

Variable pointer from hashtable pointers.

>> ${buffer}
== 0x1234abcd

${hdata.var1.var2...}
${hdata[list].var1.var2...}

Hdata value (pointers window and buffer are set by default with current window/buffer), list can be a list name (example: "gui_buffers"), a pointer (example: "0x1234abcd") or a pointer name (example: "my_pointer").
When var1 is a hashtable, methods keys(), values(), keys_sorted(), keys_values() and keys_values_sorted() can be called.

>> ${buffer[gui_buffers].full_name}
== core.weechat

>> ${buffer[my_buffer_pointer].full_name}
== core.weechat

>> ${window.buffer.number}
== 1

>> ${buffer.local_variables.keys_values()}
== plugin:core,name:weechat

>> ${buffer.local_variables.plugin}
== core

string_dyn_alloc

WeeChat ≥ 1.8.

Allocate a dynamic string, with a variable length.
Internally, a structure is allocated with the string pointer, the allocated size and current length of string.

Only the pointer to string pointer (**string) is used in all the string_dyn_* functions.

Prototipo:

char **weechat_string_dyn_alloc (int size_alloc);

Argomenti:

  • size_alloc: the initial allocated size (must be greater than zero)

Valore restituito:

  • pointer to the dynamic string

Esempio in C:

char **string = weechat_string_dyn_alloc (256);
Questa funzione non è disponibile nelle API per lo scripting.

string_dyn_copy

WeeChat ≥ 1.8.

Copy a string in a dynamic string.

The pointer *string can change if the string is reallocated (if there is not enough space to copy the string).

Prototipo:

int weechat_string_dyn_copy (char **string, const char *new_string);

Argomenti:

  • string: pointer to dynamic string

  • new_string: the string to copy

Valore restituito:

  • 1 if OK, 0 if error

Esempio in C:

char **string = weechat_string_dyn_alloc (256);
if (weechat_string_dyn_copy (string, "test"))
{
    /* OK */
}
else
{
    /* error */
}
Questa funzione non è disponibile nelle API per lo scripting.

string_dyn_concat

WeeChat ≥ 1.8, updated in 3.0.

Concatenate a string to a dynamic string.

The pointer *string can change if the string is reallocated (if there is not enough space to concatenate the string).

Prototipo:

int weechat_string_dyn_concat (char **string, const char *add, int bytes);

Argomenti:

  • string: pointer to dynamic string

  • add: the string to add

  • bytes: max number of bytes in add to concatenate, must be lower or equal to length of add (-1 = automatic: concatenate whole string add) (WeeChat ≥ 3.0)

Valore restituito:

  • 1 if OK, 0 if error

Esempio in C:

char **string = weechat_string_dyn_alloc (256);
if (weechat_string_dyn_copy (string, "test"))
{
    if (weechat_string_dyn_concat (string, "abc", -1))
    {
        /* ... */
    }
}
Questa funzione non è disponibile nelle API per lo scripting.

string_dyn_free

WeeChat ≥ 1.8.

Free a dynamic string.

Prototipo:

char *weechat_string_dyn_free (char **string, int free_string);

Argomenti:

  • string: pointer to dynamic string

  • free_string: free the string itself; if 0, the content of *string remains valid after the call to this function

Valore restituito:

  • string pointer if free_string is 0, otherwise NULL

Esempio in C:

char **string = weechat_string_dyn_alloc (256);
if (weechat_string_dyn_concat (string, "test"))
{
    /* OK */
}
else
{
    /* error */
}
/* ... */
weechat_string_dyn_free (string, 1);
Questa funzione non è disponibile nelle API per lo scripting.

string_concat

WeeChat ≥ 4.2.0.

Concatenate multiple strings using a separator.

Prototipo:

const char *weechat_string_concat (const char *separator, ...);

Argomenti:

  • separator: the separator string which is inserted between concatenated strings (can be NULL or empty string)

Last argument MUST always be NULL.
A macro called WEECHAT_STR_CONCAT can be used, where the final NULL value is not needed (usage of this macro is recommended).

Valore restituito:

  • concatenated string

Esempio in C:

const char *result = weechat_string_concat (" / ", "abc", "def", "ghi", NULL);  /* result == "abc / def / ghi" */

/* with macro */
const char *result = WEECHAT_STR_CONCAT(" / ", "abc", "def", "ghi");  /* result == "abc / def / ghi" */
Questa funzione non è disponibile nelle API per lo scripting.

3.4. UTF-8

Alcune funzioni stringa UTF-8.

utf8_has_8bits

Verifica che una stringa abbia caratteri a 8-bit.

Prototipo:

int weechat_utf8_has_8bits (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • 1 se la stringa ha caratteri a 8-bit, 0 se solo a 7-bit

Esempio in C:

if (weechat_utf8_has_8bits (string))
{
    /* ... */
}
Questa funzione non è disponibile nelle API per lo scripting.

utf8_is_valid

Updated in 1.4.

Verifica che una stringa sia valida in UTF-8.

Prototipo:

int weechat_utf8_is_valid (const char *string, int length, char **error);

Argomenti:

  • string: stringa

  • length: max number of UTF-8 chars to check; if ≤ 0, the whole string is checked (WeeChat ≥ 1.4)

  • error: se non NULL, *error è impostato con il puntatore al primo carattere UTF-8 non valido nella stringa, se esiste

Valore restituito:

  • 1 se la stringa UTF-8 è valida, altrimenti 0

Esempio in C:

char *error;
if (weechat_utf8_is_valid (string, -1, &error))
{
    /* ... */
}
else
{
    /* "error" punta al primo carattere non valido */
}
Questa funzione non è disponibile nelle API per lo scripting.

utf8_normalize

Normalizza le stringhe UTF-8: rimuove i caratteri non UTF-8 e li sostituisce con un carattere.

Prototipo:

void weechat_utf8_normalize (char *string, char replacement);

Argomenti:

  • string: stringa

  • replacement: carattere sotitutivo per i caratteri non validi

Esempio in C:

weechat_utf8_normalize (string, '?');
Questa funzione non è disponibile nelle API per lo scripting.

utf8_prev_char

Updated in 1.3.

Restituisce il puntatore al carattere UTF-8 precedente in una stringa.

Prototipo:

const char *weechat_utf8_prev_char (const char *string_start,
                                    const char *string);

Argomenti:

  • string_start: inizio della stringa (la funzione non restituirà un carattere prima di questo puntatore)

  • string: puntatore alla stringa (deve essere ≥ string_start)

Valore restituito:

  • puntatore al precedente carattere UTF-8, NULL se non trovata (raggiunta l’inizio della stringa) (WeeChat ≥ 1.3: pointer returned is a const char * instead of char *)

Esempio in C:

const char *prev_char = weechat_utf8_prev_char (string, ptr_in_string);
Questa funzione non è disponibile nelle API per lo scripting.

utf8_next_char

Updated in 1.3.

Restituisce il puntatore al successivo carattere UTF-8 in una stringa.

Prototipo:

const char *weechat_utf8_next_char (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • puntatore al carattere UTF-8 successivo, NULL se non trovato (raggiunta la fine della stringa) (WeeChat ≥ 1.3: pointer returned is a const char * instead of char *)

Esempio in C:

const char *next_char = weechat_utf8_next_char (string);
Questa funzione non è disponibile nelle API per lo scripting.

utf8_char_int

Restituisce un carattere UTF-8 come intero.

Prototipo:

int weechat_utf8_char_int (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • carattere UTF-8 come intero

Esempio in C:

int char_int = weechat_utf8_char_int ("être");  /* "ê" come intero */
Questa funzione non è disponibile nelle API per lo scripting.

utf8_char_size

Restituisce la dimensione di un carattere UTF-8 (in byte).

Prototipo:

int weechat_utf8_char_size (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • dimensione carattere UTF-8 (in byte)

Esempio in C:

int char_size = weechat_utf8_char_size ("être");  /* == 2 */
Questa funzione non è disponibile nelle API per lo scripting.

utf8_strlen

Restituisce la lunghezza della stringa UTF-8 (nei caratteri UTF-8).

Prototipo:

int weechat_utf8_strlen (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • lunghezza della stringa UTF-8 (numero di caratteri UTF-8)

Esempio in C:

int length = weechat_utf8_strlen ("chêne");  /* == 5 */
Questa funzione non è disponibile nelle API per lo scripting.

utf8_strnlen

Restituisce la lunghezza della stringa UTF-8 (in caratteri UTF-8), per un massimo di bytes nella stringa.

Prototipo:

int weechat_utf8_strnlen (const char *string, int bytes);

Argomenti:

  • string: stringa

  • bytes: massimo di byte

Valore restituito:

  • lunghezza della stringa UTF-8 (numero di caratteri UTF-8)

Esempio in C:

int length = weechat_utf8_strnlen ("chêne", 4);  /* == 3 */
Questa funzione non è disponibile nelle API per lo scripting.

utf8_strlen_screen

Restituisce il numero di caratteri necessari per visualizzare la stringa UTF-8 su schermo.

Prototipo:

int weechat_utf8_strlen_screen (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • numero di caratteri necessari per visualizzare la stringa UTF-8 su schermo

Esempio in C:

int length_on_screen = weechat_utf8_strlen_screen ("é");  /* == 1 */
Questa funzione non è disponibile nelle API per lo scripting.

utf8_char_size_screen

Updated in 3.8.

Restituisce il numero di caratteri necessari per visualizzare il carattere UTF-8 sullo schermo.

Prototipo:

int weechat_utf8_char_size_screen (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • numero di caratteri necessario per visualizzare il carattere UTF-8 su schermo:

    • -1: non printable char

    • ≥ 0: printable char

The result is the return value of function wcwidth (see man wcwidth), with exception for the following chars, that have a specific behavior in WeeChat:

  • U+0009 (Tabulation): value of option weechat.look.tab_width 

  • U+0001 (1) to U+001F (31), except U+0009 (Tabulation): 1

  • U+00AD (173, soft hyphen): -1

  • U+200B (8203, zero width space): -1

Esempio in C:

int length_on_screen = weechat_utf8_char_size_screen ("é");  /* == 1 */
Questa funzione non è disponibile nelle API per lo scripting.

utf8_add_offset

Updated in 1.3.

Si sposta in avanti di N caratteri in una stringa UTF-8.

Prototipo:

const char *weechat_utf8_add_offset (const char *string, int offset);

Argomenti:

  • string: stringa

  • offset: numero di caratteri

Valore restituito:

  • puntatore alla stringa, N caratteri dopo (NULL se non raggiungibile) (WeeChat ≥ 1.3: pointer returned is a const char * instead of char *)

Esempio in C:

const char *str = "chêne";
const char *str2 = weechat_utf8_add_offset (str, 3);  /* points to "ne" */
Questa funzione non è disponibile nelle API per lo scripting.

utf8_real_pos

Restituisce la posizione reale nella stringa UTF-8.

Prototipo:

int weechat_utf8_real_pos (const char *string, int pos);

Argomenti:

  • string: stringa

  • pos: posizione (numero di caratteri)

Valore restituito:

  • pozisione reale (in byte)

Esempio in C:

int pos = weechat_utf8_real_pos ("chêne", 3);  /* == 4 */
Questa funzione non è disponibile nelle API per lo scripting.

utf8_pos

Restituisce la posizione nella stringa UTF-8.

Prototipo:

int weechat_utf8_pos (const char *string, int real_pos);

Argomenti:

  • string: stringa

  • real_pos: posizione (byte)

Valore restituito:

  • posizione (numero di caratteri)

Esempio in C:

int pos = weechat_utf8_pos ("chêne", 4);  /* == 3 */
Questa funzione non è disponibile nelle API per lo scripting.

utf8_strndup

Restituisce la stringa duplicata, di lunghezza massima length.

Prototipo:

char *weechat_utf8_strndup (const char *string, int length);

Argomenti:

  • string: stringa

  • length: caratteri massimi da duplicare

Valore restituito:

  • stringa duplicata (deve essere liberata chiamando "free" dopo l’uso)

Esempio in C:

char *string = weechat_utf8_strndup ("chêne", 3);  /* restituisce "chê" */
/* ... */
free (string);
Questa funzione non è disponibile nelle API per lo scripting.

utf8_strncpy

WeeChat ≥ 3.8.

Copy length chars max in another string and add null byte at the end.

Prototipo:

void weechat_utf8_strncpy (char *dest, const char *string, int length);

Argomenti:

  • dest: destination string (must be long enough)

  • string: stringa

  • length: max chars to copy

Esempio in C:

char dest[256];

weechat_utf8_strncpy (dest, "chêne", 3);  /* copies "chê" to dest */
Questa funzione non è disponibile nelle API per lo scripting.

3.5. Cryptography

Some cryptographic functions.

crypto_hash

WeeChat ≥ 2.8.

Compute hash of data.

Prototipo:

int weechat_crypto_hash (const void *data, int data_size, const char *hash_algo,
                         void *hash, int *hash_size);

Argomenti:

  • data: the data to hash

  • data_size: number of bytes to hash in data

  • hash_algo: the hash algorithm, see table below

  • hash: pointer to the hash variable, which is used to store the resulting hash (the buffer must be large enough, according to the algorithm, see table below)

  • hash_size: pointer to a variable used to store the length of the hash computed (in bytes) (can be NULL)

Supported hash algorithms:

Value Algorithm Hash size Notes

crc32

CRC32

4 bytes (32 bits)

Not a hash algorithm in the cryptographic sense.

md5

MD5

16 bytes (128 bits)

Weak, not recommended for cryptography usage.

sha1

SHA-1

20 bytes (160 bits)

Weak, not recommended for cryptography usage.

sha224

SHA-224

28 bytes (224 bits)

sha256

SHA-256

32 bytes (256 bits)

sha384

SHA-384

48 bytes (384 bits)

sha512

SHA-512

64 bytes (512 bits)

sha512-224

SHA-512/224

28 bytes (224 bits)

Algorithm available with libgcrypt ≥ 1.9.4.

sha512-256

SHA-512/256

32 bytes (256 bits)

Algorithm available with libgcrypt ≥ 1.9.4.

sha3-224

SHA3-224

28 bytes (224 bits)

Algorithm available with libgcrypt ≥ 1.7.0.

sha3-256

SHA3-256

32 bytes (256 bits)

Algorithm available with libgcrypt ≥ 1.7.0.

sha3-384

SHA3-384

48 bytes (384 bits)

Algorithm available with libgcrypt ≥ 1.7.0.

sha3-512

SHA3-512

64 bytes (512 bits)

Algorithm available with libgcrypt ≥ 1.7.0.

blake2b-160

BLAKE2B-160

20 bytes (160 bits)

Algorithm available with libgcrypt ≥ 1.8.0.

blake2b-256

BLAKE2B-256

32 bytes (256 bits)

Algorithm available with libgcrypt ≥ 1.8.0.

blake2b-384

BLAKE2B-384

48 bytes (384 bits)

Algorithm available with libgcrypt ≥ 1.8.0.

blake2b-512

BLAKE2B-512

64 bytes (512 bits)

Algorithm available with libgcrypt ≥ 1.8.0.

blake2s-128

BLAKE2S-128

16 bytes (128 bits)

Algorithm available with libgcrypt ≥ 1.8.0.

blake2s-160

BLAKE2S-160

20 bytes (160 bits)

Algorithm available with libgcrypt ≥ 1.8.0.

blake2s-224

BLAKE2S-224

28 bytes (224 bits)

Algorithm available with libgcrypt ≥ 1.8.0.

blake2s-256

BLAKE2S-256

32 bytes (256 bits)

Algorithm available with libgcrypt ≥ 1.8.0.

Valore restituito:

  • 1 if OK, 0 if error

Esempio in C:

const char *data = "abcdefghijklmnopqrstuvwxyz";
char hash[256 / 8];
int rc, hash_size;
rc = weechat_crypto_hash (data, strlen (data), "sha256", hash, &hash_size);
/* rc == 1, hash_size == 32 and hash is a buffer with:
   71 c4 80 df 93 d6 ae 2f 1e fa d1 44 7c 66 c9 52 5e 31 62 18 cf 51 fc 8d 9e d8 32 f2 da f1 8b 73 */
Questa funzione non è disponibile nelle API per lo scripting.

crypto_hash_file

WeeChat ≥ 3.7.

Compute hash of a file.

Prototipo:

int weechat_crypto_hash_file (const char *filename, const char *hash_algo,
                              void *hash, int *hash_size);

Argomenti:

  • filename: percorso e nome file

  • hash_algo: the hash algorithm, see table in function crypto_hash

  • hash: pointer to the hash variable, which is used to store the resulting hash (the buffer must be large enough, according to the algorithm, see table in function crypto_hash)

  • hash_size: pointer to a variable used to store the length of the hash computed (in bytes) (can be NULL)

Valore restituito:

  • 1 if OK, 0 if error

Esempio in C:

char hash[256 / 8];
int rc, hash_size;
rc = weechat_crypto_hash_file ("/path/to/file", "sha256", hash, &hash_size);
/* rc == 1, hash_size == 32 and hash is a buffer with:
   71 c4 80 df 93 d6 ae 2f 1e fa d1 44 7c 66 c9 52 5e 31 62 18 cf 51 fc 8d 9e d8 32 f2 da f1 8b 73 */
Questa funzione non è disponibile nelle API per lo scripting.

crypto_hash_pbkdf2

WeeChat ≥ 2.8.

Compute PKCS#5 Passphrase Based Key Derivation Function number 2 (PBKDF2) hash of data.

Prototipo:

int weechat_crypto_hash_pbkdf2 (const void *data, int data_size,
                                const char *hash_algo,
                                const void *salt, int salt_size,
                                int iterations,
                                void *hash, int *hash_size);

Argomenti:

  • data: the data to hash

  • data_size: number of bytes to hash in data

  • hash_algo: hash algorithm used by the key derivation function, see table in function crypto_hash

  • salt: the salt

  • salt_size: number of bytes in salt

  • iterations: number of iterations

  • hash: pointer to the hash variable, which is used to store the resulting hash (the buffer must be large enough, according to the algorithm, see table in function crypto_hash)

  • hash_size: pointer to a variable used to store the size of the hash computed (in bytes) (can be NULL)

Valore restituito:

  • 1 if OK, 0 if error

Esempio in C:

const char *data = "abcdefghijklmnopqrstuvwxyz";
const char *salt = "12345678901234567890123456789012";  /* 32 bytes */
char hash[256 / 8];
int rc, hash_size;
rc = weechat_crypto_hash_pbkdf2 (data, strlen (data), "sha256", salt, strlen (salt), 100000,
                                 hash, &hash_size);
/* rc == 1, hash_size == 32 and hash is a buffer with:
   99 b3 5e 42 53 d1 a7 a8 49 c1 dc 2c e2 53 c2 b6 6d a1 8b dc 6e 78 a7 06 e0 ef 34 db 0a 7a a2 bb */
Questa funzione non è disponibile nelle API per lo scripting.

3.6. Cartelle

Alcune funzioni legate alle cartelle.

crypto_hmac

WeeChat ≥ 3.2.

Compute keyed-hash message authentication code (HMAC).

Prototipo:

int weechat_crypto_hmac (const void *key, int key_size, const void *message, int message_size,
                         int hash_algo, void *hash, int *hash_size);

Argomenti:

  • key: the key

  • key_size: number of bytes in key

  • message: the message

  • message_size: number of bytes in message

  • hash_algo: the hash algorithm, see table in function crypto_hash

  • hash: pointer to the hash variable, which is used to store the resulting hash (the buffer must be large enough, according to the algorithm, see table in function crypto_hash)

  • hash_size: pointer to a variable used to store the size of the hash computed (in bytes) (can be NULL)

Valore restituito:

  • 1 if OK, 0 if error

Esempio in C:

const char *key = "the key";
const char *message = "the message";
char hash[256 / 8];
int rc, hash_size;
rc = weechat_crypto_hmac (key, strlen (key), message, strlen (message), "sha256", hash, &hash_size);
/* rc == 1, hash_size == 32 and hash is a buffer with:
   47 36 67 02 fc bc b1 97 a4 25 e6 7a b9 52 92 bd 15 9a 66 91 9c fb 94 b0 b4 9a 39 cb c0 24 2d 7b */
Questa funzione non è disponibile nelle API per lo scripting.

mkdir_home

Updated in 3.2.

Crea una cartella nella home di WeeChat.

Prototipo:

int weechat_mkdir_home (char *directory, int mode);

Argomenti:

  • directory: name of directory to create; it can start with one of these strings to force a specific WeeChat directory (WeeChat ≥ 3.2):

    • ${weechat_config_dir}

    • ${weechat_data_dir} (default)

    • ${weechat_cache_dir}

    • ${weechat_runtime_dir}

  • mode: modalità per la cartella

Valore restituito:

  • 1 se la cartella è stata creata con successo, 0 in caso di errore

Esempio in C:

if (!weechat_mkdir_home ("${weechat_cache_dir}/temp", 0755))
{
    /* errore */
}

Script (Python):

# prototipo
def mkdir_home(directory: str, mode: int) -> int: ...

# esempio
weechat.mkdir_home("${weechat_cache_dir}/temp", 0755)

mkdir

Crea una cartella.

Prototipo:

int weechat_mkdir (char *directory, int mode);

Argomenti:

  • directory: nome della cartella da creare

  • mode: modalità per la cartella

Valore restituito:

  • 1 se la cartella è stata creata con successo, 0 in caso di errore

Esempio in C:

if (!weechat_mkdir ("/tmp/mydir", 0755))
{
    /* errore */
}

Script (Python):

# prototipo
def mkdir(directory: str, mode: int) -> int: ...

# esempio
weechat.mkdir("/tmp/mydir", 0755)

mkdir_parents

Crea una cartella e le cartelle genitore se necessario.

Prototipo:

int weechat_mkdir_parents (char *directory, int mode);

Argomenti:

  • directory: nome della cartella da creare

  • mode: modalità per la cartella

Valore restituito:

  • 1 se la cartella è stata creata con successo, 0 in caso di errore

Esempio in C:

if (!weechat_mkdir_parents ("/tmp/my/dir", 0755))
{
    /* errore */
}

Script (Python):

# prototipo
def mkdir_parents(directory: str, mode: int) -> int: ...

# esempio
weechat.mkdir_parents("/tmp/my/dir", 0755)

exec_on_files

Updated in 1.5, 2.0.

Cerca i file in una cartella ed esegue una callback su ogni file.

Prototipo:

void weechat_exec_on_files (const char *directory,
                            int recurse_subdirs,
                            int hidden_files,
                            void (*callback)(void *data,
                                             const char *filename),
                            void *callback_data);

Argomenti:

  • directory: cartella in cui cercare i file

  • recurse_subdirs: 1 to recurse into sub-directories (WeeChat ≥ 2.0)

  • hidden_files: 1 per includere i file nascosti, altrimenti 0

  • callback: funzione chiamata per ogni file trovato, argomenti:

    • void *data: puntatore

    • const char *filename: nome file trovato

  • callback_data: puntatore fornito alla callback quando chiamata da WeeChat

Esempio in C:

void callback (void *data, const char *filename)
{
    /* ... */
}
...
weechat_exec_on_files ("/tmp", 0, 0, &callback, NULL);
Questa funzione non è disponibile nelle API per lo scripting.

file_get_content

WeeChat ≥ 0.3.1.

Ottiene il contenuto del file di testo in una stringa.

Prototipo:

char *weechat_file_get_content (const char *filename);

Argomenti:

  • filename: percorso e nome file

Valore restituito:

  • contenuto del file come stringa (deve essere liberata chiamando "free dopo l’uso)

Esempio in C:

char *content;

content = weechat_file_get_content ("/tmp/test.txt");
/* ... */
free (content);
Questa funzione non è disponibile nelle API per lo scripting.

file_copy

WeeChat ≥ 3.3.

Copy a file to another location.

Prototipo:

int weechat_file_copy (const char *from, const char *to);

Argomenti:

  • from: source file

  • to: destination file

Valore restituito:

  • 1 if OK, 0 if error

Esempio in C:

if (weechat_file_copy ("/tmp/test.txt", "/path/to/test2.txt"))
{
    /* OK */
}
Questa funzione non è disponibile nelle API per lo scripting.

file_compress

WeeChat ≥ 3.7.

Compress a file with gzip or zstd.

Prototipo:

int weechat_file_compress (const char *from, const char *to,
                           const char *compressor, int compression_level);

Argomenti:

  • from: source file

  • to: destination file

  • compressor: the compressor to use, one of:

    • gzip: gzip compression

    • zstd: zstandard compression (available only if zstd was enabled when WeeChat was compiled)

  • compression_level: compression level, between 1 (fast, low compression) to 100 (slow, best compression)

Valore restituito:

  • 1 if OK, 0 if error

Esempio in C:

if (weechat_file_compress ("/tmp/test.txt", "/tmp/test.txt.zst", "zstd", 50))
{
    /* OK */
}
Questa funzione non è disponibile nelle API per lo scripting.

3.7. Utilità

Alcune funzioni utili.

util_timeval_cmp

Confronta due strutture "timeval".

Prototipo:

int weechat_util_timeval_cmp (struct timeval *tv1, struct timeval *tv2);

Argomenti:

  • tv1: prima struttura "timeval"

  • tv2: seconda struttura "timeval"

Valore restituito:

  • -1 se tv1 < tv2

  • zero se tv1 == tv2

  • +1 se tv1 > tv2

Esempio in C:

if (weechat_util_timeval_cmp (&tv1, &tv2) > 0)
{
    /* tv1 > tv2 */
}
Questa funzione non è disponibile nelle API per lo scripting.

util_timeval_diff

Updated in 1.1.

Return difference (in microseconds) between two "timeval" structures.

Prototipo:

long long weechat_util_timeval_diff (struct timeval *tv1, struct timeval *tv2);

Argomenti:

  • tv1: prima struttura "timeval"

  • tv2: seconda struttura "timeval"

Valore restituito:

  • difference in microseconds

With WeeChat ≤ 1.0, the returned value was in milliseconds.

Esempio in C:

long long diff = weechat_util_timeval_diff (&tv1, &tv2);
Questa funzione non è disponibile nelle API per lo scripting.

util_timeval_add

Updated in 1.1.

Add interval (in microseconds) to a timeval structure.

Prototipo:

void weechat_util_timeval_add (struct timeval *tv, long long interval);

Argomenti:

  • tv: struttura timeval

  • interval: interval (in microseconds)

With WeeChat ≤ 1.0, the interval was expressed in milliseconds.

Esempio in C:

weechat_util_timeval_add (&tv, 2000000);  /* aggiunge 2 secondi */
Questa funzione non è disponibile nelle API per lo scripting.

util_get_time_string

WeeChat ≥ 0.3.2, updated in 1.3.

Get date/time as a string built with "strftime" and the format defined in option weechat.look.time_format.

Prototipo:

const char *weechat_util_get_time_string (const time_t *date);

Argomenti:

  • date: puntatore alla data

Valore restituito:

  • pointer to a string with date/time

Esempio in C:

time_t date = time (NULL);
weechat_printf (NULL, "date: %s",
                weechat_util_get_time_string (&date));
Questa funzione non è disponibile nelle API per lo scripting.

util_strftimeval

WeeChat ≥ 4.2.0.

Format date and time like function strftime in C library, using struct timeval as input, and supporting extra specifiers for microseconds.

Prototype:

int weechat_util_strftimeval (char *string, int max, const char *format, struct timeval *tv);

Arguments:

  • string: buffer where the formatted string is stored

  • max: string size

  • format: format, the same as strftime function, with these extra specifiers:

    • %.N where N is between 1 and 6: zero-padded microseconds on N digits (for example %.3 for milliseconds)

    • %f: alias of %.6

Return value:

  • number of bytes put in string (value returned from strftime function)

C example:

char time[256];
struct timeval tv;
gettimeofday (&tv, NULL);
weechat_util_strftimeval (time, sizeof (time), "%FT%T.%f", &tv);
/* result: 2023-12-26T18:10:04.460509 */
Questa funzione non è disponibile nelle API per lo scripting.

util_parse_time

WeeChat ≥ 4.2.0.

Parse date/time with support of microseconds.

Prototype:

int util_parse_time (const char *datetime, struct timeval *tv);

Arguments:

  • date: date/time

  • tv: parsed date/time ("timeval" structure)

Return value:

  • 1 if OK, 0 if error

C example:

struct timeval tv;
weechat_util_parse_time ("2023-12-25T10:29:09.456789Z", &tv);  /* == 1 */
/* result: tv.tv_sec == 1703500149, tv.tv_usec = 456789 */
Questa funzione non è disponibile nelle API per lo scripting.

util_version_number

WeeChat ≥ 0.3.9.

Convert a string with WeeChat version to a number.

Prototipo:

int weechat_util_version_number (const char *version);

Argomenti:

  • version: WeeChat version as string (example: "0.3.9" or "0.3.9-dev")

Esempio in C:

version_number = weechat_util_version_number ("0.3.8");      /* == 0x00030800 */
version_number = weechat_util_version_number ("0.3.9-dev");  /* == 0x00030900 */
version_number = weechat_util_version_number ("0.3.9-rc1");  /* == 0x00030900 */
version_number = weechat_util_version_number ("0.3.9");      /* == 0x00030900 */
version_number = weechat_util_version_number ("1.0");        /* == 0x01000000 */
version_number = weechat_util_version_number ("4.0.0");      /* == 0x04000000 */
Questa funzione non è disponibile nelle API per lo scripting.

3.8. Elenchi ordinati

Funzioni lista ordinata.

list_new

Crea una nuova lista.

Prototipo:

struct t_weelist *weechat_list_new ();

Valore restituito:

  • puntatore alla nuova lista

Esempio in C:

struct t_weelist *list = weechat_list_new ();

Script (Python):

# prototipo
def list_new() -> str: ...

# esempio
list = weechat.list_new()

list_add

Aggiunge un elemento in una lista.

Prototipo:

struct t_weelist_item *weechat_list_add (struct t_weelist *weelist,
                                         const char *data,
                                         const char *where,
                                         void *user_data);

Argomenti:

  • weelist: puntatore alla lista

  • data: dati da inserire nella lista

  • where: posizione nella lista:

    • WEECHAT_LIST_POS_SORT: aggiunge alla lista, mantenendola ordinata

    • WEECHAT_LIST_POS_BEGINNING: aggiunge all’inizio della lista

    • WEECHAT_LIST_POS_END: aggiunge alla fine della lista

  • user_data: qualsiasi puntatore

Valore restituito:

  • puntatore al nuovo elemento

Esempio in C:

struct t_weelist_item *my_item =
    weechat_list_add (list, "my data", WEECHAT_LIST_POS_SORT, NULL);

Script (Python):

# prototipo
def list_add(list: str, data: str, where: str, user_data: str) -> str: ...

# esempio
item = weechat.list_add(list, "my data", weechat.WEECHAT_LIST_POS_SORT, "")

Cerca un elemento nella lista.

Prototipo:

struct t_weelist_item *weechat_list_search (struct t_weelist *weelist,
                                            const char *data);

Argomenti:

  • weelist: puntatore alla lista

  • data: dati da cercare nella lista

Valore restituito:

  • puntatore all’elemento trovato, NULL se non trovato

Esempio in C:

struct t_weelist_item *item = weechat_list_search (list, "my data");

Script (Python):

# prototipo
def list_search(list: str, data: str) -> str: ...

# esempio
item = weechat.list_search(list, "my data")

list_search_pos

WeeChat ≥ 0.3.4.

Cerca la posizione di un elemento nella lista.

Prototipo:

int weechat_list_search_pos (struct t_weelist *weelist,
                             const char *data);

Argomenti:

  • weelist: puntatore alla lista

  • data: dati da cercare nella lista

Valore restituito:

  • posizione dell’elemento trovato, -1 se non trovato

Esempio in C:

int pos_item = weechat_list_search_pos (list, "my data");

Script (Python):

# prototipo
def list_search_pos(list: str, data: str) -> int: ...

# esempio
pos_item = weechat.list_search_pos(list, "my data")

list_casesearch

Cerca un elemento nella lista, senza effettuare una ricerca esatta.

Prototipo:

struct t_weelist_item *weechat_list_casesearch (struct t_weelist *weelist,
                                                const char *data);

Argomenti:

  • weelist: puntatore alla lista

  • data: dati da cercare nella lista

Valore restituito:

  • puntatore all’elemento trovato, NULL se non trovato

Esempio in C:

struct t_weelist_item *item = weechat_list_casesearch (list, "my data");

Script (Python):

# prototipo
def list_casesearch(list: str, data: str) -> str: ...

# esempio
item = weechat.list_casesearch(list, "my data")

list_casesearch_pos

WeeChat ≥ 0.3.4.

Cerca la posizione di un elemento in una lista, ricerca normale.

Prototipo:

int weechat_list_casesearch_pos (struct t_weelist *weelist,
                                 const char *data);

Argomenti:

  • weelist: puntatore alla lista

  • data: dati da cercare nella lista

Valore restituito:

  • posizione dell’elemento trovato, -1 se non trovato

Esempio in C:

int pos_item = weechat_list_casesearch_pos (list, "my data");

Script (Python):

# prototipo
def list_casesearch_pos(list: str, data: str) -> int: ...

# esempio
pos_item = weechat.list_casesearch_pos(list, "my data")

list_get

Restituisce un elemento in una lista in base alla sua posizione.

Prototipo:

struct t_weelist_item *weechat_list_get (struct t_weelist *weelist,
                                         int position);

Argomenti:

  • weelist: puntatore alla lista

  • position: posizione nella lista (il primo elemento è 0)

Valore restituito:

  • puntatore all’elemento trovato, NULL se non trovato

Esempio in C:

struct t_weelist_item *item = weechat_list_get (list, 0);  /* primo elemento */

Script (Python):

# prototipo
def list_get(list: str, position: int) -> str: ...

# esempio
item = weechat.list_get(list, 0)

list_set

Imposta un nuovo valore per un elemento.

Prototipo:

void weechat_list_set (struct t_weelist_item *item, const char *value);

Argomenti:

  • item: puntatore all’elemento

  • value: nuovo valore per l’elemento

Esempio in C:

weechat_list_set (item, "nuovi dati");

Script (Python):

# prototipo
def list_set(item: str, value: str) -> int: ...

# esempio
weechat.list_set(item, "nuovi dati")

list_next

Restituisce l’elemento successivo nella lista.

Prototipo:

struct t_weelist_item *weechat_list_next (struct t_weelist_item *item);

Argomenti:

  • item: puntatore all’elemento

Valore restituito:

  • puntatore all’elemento successivo, NULL se il puntatore è l’ultimo oggetto nella lista

Esempio in C:

struct t_weelist_item *next_item = weechat_list_next (item);

Script (Python):

# prototipo
def list_next(item: str) -> str: ...

# esempio
item = weechat.list_next(item)

list_prev

Restituisce l’elemento precedente nella lista.

Prototipo:

struct t_weelist_item *weechat_list_prev (struct t_weelist_item *item);

Argomenti:

  • item: puntatore all’elemento

Valore restituito:

  • pointer to previous item, NULL if pointer was first item in list

Esempio in C:

struct t_weelist_item *prev_item = weechat_list_prev (item);

Script (Python):

# prototipo
def list_prev(item: str) -> str: ...

# esempio
item = weechat.list_prev(item)

list_string

Restituisce il valore stringa di un elemento.

Prototipo:

const char *weechat_list_string (struct t_weelist_item *item);

Argomenti:

  • item: puntatore all’elemento

Valore restituito:

  • valore stringa di un elemento

Esempio in C:

weechat_printf (NULL, "valore dell'elemento: %s", weechat_list_string (item));

Script (Python):

# prototipo
def list_string(item: str) -> str: ...

# esempio
weechat.prnt("", "valore dell'elemento: %s" % weechat.list_string(item))

list_user_data

WeeChat ≥ 2.6.

Return pointer to the user data of an item.

Prototipo:

void *weechat_list_user_data (struct t_weelist_item *item);

Argomenti:

  • item: puntatore all’elemento

Valore restituito:

  • pointer to the user data of item

Esempio in C:

weechat_printf (NULL, "user data of item: 0x%lx", weechat_list_user_data (item));
Questa funzione non è disponibile nelle API per lo scripting.

list_size

Restituisce la dimensione della lista (numero di elementi).

Prototipo:

char *weechat_list_size (struct t_weelist *weelist);

Argomenti:

  • weelist: puntatore alla lista

Valore restituito:

  • dimensione della lista (numero di elementi), 0 se la lista è vuota

Esempio in C:

weechat_printf (NULL, "dimensione della lista: %d", weechat_list_size (list));

Script (Python):

# prototipo
def list_size(list: str) -> int: ...

# esempio
weechat.prnt("", "dimensione della lista: %d" % weechat.list_size(list))

list_remove

Rimuove un elemento in una lista.

Prototipo:

void weechat_list_remove (struct t_weelist *weelist,
                          struct t_weelist_item *item);

Argomenti:

  • weelist: puntatore alla lista

  • item: puntatore all’elemento

Esempio in C:

weechat_list_remove (list, item);

Script (Python):

# prototipo
def list_remove(list: str, item: str) -> int: ...

# esempio
weechat.list_remove(list, item)

list_remove_all

Rimuove tutti gli elementi in una lista.

Prototipo:

void weechat_list_remove_all (struct t_weelist *weelist);

Argomenti:

  • weelist: puntatore alla lista

Esempio in C:

weechat_list_remove_all (list);

Script (Python):

# prototipo
def list_remove_all(list: str) -> int: ...

# esempio
weechat.list_remove_all(list)

list_free

Libera una lista.

Prototipo:

void weechat_list_free (struct t_weelist *weelist);

Argomenti:

  • weelist: puntatore alla lista

Esempio in C:

weechat_list_free (list);

Script (Python):

# prototipo
def list_free(list: str) -> int: ...

# esempio
weechat.list_free(list)

3.9. Array lists

Array list functions.

An array list is a list of pointers with a dynamic size and optional sort.

arraylist_new

WeeChat ≥ 1.8.

Create a new array list.

Prototipo:

struct t_arraylist *weechat_arraylist_new (int initial_size,
                                           int sorted,
                                           int allow_duplicates,
                                           int (*callback_cmp)(void *data,
                                                               struct t_arraylist *arraylist,
                                                               void *pointer1,
                                                               void *pointer2),
                                           void *callback_cmp_data,
                                           void (*callback_free)(void *data,
                                                                 struct t_arraylist *arraylist,
                                                                 void *pointer),
                                           void *callback_free_data);

Argomenti:

  • initial_size: initial size of the array list (not the number of items)

  • sorted: 1 to sort the array list, 0 for no sort

  • allow_duplicates: 1 to allow duplicate entries, 0 to prevent a same entry to be added again

  • callback_cmp: callback used to compare two items (optional), arguments and return value:

    • void *data: pointer

    • struct t_arraylist *arraylist: array list pointer

    • void *pointer1: pointer to first item

    • void *pointer2: pointer to second item

    • return value:

      • negative number if first item is less than second item

      • 0 if first item equals second item

      • positive number if first item is greater than second item

  • callback_cmp_data: pointer given to callback when it is called by WeeChat

  • callback_free: callback used to free an item (optional), arguments:

    • void *data: pointer

    • struct t_arraylist *arraylist: array list pointer

    • void *pointer: pointer to item

  • callback_free_data: pointer given to callback when it is called by WeeChat

Valore restituito:

  • pointer to new array list

Esempio in C:

int
cmp_cb (void *data, struct t_arraylist *arraylist,
        void *pointer1, void *pointer2)
{
    if (...)
        return -1;
    else if (...)
        return 1;
    else
        return 0;
}

struct t_arraylist *list = weechat_arraylist_new (32, 1, 1,
                                                  &cmp_cb, NULL, NULL, NULL);
Questa funzione non è disponibile nelle API per lo scripting.

arraylist_size

WeeChat ≥ 1.8.

Return size of array list (number of item pointers).

Prototipo:

int weechat_list_size (struct t_arraylist *arraylist);

Argomenti:

  • arraylist: array list pointer

Valore restituito:

  • size of array list (number of items), 0 if array list is empty

Esempio in C:

weechat_printf (NULL, "size of array list: %d", weechat_arraylist_size (arraylist));
Questa funzione non è disponibile nelle API per lo scripting.

arraylist_get

WeeChat ≥ 1.8.

Return an item pointer by position.

Prototipo:

void *weechat_arraylist_get (struct t_arraylist *arraylist, int index);

Argomenti:

  • arraylist: array list pointer

  • index: index in list (first pointer is 0)

Valore restituito:

  • pointer found, NULL if pointer was not found

Esempio in C:

void *pointer = weechat_arraylist_get (arraylist, 0);  /* first item */
Questa funzione non è disponibile nelle API per lo scripting.

WeeChat ≥ 1.8.

Search an item in an array list.

Prototipo:

void *weechat_arraylist_search (struct t_arraylist *arraylist, void *pointer,
                                int *index, int *index_insert);

Argomenti:

  • arraylist: array list pointer

  • pointer: pointer to the item to search in array list

  • index: pointer to integer that will be set to the index found, or -1 if not found (optional)

  • index_insert: pointer to integer that will be set with the index that must be used to insert the element in the arraylist (to keep arraylist sorted) (optional)

Valore restituito:

  • pointer to item found, NULL if item was not found

Esempio in C:

int index, index_insert;
void *item = weechat_arraylist_search (arraylist, pointer, &index, &index_insert);
Questa funzione non è disponibile nelle API per lo scripting.

arraylist_insert

WeeChat ≥ 1.8.

Insert an item in an array list.

Prototipo:

int weechat_arraylist_insert (struct t_arraylist *arraylist, int index, void *pointer);

Argomenti:

  • arraylist: array list pointer

  • index: position of the item in array list or -1 to add at the end (this argument is used only if the array list is not sorted, it is ignored if the array list is sorted)

  • pointer: pointer to the item to insert

Valore restituito:

  • index of new item (≥ 0), -1 if error.

Esempio in C:

int index = weechat_arraylist_insert (arraylist, -1, pointer);  /* insert at the end if not sorted */
Questa funzione non è disponibile nelle API per lo scripting.

arraylist_add

WeeChat ≥ 1.8.

Add an item in an array list.

Prototipo:

int weechat_arraylist_add (struct t_arraylist *arraylist, void *pointer);

Argomenti:

  • arraylist: array list pointer

  • pointer: pointer to the item to add

Valore restituito:

  • index of new item (≥ 0), -1 if error.

Esempio in C:

int index = weechat_arraylist_add (arraylist, pointer);
Questa funzione non è disponibile nelle API per lo scripting.

arraylist_remove

WeeChat ≥ 1.8.

Remove an item from an array list.

Prototipo:

int weechat_arraylist_remove (struct t_arraylist *arraylist, int index);

Argomenti:

  • arraylist: array list pointer

  • index: index of the item to remove

Valore restituito:

  • index of item removed, -1 if error.

Esempio in C:

int index_removed = weechat_arraylist_remove (arraylist, index);
Questa funzione non è disponibile nelle API per lo scripting.

arraylist_clear

WeeChat ≥ 1.8.

Remove all items from an array list.

Prototipo:

int weechat_arraylist_clear (struct t_arraylist *arraylist);

Argomenti:

  • arraylist: array list pointer

Valore restituito:

  • 1 if OK, 0 if error

Esempio in C:

if (weechat_arraylist_clear (arraylist))
{
    /* OK */
}
Questa funzione non è disponibile nelle API per lo scripting.

arraylist_free

WeeChat ≥ 1.8.

Free an array list.

Prototipo:

void weechat_arraylist_free (struct t_arraylist *arraylist);

Argomenti:

  • arraylist: array list pointer

Esempio in C:

weechat_arraylist_free (arraylist);
Questa funzione non è disponibile nelle API per lo scripting.

3.10. Tabelle hash

Funzioni per le tabelle hash.

hashtable_new

WeeChat ≥ 0.3.3.

Crea una nuova tabella hash.

Prototipo:

struct t_hashtable *weechat_hashtable_new (int size,
                                           const char *type_keys,
                                           const char *type_values,
                                           unsigned long long (*callback_hash_key)(struct t_hashtable *hashtable,
                                                                                   const void *key),
                                           int (*callback_keycmp)(struct t_hashtable *hashtable,
                                                                  const void *key1,
                                                                  const void *key2));

Argomenti:

  • size: dimensione dell’array interno per memorizzare le chiavi con hash, un valore più alto usa più memoria, ma ha migliori performance. (questo non è un limite per il numero di elementi nella tabella hash)

  • type_keys: tipo per le chiavi nella tabella hash:

    • WEECHAT_HASHTABLE_INTEGER

    • WEECHAT_HASHTABLE_STRING

    • WEECHAT_HASHTABLE_POINTER

    • WEECHAT_HASHTABLE_BUFFER

    • WEECHAT_HASHTABLE_TIME

  • type_values: tipo per i valori nella tabella hash:

    • WEECHAT_HASHTABLE_INTEGER

    • WEECHAT_HASHTABLE_STRING

    • WEECHAT_HASHTABLE_POINTER

    • WEECHAT_HASHTABLE_BUFFER

    • WEECHAT_HASHTABLE_TIME

  • callback_hash_key: callback used to "hash" a key (key as integer value), can be NULL if key type is not "buffer" (a default hash function is used), arguments and return value:

    • struct t_hashtable *hashtable: puntatore alla tabella hash

    • const void *key: chiave

    • return value: hash della chiave

  • callback_keycmp: callback used to compare two keys, can be NULL if key type is not "buffer" (a default comparison function is used), arguments and return value:

    • struct t_hashtable *hashtable: puntatore alla tabella hash

    • const void *key1: prima chiave

    • const void *key2: seconda chiave

    • valore restituito:

      • numero negativo se key1 è minore di key2

      • 0 se key1 è uguale a key2

      • numero positivo se key1 è maggiore di key2

Valore restituito:

  • puntatore alla nuova tabella hash, NULL in caso di errore

Esempio in C:

struct t_hashtable *hashtable = weechat_hashtable_new (8,
                                                       WEECHAT_HASHTABLE_STRING,
                                                       WEECHAT_HASHTABLE_STRING,
                                                       NULL,
                                                       NULL);
Questa funzione non è disponibile nelle API per lo scripting.

hashtable_set_with_size

WeeChat ≥ 0.3.3, updated in 0.4.2.

Aggiunge o aggiorna un elemento nella tabella hash con la dimensione per la chiave ed il valore.

Prototipo:

struct t_hashtable_item *weechat_hashtable_set_with_size (struct t_hashtable *hashtable,
                                                          const void *key, int key_size,
                                                          const void *value, int value_size);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • key: puntatore alla chiave

  • key_size: dimensione della chiave (in byte), usata solo se il tipo delle chiavi nella tabella hash è "buffer"

  • value: puntatore al valore

  • value_size: dimensione del valore (in byte), utilizzata solo se il tipo dei valori nella tabella è "buffer"

Valore restituito:

  • pointer to item created/updated, NULL if error

Esempio in C:

weechat_hashtable_set_with_size (hashtable, "my_key", 0,
                                 my_buffer, sizeof (my_buffer_struct));
Questa funzione non è disponibile nelle API per lo scripting.

hashtable_set

WeeChat ≥ 0.3.3, updated in 0.4.2.

Aggiunge o aggiorna un elemento nella tabella hash.

Prototipo:

struct t_hashtable_item *weechat_hashtable_set (struct t_hashtable *hashtable,
                                                const void *key, const void *value);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • key: puntatore alla chiave

  • value: puntatore al valore

Valore restituito:

  • pointer to item created/updated, NULL if error

Esempio in C:

weechat_hashtable_set (hashtable, "my_key", "my_value");

hashtable_get

WeeChat ≥ 0.3.3.

Ottiene il valore associato ad una chiave in una tabella hash.

Prototipo:

void *weechat_hashtable_get (struct t_hashtable *hashtable, void *key);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • key: puntatore alla chiave

Valore restituito:

  • valore per la chiave, NULL se non trovata

Esempio in C:

void *value = weechat_hashtable_get (hashtable, "my_key");
Questa funzione non è disponibile nelle API per lo scripting.

hashtable_has_key

WeeChat ≥ 0.3.4.

Check if a key is in the hashtable.

Prototipo:

int weechat_hashtable_has_key (struct t_hashtable *hashtable, void *key);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • key: puntatore alla chiave

Valore restituito:

  • 1 se la chiave si trova nella tabella hash, 0 in caso contrario

Esempio in C:

if (weechat_hashtable_has_key (hashtable, "my_key"))
{
    /* la chiave è nella tabella hash */
    /* ... */
}
Questa funzione non è disponibile nelle API per lo scripting.

hashtable_map

WeeChat ≥ 0.3.3.

Chiama una funzione su tutte le voci della tabella hash, by insertion order in the hashtable (from oldest to newest one).

Prototipo:

void weechat_hashtable_map (struct t_hashtable *hashtable,
                            void (*callback_map)(void *data,
                                                 struct t_hashtable *hashtable,
                                                 const void *key,
                                                 const void *value),
                            void *callback_map_data);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • callback_map: funzione chiamata per ogni voce nella tabella hash

  • callback_map_data: puntatore fornito alla mappa di callback quando chiamata

Esempio in C:

void
map_cb (void *data, struct t_hashtable *hashtable,
        const void *key, const void *value)
{
    /* display key and value (they are both strings here) */
    weechat_printf (NULL, "key: '%s', value: '%s'",
                    (const char *)key,
                    (const char *)value);
}
/* ... */
weechat_hashtable_map (hashtable, &map_cb, NULL);
Questa funzione non è disponibile nelle API per lo scripting.

hashtable_map_string

WeeChat ≥ 0.3.7.

Chiama una funzione su tutte le voci della tabella hash, by insertion order in the hashtable (from oldest to newest one), inviando chiavi e valori come stringhe.

Prototipo:

void weechat_hashtable_map_string (struct t_hashtable *hashtable,
                                   void (*callback_map)(void *data,
                                                        struct t_hashtable *hashtable,
                                                        const char *key,
                                                        const char *value),
                                   void *callback_map_data);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • callback_map: funzione chiamata per ogni voce nella tabella hash

  • callback_map_data: puntatore fornito alla mappa di callback quando chiamata

Le stringhe key e value inviate alla callback sono temporanee, vengono eliminate dopo la chiamata alla callback.

Esempio in C:

void
map_cb (void *data, struct t_hashtable *hashtable,
        const char *key, const char *value)
{
    /* display key and value */
    weechat_printf (NULL, "key: '%s', value: '%s'",
                    key, value);
}
/* ... */
weechat_hashtable_map_string (hashtable, &map_cb, NULL);
Questa funzione non è disponibile nelle API per lo scripting.

hashtable_dup

WeeChat ≥ 1.0.

Duplicate a hashtable.

Prototipo:

struct t_hashtable *weechat_hashtable_dup (struct t_hashtable *hashtable);

Argomenti:

  • hashtable: puntatore alla tabella hash

Valore restituito:

  • duplicated hashtable

Esempio in C:

struct t_hashtable *new_hashtable = weechat_hashtable_dup (hashtable);
Questa funzione non è disponibile nelle API per lo scripting.

hashtable_get_integer

WeeChat ≥ 0.3.3.

Restituisce un valore intero per la proprietà di una tabella hash.

Prototipo:

int weechat_hashtable_get_integer (struct t_hashtable *hashtable,
                                   void *property);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • property: nome della proprietà:

    • size: dimensione dell’array interno "htable" nella tabella hash

    • items_count: numero di elementi nella tabella hash

Valore restituito:

  • valore intero della proprietà

Esempio in C:

int items_count = weechat_hashtable_get_integer (hashtable, "items_count");
Questa funzione non è disponibile nelle API per lo scripting.

hashtable_get_string

WeeChat ≥ 0.3.4.

Restituisce il valore stringa della proprietà di una tabella hash.

Prototipo:

const char *weechat_hashtable_get_string (struct t_hashtable *hashtable,
                                          const char *property);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • property: nome della proprietà:

    • type_keys: tipo per le chiavi:

      • integer: intero

      • string: stringa

      • pointer: puntatore

      • buffer: buffer

      • time: tempo

    • type_values: tipo per i valori:

      • integer: intero

      • string: stringa

      • pointer: puntatore

      • buffer: buffer

      • time: tempo

    • keys: stringa con la lista di chiavi (formato: "chiave1,chiave2,chiave3")

    • keys_sorted: stringa con l’elenco di chiavi ordinate (formato: "chiave1,chiave2,chiave3")

    • values: stringa con la lista di valori (formato: "valore1,valore2,valore3")

    • keys_values: stringa con la lista di valori e chiavi (formato: "chiave1:valore1,chiave2:valore2,chiave3:valore3")

    • keys_values_sorted: stringa con la lista di chiavi e valori (ordinata per chiavi) (formato: "chiave1:valore1,chiave2:valore2,chiave3:valore3")

Valore restituito:

  • valore stringa della proprietà

Esempio in C:

weechat_printf (NULL, "keys are type: %s",
                weechat_hashtable_get_string (hashtable, "type_keys"));
weechat_printf (NULL, "list of keys: %s",
                weechat_hashtable_get_string (hashtable, "keys"));
Questa funzione non è disponibile nelle API per lo scripting.

hashtable_set_pointer

WeeChat ≥ 0.3.4.

Imposta il valore puntatore della proprietà di una tabella hash.

Prototipo:

void weechat_hashtable_set_pointer (struct t_hashtable *hashtable,
                                    const char *property, void *pointer);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • property: nome della proprietà:

    • callback_free_key: set callback function used to free keys in hashtable (WeeChat ≥ 0.4.2)

    • callback_free_value: imposta la funzione callback usata per liberare i valori nella tabella hash

  • pointer: new pointer value for property

Esempio in C:

void
my_free_value_cb (struct t_hashtable *hashtable, const void *key, void *value)
{
    /* ... */
}

void
my_free_key_cb (struct t_hashtable *hashtable, void *key)
{
    /* ... */
}

weechat_hashtable_set_pointer (hashtable, "callback_free_value", &my_free_value_cb);
weechat_hashtable_set_pointer (hashtable, "callback_free_key", &my_free_key_cb);
Questa funzione non è disponibile nelle API per lo scripting.

hashtable_add_to_infolist

WeeChat ≥ 0.3.3.

Aggiunge elementi della tabella hash ad un elemento della lista info, by insertion order in the hashtable (from oldest to newest one).

Prototipo:

int weechat_hashtable_add_to_infolist (struct t_hashtable *hashtable,
                                       struct t_infolist_item *infolist_item,
                                       const char *prefix);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • infolist_item: puntatore all’elemento della lista info

  • prefix: stringa usata come prefisso per i nomi nella lista info

Valore restituito:

  • 1 se ok, 0 in caso di errore

Esempio in C:

weechat_hashtable_add_to_infolist (hashtable, infolist_item, "testhash");

/* se la tabella hash contiene:
     "key1" => "value 1"
     "key2" => "value 2"
   allora le seguenti variabili verranno aggiunti all'elemento  della lista info:
     "testhash_name_00000"  = "key1"
     "testhash_value_00000" = "value 1"
     "testhash_name_00001"  = "key2"
     "testhash_value_00001" = "value 2"
*/
Questa funzione non è disponibile nelle API per lo scripting.

hashtable_add_from_infolist

WeeChat ≥ 2.2.

Add infolist items in a hashtable.

Prototipo:

int weechat_hashtable_add_from_infolist (struct t_hashtable *hashtable,
                                         struct t_infolist *infolist,
                                         const char *prefix);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • infolist: infolist pointer

  • prefix: stringa usata come prefisso per i nomi nella lista info

Valore restituito:

  • 1 se ok, 0 in caso di errore

Esempio in C:

weechat_hashtable_add_from_infolist (hashtable, infolist, "testhash");

/* if infolist contains:
     "testhash_name_00000"  = "key1"
     "testhash_value_00000" = "value 1"
     "testhash_name_00001"  = "key2"
     "testhash_value_00001" = "value 2"
   then following variables will be added to hashtable:
     "key1" => "value 1"
     "key2" => "value 2"
*/
Questa funzione non è disponibile nelle API per lo scripting.

hashtable_remove

WeeChat ≥ 0.3.3.

Rimuove un elemento in una tabella hash.

Prototipo:

void weechat_hashtable_remove (struct t_hashtable *hashtable, const void *key);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • key: puntatore alla chiave

Esempio in C:

weechat_hashtable_remove (hashtable, "my_key");
Questa funzione non è disponibile nelle API per lo scripting.

hashtable_remove_all

WeeChat ≥ 0.3.3.

Rimuove tutti gli elementi in una tabella hash.

Prototipo:

void weechat_hashtable_remove_all (struct t_hashtable *hashtable);

Argomenti:

  • hashtable: puntatore alla tabella hash

Esempio in C:

weechat_hashtable_remove_all (hashtable);
Questa funzione non è disponibile nelle API per lo scripting.

hashtable_free

WeeChat ≥ 0.3.3.

Libera una tabella hash.

Prototipo:

void weechat_hashtable_free (struct t_hashtable *hashtable);

Argomenti:

  • hashtable: puntatore alla tabella hash

Esempio in C:

weechat_hashtable_free (hashtable);
Questa funzione non è disponibile nelle API per lo scripting.

3.11. File di configurazione

Funzioni per i file di configurazione.

config_new

Updated in 1.5, 4.0.0.

Crea un nuovo file di configurazione.

Prototipo:

struct t_config_file *weechat_config_new (const char *name,
                                          int (*callback_reload)(const void *pointer,
                                                                 void *data,
                                                                 struct t_config_file *config_file),
                                          const void *callback_reload_pointer,
                                          void *callback_reload_data);

Argomenti:

  • name: nome del file di configurazione (senza percorso o estensione); a priority is allowed before the name, with format nnn|name where nnn is non-negative integer with priority; default priority is 1000; files are sorted by priority from higher to lower when running command /reload (see priority of configuration files below)

  • callback_reload: funzione chiamata quando il file di configurazione viene ricaricato con /reload (opzionale, può essere NULL, see below), argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • struct t_config_file *config_file: puntatore al file di configurazione

    • valore restituito:

      • WEECHAT_CONFIG_READ_OK

      • WEECHAT_CONFIG_READ_MEMORY_ERROR

      • WEECHAT_CONFIG_READ_FILE_NOT_FOUND

  • callback_reload_pointer: puntatore fornito per ricaricare il callback quando richiesto da WeeChat

  • callback_reload_data: puntatore fornito dalla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the configuration file is freed

Reload callback:

  • The callback must only call the function config_reload, it must not remove the configuration file.

  • A callback is needed only if it does some things before and/or after the call to the function config_reload.
    If no callback is given, WeeChat will call its internal reload function, so the configuration file will be reloaded in all cases.

Valore restituito:

  • puntatore al nuovo file di configurazione, NULL in caso di errore

Il file NON viene creato su disco da questa funzione. Verrà creato chiamando la funzione config_write. Si dovrebbe chiamare questa funzione solo dopo aver aggiunto alcune sezioni (con config_new_section) e le opzioni (con config_new_option).

Priority of default configuration files:

Rank File Priority

1

sec.conf

120000

2

weechat.conf

110000

3

plugins.conf

100000

4

charset.conf

16000

5

logger.conf

15000

6

exec.conf

14000

7

trigger.conf

13000

8

spell.conf

12000

9

alias.conf

11000

10

buflist.conf

10000

11

fifo.conf

9000

12

typing.conf

8000

13

xfer.conf

7000

14

irc.conf

6000

15

relay.conf

5000

16

guile.conf

4070

17

lua.conf

4050

18

perl.conf

4040

19

php.conf

4030

20

python.conf

4020

21

ruby.conf

4010

22

tcl.conf

4000

23

script.conf

3000

24

fset.conf

2000

Esempio in C:

int
my_config_reload_cb (const void *pointer, void *data,
                     struct t_config_file *config_file)
{
    /* ... */

    return WEECHAT_RC_OK;
}

struct t_config_file *config_file = weechat_config_new ("test",
                                                        &my_config_reload_cb,
                                                        NULL, NULL);

Script (Python):

# prototipo
def config_new(name: str, callback_reload: str, callback_reload_data: str) -> str: ...

# esempio
def my_config_reload_cb(data: str, config_file: str) -> int:
    # ...
    return weechat.WEECHAT_RC_OK

config_file = weechat.config_new("test", "my_config_reload_cb", "")

config_set_version

WeeChat ≥ 4.0.0.

Set configuration file version and a callback to update config sections/options on-the-fly when the config is read.

Prototipo:

int config_file_set_version (struct t_config_file *config_file,
                             int version,
                             struct t_hashtable *(*callback_update)(const void *pointer,
                                                                    void *data,
                                                                    struct t_config_file *config_file,
                                                                    int version_read,
                                                                    struct t_hashtable *data_read),
                             const void *callback_update_pointer,
                             void *callback_update_data);

Argomenti:

  • config_file: configuration file pointer

  • version: version, must be ≥ 2

  • callback_update: function called when configuration file is read, for each section and each option, if the version read is less than the expected version, (optional, can be NULL, see below), arguments and return value:

    • const void *pointer: pointer

    • void *data: pointer

    • struct t_config_file *config_file: configuration file pointer

    • int version_read: version read in configuration file (1 by default)

    • struct t_hashtable *data_read: hashtable with data read from configuration file (see below)

    • return value:

      • either "data_read" pointer (hashtable completed), or pointer to a new hashtable (created by callback, with keys and values of type "string")

  • callback_update_pointer: pointer given to callback when it is called by WeeChat

  • callback_update_data: pointer given to callback when it is called by WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the configuration file is freed

Update callback:

  • The callback receives a hashtable with data read from configuration file:

Key Availability Value

config

Always set

Name of configuration file, without extension (eg: weechat)

section

Always set

Name of section being read

option

For option only

Name of the option

value

For option only

Value of the option (if not NULL)

value_null

For option only

Option as NULL value (value is always 1)

  • The callback can update "section" for a line with a section and "option", "value" and "value_null" for a line with an option.

  • If "option" is set to empty string by the callback, the line read in configuration file is ignored.

  • Field "value_null" is set to force a NULL value for the option.

Valore restituito:

  • 1 if OK, 0 if error

Esempio in C:

struct t_hashtable *
my_config_update_cb (const void *pointer, void *data,
                     struct t_config_file *config_file,
                     int version_read,
                     struct t_hashtable *data_read)
{
    const char *ptr_section, *ptr_option;

    /* return now if version is already up-to-date */
    if (version_read >= 2)
        return NULL;

    ptr_section = hashtable_get (data_read, "section");
    ptr_option = hashtable_get (data_read, "option");

    /* rename section "abc" to "def" */
    if (ptr_section && !ptr_option && (strcmp (ptr_section, "abc") == 0))
    {
        hashtable_set (data_read, "section", "def");
        return data_read;
    }

    /* limit other changes to section "test" */
    if (!ptr_section || !ptr_option || (strcmp (ptr_section, "test") != 0))
        return NULL;

    /* rename option "test1" to "test2" */
    if (strcmp (ptr_option, "test1") == 0)
    {
        hashtable_set (data_read, "option", "test2");
        return data_read;
    }

    /* set value to "xxx" for option "test" */
    if (strcmp (ptr_option, "test") == 0)
    {
        hashtable_set (data_read, "value", "xxx");
        return data_read;
    }

    /* set value to NULL for option "test_null" */
    if (strcmp (ptr_option, "test_null") == 0)
    {
        hashtable_set (data_read, "value_null", "1");
        return data_read;
    }

    /* no changes */
    return NULL;
}

struct t_config_file *config_file = weechat_config_new ("test", NULL, NULL, NULL);
weechat_config_set_version (config_file, 2, &my_config_update_cb, NULL, NULL);
weechat_config_read (config_file);

Script (Python):

# prototipo
def config_set_version(config_file: str, version: int, callback_update: str, callback_update_data: str) -> int: ...

# esempio
def my_config_update_cb(data: str, config_file: str, version_read: int, data_read: Dict[str, str]) -> Dict[str, str]:
    # return now if version is already up-to-date
    if version_read >= 2:
        return {}

    section = data_read.get("section")
    option = data_read.get("option")

    # rename section "abc" to "def"
    if section and not option and section == "abc":
        data_read["section"] = "def"
        return data_read

    # limit other changes to section "test"
    if not section or not option or section != "test":
        return {}

    # rename option "test1" to "test2"
    if option == "test1":
        data_read["option"] = "test2"
        return data_read

    # set value to "xxx" for option "test"
    if option == "test":
        data_read["value"] = "xxx"
        return data_read

    # set value to NULL for option "test_null"
    if option == "test_null":
        data_read["value_null"] = "1"
        return data_read

    # no changes
    return {}

config_file = weechat.config_new("test", "", "")
weechat.config_set_version(config_file, 2, "my_config_update_cb", "")
weechat.config_read(config_file)

config_new_section

Updated in 1.5.

Crea una nuova sezione nel file di configurazione.

Prototipo:

struct t_config_section *weechat_config_new_section (
    struct t_config_file *config_file,
    const char *name,
    int user_can_add_options,
    int user_can_delete_options,
    int (*callback_read)(const void *pointer,
                         void *data,
                         struct t_config_file *config_file,
                         struct t_config_section *section,
                         const char *option_name,
                         const char *value),
    const void *callback_read_pointer,
    void *callback_read_data,
    int (*callback_write)(const void *pointer,
                          void *data,
                          struct t_config_file *config_file,
                          const char *section_name),
    const void *callback_write_pointer,
    void *callback_write_data,
    int (*callback_write_default)(const void *pointer,
                                  void *data,
                                  struct t_config_file *config_file,
                                  const char *section_name),
    const void *callback_write_default_pointer,
    void *callback_write_default_data,
    int (*callback_create_option)(const void *pointer,
                                  void *data,
                                  struct t_config_file *config_file,
                                  struct t_config_section *section,
                                  const char *option_name,
                                  const char *value),
    const void *callback_create_option_pointer,
    void *callback_create_option_data,
    int (*callback_delete_option)(const void *pointer,
                                  void *data,
                                  struct t_config_file *config_file,
                                  struct t_config_section *section,
                                  struct t_config_option *option),
    const void *callback_delete_option_pointer,
    void *callback_delete_option_data);

Argomenti:

  • config_file: puntatore al file di configurazione

  • name: nome della sezione

  • user_can_add_options: 1 se l’utente può creare nuove opzioni nella sezione, oppure 0 se non gli è consentito

  • user_can_delete_options: 1 se l’utente può eliminare le opzioni nella sezione, oppure 0 se non gli è consentito

  • callback_read: funzione chiamata quando un’opzione nella sezione viene letta da disco (dovrebbe essere NULL in molti casi, tranne se l’opzione nella sezione necessita di una funzione personalizza), argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • struct t_config_file *config_file: puntatore al file di configurazione

    • struct t_config_section *section: puntatore alla sezione

    • const char *option_name: nome dell’opzione

    • const char *value: valore

    • valore restituito:

      • WEECHAT_CONFIG_OPTION_SET_OK_CHANGED

      • WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE

      • WEECHAT_CONFIG_OPTION_SET_ERROR

      • WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND

  • callback_read_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_read_data: puntatore fornito dalla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the section is freed

  • callback_write: funzione chiamata quando la sezione è scritta nel file (dovrebbe essere NULL in molti casi, tranne se la sezione necessita di una funzione personalizzata), argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • struct t_config_file *config_file: puntatore al file di configurazione

    • const char *section_name: nome della sezione

    • valore restituito:

      • WEECHAT_CONFIG_WRITE_OK

      • WEECHAT_CONFIG_WRITE_ERROR

      • WEECHAT_CONFIG_WRITE_MEMORY_ERROR

  • callback_write_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_write_data: puntatore fornito dalla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the section is freed

  • callback_write_default: funzione chiamata quando i valori predefiniti per la sezione devono essere scritti in un file, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • struct t_config_file *config_file: puntatore al file di configurazione

    • const char *section_name: nome della sezione

    • valore restituito:

      • WEECHAT_CONFIG_WRITE_OK

      • WEECHAT_CONFIG_WRITE_ERROR

      • WEECHAT_CONFIG_WRITE_MEMORY_ERROR

  • callback_write_default_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_write_default_data: puntatore fornito dalla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the section is freed

  • callback_create_option: funzione chiamata quando viene creata una nuova opzione nella sezione (NULL se la sezione non consente di creare nuove opzioni), argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • struct t_config_file *config_file: puntatore al file di configurazione

    • struct t_config_section *section: puntatore alla sezione

    • const char *option_name: nome dell’opzione

    • const char *value: valore

    • valore restituito:

      • WEECHAT_CONFIG_OPTION_SET_OK_CHANGED

      • WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE

      • WEECHAT_CONFIG_OPTION_SET_ERROR

      • WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND

  • callback_create_option_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_create_option_data: puntatore fornito dalla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the section is freed

  • callback_delete_option: funzione chiamata quando un’opzione viene eliminata nella sezione (NULL se la sezione non consente di eliminare delle opzioni), argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • struct t_config_file *config_file: puntatore al file di configurazione

    • struct t_config_section *section: puntatore alla sezione

    • struct t_config_option *option: puntatore all’opzione

    • valore restituito:

      • WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET

      • WEECHAT_CONFIG_OPTION_UNSET_OK_RESET

      • WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED

      • WEECHAT_CONFIG_OPTION_UNSET_ERROR

  • callback_delete_option_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_delete_option_data: puntatore fornito dalla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the section is freed

Valore restituito:

  • puntatore alla nuova sezione nel file di configurazione, NULL in caso di errore

Esempio in C:

int
my_section_read_cb (const void *pointer, void *data,
                    struct t_config_file *config_file,
                    struct t_config_section *section,
                    const char *option_name,
                    const char *value)
{
    /* ... */

    return WEECHAT_CONFIG_OPTION_SET_OK_CHANGED;
    /* return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; */
    /* return WEECHAT_CONFIG_OPTION_SET_ERROR; */
    /* return WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND; */
}

int
my_section_write_cb (const void *pointer, void *data,
                     struct t_config_file *config_file,
                     const char *section_name)
{
    /* ... */

    return WEECHAT_CONFIG_WRITE_OK;
    /* return WEECHAT_CONFIG_WRITE_ERROR; */
    /* return WEECHAT_CONFIG_WRITE_MEMORY_ERROR; */
}

int
my_section_write_default_cb (const void *pointer, void *data,
                             struct t_config_file *config_file,
                             const char *section_name)
{
    /* ... */

    return WEECHAT_CONFIG_WRITE_OK;
    /* return WEECHAT_CONFIG_WRITE_ERROR; */
    /* return WEECHAT_CONFIG_WRITE_MEMORY_ERROR; */
}

int
my_section_create_option_cb (const void *pointer, void *data,
                             struct t_config_file *config_file,
                             struct t_config_section *section,
                             const char *option_name,
                             const char *value)
{
    /* ... */

    return WEECHAT_CONFIG_OPTION_SET_OK_CHANGED;
    /* return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; */
    /* return WEECHAT_CONFIG_OPTION_SET_ERROR; */
    /* return WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND; */
}

int
my_section_delete_option_cb (const void *pointer, void *data,
                             struct t_config_file *config_file,
                             struct t_config_section *section,
                             struct t_config_option *option)
{
    /* ... */

    return WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED;
    /* return WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET; */
    /* return WEECHAT_CONFIG_OPTION_UNSET_OK_RESET; */
    /* return WEECHAT_CONFIG_OPTION_UNSET_ERROR; */
}

/* sezione standard, l'utente non può aggiungere/rimuovere opzioni */
struct t_config_section *new_section1 =
    weechat_config_new_section (config_file, "section1", 0, 0,
                                NULL, NULL, NULL,
                                NULL, NULL, NULL,
                                NULL, NULL, NULL,
                                NULL, NULL, NULL,
                                NULL, NULL, NULL);

/* sezione speciale, l'utente può aggiungere/eliminare opzioni, e le
   opzioni necessitano di un callback per essere lette/scritte */
struct t_config_section *new_section2 =
    weechat_config_new_section (config_file, "section2", 1, 1,
                                &my_section_read_cb, NULL, NULL,
                                &my_section_write_cb, NULL, NULL,
                                &my_section_write_default_cb, NULL, NULL,
                                &my_section_create_option_cb, NULL, NULL,
                                &my_section_delete_option_cb, NULL, NULL);

Script (Python):

# prototipo
def config_new_section(config_file: str, name: str,
                       user_can_add_options: int, user_can_delete_options: int,
                       callback_read: str, callback_read_data: str,
                       callback_write: str, callback_write_data: str,
                       callback_write_default: str, callback_write_default_data: str,
                       callback_create_option: str, callback_create_option_data: str,
                       callback_delete_option: str, callback_delete_option_data: str) -> str: ...

# esempio
def my_section_read_cb(data: str, config_file: str, section: str, option_name: str, value: Union[str, None]) -> int:
    # ...
    return weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED
    # return weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE
    # return weechat.WEECHAT_CONFIG_OPTION_SET_ERROR
    # return weechat.WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND

def my_section_write_cb(data: str, config_file: str, section_name: str) -> int:
    # ...
    return weechat.WEECHAT_CONFIG_WRITE_OK
    # return weechat.WEECHAT_CONFIG_WRITE_ERROR
    # return weechat.WEECHAT_CONFIG_WRITE_MEMORY_ERROR

def my_section_write_default_cb(data: str, config_file: str, section_name: str) -> int:
    # ...
    return weechat.WEECHAT_CONFIG_WRITE_OK
    # return weechat.WEECHAT_CONFIG_WRITE_ERROR
    # return weechat.WEECHAT_CONFIG_WRITE_MEMORY_ERROR

def my_section_create_option_cb(data: str, config_file: str, section: str, option_name: str, value: Union[str, None]) -> int:
    # ...
    return weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED
    # return weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE
    # return weechat.WEECHAT_CONFIG_OPTION_SET_ERROR
    # return weechat.WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND

def my_section_delete_option_cb(data: str, config_file: str, section: str, option: str) -> int:
    # ...
    return weechat.WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED
    # return weechat.WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET
    # return weechat.WEECHAT_CONFIG_OPTION_UNSET_OK_RESET
    # return weechat.WEECHAT_CONFIG_OPTION_UNSET_ERROR

section = weechat.config_new_section(config_file, "section1", 1, 1,
    "my_section_read_cb", "",
    "my_section_write_cb", "",
    "my_section_write_default_cb", "",
    "my_section_create_option_cb", "",
    "my_section_delete_option_cb", "")

config_search_section

Cerca una sezione in un file di configurazione.

Prototipo:

struct t_config_section *weechat_config_search_section (
    struct t_config_file *config_file,
    const char *section_name);

Argomenti:

  • config_file: puntatore al file di configurazione

  • section_name: nome della sezione da cercare

Valore restituito:

  • puntatore alla sezione trovata, NULL se non trovata

Esempio in C:

struct t_config_section *section = weechat_config_search_section (config_file,
                                                                  "section");

Script (Python):

# prototipo
def config_search_section(config_file: str, section_name: str) -> str: ...

# esempio
section = weechat.config_search_section(config_file, "section")

config_new_option

Updated in 1.5, 4.1.0.

Crea una nuova opzione nella sezione di un file di configurazione.

Prototipo:

struct t_config_option *weechat_config_new_option (
    struct t_config_file *config_file,
    struct t_config_section *section,
    const char *name,
    const char *type,
    const char *description,
    const char *string_values,
    int min,
    int max,
    const char *default_value,
    const char *value,
    int null_value_allowed,
    int (*callback_check_value)(const void *pointer,
                                void *data,
                                struct t_config_option *option,
                                const char *value),
    const void *callback_check_value_pointer,
    void *callback_check_value_data,
    void (*callback_change)(const void *pointer,
                            void *data,
                            struct t_config_option *option),
    const void *callback_change_pointer,
    void *callback_change_data,
    void (*callback_delete)(const void *pointer,
                            void *data,
                            struct t_config_option *option),
    const void *callback_delete_pointer,
    void *callback_delete_data);

Argomenti:

  • config_file: puntatore al file di configurazione

  • section: puntatore alla sezione

  • name: nome dell’opzione; with WeeChat ≥ 1.4, the name can include a parent option name (the value of parent option will be displayed in /set command output if this option is "null"), the syntax is then: "name << file.section.option"

  • type: tipo dell’opzione:

    • boolean: valore booleano (on/off)

    • integer: valore intero

    • string: valore stringa

    • color: colore

    • enum: list of string values (stored as integer internally)

  • description: descrizione dell’opzione

  • string_values: valori come stringa (separati da |) (optional, required for type enum)

  • min: valore minimo (per il tipo integer)

  • max: valore massimo (per il tipo integer)

  • default_value: valore predefinito per l’opzione (usato per il reset dell’opzione)

  • value: valore per l’opzione

  • null_value_allowed: 1 se null (valore non definito) è consentito per l’opzione, altrimenti 0

  • callback_check_value: funzione chiamata per verificare il nuovo valore per l’opzione (ozionale), argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • struct t_config_option *option: puntatore all’opzione

    • const char *value: nuovo valore per l’opzione

    • valore restituito:

      • 1 se il valore è corretto

      • 0 se il valore non è valido

  • callback_check_value_pointer: puntatore fornito alla callback check_value quando chiamata da WeeChat

  • callback_check_value_data: puntatore fornito dalla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the option is freed

  • callback_change: funzione chiamata quando il valore dell’opzione è stata cambiata (opzionale), argomenti:

    • const void *pointer: puntatore

    • void *data: puntatore

    • struct t_config_option *option: puntatore all’opzione

  • callback_change_pointer: puntatore fornito per cambiare alla callback quando chiamato da WeeChat

  • callback_change_data: puntatore fornito dalla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the option is freed

  • callback_delete: funzione chiamata quando l’opzione verrà eliminata (opzionale), argomenti:

    • const void *pointer: puntatore

    • void *data: puntatore

    • struct t_config_option *option: puntatore all’opzione

  • callback_delete_pointer: puntatore fornito per eiliminare alla callback quando chiamato da WeeChat

  • callback_delete_data: puntatore fornito dalla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the option is freed

Valore restituito:

alla nuova opzione nella sezione, NULL in caso di errore

Esempio in C:

/* booleano */
struct t_config_option *option_bool =
    weechat_config_new_option (config_file, section, "option_bool", "boolean",
                               "My option, type boolean",
                               NULL,
                               0, 0,
                               "on",
                               "on",
                               0,
                               NULL, NULL, NULL,
                               NULL, NULL, NULL,
                               NULL, NULL, NULL);

/* intero */
struct t_config_option *option_int =
    weechat_config_new_option (config_file, section, "option_int", "integer",
                               "My option, type integer",
                               NULL,
                               0, 100,
                               "15",
                               "15",
                               0,
                               NULL, NULL, NULL,
                               NULL, NULL, NULL,
                               NULL, NULL, NULL);

/* stringa */
struct t_config_option *option_str =
    weechat_config_new_option (config_file, section, "option_str", "string",
                               "My option, type string",
                               NULL,
                               0, 0,
                               "test",
                               "test",
                               1,
                               NULL, NULL, NULL,
                               NULL, NULL, NULL,
                               NULL, NULL, NULL);

/* colore */
struct t_config_option *option_col =
    weechat_config_new_option (config_file, section, "option_col", "color",
                               "My option, type color",
                               NULL,
                               0, 0,
                               "lightblue",
                               "lightblue",
                               0,
                               NULL, NULL, NULL,
                               NULL, NULL, NULL,
                               NULL, NULL, NULL);

/* enum */
struct t_config_option *option_enum =
    weechat_config_new_option (config_file, section, "option_enum", "enum",
                               "My option, type enum",
                               "top|bottom|left|right",
                               0, 0,
                               "bottom",
                               "bottom",
                               0,
                               NULL, NULL, NULL,
                               NULL, NULL, NULL,
                               NULL, NULL, NULL);

Script (Python):

# prototipo
def config_new_option(config_file: str, section: str, name: str, type: str, description: str,
                      string_values: str, min: int, max: int,
                      default_value: Union[str, None], value: Union[str, None], null_value_allowed: int,
                      callback_check_value: str, callback_check_value_data: str,
                      callback_change: str, callback_change_data: str,
                      callback_delete: str, callback_delete_data: str) -> str: ...

# esempio
def option_str_check_value_cb(data: str, option: str, value: str) -> int:
    # ...
    return 1
    # return 0

def option_str_change_cb(data: str, option: str) -> None:
    # ...

def option_str_delete_cb(data: str, option: str) -> None:
    # ...

option_bool = weechat.config_new_option(config_file, section, "option_bool", "boolean",
    "My option, type boolean",
    "", 0, 0, "on", "on", 0,
    "", "",
    "", "",
    "", "")

option_int = weechat.config_new_option(config_file, section, "option_int", "integer",
    "My option, type integer",
    "", 0, 100, "15", "15", 0,
    "", "",
    "", "",
    "", "")

option_str = weechat.config_new_option(config_file, section, "option_str", "string",
    "My option, type string",
    "", 0, 0, "test", "test", 1,
    "option_str_check_value_cb", "",
    "option_str_change_cb", "",
    "option_str_delete_cb", "")

option_col = weechat.config_new_option(config_file, section, "option_col", "color",
    "My option, type color",
    "", 0, 0, "lightblue", "lightblue", 0,
    "", "",
    "", "",
    "", "")

option_enum = weechat.config_new_option(config_file, section, "option_enum", "enum",
    "My option, type enum",
    "top|bottom|left|right",
    0, 0, "bottom", "bottom", 0,
    "", "",
    "", "",
    "", "")
In Ruby, the 3 callbacks + data (6 strings) must be given in an array of 6 strings (due to a Ruby limitation of 15 arguments by function), see the WeeChat Scripting Guide  for more info (fixed in version 0.4.1).

config_search_option

Cerca un’opzione nella sezione di un file di configurazione.

Prototipo:

struct t_config_option *weechat_config_search_option (
    struct t_config_file *config_file,
    struct t_config_section *section,
    const char *option_name);

Argomenti:

  • config_file: puntatore al file di configurazione

  • section: puntatore alla sezione

  • name: nome dell’opzione da cercare

Valore restituito:

  • puntatore all’opzione trovata, NULL se non trovata

Esempio in C:

struct t_config_option *option =
    weechat_config_search_option (config_file, section, "option");

Script (Python):

# prototipo
def config_search_option(config_file: str, section: str, option_name: str) -> str: ...

# esempio
option = weechat.config_search_option(config_file, section, "option")

config_search_section_option

Cerca una sezione ed un’opzione in un file di configurazione o sezione.

Prototipo:

void weechat_config_search_section_option (struct t_config_file *config_file,
                                           struct t_config_section *section,
                                           const char *option_name,
                                           struct t_config_section **section_found,
                                           struct t_config_option **option_found);

Argomenti:

  • config_file: puntatore al file di configurazione

  • section: puntatore alla sezione

  • option_name: nome dell’opzione

  • section_found: puntatore al puntatore della sezione, sarà impostato alla sezione dell’opzione, se viene trovata

  • option_found: puntatore al puntatore dell’opzione, sarà impostato al puntatore di un’opzione, se viene trovata

Esempio in C:

struct t_config_section *ptr_section;
struct t_config_option *ptr_option;

weechat_config_search_section_option(config_file,
                                     section,
                                     "option",
                                     &ptr_section,
                                     &ptr_option);
if (ptr_option)
{
    /* opzione trovata */
}
else
{
    /* opzione non trovata */
}
Questa funzione non è disponibile nelle API per lo scripting.

config_search_with_string

Get file/section/option info about an option with full name.

Prototipo:

void weechat_config_search_with_string (const char *option_name,
                                        struct t_config_file **config_file,
                                        struct t_config_section **section,
                                        struct t_config_option **option,
                                        char **pos_option_name);

Argomenti:

  • option_name: nome completo dell’opzione (formato: "file.section.option")

  • config_file: puntatore al puntatore del file di configurazione, sarà impostato al puntatore al file di configurazione se l’opzione viene trovata

  • section: puntatore al puntatore della sezione, sarà impostato alla sezione dell’opzione, se viene trovata

  • option: puntatore al puntatore dell’opzione, sarà impostato al puntatore di un’opzione, se viene trovata

  • pos_option_name: pointer to a string pointer, will be set to pointer to name of option, if found

Esempio in C:

struct t_config_file *ptr_config_file;
struct t_config_section *ptr_section;
struct t_config_option *ptr_option;
char *option_name;

weechat_config_search_with_string ("file.section.option",
                                   &ptr_config_file,
                                   &ptr_section,
                                   &ptr_option,
                                   &option_name);
if (ptr_option)
{
    /* opzione trovata */
}
else
{
    /* opzione non trovata */
}
Questa funzione non è disponibile nelle API per lo scripting.

config_string_to_boolean

Verifica se un testo è "vero" o "falso", come valore booleano.

Prototipo:

int weechat_config_string_to_boolean (const char *text);

Argomenti:

  • text: testo da analizzare

Valore restituito:

  • 1 se il testo è "true" ("on", "yes", "y", "true", "t", "1")

  • 0 se il testo è "false" ("off", "no", "n", "false", "f", "0")

Esempio in C:

if (weechat_config_string_to_boolean (option_value))
{
    /* il valore è "true" */
}
else
{
    /* il valore è "false" */
}

Script (Python):

# prototipo
def config_string_to_boolean(text: str) -> int: ...

# esempio
if weechat.config_string_to_boolean(text):
    # ...

config_option_reset

Resetta un’opzione al proprio valore predefinito.

Prototipo:

int weechat_config_option_reset (struct t_config_option *option,
                                 int run_callback);

Argomenti:

  • option: puntatore all’opzione

  • run_callback: 1 per la chiamata alla callbackse il valore dell’opzione è cambiato, altrimenti 0

Valore restituito:

  • WEECHAT_CONFIG_OPTION_SET_OK_CHANGED se il valore dell’opzione è stato resettato

  • WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE se il valore non è stato modificato

  • WEECHAT_CONFIG_OPTION_SET_ERROR in caso di errore

Esempio in C:

switch (weechat_config_option_reset (option, 1))
{
    case WEECHAT_CONFIG_OPTION_SET_OK_CHANGED:
        /* .... */
        break;
    case WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE:
        /* .... */
        break;
    case WEECHAT_CONFIG_OPTION_SET_ERROR:
        /* .... */
        break;
}

Script (Python):

# prototipo
def config_option_reset(option: str, run_callback: int) -> int: ...

# esempio
rc = weechat.config_option_reset(option, 1)
if rc == weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED:
    # ...
elif rc == weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE:
    # ...
elif rc == weechat.WEECHAT_CONFIG_OPTION_SET_ERROR:
    # ...

config_option_set

Imposta un nuovo valore per l’opzione.

Prototipo:

int weechat_config_option_set (struct t_config_option *option,
                               const char *value, int run_callback);

Argomenti:

  • option: puntatore all’opzione

  • value: new value for option, special values are possible according to the type of option:

    • boolean:

      • toggle: toggle the current value

    • integer, color or enum:

      • ++N: add N (any integer) to the current value

      • --N: subtract N (any integer) from the current value

  • run_callback: 1 per la chiamata alla callback chang se il valore dell’opzione è cambiato, altrimenti 0

Valore restituito:

  • WEECHAT_CONFIG_OPTION_SET_OK_CHANGED se il valore dell’opzione è cambiato

  • WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE se il valore non è cambiato

  • WEECHAT_CONFIG_OPTION_SET_ERROR in caso di errore

Esempio in C:

switch (weechat_config_option_set (option, "new_value", 1))
{
    case WEECHAT_CONFIG_OPTION_SET_OK_CHANGED:
        /* .... */
        break;
    case WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE:
        /* .... */
        break;
    case WEECHAT_CONFIG_OPTION_SET_ERROR:
        /* .... */
        break;
}

Script (Python):

# prototipo
def config_option_set(option: str, value: str, run_callback: int) -> int: ...

# esempio
rc = weechat.config_option_set(option, "new_value", 1)
if rc == weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED:
    # ...
elif rc == weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE:
    # ...
elif rc == weechat.WEECHAT_CONFIG_OPTION_SET_ERROR:
    # ...

config_option_set_null

Imposta null (valore non definito) per un’opzione.

Prototipo:

int weechat_config_option_set_null (struct t_config_option *option,
                                    int run_callback);

Argomenti:

  • option: puntatore all’opzione

  • run_callback: 1 per la chiamata alla callback chang se il valore dell’opzione è cambiato (se non è null), altrimenti 0

È possibile impostare il valore a null solo se è consentito per l’opzione (consultare config_new_option).

Valore restituito:

  • WEECHAT_CONFIG_OPTION_SET_OK_CHANGED se il valore dell’opzione è cambiato

  • WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE se il valore non è cambiato

  • WEECHAT_CONFIG_OPTION_SET_ERROR in caso di errore

Esempio in C:

switch (weechat_config_option_set_null (option, 1))
{
    case WEECHAT_CONFIG_OPTION_SET_OK_CHANGED:
        /* .... */
        break;
    case WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE:
        /* .... */
        break;
    case WEECHAT_CONFIG_OPTION_SET_ERROR:
        /* .... */
        break;
}

Script (Python):

# prototipo
def config_option_set_null(option: str, run_callback: int) -> int: ...

# esempio
rc = weechat.config_option_set_null(option, 1)
if rc == weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED:
    # ...
elif rc == weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE:
    # ...
elif rc == weechat.WEECHAT_CONFIG_OPTION_SET_ERROR:
    # ...

config_option_unset

Rimuove/ripristina un’opzione.

Prototipo:

int weechat_config_option_unset (struct t_config_option *option);

Argomenti:

  • option: puntatore all’opzione

Valore restituito:

  • WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET se il valore dell’opzione non è stato ripristinato

  • WEECHAT_CONFIG_OPTION_UNSET_OK_RESET se il valore dell’opzione è stato ripristinato

  • WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED se l’opzione è stata rimossa

  • WEECHAT_CONFIG_OPTION_UNSET_ERROR in caso di errore

Esempio in C:

switch (weechat_config_option_unset (option))
{
    case WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET:
        /* .... */
        break;
    case WEECHAT_CONFIG_OPTION_UNSET_OK_RESET:
        /* .... */
        break;
    case WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED:
        /* .... */
        break;
    case WEECHAT_CONFIG_OPTION_UNSET_ERROR:
        /* .... */
        break;
}

Script (Python):

# prototipo
def config_option_unset(option: str) -> int: ...

# esempio
rc = weechat.config_option_unset(option)
if rc == weechat.WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET:
    # ...
elif rc == weechat.WEECHAT_CONFIG_OPTION_UNSET_OK_RESET:
    # ...
elif rc == weechat.WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED:
    # ...
elif rc == weechat.WEECHAT_CONFIG_OPTION_UNSET_ERROR:
    # ...

config_option_rename

Rinomina un’opzione.

Prototipo:

void weechat_config_option_rename (struct t_config_option *option,
                                   const char *new_name);

Argomenti:

  • option: puntatore all’opzione

  • new_name: nuovo nome per l’opzione

Esempio in C:

weechat_config_option_rename (option, "new_name");

Script (Python):

# prototipo
def config_option_rename(option: str, new_name: str) -> int: ...

# esempio
weechat.config_option_rename(option, "new_name")

config_option_get_string

WeeChat ≥ 1.9.

Return string value of an option property.

Prototipo:

const char *weechat_config_option_get_string (struct t_config_option *option,
                                              const char *property);

Argomenti:

  • option: puntatore all’opzione

  • property: nome della proprietà:

    • config_name: file name

    • section_name: section name

    • name: option name

    • parent_name: name of parent option

    • type: option type, one of:

      • boolean

      • integer

      • string

      • color

      • enum

    • description: option description

Valore restituito:

  • string value of property

Esempio in C:

const char *type = weechat_config_option_get_string (option, "type");
Questa funzione non è disponibile nelle API per lo scripting.

config_option_get_pointer

Restituisce un puntatore alla proprietà di un’opzione.

Prototipo:

void *weechat_config_option_get_pointer (struct t_config_option *option,
                                         const char *property);

Argomenti:

  • option: puntatore all’opzione

  • property: nome della proprietà:

    • config_file: puntatore al file di configurazione (struct t_config_file *)

    • section: puntatore alla sezione (struct t_config_section *)

    • name: nome dell’opzione (char *)

    • parent_name: name of parent option (char *) (WeeChat ≥ 1.4)

    • type: tipo dell’opzione (int *)

    • description: descrizione dell’opzione (char *)

    • string_values: valori stringa (char *)

    • min: valore minimo (int *)

    • max: valore massimo (int *)

    • default_value: valore predefinito (dipende dal tipo)

    • value: valore corrente (dipende dal tipo)

    • prev_option: puntatore all’opzione precedente (struct t_config_option *)

    • next_option: puntatore all’opzione successiva (struct t_config_option *)

Valore restituito:

  • puntatore alla proprietà richiesta

Esempio in C:

char *description = weechat_config_option_get_pointer (option, "description");
Questa funzione non è disponibile nelle API per lo scripting.

config_option_is_null

Verifica se un opzione è "null" (valore non definito).

Prototipo:

int weechat_config_option_is_null (struct t_config_option *option);

Argomenti:

  • option: puntatore all’opzione

Valore restituito:

  • 1 se il valore dell’opzione è "null"

  • 0 se il valore dell’opzione non è "null"

Esempio in C:

if (weechat_config_option_is_null (option))
{
    /* il valore è "null" */
}
else
{
    /* il valore non è "null" */
}

Script (Python):

# prototipo
def config_option_is_null(option: str) -> int: ...

# esempio
if weechat.config_option_is_null(option):
    # ...

config_option_default_is_null

Verifica che il valore predefinito di un’opzione sia "null" (valore non definito).

Prototipo:

int weechat_config_option_default_is_null (struct t_config_option *option);

Argomenti:

  • option: puntatore all’opzione

Valore restituito:

  • 1 se il valore predefinito di un’opzione è "null"

  • 0 se il valore predefinito di un’opzione non è "null"

Esempio in C:

if (weechat_config_option_default_is_null (option))
{
    /* il valore predefinito è "null" */
}
else
{
    /* il valore predefinito non è "null" */
}

Script (Python):

# prototipo
def config_option_default_is_null(option: str) -> int: ...

# esempio
if weechat.config_option_default_is_null(option):
    # ...

config_boolean

Restituisce il valore bool di un’opzione.

Prototipo:

int weechat_config_boolean (struct t_config_option *option);

Argomenti:

  • option: puntatore all’opzione

Return value, depending on the option type:

  • boolean: boolean value of option (0 or 1)

  • integer: 0

  • string: 0

  • color: 0

  • enum: 0

Esempio in C:

struct t_config_option *option = weechat_config_get ("plugin.section.option");
if (weechat_config_boolean (option))
{
    /* il valore è "true" */
}
else
{
    /* il valore è "false" */
}

Script (Python):

# prototipo
def config_boolean(option: str) -> int: ...

# esempio
option = weechat.config_get("plugin.section.option")
if weechat.config_boolean(option):
    # ...

config_boolean_default

Restituisce il valore bool predefinito di un’opzione.

Prototipo:

int weechat_config_boolean_default (struct t_config_option *option);

Argomenti:

  • option: puntatore all’opzione

Return value, depending on the option type:

  • boolean: default boolean value of option (0 or 1)

  • integer: 0

  • string: 0

  • color: 0

  • enum: 0

Esempio in C:

struct t_config_option *option = weechat_config_get ("plugin.section.option");
if (weechat_config_boolean_default (option))
{
    /* il valore è "true" */
}
else
{
    /* il valore è "false" */
}

Script (Python):

# prototipo
def config_boolean_default(option: str) -> int: ...

# esempio
option = weechat.config_get("plugin.section.option")
if weechat.config_boolean_default(option):
    # ...

config_integer

Restituisce il valore intero di un’opzione.

Prototipo:

int weechat_config_integer (struct t_config_option *option);

Argomenti:

  • option: puntatore all’opzione

Return value, depending on the option type:

  • boolean: boolean value of option (0 or 1)

  • integer: integer value of option

  • string: 0

  • color: color index

  • enum: integer value of option (index of enum value)

Esempio in C:

struct t_config_option *option = weechat_config_get ("plugin.section.option");
int value = weechat_config_integer (option);

Script (Python):

# prototipo
def config_integer(option: str) -> int: ...

# esempio
option = weechat.config_get("plugin.section.option")
value = weechat.config_integer(option)

config_integer_default

Restituisce il valore intero predefinito di un’opzione.

Prototipo:

int weechat_config_integer_default (struct t_config_option *option);

Argomenti:

  • option: puntatore all’opzione

Return value, depending on the option type:

  • boolean: default boolean value of option (0 or 1)

  • integer: default integer value of option

  • string: 0

  • color: default color index

  • enum: default integer value of option (index of enum value)

Esempio in C:

struct t_config_option *option = weechat_config_get ("plugin.section.option");
int value = weechat_config_integer_default (option);

Script (Python):

# prototipo
def config_integer_default(option: str) -> int: ...

# esempio
option = weechat.config_get("plugin.section.option")
value = weechat.config_integer_default(option)

config_string

Restituisce il valore stringa di un’opzione.

Prototipo:

const char *weechat_config_string (struct t_config_option *option);

Argomenti:

  • option: puntatore all’opzione

Return value, depending on the option type:

  • boolean: "on" if value is true, otherwise "off"

  • integer: NULL

  • string: string value of option

  • color: name of color

  • enum: string value of option

Esempio in C:

struct t_config_option *option = weechat_config_get ("plugin.section.option");
const char *value = weechat_config_string (option);

Script (Python):

# prototipo
def config_string(option: str) -> str: ...

# esempio
option = weechat.config_get("plugin.section.option")
value = weechat.config_string(option)

config_string_default

Restituisce il valore stringa predefinito di un’opzione.

Prototipo:

const char *weechat_config_string_default (struct t_config_option *option);

Argomenti:

  • option: puntatore all’opzione

Return value, depending on the option type:

  • boolean: "on" if default value is true, otherwise "off"

  • integer: NULL

  • string: default string value of option

  • color: name of default color

  • enum: default string value of option

Esempio in C:

struct t_config_option *option = weechat_config_get ("plugin.section.option");
const char *value = weechat_config_string_default (option);

Script (Python):

# prototipo
def config_string_default(option: str) -> str: ...

# esempio
option = weechat.config_get("plugin.section.option")
value = weechat.config_string_default(option)

config_color

Restituisce il valore colore di un’opzione.

Prototipo:

const char *weechat_config_color (struct t_config_option *option);

Argomenti:

  • option: puntatore all’opzione

Return value, depending on the option type:

  • boolean: NULL

  • integer: NULL

  • string: NULL

  • color: name of color

  • enum: NULL

Esempio in C:

struct t_config_option *option = weechat_config_get ("plugin.section.option");
const char *color = weechat_config_color (option);

Script (Python):

# prototipo
def config_color(option: str) -> str: ...

# esempio
option = weechat.config_get("plugin.section.option")
value = weechat.config_color(option)

config_color_default

Restituisce il valore colore predefinito di un’opzione.

Prototipo:

const char *weechat_config_color_default (struct t_config_option *option);

Argomenti:

  • option: puntatore all’opzione

Return value, depending on the option type:

  • boolean: NULL

  • integer: NULL

  • string: NULL

  • color: name of default color

  • enum: NULL

Esempio in C:

struct t_config_option *option = weechat_config_get ("plugin.section.option");
const char *color = weechat_config_color_default (option);

Script (Python):

# prototipo
def config_color_default(option: str) -> str: ...

# esempio
option = weechat.config_get("plugin.section.option")
value = weechat.config_color_default(option)

config_enum

WeeChat ≥ 4.1.0.

Return enum value of option, as integer.

Prototype:

int weechat_config_enum (struct t_config_option *option);

Arguments:

  • option: option pointer

Return value, depending on the option type:

  • boolean: boolean value of option (0 or 1)

  • integer: integer value of option

  • string: 0

  • color: color index

  • enum: integer value of option (index of enum value)

C example:

struct t_config_option *option = weechat_config_get ("plugin.section.option");
int value = weechat_config_enum (option);

Script (Python):

# prototype
def config_enum(option: str) -> int: ...

# example
option = weechat.config_get("plugin.section.option")
value = weechat.config_enum(option)

config_enum_default

WeeChat ≥ 4.1.0.

Return default enum value of option, as integer.

Prototype:

int weechat_config_enum_default (struct t_config_option *option);

Arguments:

  • option: option pointer

Return value, depending on the option type:

  • boolean: default boolean value of option (0 or 1)

  • integer: default integer value of option

  • string: 0

  • color: default color index

  • enum: integer value of option (index of enum value)

C example:

struct t_config_option *option = weechat_config_get ("plugin.section.option");
int value = weechat_config_enum_default (option);

Script (Python):

# prototype
def config_enum_default(option: str) -> int: ...

# example
option = weechat.config_get("plugin.section.option")
value = weechat.config_enum_default(option)

config_write_option

Scrive una riga nel file di configurazione con l’opzione ed il suo valore (questa funzione dovrebbe essere chiamata solo nelle callback "write" o "write_default" per una sezione).

Prototipo:

void weechat_config_write_option (struct t_config_file *config_file,
                                  struct t_config_option *option);

Argomenti:

  • config_file: puntatore al file di configurazione

  • option: puntatore all’opzione

Esempio in C:

int
my_section_write_cb (const void *pointer, void *data,
                     struct t_config_file *config_file,
                     const char *section_name)
{
    weechat_config_write_line (config_file, "my_section", NULL);

    weechat_config_write_option (config_file, option);

    return WEECHAT_RC_OK;
}

Script (Python):

# prototipo
def config_write_option(config_file: str, option: str) -> int: ...

# esempio
def my_section_write_cb(data: str, config_file: str, section_name: str) -> int:
    weechat.config_write_line(config_file, "my_section", "")
    weechat.config_write_option(config_file, option)
    return weechat.WEECHAT_RC_OK

config_write_line

Scrive una riga nel file di configurazione (questa funzione dovrebbe essere chiamata solo nelle callback "write" o "write_default" per una sezione).

Prototipo:

void weechat_config_write_line (struct t_config_file *config_file,
                                const char *option_name,
                                const char *value, ...);

Argomenti:

  • config_file: puntatore al file di configurazione

  • option_name: nome dell’opzione

  • value: valore (se NULL, allora la riga con il nome della sezione viene scritto, ad esempio: "[section]")

Esempio in C:

int
my_section_write_cb (const void *pointer, void *data,
                     struct t_config_file *config_file,
                     const char *section_name)
{
    weechat_config_write_line (config_file, "my_section", NULL);

    weechat_config_write_line (config_file, "option", "%s;%d",
                               "value", 123);

    return WEECHAT_RC_OK;
}

Script (Python):

# prototipo
def config_write_line(config_file: str, option_name: str, value: str) -> int: ...

# esempio
def my_section_write_cb(data: str, config_file: str, section_name: str) -> int:
    weechat.config_write_line(config_file, "my_section", "")
    weechat.config_write_line(config_file, "option", "value")
    return weechat.WEECHAT_RC_OK

config_write

Scrive il file di configurazione su disco.

Prototipo:

int weechat_config_write (struct t_config_file *config_file);

Argomenti:

  • config_file: puntatore al file di configurazione

Valore restituito:

  • WEECHAT_CONFIG_WRITE_OK se la configurazione è stata scritta

  • WEECHAT_CONFIG_WRITE_MEMORY_ERROR se non c’è memoria sufficiente

  • WEECHAT_CONFIG_WRITE_ERROR se si è verificato un altro errore

Esempio in C:

switch (weechat_config_write (config_file))
{
    case WEECHAT_CONFIG_WRITE_OK:
        /* ... */
        break;
    case WEECHAT_CONFIG_WRITE_MEMORY_ERROR:
        /* ... */
        break;
    case WEECHAT_CONFIG_WRITE_ERROR:
        /* ... */
        break;
}

Script (Python):

# prototipo
def config_write(config_file: str) -> int: ...

# esempio
rc = weechat.config_write(config_file)
if rc == weechat.WEECHAT_CONFIG_WRITE_OK:
    # ...
elif rc == weechat.WEECHAT_CONFIG_WRITE_MEMORY_ERROR:
    # ...
elif rc == weechat.WEECHAT_CONFIG_WRITE_ERROR:
    # ...

config_read

Legge il file di configurazione da disco.

Prototipo:

int weechat_config_read (struct t_config_file *config_file);

Argomenti:

  • config_file: puntatore al file di configurazione

Valore restituito:

  • WEECHAT_CONFIG_READ_OK se la configurazione è stata caricata

  • WEECHAT_CONFIG_READ_MEMORY_ERROR se non c’è memoria sufficiente

  • WEECHAT_CONFIG_READ_FILE_NOT_FOUND se il file non è stato trovato

Esempio in C:

switch (weechat_config_read (config_file))
{
    case WEECHAT_CONFIG_READ_OK:
        /* ... */
        break;
    case WEECHAT_CONFIG_READ_MEMORY_ERROR:
        /* ... */
        break;
    case WEECHAT_CONFIG_READ_FILE_NOT_FOUND:
        /* ... */
        break;
}

Script (Python):

# prototipo
def config_read(config_file: str) -> int: ...

# esempio
rc = weechat.config_read(config_file)
if rc == weechat.WEECHAT_CONFIG_READ_OK:
    # ...
elif rc == weechat.WEECHAT_CONFIG_READ_MEMORY_ERROR:
    # ...
elif rc == weechat.WEECHAT_CONFIG_READ_FILE_NOT_FOUND:
    # ...

config_reload

Ricarica il file di configurazione da disco.

Prototipo:

int weechat_config_reload (struct t_config_file *config_file);

Argomenti:

  • config_file: configuration file pointer

Valore restituito:

  • WEECHAT_CONFIG_READ_OK se il file di configurazione è stato ricaricato

  • WEECHAT_CONFIG_READ_MEMORY_ERROR se non c’è memoria sufficiente

  • WEECHAT_CONFIG_READ_FILE_NOT_FOUND se il file non è stato trovato

Esempio in C:

switch (weechat_config_reload (config_file))
{
    case WEECHAT_CONFIG_READ_OK:
        /* ... */
        break;
    case WEECHAT_CONFIG_READ_MEMORY_ERROR:
        /* ... */
        break;
    case WEECHAT_CONFIG_READ_FILE_NOT_FOUND:
        /* ... */
        break;
}

Script (Python):

# prototipo
def config_reload(config_file: str) -> int: ...

# esempio
rc = weechat.config_reload(config_file)
if rc == weechat.WEECHAT_CONFIG_READ_OK:
    # ...
elif rc == weechat.WEECHAT_CONFIG_READ_MEMORY_ERROR:
    # ...
elif rc == weechat.WEECHAT_CONFIG_READ_FILE_NOT_FOUND:
    # ...

config_option_free

Libera un’opzione.

Prototipo:

void weechat_config_option_free (struct t_config_option *option);

Argomenti:

  • option: puntatore all’opzione

Esempio in C:

weechat_config_option_free (option);

Script (Python):

# prototipo
def config_option_free(option: str) -> int: ...

# esempio
weechat.config_option_free(option)

config_section_free_options

Libera tutte le opzioni in una sessione.

Prototipo:

void weechat_config_section_free_options (struct t_config_section *section);

Argomenti:

  • section: puntatore alla sezione

Esempio in C:

weechat_config_section_free_options (section);

Script (Python):

# prototipo
def config_section_free_options(section: str) -> int: ...

# esempio
weechat.config_section_free_options(section)

config_section_free

Libera una sezione.

Prototipo:

void weechat_config_section_free (struct t_config_section *section);

Argomenti:

  • section: puntatore alla sezione

Esempio in C:

weechat_config_section_free (section);

Script (Python):

# prototipo
def config_section_free(section: str) -> int: ...

# esempio
weechat.config_section_free(section)

config_free

Libera un file di configurazione.

Prototipo:

void weechat_config_free (struct t_config_file *config_file);

Argomenti:

  • config_file: puntatore al file di configurazione

Esempio in C:

weechat_config_free (config_file);

Script (Python):

# prototipo
def config_free(config_file: str) -> int: ...

# esempio
weechat.config_free(config_file)

config_get

Cerca un’opzione con il nome completo.

Prototipo:

struct t_config_option *weechat_config_get (const char *option_name);

Argomenti:

  • option_name: nome completo dell’opzione (formato: "file.section.option")

Valore restituito:

  • puntatore all’opzione trovata, NULL se non trovata

Esempio in C:

struct t_config_option *option = weechat_config_get ("weechat.look.item_time_format");

Script (Python):

# prototipo
def config_get(option_name: str) -> str: ...

# esempio
option = weechat.config_get("weechat.look.item_time_format")

config_get_plugin

Cerca un’opzione nei file di configurazione dei plugin (plugins.conf).

Prototipo:

const char *weechat_config_get_plugin (const char *option_name);

Argomenti:

  • option_name: nome dell’opzione, WeeChat aggiungerà il prefisso "plugins.var.xxx." (dove "xxx" è il nome del plugin corrente)

Valore restituito:

  • valore dell’opzione trovata, NULL se non trovata

Esempio in C:

/* se il plugin corrente è "test", allora cerca il valore
   dell'opzione "plugins.var.test.option" nel file plugins.conf */
char *value = weechat_config_get_plugin ("option");

Script (Python):

# prototipo
def config_get_plugin(option_name: str) -> str: ...

# esempio
value = weechat.config_get_plugin("option")

config_is_set_plugin

Verifica se un’opzione è impostata nel file di configurazione dei plugin (plugins.conf).

Prototipo:

int weechat_config_is_set_plugin (const char *option_name);

Argomenti:

  • option_name: nome dell’opzione, WeeChat aggiunge il prefisso "plugins.var.xxx." (dove "xxx" è il nome del plugin corrente)

Valore restituito:

  • 1 se l’opzione è impostata, 0 se l’opzione non esiste

Esempio in C:

if (weechat_config_is_set_plugin ("option"))
{
    /* l'opzione è impostata */
}
else
{
    /* l'opzione non esiste */
}

Script (Python):

# prototipo
def config_is_set_plugin(option_name: str) -> int: ...

# esempio
if weechat.config_is_set_plugin("option"):
    # l'opzione è impostata
    # ...
else:
    # l'opzione non esiste
    # ...

config_set_plugin

Imposta il nuovo valore per l’opzione nel file di configurazione dei plugin (plugins.conf).

Prototipo:

int weechat_config_set_plugin (const char *option_name, const char *value);

Argomenti:

  • option_name: nome dell’opzione, WeeChat aggiunge il prefisso "plugins.var.xxx." (dove "xxx" è il nome del plugin corrente)

  • value: new value for option

Valore restituito:

  • WEECHAT_CONFIG_OPTION_SET_OK_CHANGED se il valore dell’opzione è stato modificato

  • WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE se il valore non è cambiato

  • WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND se l’opzione non è stata trovata

  • WEECHAT_CONFIG_OPTION_SET_ERROR in caso di errore

Esempio in C:

switch (weechat_config_set_plugin ("option", "test_value"))
{
    case WEECHAT_CONFIG_OPTION_SET_OK_CHANGED:
        /* ... */
        break;
    case WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE:
        /* ... */
        break;
    case WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND:
        /* ... */
        break;
    case WEECHAT_CONFIG_OPTION_SET_ERROR:
        /* ... */
        break;
}

Script (Python):

# prototipo
def config_set_plugin(option_name: str, value: str) -> int: ...

# esempio
rc = weechat.config_set_plugin("option", "test_value")
if rc == weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED:
    # ...
elif rc == weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE:
    # ...
elif rc == weechat.WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND:
    # ...
elif rc == weechat.WEECHAT_CONFIG_OPTION_SET_ERROR:
    # ...

config_set_desc_plugin

WeeChat ≥ 0.3.5.

Imposta la descrizione per l’opzione nel file di configurazione dei plugin (plugins.conf).

Prototipo:

void weechat_config_set_desc_plugin (const char *option_name,
                                     const char *description);

Argomenti:

  • option_name: nome dell’opzione, WeeChat aggiungerà il prefisso "plugins.desc.xxx." (dove "xxx" è il nome del plugin corrente)

  • description: descrizione per l’opzione

Non è un problema se l’opzione (plugins.var.xx.option_name) non esiste. Una futura creazione dell’opzione con questo nome userà questa descrizione.

Esempio in C:

weechat_config_set_desc_plugin ("option", "description of option");

Script (Python):

# prototipo
def config_set_desc_plugin(option_name: str, description: str) -> int: ...

# esempio
version = weechat.info_get("version_number", "") or 0
if int(version) >= 0x00030500:
    weechat.config_set_desc_plugin("option", "description of option")

config_unset_plugin

Disattiva l’opzione nel file di configurazione dei plugin (plugins.conf).

Prototipo:

int weechat_config_unset_plugin (const char *option_name);

Argomenti:

  • option_name: nome dell’opzione, WeeChat aggiunge il prefisso "plugins.var.xxx." (dove xxx è il nome del plugin corrente)

Valore restituito:

  • WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET se il valore dell’opzione non è stato resettato

  • WEECHAT_CONFIG_OPTION_UNSET_OK_RESET se il valore dell’opzione è stato resettato

  • WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED se l’opzione è stata rimossa

  • WEECHAT_CONFIG_OPTION_UNSET_ERROR in caso di errore

Esempio in C:

switch (weechat_config_unset_plugin ("option"))
{
    case WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET:
        /* ... */
        break;
    case WEECHAT_CONFIG_OPTION_UNSET_OK_RESET:
        /* ... */
        break;
    case WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED:
        /* ... */
        break;
    case WEECHAT_CONFIG_OPTION_UNSET_ERROR:
        /* ... */
        break;
}

Script (Python):

# prototipo
def config_unset_plugin(option_name: str) -> int: ...

# esempio
rc = weechat.config_unset_plugin("option")
if rc == weechat.WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET:
    # ...
elif rc == weechat.WEECHAT_CONFIG_OPTION_UNSET_OK_RESET:
    # ...
elif rc == weechat.WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED:
    # ...
elif rc == weechat.WEECHAT_CONFIG_OPTION_UNSET_ERROR:
    # ...

3.12. Combinazione tasti

Funzioni per le combinazioni dei tasti.

key_bind

WeeChat ≥ 0.3.6, updated in 1.8.

Aggiunge una nuova combinazione tasto.

A differenza del comando /key bind, questa funzione non cambia mai una combinazione tasti esistente, ma ne vengono create di nuove. Per rimuovere una combinazione tasti, usare key_unbind.

Prototipo:

int weechat_key_bind (const char *context, struct t_hashtable *keys);

Argomenti:

  • context: contesto per i tasti:

    • default: contesto default (azioni comuni)

    • search: contesto search (quando si cerca testo nel buffer)

    • cursor: movimento libero del cursore sullo schermo

    • mouse: tasti per gli eventi del mouse

  • keys: hashtable with key bindings; it can contain following special keys:

    • __quiet: do not display the keys added in core buffer (WeeChat ≥ 1.8)

Valore restituito:

  • numero delle combinazioni tasti aggiunte

Esempio in C:

struct t_hashtable *keys = weechat_hashtable_new (8,
                                                  WEECHAT_HASHTABLE_STRING,
                                                  WEECHAT_HASHTABLE_STRING,
                                                  NULL,
                                                  NULL);
if (keys)
{
    weechat_hashtable_set (keys, "@chat(plugin.buffer):button1", "hsignal:test_mouse");
    weechat_hashtable_set (keys, "@chat(plugin.buffer):wheelup", "/mycommand up");
    weechat_hashtable_set (keys, "@chat(plugin.buffer):wheeldown", "/mycommand down");
    weechat_key_bind ("mouse", keys);
    weechat_hashtable_free (keys);
}

Script (Python):

# prototipo
def key_bind(context: str, keys: Dict[str, str]) -> int: ...

# esempio
keys = {"@chat(python.test):button1": "hsignal:test_mouse",
        "@chat(python.test):wheelup": "/mycommand up",
        "@chat(python.test):wheeldown": "/mycommand down"}
weechat.key_bind("mouse", keys)

key_unbind

WeeChat ≥ 0.3.6, updated in 2.0.

Rimuove una o più associazioni tasti.

Alla chiamata di questa funzione, assicurarsi che non venga rimossa una combinazione tasti definita dall’utente.

Prototipo:

int weechat_key_unbind (const char *context, const char *key);

Argomenti:

  • context: contesto per i tasti (consultare key_bind)

  • key: tasto da rimuovere o un valore speciale "area:XXX" per rimuovere tutti i tasti che hanno XXX come prima o seconda area; if the key starts with "quiet:", the keys removed are not displayed in core buffer (WeeChat ≥ 2.0).

Valore restituito:

  • numero di combinazioni tasti rimosse

Esempio in C:

/* rimuove un singolo tasto */
weechat_key_unbind ("mouse", "@chat(plugin.buffer):button1");

/* rimuove tutti i tasti con la zona "chat(plugin.buffer)" */
weechat_key_unbind ("mouse", "area:chat(plugin.buffer)");

Script (Python):

# prototipo
def key_unbind(context: str, key: str) -> int: ...

# esempi

# rimuove un singolo tasto
weechat.key_unbind("mouse", "@chat(plugin.buffer):button1")

# rimuove tutti i tasti con la zona "chat(python.test)"
weechat.key_unbind("mouse", "area:chat(python.test)")

3.13. Visualizzazione

Funzioni per visualizzare il testo nei buffer.

prefix

Restituisce un prefisso.

Prototipo:

const char *weechat_prefix (const char *prefix);

Argomenti:

  • prefix: nome del prefisso, see table below

Valore restituito:

  • valore del prefisso (stringa con prefisso e codici colori), stringa vuota se il prefisso non è stato trovato

List of prefixes:

Prefisso Valore Colore Descrizione

error

=!=

giallo

Messaggio di errore.

network

--

magenta

Messaggio dalla rete.

action

*

bianco

Azione automatica.

join

-->

verde chiaro

Qualcuno entra nella chat corrente.

quit

<--

rosso chiaro

Qualcuno lascia la chat corrente.

Valori e colori possono essere personalizzati con il comando /set.

Esempio in C:

weechat_printf (NULL, "%sQuesto è un errore...", weechat_prefix ("error"));

Script (Python):

# prototipo
def prefix(prefix: str) -> str: ...

# esempio
weechat.prnt("", "%sQuesto è un errore..." % weechat.prefix("error"))

color

Restituisce una codice colore stringa da visualizzare.

Prototipo:

const char *weechat_color (const char *color_name);

Argomenti:

  • color_name: nome del colore, uno di:

    • WeeChat color option name (from weechat.color.xxx), for example chat_delimiters

    • option name (format: file.section.option), for example irc.color.message_quit (WeeChat ≥ 1.2)

    • colore con attributi/sfondo opzionali (vedi sotto)

    • attributo:

      • blink: set blink

      • -blink: remove blink

      • dim: set "dim" (half bright)

      • -dim: remove "dim" (half bright)

      • bold: imposta grassetto

      • -bold: rimuove grassetto

      • reverse: imposta inverso

      • -reverse: rimuove inverso

      • italic: imposta corsivo

      • -italic: rimuove corsivo

      • underline: imposta sottolineato

      • -underline: rimuove sottolineato

      • emphasis: toggle the emphasis for text (note: this should be used only in bars, because WeeChat uses text emphasis when searching text in buffer) (WeeChat ≥ 0.4.2)

    • nome colore della barra:

      • bar_fg: colore di primo piano della barra

      • bar_delim: colore dei delimitatori della barra

      • bar_bg: colore di sfondo della barra

    • reset:

      • reset: ripristina colore ed attributi

      • resetcolor: ripristina colore (mantiene attributi) (WeeChat ≥ 0.3.6)

Il formato del colore è: attributi (opzionale) + nome colore +",sfondo" (opzionale). Gli attributi possibili sono:

  • %: blink

  • .: "dim" (half bright)

  • * : testo in grassetto

  • ! : video inverso

  • / : corsivo

  • _ : testo sottolineato

  • | : mantiene attributi: non ripristina grassetto/inverso/corsivo/sottolineato al cambio di colore (WeeChat ≥ 0.3.6)

Esempi:

  • yellow : giallo

  • _green : verde sottolineato

  • *214 : arancione grassetto

  • yellow,red : giallo su rosso

  • |cyan : ciano (e mantiene qualsiasi attributo impostato in precedenza)

Valore restituito:

  • stringa con il codice colore, o una stringa vuota se non trovata

Esempio in C:

weechat_printf (NULL, "Color: %sblue %sdefault color %syellow on red",
                weechat_color ("blue"),
                weechat_color ("chat"),
                weechat_color ("yellow,red"));

Script (Python):

# prototipo
def color(color_name: str) -> str: ...

# esempio
weechat.prnt("", "Color: %sblue %sdefault color %syellow on red"
    % (weechat.color("blue"), weechat.color("chat"), weechat.color("yellow,red")))

printf

Visualizza un messaggio su un buffer.

Prototipo:

void weechat_printf (struct t_gui_buffer *buffer, const char *message, ...);

This function is a shortcut for function printf_datetime_tags.
These two calls give exactly same result:

weechat_printf (buffer, "message");
weechat_printf_datetime_tags (buffer, 0, 0, NULL, "message");

Argomenti:

  • buffer: puntatore al buffer, se NULL il messaggio viene visualizzato sul buffer di WeeChat

  • message: messaggio da visualizzare

La prima tabulazione nel messaggio ("\t") è usata per separare il prefisso dal messaggio.
Se il proprio messaggio ha alcune tabulazioni e non si vuole il prefisso, allora bisogna utilizzare uno spazio, una tabulazione, poi il messaggio (consultare l’esempio successivo): ciò disabilita il prefisso (lo spazio prima della tabulazione non verrà mostrato).
With two tabs ("\t") at beginning of message, time will not be displayed and message will have no alignment at all. Moreover, the date in message will be set to 0.

Esempio in C:

weechat_printf (NULL, "Benvenuto sul buffer di WeeChat");
weechat_printf (buffer, "Benvenuto su questo buffer");
weechat_printf (buffer, "%sQuesto è un errore!", weechat_prefix ("error"));
weechat_printf (buffer, " \tMessaggio senza prefisso ma con \t alcune \t tabulazioni");
weechat_printf (buffer, "\t\tMessage without time/alignment");
weechat_printf (buffer, "\t\t");  /* empty line (without time) */

Script (Python):

# prototipo
def prnt(buffer: str, message: str) -> int: ...

# esempio
weechat.prnt("", "Benvenuto sul buffer di WeeChat")
weechat.prnt(buffer, "Benvenuto su questo buffer")
weechat.prnt(buffer, "%sQuesto è un errore!" % weechat.prefix("error"))
weechat.prnt(buffer, " \tMessaggio senza prefisso ma con \t alcune \t tabulazioni")
weechat.prnt(buffer, "\t\tMessage without time/alignment")
weechat.prnt(buffer, "\t\t")  # empty line (without time)
La funzione è chiamata "print" negli script ("prnt" in Python).

printf_date_tags

Visualizza un messaggio sul buffer, usando tag e data personalizzati.

Prototipo:

void weechat_printf_date_tags (struct t_gui_buffer *buffer, time_t date,
                               const char *tags, const char *message, ...);

This function is a shortcut for function printf_datetime_tags.
These two calls give exactly same result:

weechat_printf_date_tags (buffer, 0, NULL, "message");
weechat_printf_datetime_tags (buffer, 0, 0, NULL, "message");

Argomenti:

  • buffer: puntatore al buffer, se NULL il messaggio viene visualizzato sul buffer di WeeChat

  • date: data per il messaggio (0 indica data/ora corrente)

  • tags: lista di tag separati da virgole (NULL means no tags)

  • message: messaggio da visualizzare

See the WeeChat user’s guide / Lines tags  for a list of commonly used tags in WeeChat.

Esempio in C:

weechat_printf_date_tags (NULL, time (NULL) - 120, "notify_message",
                          "Messaggio 2 minuti fa, con tag 'notify_message'");

Script (Python):

# prototipo
def prnt_date_tags(buffer: str, date: int, tags: str, message: str) -> int: ...

# esempio
time = int(time.time())
weechat.prnt_date_tags("", time - 120, "notify_message",
    "Messaggio 2 minuti fa, con tag 'notify_message'")
La funzione è chiamata "print_date_tags" negli script ("prnt_date_tags" in Python).

printf_datetime_tags

WeeChat ≥ 4.2.0.

Display a message on a buffer, using a custom date/time (with microseconds) and tags.

Prototipo:

void weechat_printf_datetime_tags (struct t_gui_buffer *buffer, time_t date,
                                   int date_usec, const char *tags, const char *message, ...);

Argomenti:

  • buffer: puntatore al buffer, se NULL il messaggio viene visualizzato sul buffer di WeeChat

  • date: data per il messaggio (0 indica data/ora corrente)

  • date_usec: microseconds of date (between 0 and 999999)

  • tags: lista di tag separati da virgole (NULL means no tags)

  • message: messaggio da visualizzare

See the WeeChat user’s guide / Lines tags  for a list of commonly used tags in WeeChat.

Esempio in C:

struct timeval tv_now;

gettimeofday (&tv_now, NULL);
weechat_printf_datetime_tags (NULL, tv_now.tv_sec - 120, tv_now.tv_usec,
                              "notify_message",
                              "Messaggio 2 minuti fa, con tag 'notify_message'");

Script (Python):

# prototipo
def prnt_datetime_tags(buffer: str, date: int, date_usec: int, tags: str, message: str) -> int: ...

# esempio
now = time.time()
time_sec = int(now)
time_usec = int((now * 1000000) % 1000000)
weechat.prnt_datetime_tags("", time_sec - 120, time_usec, "notify_message",
                           "Messaggio 2 minuti fa, con tag 'notify_message'")
La funzione è chiamata "print_datetime_tags" negli script ("prnt_datetime_tags" in Python).

printf_y

Visualizza un messaggio sulla riga di un buffer con contenuto libero.

Prototipo:

void weechat_printf_y (struct t_gui_buffer *buffer, int y, const char *message, ...);

This function is a shortcut for function printf_y_datetime_tags.
These two calls give exactly same result:

weechat_printf_y (buffer, 0, "message");
weechat_printf_y_datetime_tags (buffer, 0, 0, 0, NULL, "message");

Argomenti:

  • buffer: puntatore al buffer

  • y: numero di riga (la prima riga è 0); a negative value adds a line after last line displayed: absolute value of y is the number of lines after last line (for example -1 is immediately after last line, -2 is 2 lines after last line) (WeeChat ≥ 1.0)

  • message: messaggio da visualizzare

Esempio in C:

weechat_printf_y (buffer, 2, "Mio messaggio sulla terza riga");

Script (Python):

# prototipo
def prnt_y(buffer: str, y: int, message: str) -> int: ...

# esempio
weechat.prnt_y("", 2, "Mio messaggio sulla terza riga")
La funzione è chiamata "print_y" negli script ("prnt_y in Python).

printf_y_date_tags

WeeChat ≥ 3.5.

Display a message on a line of a buffer with free content, using a custom date and tags.

Prototipo:

void weechat_printf_y_date_tags (struct t_gui_buffer *buffer, int y, time_t date,
                                 const char *tags, const char *message, ...);

This function is a shortcut for function printf_y_datetime_tags.
These two calls give exactly same result:

weechat_printf_y_date_tags (buffer, 0, 0, NULL, "message");
weechat_printf_y_datetime_tags (buffer, 0, 0, 0, NULL, "message");

Argomenti:

  • buffer: puntatore al buffer

  • y: numero di riga (la prima riga è 0); a negative value adds a line after last line displayed: absolute value of y is the number of lines after last line (for example -1 is immediately after last line, -2 is 2 lines after last line)

  • date: data per il messaggio (0 indica data/ora corrente)

  • tags: lista di tag separati da virgole (NULL means no tags)

  • message: messaggio da visualizzare

Esempio in C:

weechat_printf_y_date_tags (buffer, 2, 0, "my_tag", "My message on third line with a tag");

Script (Python):

# prototipo
def prnt_y_date_tags(buffer: str, y: int, date: int, tags: str, message: str) -> int: ...

# esempio
weechat.prnt_y_date_tags("", 2, 0, "my_tag", "My message on third line with a tag")
La funzione è chiamata "print_y_date_tags" negli script ("prnt_y_date_tags in Python).

printf_y_datetime_tags

WeeChat ≥ 4.2.0.

Display a message on a line of a buffer with free content, using a custom date/time (with microseconds) and tags.

Prototipo:

void weechat_printf_y_datetime_tags (struct t_gui_buffer *buffer, int y, time_t date,
                                     int date_usec, const char *tags, const char *message, ...);

Argomenti:

  • buffer: puntatore al buffer

  • y: numero di riga (la prima riga è 0); a negative value adds a line after last line displayed: absolute value of y is the number of lines after last line (for example -1 is immediately after last line, -2 is 2 lines after last line)

  • date: data per il messaggio (0 indica data/ora corrente)

  • date_usec: microseconds of date (between 0 and 999999)

  • tags: lista di tag separati da virgole (NULL means no tags)

  • message: messaggio da visualizzare

Esempio in C:

weechat_printf_y_datetime_tags (buffer, 2, 0, 0, "my_tag", "My message on third line with a tag");

Script (Python):

# prototipo
def prnt_y_datetime_tags(buffer: str, y: int, date: int, date_usec: int, tags: str, message: str) -> int: ...

# esempio
weechat.prnt_y_datetime_tags("", 2, 0, 0, "my_tag", "My message on third line with a tag")
La funzione è chiamata "print_y_datetime_tags" negli script ("prnt_y_datetime_tags in Python).

log_printf

Scrive un messaggio nel file di log di WeeChat (weechat.log).

Prototipo:

void weechat_log_printf (const char *message, ...);

Argomenti:

  • message: messaggio da scrivere

Esempio in C:

weechat_log_printf ("Mio messaggio nel file di log");

Script (Python):

# prototipo
def log_print(message: str) -> int: ...

# esempio
weechat.log_print("Mio messaggio nel file di log")
La funzione è chiamata "log_print" negli script.

3.14. Hook

Priorità degli hook

WeeChat ≥ 0.3.4.

In alcuni hook è possibile impostare una priorità. Un hook con priorità maggiore si trova all’inizio della lista, in modo da poter essere eseguita prima di altri. Può risultare utile per i modificatori, data l’importanza nell’ordine di esecuzione.

Per impostare la priorità, è necessario usare questa sintassi per gli argomenti dove è consentita la priorità: nnn|nome dove nnn è un intero non negativo con la priorità e nome è il nome per l’argomenti (la priorità non compare nel nome, viene rimossa automaticamente dalla stringa).
Only a single priority per hook is allowed.

La priorità predefinita è 1000.

C examples:

/* hook per il modificatore con priorità = 2000 */
/* high priority: called before other modifier calbacks */
weechat_hook_modifier ("2000|input_text_display", &modifier_cb, NULL, NULL);

/* hook two signals with priority = 3000 */
/* high priority: called before other signal callbacks */
weechat_hook_signal ("3000|quit;upgrade", &signal_cb, NULL, NULL);

/* hook lines printed in formatted buffers with priority = 500 */
/* low priority: called after other line callbacks */
weechat_hook_line ("500|formatted", "*", NULL, &line_cb, NULL, NULL);

I tipi di hook che seguono consentono la priorità:

hook_command

Updated in 1.5.

Hook su un comando.

Prototipo:

struct t_hook *weechat_hook_command (const char *command,
                                     const char *description,
                                     const char *args,
                                     const char *args_description,
                                     const char *completion,
                                     int (*callback)(const void *pointer,
                                                     void *data,
                                                     struct t_gui_buffer *buffer,
                                                     int argc,
                                                     char **argv,
                                                     char **argv_eol),
                                     const void *callback_pointer,
                                     void *callback_data);

Argomenti:

  • command: nome del comando (a priority is allowed before the command, see note about priority)

  • description: descrizione per il comando (visualizzata con /help comando)

  • args: argomenti per il comando (visualizzati con /help command)

  • args_description: descrizione degli argomenti (visualizzata con /help command)

  • completion: modello di completamento per il comando:: elenco di completamenti per ogni argomento, separati da spazio. Sono possibili più completamenti sono possibili per un singolo argomento, separati da |. Più modelli sono possibili per lo stesso comando, separati da ||.

  • callback: funzione chiamata quando viene utilizzato il comando, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • struct t_gui_buffer *buffer: buffer quando il comando viene eseguito

    • int argc: numero di argomenti forniti per un comando

    • char **argv: argomenti forniti per un comando

    • char **argv_eol: argomenti forniti per un comando (fino a fine riga per ogni argomento)

    • valore restituito:

      • WEECHAT_RC_OK

      • WEECHAT_RC_ERROR

  • callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_data: puntatore fornito dalla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the hook is deleted

I codici predefiniti per il completamento sono:

Plugin Nome Descrizione

alias

alias

elenco di alias

alias

alias_value

valore dell’alias

buflist

buflist_items

buflist bar items

buflist

buflist_items_used

buflist bar items used (according to option buflist.look.use_items)

exec

exec_commands_ids

ids (numbers and names) of executed commands

fset

fset_options

configuration files, sections, options and words of options

guile

guile_script

elenco degli script

irc

irc_channel

canale IRC corrente

irc

irc_channel_nicks_hosts

nick e host del canale IRC corrente

irc

irc_channel_topic

argomento del canale IRC attivo

irc

irc_channels

canali su tutti i server IRC

irc

irc_channels_autojoin

channels automatically joined on the current server (option "autojoin")

irc

irc_ignores_numbers

numero di ignore definiti

irc

irc_modelist_masks

modelist masks of current IRC channel; required argument: modelist mode

irc

irc_modelist_numbers

modelist numbers of current IRC channel; required argument: modelist mode

irc

irc_msg_kick

default kick message

irc

irc_msg_part

messaggio di uscita predefinito per il canale IRC

irc

irc_notify_nicks

nick nella lista notifiche

irc

irc_privates

privati su tutti i server IRC

irc

irc_raw_filters

filters for irc raw buffer

irc

irc_server

server IRC corrente

irc

irc_server_channels

canali sul server IRC corrente

irc

irc_server_nick

nick sul server IRC corrente

irc

irc_server_nicks

nick su tutti i canali del server IRC corrente

irc

irc_server_prefix_modes_filter

arguments to filter by prefix mode (for example: "-o", "-h", "-v", "-*")

irc

irc_server_privates

privati sul server IRC corrente

irc

irc_servers

server IRC (nomi interni)

irc

nick

nick del canale IRC corrente

lua

lua_script

elenco degli script

perl

perl_script

elenco degli script

php

php_script

elenco degli script

python

python_script

elenco degli script

relay

relay_free_port

prima porta libera per il plugin relay

relay

relay_protocol_name

protocollo.nome possibile per il plugin relay

relay

relay_relays

protocollo.nome dei relay correnti per il plugin relay

ruby

ruby_script

elenco degli script

script

script_extensions

list of script extensions

script

script_files

file nella directory degli script

script

script_languages

list of script languages

script

script_scripts

elenco degli script nel repository

script

script_scripts_installed

elenco degli script installati (dal repository)

script

script_tags

tag degli script nel repository

spell

spell_dicts

list of installed dictionaries

spell

spell_langs

list of all languages supported

tcl

tcl_script

elenco degli script

trigger

trigger_add_arguments

arguments for command that adds a trigger: trigger name, hooks, hook arguments, hook conditions, hook regex, hook command, hook return code, post actions

trigger

trigger_hook_arguments

default arguments for a hook

trigger

trigger_hook_command

default command for a hook

trigger

trigger_hook_conditions

default conditions for a hook

trigger

trigger_hook_rc

default return codes for hook callback

trigger

trigger_hook_regex

default regular expression for a hook

trigger

trigger_hooks

hooks for triggers

trigger

trigger_hooks_filter

hooks for triggers (for filter in monitor buffer)

trigger

trigger_names

triggers

trigger

trigger_names_default

default triggers

trigger

trigger_names_disabled

disabled triggers

trigger

trigger_names_enabled

enabled triggers

trigger

trigger_option_value

value of a trigger option

trigger

trigger_options

options for triggers

trigger

trigger_post_action

trigger post actions

weechat

bars_names

nomi delle barre

weechat

bars_options

opzioni per le barre

weechat

buffer_local_variable_value

value of a buffer local variable

weechat

buffer_local_variables

buffer local variables

weechat

buffer_properties_get

proprietà che possono essere lette su un buffer

weechat

buffer_properties_set

proprietà che possono essere impostate su un buffer

weechat

buffer_properties_setauto

properties that can be automatically set on a buffer

weechat

buffers_names

nomi dei buffer

weechat

buffers_numbers

numeri dei buffer

weechat

buffers_plugins_names

nomi dei buffer (inclusi i nomi dei plugin)

weechat

colors

color names

weechat

commands

commands (weechat and plugins); optional argument: prefix to add before the commands

weechat

config_files

file di configurazione

weechat

config_option_values

valori per una opzione di configurazione

weechat

config_options

opzioni di configurazione

weechat

cursor_areas

aree ("chat" o nome barra) per il movimento libero del cursore

weechat

custom_bar_item_add_arguments

arguments for command that adds a custom bar item: item name, conditions, content

weechat

custom_bar_item_conditions

conditions for custom bar item

weechat

custom_bar_item_contents

contents for custom bar item

weechat

custom_bar_items_names

names of custom bar items

weechat

env_value

value of an environment variable

weechat

env_vars

environment variables

weechat

eval_variables

variables that can be used in /eval command

weechat

filename

filename; optional argument: default path (evaluated, see /help eval)

weechat

filters_names

nomi dei filtri

weechat

filters_names_disabled

names of disabled filters

weechat

filters_names_enabled

names of enabled filters

weechat

infolists

nomi degli hook liste info

weechat

infos

nomi degli hook sulle info

weechat

keys_codes

codici tasto

weechat

keys_codes_for_reset

codici tasti che possono essere ripristinati (tasti aggiunti, ridefiniti o rimossi)

weechat

keys_contexts

contesti del tasto

weechat

layouts_names

nomi dei layout

weechat

nicks

nick nella lista nick del buffer corrente

weechat

palette_colors

Tavolozza dei colori

weechat

plugins_commands

commands defined by plugins; optional argument: prefix to add before the commands

weechat

plugins_installed

names of plugins installed

weechat

plugins_names

nomi dei plugin

weechat

proxies_names

nomi dei proxy

weechat

proxies_options

opzioni per i proxy

weechat

secured_data

names of secured data (file sec.conf, section data)

weechat

weechat_commands

weechat commands; optional argument: prefix to add before the commands

weechat

windows_numbers

numeri delle finestre

xfer

nick

nick della chat DCC

Codici speciali:

  • %%command: riutilizza il modello di completamento dal comando command

  • %-: ferma completamento

  • %*: ripete l’ultimo completamento

Valore restituito:

  • puntatore al nuovo hook, NULL in caso di errore

Esempio in C:

int
my_command_cb (const void *pointer, void *data, struct t_gui_buffer *buffer,
               int argc, char **argv, char **argv_eol)
{
    /* ... */
    return WEECHAT_RC_OK;
}

/* questo esempio si ispira al comando /filter */
struct t_hook *my_command_hook =
    weechat_hook_command ("myfilter",
                          "description of myfilter",
                          "[list] | [enable|disable|toggle [name]] | "
                          "[add name plugin.buffer tags regex] | "
                          "[del name|-all]",
                          "description of arguments...",
                          "list"
                          " || enable %(filters_names)"
                          " || disable %(filters_names)"
                          " || toggle %(filters_names)"
                          " || add %(filters_names) %(buffers_plugins_names)|*"
                          " || del %(filters_names)|-all",
                          &my_command_cb, NULL, NULL);

Ad esempio, se il comando chiamato è /comando abc def ghi, allora argv e argv_eol contengono i seguenti valori:

  • argv:

    • argv[0] == "/command"

    • argv[1] == "abc"

    • argv[2] == "def"

    • argv[3] == "ghi"

  • argv_eol:

    • argv_eol[0] == "/command abc def ghi"

    • argv_eol[1] == "abc def ghi"

    • argv_eol[2] == "def ghi"

    • argv_eol[3] == "ghi"

Per gli script, args ha valore "abc def ghi".

Script (Python):

# prototipo
def hook_command(command: str, description: str, args: str, args_description: str,
                 completion: str, callback: str, callback_data: str) -> str: ...

# esempio
def my_command_cb(data: str, buffer: str, args: str) -> int:
    # ...
    return weechat.WEECHAT_RC_OK

hook = weechat.hook_command("myfilter", "descrizione di myfilter",
    "[list] | [enable|disable|toggle [name]] | "
    "[add name plugin.buffer tags regex] | "
    "[del name|-all]",
    "description of arguments...",
    "list"
    " || enable %(filters_names)"
    " || disable %(filters_names)"
    " || toggle %(filters_names)"
    " || add %(filters_names) %(buffers_plugins_names)|*"
    " || del %(filters_names)|-all",
    "my_command_cb", "")

hook_completion

Updated in 1.5.

Hook su un completamento.

Prototipo:

struct t_hook *weechat_hook_completion (const char *completion_item,
                                        const char *description,
                                        int (*callback)(const void *pointer,
                                                        void *data,
                                                        const char *completion_item,
                                                        struct t_gui_buffer *buffer,
                                                        struct t_gui_completion *completion),
                                        const void *callback_pointer,
                                        void *callback_data);

Argomenti:

  • completion_item: nome dell’elemento del completamento, è possibile usare in seguito %(name) in un comando con un hook (argomento completion) (a priority is allowed before the completion item, see note about priority)

  • callback: funzione chiamata quando viene usato l’elemento completamento (l’utente sta completando qualcosa usando questo elemento), argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • const char *completion_item: nome dell’elemento del completamento

    • struct t_gui_buffer *buffer: buffer dove viene eseguito il completamento

    • struct t_gui_completion *completion: struttura usata per aggiungere parole per il completamento (consultare completion_list_add)

    • valore restituito:

      • WEECHAT_RC_OK

      • WEECHAT_RC_ERROR

  • callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_data: puntatore fornito alla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the hook is deleted

I nomi del completamento sono globali (condivisi tra WeeChat e plugin). Si raccomanda pertanto di scegliere un nome con un prefisso unico, come "plugin_xxx" (dove "xxx" è il nome del proprio elemento).
The callback must only call completion functions like completion_list_add and must NOT update the command line.
To update the command line when Tab is pressed, you can use the function hook_command_run with command: /input complete_next (and you must return WEECHAT_RC_OK_EAT if your callback has updated the command line, so that WeeChat will not perform the completion).

Valore restituito:

  • puntatore al nuovo hook, NULL in caso di errore

Esempio in C:

int
my_completion_cb (const void *pointer, void *data, const char *completion_item,
                  struct t_gui_buffer *buffer,
                  struct t_gui_completion *completion)
{
    weechat_completion_list_add (completion, "word1", 0, WEECHAT_LIST_POS_SORT);
    weechat_completion_list_add (completion, "test_word2", 0, WEECHAT_LIST_POS_SORT);
    return WEECHAT_RC_OK;
}

struct t_hook *my_completion_hook = weechat_hook_completion ("plugin_item",
                                                             "my custom completion!",
                                                             &my_completion_cb, NULL, NULL);

Script (Python):

# prototipo
def hook_completion(completion_item: str, description: str, callback: str, callback_data: str) -> str: ...

# esempio
def my_completion_cb(data: str, completion_item: str, buffer: str, completion: str) -> int:
    weechat.completion_list_add(completion, "word1", 0, weechat.WEECHAT_LIST_POS_SORT)
    weechat.completion_list_add(completion, "test_word2", 0, weechat.WEECHAT_LIST_POS_SORT)
    return weechat.WEECHAT_RC_OK

hook = weechat.hook_completion("plugin_item", "my custom completion!",
                               "my_completion_cb", "")

hook_completion_get_string

Novità nella versioe 0.3.4.

Deprecated since WeeChat 2.9 (still there for compatibility).
This function has been replaced by completion_get_string.

hook_completion_list_add

Deprecated since WeeChat 2.9 (still there for compatibility).
This function has been replaced by completion_list_add.

hook_command_run

Updated in 1.5.

Hook su un comando quando eseguito da WeeChat.

Prototipo:

struct t_hook *weechat_hook_command_run (const char *command,
                                         int (*callback)(const void *pointer,
                                                         void *data,
                                                         struct t_gui_buffer *buffer,
                                                         const char *command),
                                         const void *callback_pointer,
                                         void *callback_data);

Argomenti:

  • command: comando su cui eseguire l’hook (wildcard * is allowed) (a priority is allowed before the command, see note about priority)

  • callback: funzione chiamata quando il comando è in esecuzione, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • struct t_gui_buffer *buffer: buffer dove viene eseguito il comando

    • const char *command: il comando eseguito, con i propri argomenti

    • valore restituito:

      • WEECHAT_RC_OK

      • WEECHAT_RC_OK_EAT: il comando non verrà eseguito da WeeChat dopo la callback

      • WEECHAT_RC_ERROR

  • callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_data: puntatore fornito alla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the hook is deleted

Valore restituito:

  • puntatore al nuovo hook, NULL in caso di errore

Esempio in C:

int
my_command_run_cb (const void *pointer, void *data, struct t_gui_buffer *buffer,
                   const char *command)
{
    weechat_printf (NULL, "Sto mangiando il completamento!");
    return WEECHAT_RC_OK_EAT;
}

struct t_hook *my_command_run_hook =
    weechat_hook_command_run ("/input complete*",
                              &my_command_run_cb, NULL, NULL);

Script (Python):

# prototipo
def hook_command_run(command: str, callback: str, callback_data: str) -> str: ...

# esempio
def my_command_run_cb(data: str, buffer: str, command: str) -> int:
    weechat.prnt("", "Sto mangiando il completamento!")
    return weechat.WEECHAT_RC_OK_EAT

hook = weechat.hook_command_run("/input complete*", "my_command_run_cb", "")

hook_timer

Updated in 1.5.

Hook sul timer.

Prototipo:

struct t_hook *weechat_hook_timer (long interval,
                                   int align_second,
                                   int max_calls,
                                   int (*callback)(const void *pointer,
                                                   void *data,
                                                   int remaining_calls),
                                   const void *callback_pointer,
                                   void *callback_data);

Argomenti:

  • interval: intervallo tra due chiamate (millisecondi, 1000 = 1 secondo)

  • align_second: allineamento su un secondo. Per esempio, rrent time is 09:00, if interval = 60000 (60 seconds), and align_second = 60, then timer is called each minute when second is 0

  • max_calls: number of calls to timer (if 0, then timer has no end)

  • callback: function called when time is reached, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • int remaining_calls: remaining calls (-1 if timer has no end)

    • valore restituito:

      • WEECHAT_RC_OK

      • WEECHAT_RC_ERROR

  • callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_data: puntatore fornito alla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the hook is deleted

Valore restituito:

  • puntatore al nuovo hook, NULL in caso di errore

Esempio in C:

int
my_timer_cb (const void *pointer, void *data, int remaining_calls)
{
    /* ... */
    return WEECHAT_RC_OK;
}

/* timer chiamato ogni 20 secondi */
struct t_hook *my_timer_hook =
    weechat_hook_timer (20 * 1000, 0, 0, &my_timer_cb, NULL, NULL);

Script (Python):

# prototipo
def hook_timer(interval: int, align_second: int, max_calls: int, callback: str, callback_data: str) -> str: ...

# esempio
def my_timer_cb(data: str, remaining_calls: int) -> int:
    # ...
    return weechat.WEECHAT_RC_OK

# timer chiamato ogni 20 secondi
hook = weechat.hook_timer(20 * 1000, 0, 0, "my_timer_cb", "")

hook_fd

Updated in 1.3, 1.5, 2.0.

Hook su un descrittore file (file oppure socket).

Prototipo:

struct t_hook *weechat_hook_fd (int fd,
                                int flag_read,
                                int flag_write,
                                int flag_exception,
                                int (*callback)(const void *pointer,
                                                void *data,
                                                int fd),
                                const void *callback_pointer,
                                void *callback_data);

Argomenti:

  • fd: descrittore file

  • flag_read: 1 = cattura l’evento lettura (read), 0 = ignora

  • flag_write: 1 = cattura l’evento scrittura (write), 0 = ignora

  • flag_exception: 1 = cattura l’eccezione evento (event), 0 = ignora (WeeChat ≥ 1.3: this argument is ignored and not used any more)

  • callback: funzione che chiama un evento selezionato che si verifica per un file (o un socket), argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • int fd: descrittore file

    • valore restituito:

      • WEECHAT_RC_OK

      • WEECHAT_RC_ERROR

  • callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_data: puntatore fornito alla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the hook is deleted

Valore restituito:

  • puntatore al nuovo hook, NULL in caso di errore

In scripts, with WeeChat ≥ 2.0, the callback argument fd is an integer (with WeeChat ≤ 1.9, it was a string).
To be compatible with all versions, it is recommended to convert the argument to integer before using it, for example in Python: int(fd).

Esempio in C:

int
my_fd_cb (const void *pointer, void *data, int fd)
{
    /* ... */
    return WEECHAT_RC_OK;
}

int sock = socket (AF_INET, SOCK_STREAM, 0);
/* imposta le opzioni del socket */
/* ... */
struct t_hook *my_fd_hook = weechat_hook_fd (sock, 1, 0, 0, &my_fd_cb, NULL, NULL);

Script (Python):

# prototipo
def hook_fd(fd: int, flag_read: int, flag_write: int, flag_exception: int, callback: str, callback_data: str) -> str: ...

# esempio
def my_fd_cb(data: str, fd: int) -> int:
    # ...
    return weechat.WEECHAT_RC_OK

sock = ...
hook = weechat.hook_fd(sock, 1, 0, 0, "my_fd_cb", "")

hook_process

Updated in 1.5.

Hook su un processo (lanciato con un fork), e cattura l’output.

Since version 0.3.9.2, the shell is not used any more to execute the command. WeeChat makes an automatic split of command and arguments (like the shell does). If the split is not correct (according to quotes in your command), or if you want to use shell, you can use function hook_process_hashtable with arguments in the hashtable options (WeeChat ≥ 0.4.0).

Prototipo:

struct t_hook *weechat_hook_process (const char *command,
                                     int timeout,
                                     int (*callback)(const void *pointer,
                                                     void *data,
                                                     const char *command,
                                                     int return_code,
                                                     const char *out,
                                                     const char *err),
                                     const void *callback_pointer,
                                     void *callback_data);

Argomenti:

  • command: command to launch in child process, URL (WeeChat ≥ 0.3.7) or function (WeeChat ≥ 1.5) (see below)

  • timeout: timeout per il comando (in millisecondi): dopo questo timeout, il processo figlio viene terminato (0 indica nessun timeout)

  • callback: funzione chiamata quando i dati dal processo figlio sono disponibili, oppure quando è terminato, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • const char *command: comando eseguito dal processo figlio

    • int return_code: codice restituito:

      • ≥ 0: codice ritorno figlio per un comando, e per un URL i valori possibili sono:

        • 0: trasferimento riuscito

        • 1: URL non valido

        • 2: errore di trasferimento

        • 3: memoria non sufficiente

        • 4: errore con un file

      • < 0:

        • WEECHAT_HOOK_PROCESS_RUNNING (-1): dati disponibili, ma figlio ancora in esecuzione

        • WEECHAT_HOOK_PROCESS_ERROR (-2): errore nella esecuzione del comando

        • WEECHAT_HOOK_PROCESS_CHILD (-3): callback is called in the child process (used only in C API, not scripting API)

    • out: output standard del comando (stdout)

    • err: output di errore del comando (stderr)

    • valore restituito:

      • WEECHAT_RC_OK

      • WEECHAT_RC_ERROR

      • child process return code (in case of function with "func:" in command)

  • callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_data: puntatore fornito alla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the hook is deleted

Valore restituito:

  • puntatore al nuovo hook, NULL in caso di errore

Quando il comando ha terminato, o se viene raggiunto il timeout, WeeChat effettua automaticamente l’unhook (e termina il processo se ancora in esecuzione).

Il comando può essere un URL con il formato: "url:https://www.example.com", per scaricare il contenuto dell’URL (WeeChat ≥ 0.3.7). Le opzioni per un URL sono disponibili con la funzione hook_process_hashtable.

The command can also be a function name with format: "func:name", to execute the function "name" (WeeChat ≥ 1.5). This function receives a single argument (data) and must return a string, which is sent to the callback.
In C API, the callback is called with the return code set to WEECHAT_HOOK_PROCESS_CHILD, which means the callback is running in the child process (after fork).
In scripting API, the function name is called directly and its result (string) is sent to the callback (like the output of an external command).

If you want to retrieve infos about WeeChat (like current stable version, latest git commit, etc.), you can use URLs on this page .
La dimensione del buffer per l’invio dei dati alla callback è di 64KB (ci sono 2 buffer: uno per stdout ed uno per stderr). Se l’output che viene da un processo figlio (stdout o stderr) è più lungo di 64KB, la callback verrà chiamata più di una volta.
Anche se la maggior parte delle volte la callback viene chiamata una sola volta, ci si deve assicurare che più chiamate alla callback siano corrette nel codice: bisogna concatenare i dati forniti da più chiamate ed utilizzarli quando il codice restituito è non-negativo.

Esempio in C:

/* example with an external command */
int
my_process_cb (const void *pointer, void *data, const char *command,
               int return_code, const char *out, const char *err)
{
    if (return_code == WEECHAT_HOOK_PROCESS_ERROR)
    {
        weechat_printf (NULL, "Errore con il comando '%s'", command);
        return WEECHAT_RC_OK;
    }

    if (return_code >= 0)
    {
        weechat_printf (NULL, "return_code = %d", return_code);
    }

    if (out)
    {
        weechat_printf (NULL, "stdout: %s", out);
    }

    if (err)
    {
        weechat_printf (NULL, "stderr: %s", err);
    }

    return WEECHAT_RC_OK;
}

struct t_hook *my_process_hook = weechat_hook_process ("ls", 5000,
                                                       &my_process_cb, NULL, NULL);

/* example with the callback called in the child process */
int
my_process_func_cb (const void *pointer, void *data, const char *command,
                    int return_code, const char *out, const char *err)
{
    if (return_code == WEECHAT_HOOK_PROCESS_CHILD)
    {
        /* do something blocking... */
        /* ... */

        /* the stdout will be sent as "out" in the parent callback */
        printf ("this is the result");

        /* return code of the process */
        return 0;
    }
    else
    {
        if (return_code == WEECHAT_HOOK_PROCESS_ERROR)
        {
            weechat_printf (NULL, "Error with command '%s'", command);
            return WEECHAT_RC_OK;
        }

        if (return_code >= 0)
        {
            weechat_printf (NULL, "return_code = %d", return_code);
        }

        if (out)
        {
            weechat_printf (NULL, "stdout: %s", out);
        }

        if (err)
        {
            weechat_printf (NULL, "stderr: %s", err);
        }

        return WEECHAT_RC_OK;
    }
}

struct t_hook *my_process_hook = weechat_hook_process ("func:get_status", 5000,
                                                       &my_process_func_cb, NULL, NULL);

Script (Python):

# prototipo
def hook_process(command: str, timeout: int, callback: str, callback_data: str) -> str: ...

# example with an external command
def my_process_cb(data: str, command: str, return_code: int, out: str, err: str) -> int:
    if return_code == weechat.WEECHAT_HOOK_PROCESS_ERROR:
        weechat.prnt("", "Error with command '%s'" % command)
        return weechat.WEECHAT_RC_OK
    if return_code >= 0:
        weechat.prnt("", "return_code = %d" % return_code)
    if out:
        weechat.prnt("", "stdout: %s" % out)
    if err:
        weechat.prnt("", "stderr: %s" % err)
    return weechat.WEECHAT_RC_OK

hook = weechat.hook_process("ls", 5000, "my_process_cb", "")

# example with a script function
def get_status(data: str) -> str:
    # do something blocking...
    # ...
    return "this is the result"

def my_process_cb(data: str, command: str, return_code: int, out: str, err: str) -> int:
    if return_code == weechat.WEECHAT_HOOK_PROCESS_ERROR:
        weechat.prnt("", "Error with command '%s'" % command)
        return weechat.WEECHAT_RC_OK
    if return_code >= 0:
        weechat.prnt("", "return_code = %d" % return_code)
    if out:
        weechat.prnt("", "stdout: %s" % out)
    if err:
        weechat.prnt("", "stderr: %s" % err)
    return weechat.WEECHAT_RC_OK

hook = weechat.hook_process("func:get_status", 5000, "my_process_cb", "")

hook_process_hashtable

WeeChat ≥ 0.3.7, updated in 1.5.

Hook su un processo (avviato con un fork) usando le opzioni nella tabella hash, e cattura dell’output.

Prototipo:

struct t_hook *weechat_hook_process_hashtable (const char *command,
                                               struct t_hashtable *options,
                                               int timeout,
                                               int (*callback)(const void *pointer,
                                                               void *data,
                                                               const char *command,
                                                               int return_code,
                                                               const char *out,
                                                               const char *err),
                                               const void *callback_pointer,
                                               void *callback_data);

Gli argomenti sono gli stessi della funzione hook_process, con un argomento aggiuntivo:

  • options: le opzioni per il comando eseguito; la tabella hash è duplicata nella funzione, per cui è possibile liberarla dopo questa chiamata

For a standard command (not beginning with "url:"), following options are available:

Option Min WeeChat Value Default Description

argN (N ≥ 1)

0.4.0

any string

no arguments

Arguments for command; if no argument is given with these options, the command is automatically split like the shell does (and then command arguments are read in the command argument).

stdin

0.4.3

(not used)

no stdin

Create a pipe for writing data on standard input (stdin) of child process (see function hook_set).

buffer_flush

1.0

number of bytes

65536

Minimum number of bytes to flush stdout/stderr (to send output to callback), between 1 and 65536. With the value 1, the output is sent immediately to the callback.

detached

1.0

(not used)

not detached

Run the process in a detached mode: stdout and stderr are redirected to /dev/null.

For command "url:…​", see available options in function hook_url.

Valore restituito:

  • puntatore al nuovo hook, NULL in caso di errore

Esempio in C:

int
my_process_cb (const void *pointer, void *data, const char *command,
               int return_code, const char *out, const char *err)
{
    if (return_code == WEECHAT_HOOK_PROCESS_ERROR)
    {
        weechat_printf (NULL, "Error with command '%s'", command);
        return WEECHAT_RC_OK;
    }

    if (return_code >= 0)
    {
        weechat_printf (NULL, "return_code = %d", return_code);
    }

    if (out)
    {
        weechat_printf (NULL, "stdout: %s", out);
    }

    if (err)
    {
        weechat_printf (NULL, "stderr: %s", err);
    }

    return WEECHAT_RC_OK;
}

/* example 1: download URL */
struct t_hashtable *options_url1 = weechat_hashtable_new (8,
                                                          WEECHAT_HASHTABLE_STRING,
                                                          WEECHAT_HASHTABLE_STRING,
                                                          NULL,
                                                          NULL);
if (options_url1)
{
    weechat_hashtable_set (options_url1, "file_out", "/tmp/weechat.org.html");
    struct t_hook *my_process_hook = weechat_hook_process_hashtable ("url:https://weechat.org/",
                                                                     options_url1,
                                                                     20000,
                                                                     &my_process_cb, NULL, NULL);
    weechat_hashtable_free (options_url1);
}

/* example 2: open URL with custom HTTP headers */
struct t_hashtable *options_url2 = weechat_hashtable_new (8,
                                                          WEECHAT_HASHTABLE_STRING,
                                                          WEECHAT_HASHTABLE_STRING,
                                                          NULL,
                                                          NULL);
if (options_url2)
{
    weechat_hashtable_set (options_url2, "httpheader",
                           "Header1: value1\n"
                           "Header2: value2");
    struct t_hook *my_process_hook = weechat_hook_process_hashtable ("url:http://localhost:8080/",
                                                                     options_url2,
                                                                     20000,
                                                                     &my_process_cb, NULL, NULL);
    weechat_hashtable_free (options_url2);
}

/* example 3: execute a notify program with a message from someone */
struct t_hashtable *options_cmd1 = weechat_hashtable_new (8,
                                                          WEECHAT_HASHTABLE_STRING,
                                                          WEECHAT_HASHTABLE_STRING,
                                                          NULL,
                                                          NULL);
if (options_cmd1)
{
    weechat_hashtable_set (options_cmd1, "arg1", "-from");
    weechat_hashtable_set (options_cmd1, "arg2", nick);
    weechat_hashtable_set (options_cmd1, "arg3", "-msg");
    weechat_hashtable_set (options_cmd1, "arg4", message);  /* unsafe argument */
    struct t_hook *my_process_hook = weechat_hook_process_hashtable ("my-notify-command",
                                                                     options_cmd1,
                                                                     20000,
                                                                     &my_process_cb, NULL, NULL);
    weechat_hashtable_free (options_cmd1);
}

/* example 4: call shell to execute a command (command must be SAFE) */
struct t_hashtable *options_cmd2 = weechat_hashtable_new (8,
                                                          WEECHAT_HASHTABLE_STRING,
                                                          WEECHAT_HASHTABLE_STRING,
                                                          NULL,
                                                          NULL);
if (options_cmd2)
{
    weechat_hashtable_set (options_cmd2, "arg1", "-c");
    weechat_hashtable_set (options_cmd2, "arg2", "ls -l /tmp | grep something");
    struct t_hook *my_process_hook = weechat_hook_process_hashtable ("sh",
                                                                     options_cmd2,
                                                                     20000,
                                                                     &my_process_cb, NULL, NULL);
    weechat_hashtable_free (options_cmd2);
}

Script (Python):

# prototipo
def hook_process_hashtable(command: str, options: Dict[str, str], timeout: int, callback: str, callback_data: str) -> str: ...

# esempio
def my_process_cb(data: str, command: str, return_code: int, out: str, err: str) -> int:
    if return_code == weechat.WEECHAT_HOOK_PROCESS_ERROR:
        weechat.prnt("", "Error with command '%s'" % command)
        return weechat.WEECHAT_RC_OK
    if return_code >= 0:
        weechat.prnt("", "return_code = %d" % return_code)
    if out:
        weechat.prnt("", "stdout: %s" % out)
    if err:
        weechat.prnt("", "stderr: %s" % err)
    return weechat.WEECHAT_RC_OK

# example 1: download URL
hook1 = weechat.hook_process_hashtable("url:https://weechat.org/",
                                       {"file_out": "/tmp/weechat.org.html"},
                                       20000, "my_process_cb", "")

# example 2: open URL with custom HTTP headers
options = {
    "httpheader": "\n".join([
        "Header1: value1",
        "Header2: value2",
    ]),
}
hook2 = weechat.hook_process_hashtable("url:http://localhost:8080/",
                                       options,
                                       20000, "my_process_cb", "")

# example 3: execute a notify program with a message from someone
hook3 = weechat.hook_process_hashtable("my-notify-command",
                                       {"arg1": "-from",
                                        "arg2": nick,
                                        "arg3": "-msg",
                                        "arg4": message},  # unsafe argument
                                       20000, "my_process_cb", "")

# example 4: call shell to execute a command (command must be SAFE)
hook4 = weechat.hook_process_hashtable("sh",
                                       {"arg1": "-c",
                                        "arg2": "ls -l /tmp | grep something"},
                                       20000, "my_process_cb", "")

hook_url

WeeChat ≥ 4.1.0.

URL transfer.

Prototipo:

struct t_hook *weechat_hook_url (const char *url,
                                 struct t_hashtable *options,
                                 int timeout,
                                 int (*callback)(const void *pointer,
                                                 void *data,
                                                 const char *url,
                                                 struct t_hashtable *options,
                                                 struct t_hashtable *output),
                                 const void *callback_pointer,
                                 void *callback_data);

Argomenti:

  • url: URL

  • options: options for URL transfer (see below); la tabella hash è duplicata nella funzione, per cui è possibile liberarla dopo questa chiamata

  • timeout: timeout for URL transfer (in milliseconds): after this timeout, the transfer is stopped (0 means no timeout)

  • callback: function called when the transfer has ended, arguments and return value:

    • const void *pointer: pointer

    • void *data: pointer

    • const char *url: URL

    • struct t_hashtable *options: options

    • struct t_hashtable *output: result (keys and values are strings), which may contain the following keys:

      • response_code: HTTP response code

      • headers: HTTP headers in response

      • output: standard output (set only if file_out was not set in options)

      • error: error message (set only in case of error)

    • return value:

      • WEECHAT_RC_OK

      • WEECHAT_RC_ERROR

  • callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_data: puntatore fornito alla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the hook is deleted

The following Curl options are available (see man curl_easy_setopt for a description of each option):

Opzione Tipo (1) Costanti (2)

verbose

long

header

long

noprogress

long

nosignal

long

wildcardmatch

long

failonerror

long

keep_sending_on_error

long

proxy

string

proxyport

long

port

long

pre_proxy

string

httpproxytunnel

long

interface

string

dns_cache_timeout

long

proxytype

long

http, socks4, socks5, socks4a, socks5_hostname, http_1_0, https

buffersize

long

tcp_nodelay

long

localport

long

localportrange

long

address_scope

long

noproxy

string

socks5_gssapi_nec

long

tcp_keepalive

long

tcp_keepidle

long

tcp_keepintvl

long

unix_socket_path

string

abstract_unix_socket

string

path_as_is

long

proxy_service_name

string

service_name

string

default_protocol

string

tcp_fastopen

long

socks5_auth

long

haproxyprotocol

long

doh_url

string

protocols_str

string

redir_protocols_str

string

netrc

long

ignored, optional, required

userpwd

string

proxyuserpwd

string

httpauth

mask

none, basic, digest, ntlm, any, anysafe, digest_ie, only, ntlm_wb, negotiate, gssapi, bearer, aws_sigv4

proxyauth

mask

none, basic, digest, ntlm, any, anysafe, digest_ie, only, ntlm_wb, negotiate, gssapi, bearer, aws_sigv4

netrc_file

string

username

string

password

string

proxyusername

string

proxypassword

string

tlsauth_type

mask

none, srp

tlsauth_username

string

tlsauth_password

string

sasl_authzid

string

sasl_ir

long

xoauth2_bearer

string

login_options

string

disallow_username_in_url

long

autoreferer

long

followlocation

long

post

long

postfields

string

referer

string

useragent

string

httpheader

list

cookie

string

cookiefile

string

postfieldsize

long

maxredirs

long

httpget

long

cookiejar

string

http_version

long

none, 1_0, 1_1, 2_0, 2, 2tls, 2_prior_knowledge, 3

cookiesession

long

http200aliases

list

unrestricted_auth

long

postfieldsize_large

long long

cookielist

string

ignore_content_length

long

accept_encoding

string

transfer_encoding

long

http_content_decoding

long

http_transfer_decoding

long

copypostfields

string

postredir

mask

post_301, post_302

expect_100_timeout_ms

long

headeropt

mask

unified, separate

proxyheader

list

pipewait

long

stream_weight

long

request_target

string

http09_allowed

long

hsts

string

hsts_ctrl

mask

enable, readonlyfile

mail_from

string

mail_rcpt

list

mail_auth

string

mail_rcpt_alllowfails

long

tftp_blksize

long

tftp_no_options

long

ftpport

string

quote

list

postquote

list

ftp_use_epsv

long

prequote

list

ftp_use_eprt

long

ftp_create_missing_dirs

long

ftpsslauth

long

default, ssl, tls

ftp_account

string

ftp_skip_pasv_ip

long

ftp_filemethod

long

multicwd, nocwd, singlecwd

ftp_alternative_to_user

string

ftp_ssl_ccc

long

ccc_none, ccc_active, ccc_passive

dirlistonly

long

append

long

ftp_use_pret

long

rtsp_request

long

options, describe, announce, setup, play, pause, teardown, get_parameter, set_parameter, record, receive

rtsp_session_id

string

rtsp_stream_uri

string

rtsp_transport

string

rtsp_client_cseq

long

rtsp_server_cseq

long

aws_sigv4

string

crlf

long

range

string

resume_from

long

customrequest

string

nobody

long

infilesize

long

upload

long

timecondition

long

none, ifmodsince, ifunmodsince, lastmod

timevalue

long

transfertext

long

filetime

long

maxfilesize

long

proxy_transfer_mode

long

resume_from_large

long long

infilesize_large

long long

maxfilesize_large

long long

timevalue_large

long long

upload_buffersize

long

mime_options

mask

formescape

timeout

long

low_speed_limit

long

low_speed_time

long

fresh_connect

long

forbid_reuse

long

connecttimeout

long

ipresolve

long

whatever, v4, v6

connect_only

long

max_send_speed_large

long long

max_recv_speed_large

long long

timeout_ms

long

connecttimeout_ms

long

maxage_conn

long

maxconnects

long

use_ssl

long

none, try, control, all

resolve

list

dns_servers

string

accepttimeout_ms

long

dns_interface

string

dns_local_ip4

string

dns_local_ip6

string

connect_to

list

happy_eyeballs_timeout_ms

long

dns_shuffle_addresses

long

upkeep_interval_ms

long

maxlifetime_conn

long

sslcert

string

sslversion

long

default, tlsv1, sslv2, sslv3, tlsv1_0, tlsv1_1, tlsv1_2, tlsv1_3, max_default, max_none, max_tlsv1_0, max_tlsv1_1, max_tlsv1_2, max_tlsv1_3

ssl_verifypeer

long

cainfo

string

ssl_verifyhost

long

ssl_cipher_list

string

sslcerttype

string

sslkey

string

sslkeytype

string

sslengine

string

sslengine_default

long

capath

string

ssl_sessionid_cache

long

krblevel

string

keypasswd

string

issuercert

string

crlfile

string

certinfo

long

gssapi_delegation

long

none, policy_flag, flag

ssl_options

long

allow_beast, no_revoke, no_backends, ok, too_late, unknown_backend, no_partialchain, revoke_best_effort, native_ca, auto_client_cert

ssl_enable_alpn

long

pinnedpublickey

string

ssl_verifystatus

long

ssl_falsestart

long

proxy_cainfo

string

proxy_capath

string

proxy_crlfile

string

proxy_keypasswd

string

proxy_pinnedpublickey

string

proxy_sslcert

string

proxy_sslcerttype

string

proxy_sslkey

string

proxy_sslkeytype

string

proxy_sslversion

long

default, tlsv1, sslv2, sslv3, tlsv1_0, tlsv1_1, tlsv1_2, tlsv1_3, max_default, max_none, max_tlsv1_0, max_tlsv1_1, max_tlsv1_2, max_tlsv1_3

proxy_ssl_cipher_list

list

proxy_ssl_options

long

allow_beast, no_revoke, no_backends, ok, too_late, unknown_backend, no_partialchain, revoke_best_effort, native_ca, auto_client_cert

proxy_ssl_verifyhost

long

proxy_ssl_verifypeer

long

proxy_tlsauth_password

string

proxy_tlsauth_type

string

proxy_tlsauth_username

string

tls13_ciphers

list

proxy_tls13_ciphers

list

proxy_issuercert

string

ssl_ec_curves

string

doh_ssl_verifyhost

long

doh_ssl_verifypeer

long

doh_ssl_verifystatus

long

ca_cache_timeout

long

ssh_auth_types

mask

none, policy_flag, flag

ssh_public_keyfile

string

ssh_private_keyfile

string

ssh_host_public_key_md5

string

ssh_knownhosts

string

ssh_compression

long

ssh_host_public_key_sha256

string

telnetoptions

list

ws_options

mask

binary, close, cont, offset, ping, pong, raw_mode, text

new_file_perms

long

new_directory_perms

long

quick_exit

long

(1) Per le opzioni con il tipo "mask" il formato è: "value1+value2+value3"; for options with type "list", the list items must be separated by a newline (\n).
(2) Quando sono disponibili le costanti, esse vanno usate come valore per l’opzione.

These two extra options (strings) are allowed for input/output file:

Option Type Description

file_in

string

file da leggere e inviare con gli URL (invio del file "post")

file_out

string

scrive URL scaricato/file in questo file (invece dello standard output)

Valore restituito:

  • puntatore al nuovo hook, NULL in caso di errore

Esempio in C:

int
my_url_cb (const void *pointer, void *data, const char *url,
           struct t_hashtable *options, struct t_hashtable *output)
{
    weechat_printf (NULL, "response_code: %s", weechat_hashtable_get (output, "response_code"));
    weechat_printf (NULL, "headers: %s", weechat_hashtable_get (output, "headers"));
    weechat_printf (NULL, "output: %s", weechat_hashtable_get (output, "output"));
    weechat_printf (NULL, "error: %s", weechat_hashtable_get (output, "error"));
    return WEECHAT_RC_OK;
}

/* example 1: output to a file */
struct t_hashtable *options_url1 = weechat_hashtable_new (8,
                                                          WEECHAT_HASHTABLE_STRING,
                                                          WEECHAT_HASHTABLE_STRING,
                                                          NULL,
                                                          NULL);
if (options_url1)
{
    weechat_hashtable_set (options_url1, "file_out", "/tmp/weechat.org.html");
    struct t_hook *my_url_hook = weechat_hook_url ("https://weechat.org/",
                                                   options_url1,
                                                   20000,
                                                   &my_url_cb, NULL, NULL);
    weechat_hashtable_free (options_url1);
}

/* example 2: custom HTTP headers, output sent to callback */
struct t_hashtable *options_url2 = weechat_hashtable_new (8,
                                                          WEECHAT_HASHTABLE_STRING,
                                                          WEECHAT_HASHTABLE_STRING,
                                                          NULL,
                                                          NULL);
if (options_url2)
{
    weechat_hashtable_set (options_url2, "httpheader",
                           "Header1: value1\n"
                           "Header2: value2");
    struct t_hook *my_url_hook = weechat_hook_url ("http://localhost:8080/",
                                                   options_url2,
                                                   20000,
                                                   &my_url_cb, NULL, NULL);
    weechat_hashtable_free (options_url2);
}

Script (Python):

# prototipo
def hook_url(url: str, options: Dict[str, str], timeout: int, callback: str, callback_data: str) -> str: ...

# esempio
def my_url_cb(data: str, url: str, options: Dict[str, str], output: Dict[str, str]) -> int:
    weechat.prnt("", "output: %s" % output)
    return weechat.WEECHAT_RC_OK

# example 1: output to a file
hook1 = weechat.hook_url("https://weechat.org/",
                         {"file_out": "/tmp/weechat.org.html"},
                         20000, "my_url_cb", "")

# example 2: custom HTTP headers, output sent to callback
options = {
    "httpheader": "\n".join([
        "Header1: value1",
        "Header2: value2",
    ]),
}
hook2 = weechat.hook_url("http://localhost:8080/", options, 20000, "my_url_cb", "")

hook_connect

Updated in 1.5, 2.0.

Hook su una connessione (connessione in secondo piano ad un host remoto).

Prototipo:

struct t_hook *weechat_hook_connect (const char *proxy,
                                     const char *address,
                                     int port,
                                     int ipv6,
                                     int retry,
                                     void *gnutls_sess,
                                     void *gnutls_cb,
                                     int gnutls_dhkey_size,
                                     const char *gnutls_priorities,
                                     const char *local_hostname,
                                     int (*callback)(const void *pointer,
                                                     void *data,
                                                     int status,
                                                     int gnutls_rc,
                                                     int sock,
                                                     const char *error,
                                                     const char *ip_address),
                                     const void *callback_pointer,
                                     void *callback_data);

Argomenti:

  • proxy: nome del proxy da utilizzare per la connessione (opzionale, NULL significa connessione senza proxy)

  • address: nome o indirizzo IP al quale connettersi

  • port: numero della porta

  • ipv6: 1 to use IPv6 (with fallback to IPv4), 0 to use only IPv4

  • retry: retry count, used to fallback to IPv4 hosts if IPv6 hosts connect but then fail to accept the client

  • gnutls_sess: sessione GnuTLS (opzionale)

  • gnutls_cb callback GnuTLS (opzionale)

  • gnutls_dhkey_size: dimensione della chiave utilizzata nello Scambio Chiavi Diffie-Hellman (GnuTLS)

  • gnutls_priorities: priorità per gnutls (per la sintassi, consultare la documentazione della funzione gnutls_priority_init nel manuale di gnutls), i valori di base sono:

    • PERFORMANCE

    • NORMAL (predefinito)

    • SECURE128

    • SECURE256

    • EXPORT

    • NONE

  • local_hostname: nome host locale da utilizzare per la connessione (opzionale)

  • callback: funzione chiamata quando la connessione è avvenuta con successo oppure no, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • int status: stato della connessione:

      • WEECHAT_HOOK_CONNECT_OK: connessione avvenuta con successo

      • WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND: indirizzo non trovato

      • WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND: indirizzo IP non trovato

      • WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED: connessione rifiutata

      • WEECHAT_HOOK_CONNECT_PROXY_ERROR: errore con il proxy

      • WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR: errore con il nome host locale

      • WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR: errore inizializzazione GnuTLS

      • WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR: errore di handshake GnuTLS

      • WEECHAT_HOOK_CONNECT_MEMORY_ERROR: memoria insufficiente

      • WEECHAT_HOOK_CONNECT_TIMEOUT: timeout

      • WEECHAT_HOOK_CONNECT_SOCKET_ERROR: errore nella creazione socket

    • gnutls_rc: valore del risultato di gnutls_handshake()

    • sock: socket utilizzato per la connessione

    • const char *error: valore del risultato di gnutls_strerror(gnutls_rc)

    • const char *ip_address: indirizzo IP trovato

    • valore restituito:

      • WEECHAT_RC_OK

      • WEECHAT_RC_ERROR

  • callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_data: puntatore fornito alla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the hook is deleted

Valore restituito:

  • puntatore al nuovo hook, NULL in caso di errore

In scripts, with WeeChat ≥ 2.0, the callback arguments status, gnutls_rc and sock are integers (with WeeChat ≤ 1.9, they were strings).
To be compatible with all versions, it is recommended to convert the argument to integer before using it, for example in Python: int(sock).

Esempio in C:

int
my_connect_cb (const void *pointer, void *data, int status, int gnutls_rc,
               int sock, const char *error, const char *ip_address)
{
    switch (status)
    {
        case WEECHAT_HOOK_CONNECT_OK:
            /* ... */
            break;
        case WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND:
            /* ... */
            break;
        case WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND:
            /* ... */
            break;
        case WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED:
            /* ... */
            break;
        case WEECHAT_HOOK_CONNECT_PROXY_ERROR:
            /* ... */
            break;
        case WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR:
            /* ... */
            break;
        case WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR:
            /* ... */
            break;
        case WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR:
            /* ... */
            break;
        case WEECHAT_HOOK_CONNECT_MEMORY_ERROR:
            /* ... */
            break;
        case WEECHAT_HOOK_CONNECT_TIMEOUT:
            /* ... */
            break;
        case WEECHAT_HOOK_CONNECT_SOCKET_ERROR:
            /* ... */
            break;
    }
    return WEECHAT_RC_OK;
}

struct t_hook *my_connect_hook = weechat_hook_connect (NULL,
                                                       "my.server.org", 1234,
                                                       1, 0,
                                                       NULL, NULL, 0,  /* GnuTLS */
                                                       NULL,
                                                       &my_connect_cb, NULL, NULL);

Script (Python):

# prototipo
def hook_connect(proxy: str, address: str, port: int, ipv6: int, retry: int, local_hostname: str,
                 callback: str, callback_data: str) -> str: ...

# esempio
def my_connect_cb(data: str, status: int, gnutls_rc: int, sock: int, error: str, ip_address: str) -> int:
    if status == WEECHAT_HOOK_CONNECT_OK:
        # ...
    elif status == WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND:
        # ...
    elif status == WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND:
        # ...
    elif status == WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED:
        # ...
    elif status == WEECHAT_HOOK_CONNECT_PROXY_ERROR:
        # ...
    elif status == WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR:
        # ...
    elif status == WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR:
        # ...
    elif status == WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR:
        # ...
    elif status == WEECHAT_HOOK_CONNECT_MEMORY_ERROR:
        # ...
    elif status == WEECHAT_HOOK_CONNECT_TIMEOUT:
        # ...
    elif status == WEECHAT_HOOK_CONNECT_SOCKET_ERROR:
        # ...
    return weechat.WEECHAT_RC_OK

hook = weechat.hook_connect("", "my.server.org", 1234, 1, 0, "",
                            "my_connect_cb", "")

hook_line

WeeChat ≥ 2.3, updated in 4.2.0.

Hook a line to be printed in a buffer.

When a line is printed in a buffer, hooks are called in this order:

  • hook line (this hook): it can change the buffer, prefix, message, tags, notify level, … (see below)

  • hook modifier "weechat_print": it can change the prefix and message on a buffer with formatted content

  • hook print: called when the line has been added in a buffer with formatted content (nothing can be changed directly with this hook).

The "line" hook is the only one among these three hooks that can work on buffers with free content.

Prototipo:

struct t_hook *weechat_hook_line (const char *buffer_type,
                                  const char *buffer_name,
                                  const char *tags,
                                  struct t_hashtable *(*callback)(const void *pointer,
                                                                  void *data,
                                                                  struct t_hashtable *line),
                                  const void *callback_pointer,
                                  void *callback_data);

Argomenti:

  • buffer_type: catch lines on the given buffer type (if NULL or empty string, formatted is the default) (WeeChat ≥ 3.7: a priority is allowed before the buffer type, see note about priority):

    • formatted: catch lines on formatted buffers only (default)

    • free: catch lines on buffers with free content only

    • *: catch lines on all buffer types

  • buffer_name: comma-separated list of buffer masks (see buffer_match_list); NULL, empty string or "*" matches any buffer

  • tags: catch only messages with these tags (optional): comma-separated list of tags that must be in message (logical "or"); it is possible to combine many tags as a logical "and" with separator +; wildcard * is allowed in tags

  • callback: function called when a line is added in a buffer, arguments and return value:

    • const void *pointer: pointer

    • void *data: pointer

    • struct t_hashtable *line: hashtable with the line info, keys and values are strings (see table below)

    • return value: hashtable with new values (see table below)

  • callback_pointer: pointer given to callback when it is called by WeeChat

  • callback_data: pointer given to callback when it is called by WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the hook is deleted

Valore restituito:

  • puntatore al nuovo hook, NULL in caso di errore

Line data sent to the callback is a hashtable, with following values (keys and values are strings):

Key Value (formatted buffer) Value (free buffer) Examples

buffer

Buffer pointer.

Buffer pointer.

0x1234abcd

buffer_name

Buffer name.

Buffer name.

core.weechat
irc.server.libera
irc.libera.#weechat

buffer_type

"formatted"

"free"

formatted
free

y

N/A ("-1").

Line number (≥ "0").

-1
8

date

Line date (timestamp).

N/A ("0").

1533792000

date_usec

Microseconds of line date (between 0 and 999999).

N/A ("0").

123456

date_printed

Date when line was displayed (timestamp).

N/A ("0").

1533792012

date_usec_printed

Microseconds of date when line was displayed (between 0 and 999999).

N/A ("0").

654321

str_time

Date for display (possible color codes inside).

N/A (empty string).

09:07:20

tags_count

Number of tags in the line (≥ "0").

N/A ("0").

2

tags

Comma-separated list of tags.

N/A (empty string).

irc_join,nick_test

displayed

"0" = line is filtered (hidden)
"1" = line is not filtered (displayed).

"0" = line is filtered (hidden)
"1" = line is not filtered (displayed).

0
1

notify_level

"-1" = no notify
"0" = low level
"1" = message
"2" = private message
"3" = highlight

N/A ("0").

2

highlight

"0" = no highlight
"1" = line has highlight.

N/A ("0").

0
1

prefix

Prefix of the line.

N/A (empty string).

-->

message

Message of the line.

Message of the line.

test (~test@example.com) has joined #channel

The callback can return a hashtable with some fields to update the line. Any invalid value in a field is silently ignored by WeeChat.

The following keys can be set in the hashtable (keys and values are strings in this hashtable):

Key Allowed value (formatted buffer) Allowed value (free buffer) Result

buffer

Pointer of a buffer with formatted content.

Pointer of a buffer with free content.

The line is displayed on this buffer.
If the value is empty, the line is deleted (anything else in the hashtable is then ignored); the next hooks of type "line" are not called.

buffer_name

Name of a buffer with formatted content.

Name of a buffer with free content.

The line is displayed on this buffer.
If buffer is also set, the value of buffer_name has higher priority and is used.
If the value is empty, the line is deleted (anything else in the hashtable is then ignored); the next hooks of type "line" are not called.

y

N/A.

Integer (≥ "0").

The line number is set to this value.

date

Timestamp.

N/A.

The date is set to this value.
The value of str_time is updated accordingly.

date_usec

Integer ("0" to "999999").

N/A.

The microseconds of line date is set to this value.
The value of str_time is updated accordingly.

date_printed

Timestamp.

N/A.

The printed date is set to this timestamp (not displayed).

date_usec_printed

Integer ("0" to "999999").

N/A.

The microseconds of printed date is set to this value.

str_time

String.

N/A.

This string is used to display the date line.
If date is also set, the value of str_time has higher priority and is used.

tags

String.

N/A.

The line tags are replaced with this comma-separated list of tags.
The values of notify_level and highlight are updated accordingly.

notify_level

Integer ("-1" to "3").

N/A.

The notify level is set to this value. The hotlist will be updated accordingly once the line is added in the buffer.
The value of highlight is updated accordingly.
If tags is also set, the value of notify_level has higher priority and is used.

highlight

Integer ("0" or "1").

N/A.

"0" disables highlight on the line, "1" forces a highlight on the line.
If tags or notify_level are set, the value of highlight has higher priority and is used.

prefix

String.

N/A.

The line prefix is set to this value.

message

String.

String.

The line message is set to this value.

Esempio in C:

int
my_line_cb (const void *pointer, void *data, struct t_hasbtable *line)
{
    struct t_hashtable *hashtable;

    hashtable = weechat_hashtable_new (8,
                                       WEECHAT_HASHTABLE_STRING,
                                       WEECHAT_HASHTABLE_STRING,
                                       NULL,
                                       NULL);
    /* force a highlight on the line */
    weechat_hashtable_set (hashtable, "highlight", "1");
    return hashtable;
}

/* catch lines with tag "irc_join" */
struct t_hook *my_line_hook =
    weechat_hook_line ("", "", "irc_join", &my_line_cb, NULL, NULL);

Script (Python):

# prototipo
def hook_line(buffer_type: str, buffer_name: str, tags: str, callback: str, callback_data: str) -> str: ...

# esempio
def my_line_cb(data: str, line: Dict[str, str]) -> Dict[str, str]:
    # force a highlight on the line
    return {"highlight": "1"}

# catch lines with tag "irc_join"
hook = weechat.hook_line("", "", "irc_join", "my_line_cb", "")

hook_print

Updated in 0.4.3, 1.0, 1.5, 4.2.0.

Hook su un messaggio stampato. It is called when a line has been added in a buffer with formatted content.

For more information on the hooks called when a line is printed, see hook_line.

Prototipo:

struct t_hook *weechat_hook_print (struct t_gui_buffer *buffer,
                                   const char *tags,
                                   const char *message,
                                   int strip_colors,
                                   int (*callback)(const void *pointer,
                                                   void *data,
                                                   struct t_gui_buffer *buffer,
                                                   time_t date,
                                                   int date_usec,
                                                   int tags_count,
                                                   const char **tags,
                                                   int displayed,
                                                   int highlight,
                                                   const char *prefix,
                                                   const char *message),
                                   const void *callback_pointer,
                                   void *callback_data);

Argomenti:

  • buffer: puntatore al buffer, se NULL, verranno catturati i messaggi da qualsiasi buffer

  • tags: catch only messages with these tags (optional):

    • with WeeChat ≥ 0.4.3: comma-separated list of tags that must be in message (logical "or"); it is possible to combine many tags as a logical "and" with separator +; wildcard * is allowed in tags

    • with WeeChat ≤ 0.4.2: comma-separated list of tags that must all be in message (logical "and")

  • message: verranno catturati solo i messaggi con questa stringa (opzionale, non sensibile alle maiuscole)

  • strip_colors: se 1, i colori verranno estratti dal messaggio visualizzato, prima di chiamare la callback

  • callback: funzione chiamata quando viene stampato un messaggio, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • struct t_gui_buffer *buffer: puntatore al buffer

    • time_t date: data

    • int date_usec: microseconds of date

    • int tags_count: numero di tag per riga

    • const char **tags: array con tag per riga

    • int displayed: 1 se la riga è visualizzata, 0 se filtrata (nascosta)

    • int highlight: 1 se la riga viene evidenziata, altrimenti 0

    • const char *prefix: prefisso

    • const char *message: messaggio

    • valore restituito:

      • WEECHAT_RC_OK

      • WEECHAT_RC_ERROR

  • callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_data: puntatore fornito alla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the hook is deleted

Valore restituito:

  • puntatore al nuovo hook, NULL in caso di errore

In scripts, with WeeChat ≥ 1.0, the callback arguments displayed and highlight are integers (with WeeChat ≤ 0.4.3, they were strings).
To be compatible with all versions, it is recommended to convert the argument to integer before testing it, for example in Python: if int(highlight):.

Esempio in C:

int
my_print_cb (const void *pointer, void *data, struct t_gui_buffer *buffer,
             time_t date, int date_usec, int tags_count, const char **tags,
             int displayed, int highlight,
             const char *prefix, const char *message)
{
    /* ... */
    return WEECHAT_RC_OK;
}

/* cattura tutti i messaggi, su tutti i buffer, senza colore */
struct t_hook *my_print_hook =
    weechat_hook_print (NULL, NULL, NULL, 1, &my_print_cb, NULL, NULL);

Script (Python):

# prototipo
def hook_print(buffer: str, tags: str, message: str, strip_colors: int, callback: str, callback_data: str) -> str: ...

# esempio
def my_print_cb(data: str, buffer: str, date: str, tags: str, displayed: int, highlight: int, prefix: str, message: str) -> int:
    if highlight:
        # ...
    return weechat.WEECHAT_RC_OK

# cattura tutti i messaggi, su tutti i buffer, senza colore
hook = weechat.hook_print("", "", "", 1, "my_print_cb", "")

hook_signal

Updated in 1.5, 3.6.

Hook su un segnale.

Prototipo:

struct t_hook *weechat_hook_signal (const char *signal,
                                    int (*callback)(const void *pointer,
                                                    void *data,
                                                    const char *signal,
                                                    const char *type_data,
                                                    void *signal_data),
                                    const void *callback_pointer,
                                    void *callback_data);

Argomenti:

  • signal: segnale da catturare, wildcard * is allowed, multiple signals can be separated by semi-colons (a priority is allowed before one or more signals, see note about priority) (see table below)

  • callback: funzione chiamata a segnale ricevuto, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • const char *signal: segnale ricevuto

    • const char *type_data: tipo di dati inviati con il segnale:

      • WEECHAT_HOOK_SIGNAL_STRING: stringa

      • WEECHAT_HOOK_SIGNAL_INT: numero intero

      • WEECHAT_HOOK_SIGNAL_POINTER: puntatore

    • void *signal_data: dati inviati con il segnale

    • valore restituito:

      • WEECHAT_RC_OK

      • WEECHAT_RC_OK_EAT (stop sending the signal immediately) (WeeChat ≥ 0.4.0)

      • WEECHAT_RC_ERROR

  • callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_data: puntatore fornito alla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the hook is deleted

Valore restituito:

  • puntatore al nuovo hook, NULL in caso di errore

List of signals sent by WeeChat and plugins:

Plugin Segnale Min WeeChat Argomenti Descrizione

guile

guile_script_loaded

0.3.9

String: path to script.

Scheme script loaded.

guile

guile_script_unloaded

0.3.9

String: path to script.

Scheme script unloaded.

guile

guile_script_installed

0.3.9

String: comma-separated list of paths to scripts installed.

Scheme script(s) installed.

guile

guile_script_removed

0.3.9

String: comma-separated list of scripts removed.

Scheme script(s) removed.

irc

xxx,irc_in_yyy (1)

String: messaggio.

Messaggio IRC dal server (prima di essere utilizzato dal plugin irc, il segnale viene inviato solo se il messaggio non viene ignorato).
Since version 2.2, the whole IRC message is sent, including tags.
If the return code of a callback is WEECHAT_RC_OK_EAT, then the IRC message is immediately destroyed and not processed (WeeChat ≥ 3.3).

irc

xxx,irc_in2_yyy (1)

String: messaggio.

Messaggio IRC dal server (dopo essere stato utilizzato dal plugin irc, il segnale viene inviato solo se il messaggio non viene ignorato).
Since version 2.2, the whole IRC message is sent, including tags.

irc

xxx,irc_raw_in_yyy (1)

0.3.2

String: messaggio.

Messaggio IRC dal server (prima di essere utilizzato dal plugin irc, il segnale viene inviato anche se il messaggio è stato ignorato).
Since version 2.2, the whole IRC message is sent, including tags.
If the return code of a callback is WEECHAT_RC_OK_EAT, then the IRC message is immediately destroyed and not processed (WeeChat ≥ 3.3).

irc

xxx,irc_raw_in2_yyy (1)

0.3.2

String: messaggio.

Messaggio IRC dal server (dopo essere stato utilizzato dal plugin irc, il segnale viene inviato anche se il messaggio è stato ignorato).
Since version 2.2, the whole IRC message is sent, including tags.

irc

xxx,irc_out1_yyy (1)

0.3.7

String: messaggio.

IRC message sent to server before automatic split (to fit in 512 bytes by default).

irc

xxx,irc_out_yyy (1)

String: messaggio.

IRC message sent to server after automatic split (to fit in 512 bytes by default).
Warning: the string may contain invalid UTF-8 data. Signal "xxx,irc_out1_yyy" is recommended instead.

irc

xxx,irc_outtags_yyy (1)

0.3.4

Stringa: tag + ";" + messaggio.

Tag + messaggio IRC inviato al server.
Warning: the string may contain invalid UTF-8 data. Signal "xxx,irc_out1_yyy" is recommended instead.

irc

irc_ctcp

String: messaggio.

CTCP ricevuto.

irc

irc_dcc

String: messaggio.

Nuova DCC.

irc

irc_pv

String: messaggio.

Messaggio privato ricevuto.

irc

irc_channel_opened

Puntatore: buffer.

Canale aperto.

irc

irc_pv_opened

Puntatore: buffer.

Chat privata aperta.

irc

irc_server_opened

0.3.7

Puntatore: buffer.

Server del buffer aperto.

irc

irc_server_connecting

String: nome server.

Connessione al server.

irc

irc_server_connected

String: nome server.

Connesso al server.

irc

irc_server_disconnected

String: nome server.

Disconnesso dal server.

irc

irc_server_lag_changed

1.8

String: server name.

Lag changed on the server.

irc

irc_ignore_removing

Puntatore: ignore.

Rimozione dell’ignore.

irc

irc_ignore_removed

-

Ignore rimosso.

irc

irc_notify_join

0.3.8

String: nome server + "," + nick.

Un nick nella lista notifiche è entrato sul server.

irc

irc_notify_quit

0.3.8

String: nome server + "," + nick.

Un nick nella lista notifiche è uscito dal server.

irc

irc_notify_away

0.3.8

String: nome server + "," + nick + "," + messaggio di assenza.

Un nick nella lista notifiche è ora assente sul server.

irc

irc_notify_still_away

0.3.8

String: nome server + "," + nick + "," + messaggio di assenza.

Un nick nella lista notifiche è ancora assente sul server (messaggio di assenza cambiato).

irc

irc_notify_back

0.3.8

String: nome server + "," + nick.

Un nick nella lista notifiche è tornato (messaggio di assenza rimosso).

javascript

javascript_script_loaded

1.2

String: path to script.

JavaScript script loaded.

javascript

javascript_script_unloaded

1.2

String: path to script.

JavaScript script unloaded.

javascript

javascript_script_installed

1.2

String: comma-separated list of paths to scripts installed.

JavaScript script(s) installed.

javascript

javascript_script_removed

1.2

String: comma-separated list of scripts removed.

JavaScript script(s) removed.

logger

logger_start

Puntatore: buffer.

Avvia il logging per il buffer.

logger

logger_stop

Puntatore: buffer.

Ferma il logging per il buffer.

logger

logger_backlog

Puntatore: buffer.

Visualizza log precedenti per il buffer.

lua

lua_script_loaded

0.3.9

String: path to script.

Lua script loaded.

lua

lua_script_unloaded

0.3.9

String: path to script.

Lua script unloaded.

lua

lua_script_installed

0.3.9

String: comma-separated list of paths to scripts installed.

Lua script(s) installed.

lua

lua_script_removed

0.3.9

String: comma-separated list of scripts removed.

Lua script(s) removed.

perl

perl_script_loaded

0.3.9

String: path to script.

Perl script loaded.

perl

perl_script_unloaded

0.3.9

String: path to script.

Perl script unloaded.

perl

perl_script_installed

0.3.9

String: comma-separated list of paths to scripts installed.

Perl script(s) installed.

perl

perl_script_removed

0.3.9

String: comma-separated list of scripts removed.

Perl script(s) removed.

php

php_script_loaded

2.0

String: path to script.

PHP script loaded.

php

php_script_unloaded

2.0

String: path to script.

PHP script unloaded.

php

php_script_installed

2.0

String: comma-separated list of paths to scripts installed.

PHP script(s) installed.

php

php_script_removed

2.0

String: comma-separated list of scripts removed.

PHP script(s) removed.

python

python_script_loaded

0.3.9

String: path to script.

Python script loaded.

python

python_script_unloaded

0.3.9

String: path to script.

Python script unloaded.

python

python_script_installed

0.3.9

String: comma-separated list of paths to scripts installed.

Python script(s) installed.

python

python_script_removed

0.3.9

String: comma-separated list of scripts removed.

Python script(s) removed.

relay

relay_client_connecting

1.0

Pointer: relay client.

A relay client is connecting.

relay

relay_client_waiting_auth

1.0

Pointer: relay client.

Waiting for authentication from a relay client.

relay

relay_client_auth_ok

1.0

Pointer: relay client.

Successful authentication from a relay client.

relay

relay_client_connected

1.0

Pointer: relay client.

A relay client is connected.

relay

relay_client_auth_failed

1.0

Pointer: relay client.

Authentication of a relay client has failed.

relay

relay_client_disconnected

1.0

Pointer: relay client.

A relay client is disconnected.

ruby

ruby_script_loaded

0.3.9

String: path to script.

Ruby script loaded.

ruby

ruby_script_unloaded

0.3.9

String: path to script.

Ruby script unloaded.

ruby

ruby_script_installed

0.3.9

String: comma-separated list of paths to scripts installed.

Ruby script(s) installed.

ruby

ruby_script_removed

0.3.9

String: comma-separated list of scripts removed.

Ruby script(s) removed.

spell

spell_suggest

2.4

Pointer: buffer.

New suggestions for a misspelled word.

tcl

tcl_script_loaded

0.3.9

String: path to script.

Tcl script loaded.

tcl

tcl_script_unloaded

0.3.9

String: path to script.

Tcl script unloaded.

tcl

tcl_script_installed

0.3.9

String: comma-separated list of paths to scripts installed.

Tcl script(s) installed.

tcl

tcl_script_removed

0.3.9

String: comma-separated list of scripts removed.

Tcl script(s) removed.

typing

typing_self_typing

3.3

Pointer: buffer.

User is typing a message (sent by typing plugin, used by irc plugin).

typing

typing_self_paused

3.3

Pointer: buffer.

User paused during typing (sent by typing plugin, used by irc plugin).

typing

typing_self_cleared

3.3

Pointer: buffer.

User cleared the input without sending the message (sent by typing plugin, used by irc plugin).

typing

typing_self_sent

3.3

Pointer: buffer.

Message (not a command) sent to the buffer (sent by typing plugin, used by irc plugin).

typing

typing_set_nick

3.3

String: buffer pointer + ";" + state (one of: "off", "typing", "paused", "cleared") + ";" + nick.

Set typing state for a nick on a buffer (sent by irc plugin, handled by typing plugin).

typing

typing_reset_buffer

3.3

Pointer: buffer.

Remove typing state for all nicks on a buffer (sent by irc plugin, handled by typing plugin).

weechat

buffer_opened

Puntatore: buffer.

Buffer aperto.

weechat

buffer_closing

Puntatore: buffer.

Chiusura del buffer.

weechat

buffer_closed

Puntatore: buffer.

Buffer chiuso.

weechat

buffer_cleared

Puntatore: buffer.

Buffer cleared.

weechat

buffer_filters_enabled

2.0

Pointer: buffer.

Filters enabled in buffer.

weechat

buffer_filters_disabled

2.0

Pointer: buffer.

Filters disabled in buffer.

weechat

buffer_hidden

Pointer: buffer.

Buffer hidden.

weechat

buffer_unhidden

Pointer: buffer.

Buffer unhidden.

weechat

buffer_line_added

0.3.7

Puntatore: riga.

Riga aggiunta in un buffer.

weechat

buffer_lines_hidden

Puntatore: buffer.

Righe nascoste nel buffer.

weechat

buffer_localvar_added

Puntatore: buffer.

Variabili locali aggiunte.

weechat

buffer_localvar_changed

Puntatore: buffer.

Variabili locali modificate.

weechat

buffer_localvar_removed

Puntatore: buffer.

Variabili locali rimosse.

weechat

buffer_merged

Puntatore: buffer.

Buffer merged.

weechat

buffer_unmerged

Puntatore: buffer.

Buffer unmerged.

weechat

buffer_moved

Puntatore: buffer.

Buffer spostato.

weechat

buffer_renamed

Puntatore: buffer.

Buffer rinominato.

weechat

buffer_switch

Puntatore: buffer.

Passaggio tra buffer.

weechat

buffer_title_changed

Puntatore: buffer.

Titolo del buffer modificato.

weechat

buffer_type_changed

Puntatore: buffer.

Tipo di buffer modificato.

weechat

buffer_zoomed

0.4.3

Puntatore: buffer.

Merged buffer zoomed.

weechat

buffer_unzoomed

0.4.3

Puntatore: buffer.

Merged buffer unzoomed.

weechat

buffer_user_input_xxx (2)

3.8

String: text sent to buffer.

Text sent to a user buffer as input (sent only for buffers created with /buffer add).
If the return code of a callback is WEECHAT_RC_OK_EAT, then the string "q" can not be used any more to close the buffer.

weechat

buffer_user_closing_xxx (2)

3.8

-

User buffer is closing (sent only for buffers created with /buffer add).

weechat

cursor_start

3.2

-

Start cursor mode.

weechat

cursor_end

3.2

-

End cursor mode.

weechat

day_changed

0.3.2

String: nuova data, formato: "2010-01-31".

Data di sistema modificata.

weechat

debug_dump

Stringa: nome plugin.

Richiesta di dump.

weechat

debug_libs

-

Display external libraries used.

weechat

filter_added

Puntatore: filtro.

Filtro aggiunto.

weechat

filter_removing

Puntatore: filtro.

Rimozione del filtro.

weechat

filter_removed

-

Filtro rimosso.

weechat

filters_enabled

-

Filtri abilitati.

weechat

filters_disabled

-

Filtri disabilitati.

weechat

hotlist_changed

Pointer: buffer (can be NULL).

Hotlist modificata.

weechat

input_paste_pending

-

Incolla testo in attesa.

weechat

input_search

Puntatore: buffer.

Ricerca testo nel buffer.

weechat

input_text_changed

Puntatore: buffer.

Testo in input modificato.

weechat

input_text_cursor_moved

Puntatore: buffer.

Cursore del testo di input spostato.

weechat

key_bind

String: key.

Key added.

weechat

key_unbind

String: key.

Key removed.

weechat

key_pressed

String: tasto digitato.

Tasto digitato.

weechat

key_combo_default

1.0

String: key combo.

Key combo in default context.

weechat

key_combo_search

1.0

String: key combo.

Key combo in search context.

weechat

key_combo_cursor

1.0

String: key combo.

Key combo in cursor context.

weechat

mouse_enabled

1.1

-

Mouse enabled.

weechat

mouse_disabled

1.1

-

Mouse disabled.

weechat

nicklist_group_added

0.3.2

String: buffer pointer + "," + group name.

Group added in nicklist.

weechat

nicklist_group_changed

0.3.4

String: buffer pointer + "," + group name.

Group changed in nicklist.

weechat

nicklist_group_removing

0.4.1

String: buffer pointer + "," + group name.

Removing group from nicklist.

weechat

nicklist_group_removed

0.3.2

String: buffer pointer + "," + group name.

Group removed from nicklist.

weechat

nicklist_nick_added

0.3.2

String: buffer pointer + "," + nick name.

Nick added in nicklist.

weechat

nicklist_nick_changed

0.3.4

String: buffer pointer + "," + nick name.

Nick changed in nicklist.

weechat

nicklist_nick_removing

0.4.1

String: buffer pointer + "," + nick name.

Removing nick from nicklist.

weechat

nicklist_nick_removed

0.3.2

String: buffer pointer + "," + nick name.

Nick removed from nicklist.

weechat

partial_completion

-

Completamento parziale avvenuto.

weechat

plugin_loaded

0.3.9

String: path to plugin loaded.

Plugin loaded.

weechat

plugin_unloaded

0.3.9

String: name of plugin unloaded (example: "irc").

Plugin unloaded.

weechat

quit

String: argomenti per /quit.

Comando /quit digitato dall’utente.

weechat

signal_sighup

1.3

-

Signal SIGHUP received.

weechat

signal_sigquit

1.2

-

Signal SIGQUIT received (quit request with core dump).

weechat

signal_sigterm

1.2

-

Signal SIGTERM received (graceful termination of WeeChat process).

weechat

signal_sigwinch

0.4.3

-

Signal SIGWINCH received (terminal was resized).

weechat

upgrade

String: "quit" if "-quit" argument was given for /upgrade, "save" if "-save" if "-save" argument was given for /upgrade, otherwise NULL.

Comando /upgrade digitato dall’utente.

weechat

upgrade_ended

0.3.4

-

Fine del processo di aggiornamento (comando /upgrade).

weechat

weechat_highlight

String: messaggio con prefisso.

Evento accaduto.

weechat

weechat_pv

String: messaggio con prefisso.

Messaggio privato visualizzato.

weechat

window_closing

0.3.6

Puntatore: finestra.

Closing window.

weechat

window_closed

0.3.6

Puntatore: finestra.

Window closed.

weechat

window_opened

0.4.1

Puntatore: finestra.

Window opened.

weechat

window_scrolled

Puntatore: finestra.

Scroll nella finestra.

weechat

window_switch

0.3.7

Puntatore: finestra.

Passaggio alla finestra.

weechat

window_zoom

Puntatore: finestra corrente.

Massimizzazione della finestra.

weechat

window_zoomed

Puntatore: finestra corrente.

Finestra massimizzata.

weechat

window_unzoom

Puntatore: finestra corrente.

Minimizzazione della finestra.

weechat

window_unzoomed

Puntatore: finestra corrente.

Finestra minimizzata.

xfer

xfer_add

Puntatore: lista info con info per xfe.r

Nuovo xfer.

xfer

xfer_send_ready

Puntatore: lista info xon info per xfer.

Xfer pronto.

xfer

xfer_accept_resume

Puntatore: lista info con info per xfer.

Accept xfer resume.

xfer

xfer_send_accept_resume

Puntatore: lista info con info per xfer.

Xfer resumed.

xfer

xfer_start_resume

Puntatore: lista info con info per xfer.

Avvia ripresa.

xfer

xfer_resume_ready

Puntatore: lista info con info per xfer.

Ripresa xfer pronta.

xfer

xfer_ended

0.3.2

Puntatore: lista info con info per xfer.

Xfer terminato.

(1) xxx è il nome del server IRC, yyy è il nome del comando IRC.
(2) xxx is buffer name.

Esempio in C:

int
my_signal_cb (const void *pointer, void *data, const char *signal,
              const char *type_data, void *signal_data)
{
    /* ... */
    return WEECHAT_RC_OK;
}

/* catch signals "quit" and "upgrade" */
struct t_hook *my_signal_hook = weechat_hook_signal ("quit;upgrade",
                                                     &my_signal_cb, NULL, NULL);

Script (Python):

# prototipo
def hook_signal(signal: str, callback: str, callback_data: str) -> str: ...

# esempio
def my_signal_cb(data: str, signal: str, signal_data: str) -> int:
    # ...
    return weechat.WEECHAT_RC_OK

# catch signals "quit" and "upgrade"
hook = weechat.hook_signal("quit;upgrade", "my_signal_cb", "")

hook_signal_send

Updated in 1.0.

Invia un segnale.

Prototipo:

int weechat_hook_signal_send (const char *signal, const char *type_data,
                              void *signal_data);

Argomenti:

  • signal: segnale da inviare

  • type_data: tipo di dati inviati con il segnale (consultare hook_signal)

  • signal_data: dati inviati con il segnale

Return value (WeeChat ≥ 1.0):

  • return code of last callback executed (WEECHAT_RC_OK if no callback was executed):

    • WEECHAT_RC_OK

    • WEECHAT_RC_OK_EAT

    • WEECHAT_RC_ERROR

Esempio in C:

int rc = weechat_hook_signal_send ("my_signal", WEECHAT_HOOK_SIGNAL_STRING, my_string);

Script (Python):

# prototipo
def hook_signal_send(signal: str, type_data: str, signal_data: str) -> int: ...

# esempio
rc = weechat.hook_signal_send("my_signal", weechat.WEECHAT_HOOK_SIGNAL_STRING, my_string)
Signal logger_backlog

Il segnale "logger_backlog" può essere inviato per visualizzare il backlog (cronologia di chat) nel buffer (ad esempio se il proprio buffer viene aperto in un plugin/script).

L’argomento è un puntatore al buffer.

Esempio in C:

weechat_hook_signal_send ("logger_backlog", WEECHAT_HOOK_SIGNAL_POINTER, buffer);

Script (Python):

weechat.hook_signal_send("logger_backlog", weechat.WEECHAT_HOOK_SIGNAL_POINTER, buffer)
Signals xxx_script_install

Cinque segnali che possono essere inviati per installare uno script, a seconda del linguaggio:

  • perl_script_install

  • python_script_install

  • ruby_script_install

  • lua_script_install

  • tcl_script_install

  • guile_script_install

  • javascript_script_install

  • php_script_install

La callback compirà le seguenti azioni alla ricezione del segnale:

  1. Scarica e rimuove lo script installato.

  2. Sposta il nuovo script nella cartella ~/.local/share/weechat/xxx/ (dove xxx è il linguaggio).

  3. Crea un link al nuovo script nella cartella ~/.local/share/weechat/xxx/autoload/ (only if the script was already auto-loaded, or if the option script.scripts.autoload is enabled for a new script).

  4. Carica il nuovo script (if the script was loaded).

These signals are used by script plugin to install scripts.

L’argomento è una stringa con il percorso dello script da installare.

Esempio in C:

weechat_hook_signal_send ("python_script_install", WEECHAT_HOOK_SIGNAL_STRING, "/path/to/test.py");

Script (Python):

weechat.hook_signal_send("python_script_install", WEECHAT_HOOK_SIGNAL_STRING, "/path/to/test.py")
Signals xxx_script_remove

Cinque segnali che possono essere inviati per rimuovere un elenco di script, a seconda del linguaggio:

  • perl_script_remove

  • python_script_remove

  • ruby_script_remove

  • lua_script_remove

  • tcl_script_remove

  • guile_script_remove

  • javascript_script_remove

  • php_script_remove

Per ogni script nella lista, la callback scaricherà e rimuoverà lo script.

These signals are used by script plugin to remove scripts.

L’argomento è una stringa con una lista separata da virgole di script da rimuovere (script è il nome senza percorso, ad esempio script.py).

Esempio in C:

/* scarica e rimuove gli script test.py e script.py */
weechat_hook_signal_send ("python_script_remove", WEECHAT_HOOK_SIGNAL_STRING,
                          "test.py,script.py");

Script (Python):

# scarica e rimuove gli script test.py e script.py
weechat.hook_signal_send("python_script_remove", WEECHAT_HOOK_SIGNAL_STRING,
                         "test.py,script.py")
Signal irc_input_send

WeeChat ≥ 0.3.4, updated in 1.5.

Il segnale "irc_input_send" può essere inviato per simulare input in un buffer irc (server, canale o privato).

L’argomento è una stringa con il seguente formato:

  • nome interno del server (richiesto)

  • punto e virgola

  • nome canale (opzionale)

  • punto e virgola

  • comma-separated list of options (optional):

    • priority_high: queue with high priority (like user messages); this is the default priority

    • priority_low: queue with low priority (like messages automatically sent by WeeChat)

    • user_message: force user message (don’t execute a command)

  • punto e virgola

  • elenco separato da virgole di tag usate per l’invio di un messaggio (opzionale)

  • punto e virgola

  • testo o comando (richiesto)

Esempi in C:

/* dice "Hello!" sul server libera, canale #weechat */
weechat_hook_signal_send ("irc_input_send", WEECHAT_HOOK_SIGNAL_STRING,
                          "libera;#weechat;priority_high,user_message;;Hello!");

/* invia il comando "/whois FlashCode" sul server libera, con priorità minore */
weechat_hook_signal_send ("irc_input_send", WEECHAT_HOOK_SIGNAL_STRING,
                          "libera;;priority_low;;/whois FlashCode");

Script (Python):

# dice "Hello!" sul server libera server, canale #weechat
weechat.hook_signal_send("irc_input_send", weechat.WEECHAT_HOOK_SIGNAL_STRING,
                         "libera;#weechat;priority_high,user_message;;Hello!")

# invia il comando "/whois FlashCode" sul server libera, con priorità minore
weechat.hook_signal_send("irc_input_send", weechat.WEECHAT_HOOK_SIGNAL_STRING,
                         "libera;;priority_low;;/whois FlashCode")

hook_hsignal

WeeChat ≥ 0.3.4, updated in 1.5, 3.6.

Hook su hsignal (segnale con tabella hash).

Prototipo:

struct t_hook *weechat_hook_hsignal (const char *signal,
                                     int (*callback)(const void *pointer,
                                                     void *data,
                                                     const char *signal,
                                                     struct t_hashtable *hashtable),
                                     const void *callback_pointer,
                                     void *callback_data);

Argomenti:

  • signal: segnale da catturare, wildcard * is allowed, multiple signals can be separated by semi-colons (a priority is allowed before one or more signals, see note about priority) (see table below)

  • callback: funzione chiamata a segnale ricevuto, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • const char *signal: segnale ricevuto

    • struct t_hashtable *hashtable: tabella hash

    • valore restituito:

      • WEECHAT_RC_OK

      • WEECHAT_RC_OK_EAT (stop sending the signal immediately) (WeeChat ≥ 0.4.0)

      • WEECHAT_RC_ERROR

  • callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_data: puntatore fornito alla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the hook is deleted

Valore restituito:

  • puntatore al nuovo hook, NULL in caso di errore

List of hsignals sent by WeeChat and plugins:

Plugin Segnale Min WeeChat Argomenti Descrizione

irc

irc_redirection_xxx_yyy (1)

0.3.4

Consultare hsignal_irc_redirect_command

Redirection output.

weechat

nicklist_group_added

0.4.1

buffer (struct t_gui_buffer *): buffer
parent_group (struct t_gui_nick_group *): parent group
group (struct t_gui_nick_group *): group

Group added in nicklist.

weechat

nicklist_nick_added

0.4.1

buffer (struct t_gui_buffer *): buffer
parent_group (struct t_gui_nick_group *): parent group
nick (struct t_gui_nick *): nick

Nick added in nicklist.

weechat

nicklist_group_removing

0.4.1

buffer (struct t_gui_buffer *): buffer
parent_group (struct t_gui_nick_group *): parent group
group (struct t_gui_nick_group *): group

Removing group from nicklist.

weechat

nicklist_nick_removing

0.4.1

buffer (struct t_gui_buffer *): buffer
parent_group (struct t_gui_nick_group *): parent group
nick (struct t_gui_nick *): nick

Removing nick from nicklist.

weechat

nicklist_group_changed

0.4.1

buffer (struct t_gui_buffer *): buffer
parent_group (struct t_gui_nick_group *): parent group
group (struct t_gui_nick_group *): group

Group changed in nicklist.

weechat

nicklist_nick_changed

0.4.1

buffer (struct t_gui_buffer *): buffer
parent_group (struct t_gui_nick_group *): parent group
nick (struct t_gui_nick *): nick

Nick changed in nicklist.

(1) xxx è l’argomento del segnale usato nella redirezione, yyy è lo schema di redirezione.

Esempio in C:

int
my_hsignal_cb (const void *pointer, void *data, const char *signal,
               struct t_hashtable *hashtable)
{
    /* ... */
    return WEECHAT_RC_OK;
}

struct t_hook *my_hsignal_hook = weechat_hook_hsignal ("test",
                                                       &my_hsignal_cb, NULL, NULL);

Script (Python):

# prototipo
def hook_hsignal(signal: str, callback: str, callback_data: str) -> str: ...

# esempio
def my_hsignal_cb(data: str, signal: str, hashtable: Dict[str, str]) -> int:
    # ...
    return weechat.WEECHAT_RC_OK

hook = weechat.hook_hsignal("test", "my_hsignal_cb", "")

hook_hsignal_send

WeeChat ≥ 0.3.4, updated in 1.0.

Invia un hsignal (segnale con tabella hash).

Prototipo:

int weechat_hook_hsignal_send (const char *signal, struct t_hashtable *hashtable);

Argomenti:

  • signal: segnale da inviare

  • hashtable: tabella hash

Return value (WeeChat ≥ 1.0):

  • return code of last callback executed (WEECHAT_RC_OK if no callback was executed):

    • WEECHAT_RC_OK

    • WEECHAT_RC_OK_EAT

    • WEECHAT_RC_ERROR

Esempio in C:

int rc;
struct t_hashtable *hashtable = weechat_hashtable_new (8,
                                                       WEECHAT_HASHTABLE_STRING,
                                                       WEECHAT_HASHTABLE_STRING,
                                                       NULL,
                                                       NULL);
if (hashtable)
{
    weechat_hashtable_set (hashtable, "key", "value");
    rc = weechat_hook_hsignal_send ("my_hsignal", hashtable);
    weechat_hashtable_free (hashtable);
}

Script (Python):

# prototipo
def hook_hsignal_send(signal: str, hashtable: Dict[str, str]) -> int: ...

# esempio
rc = weechat.hook_hsignal_send("my_hsignal", {"key": "value"})
Hsignal irc_redirect_command

WeeChat ≥ 0.3.4.

L’hsignal "irc_redirect_command" può essere inviato per redirigere l’output di un comando irc ad una callback.

L’argomento è una tabella hash con le seguenti componenti (chiavi e valori sono stringhe):

  • server: nome interno del server (richiesto)

  • pattern: schema di redirezione da usare (richiesto), sia uno di default (definito dal plugin irc), oppure definito dall’utente (consultare Hsignal irc_redirect_pattern), gli schemi predefiniti sono:

    • ison

    • list

    • mode_channel

    • mode_channel_ban ("mode #channel b")

    • mode_channel_ban_exception ("mode #channel e")

    • mode_channel_invite ("mode #channel I")

    • mode_user

    • monitor

    • names

    • ping

    • time

    • topic

    • userhost

    • who

    • whois

    • whowas

  • signal: nome segnale (richiesto)

  • count: numero di volte in cui verrà utilizzata la redirezione (opzionale, predefinito è 1)

  • string: stringa che deve essere presente nei messaggi irc ricevuti (opzionale, ma raccomandata, se una stringa può essere usata per identificare i messaggi)

  • timeout: timeout per la redirezione, in secondi (opzionale, predefiniti sono)

  • cmd_filter: elenco separato da virgole di comandi irc da filtrare (solo questi comandi verranno inviati alle callback, altri ignorati) (opzionale)

Subito dopo aver inviato questo hsignal, è necessario inviare il comando al server irc, e la redirezione verrà usata per questo comando.

Quando è stata ricevuta la risposta completa dal proprio comando, verrà inviato un hsignal. Questo hsignal ha il nome irc_redirection_xxx_yyy dove xxx è il segnale e yyy lo schema usato.

La tabella hash inviata in hsignal ha il seguente contenuto (chiavi e valori sono stringhe):

  • output: output del comando (i messaggi vengono separati da "\n")

  • output_size: numero di byte in output (come stringa)

  • error: stringa di errore (in caso di errore):

    • timeout: redirezione fermata dopo il timeout

  • server: nome interno del server

  • pattern: schema di redirezione

  • signal: nome del segnale

  • command: comando rediretto

Esempio in C:

int
test_whois_cb (const void *pointer, void *data, const char *signal,
               struct t_hashtable *hashtable)
{
    weechat_printf (NULL, "error = %s", weechat_hashtable_get (hashtable, "error"));
    weechat_printf (NULL, "output = %s", weechat_hashtable_get (hashtable, "output"));
    return WEECHAT_RC_OK;
}

weechat_hook_hsignal ("irc_redirection_test_whois", &test_whois_cb, NULL, NULL);
struct t_hashtable *hashtable = weechat_hashtable_new (8,
                                                       WEECHAT_HASHTABLE_STRING,
                                                       WEECHAT_HASHTABLE_STRING,
                                                       NULL,
                                                       NULL);
if (hashtable)
{
    weechat_hashtable_set (hashtable, "server", "libera");
    weechat_hashtable_set (hashtable, "pattern", "whois");
    weechat_hashtable_set (hashtable, "signal", "test");
    weechat_hashtable_set (hashtable, "string", "FlashCode");
    weechat_hook_hsignal_send ("irc_redirect_command", hashtable);
    weechat_hook_signal_send ("irc_input_send", WEECHAT_HOOK_SIGNAL_STRING,
                              "libera;;2;;/whois FlashCode");
    weechat_hashtable_free (hashtable);
}

Script (Python):

def test_whois_cb(data: str, signal: str, hashtable: Dict[str, str]) -> int:
    weechat.prnt("", "error = %s" % hashtable["error"])
    weechat.prnt("", "output = %s" % hashtable["output"])
    return weechat.WEECHAT_RC_OK

weechat.hook_hsignal("irc_redirection_test_whois", "test_whois_cb", "")
weechat.hook_hsignal_send("irc_redirect_command",
                          {"server": "libera", "pattern": "whois", "signal": "test",
                           "string": "FlashCode"})
weechat.hook_signal_send("irc_input_send", weechat.WEECHAT_HOOK_SIGNAL_STRING,
                         "libera;;2;;/whois FlashCode")
Hsignal irc_redirect_pattern

WeeChat ≥ 0.3.4.

L’hsignal "irc_redirect_pattern" può essere inviato per creare uno schema per la redirezione irc (consultare Hsignal irc_redirect_command).

L’argomento è una tabella hash con le seguenti voci (chiavi e valori sono stringa):

  • pattern: nome dello schema (richiesto)

  • timeout: timeout predefinito per lo schema, in secondi (opzionale, predefinito è 60)

  • cmd_start: elenco separato da virgole di comandi che avviano la redirezione (opzionale)

  • cmd_stop: elenco separato da virgole di comandi che fermano la redirezione (richiesto)

  • cmd_extra: elenco separato da virgole di comandi che possono essere ricevuti dopo aver fermato i comandi (opzionale)

Per ogni comando in cmd_start, cmd_stop e cmd_extra, è possibile fornire un intero con la posizione di "string" che va trovato nel messaggio ricevuto, ad esempio:

352:1,354,401:1

Per i comandi 352 e 401, "string" deve essere trovata nel messaggio ricevuto, come primo argomento.

Lo schema viene rimosso quando usato da una redirezione. Se uno schema si rivelasse necessario per diverse redirezioni, è necessario crearne uno prima di ogni redirezione.

Esempio in C:

struct t_hashtable *hashtable = weechat_hashtable_new (8,
                                                       WEECHAT_HASHTABLE_STRING,
                                                       WEECHAT_HASHTABLE_STRING,
                                                       NULL,
                                                       NULL);
if (hashtable)
{
    weechat_hashtable_set (hashtable, "pattern", "my_whois");
    weechat_hashtable_set (hashtable, "timeout", "30");
    weechat_hashtable_set (hashtable, "cmd_start", "311:1");
    weechat_hashtable_set (hashtable, "cmd_stop", "318:1,401:1,402:1,431:1,461");
    weechat_hashtable_set (hashtable, "cmd_extra", "318:1");
    weechat_hook_hsignal_send ("irc_redirect_pattern", hashtable);
    /*
     * now redirect irc whois command with hsignal irc_redirect_command,
     * using pattern "my_whois"
     */
    /* ... */
    weechat_hashtable_free (hashtable);
}

Script (Python):

weechat.hook_hsignal_send("irc_redirect_pattern",
                          {"pattern": "my_whois", "timeout": "30",
                           "cmd_start": "311:1",
                           "cmd_stop": "318:1,401:1,402:1,431:1,461",
                           "cmd_extra": "318:1"})
# now redirect irc whois command with hsignal irc_redirect_command
# using pattern "my_whois"
# ...

hook_config

Updated in 1.5.

Hook su un’opzione di configurazione.

Prototipo:

struct t_hook *weechat_hook_config (const char *option,
                                    int (*callback)(const void *pointer,
                                                    void *data,
                                                    const char *option,
                                                    const char *value),
                                    const void *callback_pointer,
                                    void *callback_data);

Argomenti:

  • option: opzione, il formato è il nome completo, come usato con il comando /set (ad esempio: weechat.look.item_time_format), wildcard * is allowed (a priority is allowed before the option, see note about priority)

  • callback: funzione chiamata quando l’opzione di configurazione è cambiata, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • const char *option: nome dell’opzione

    • const char *value: nuovo valore per l’opzione

    • valore restituito:

      • WEECHAT_RC_OK

      • WEECHAT_RC_ERROR

  • callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_data: puntatore fornito alla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the hook is deleted

Valore restituito:

  • puntatore al nuovo hook, NULL in caso di errore

Esempio in C:

int
my_config_cb (const void *pointer, void *data, const char *option,
              const char *value)
{
    /* ... */
    return WEECHAT_RC_OK;
}

/* cattura le modifiche dell'opzione "weechat.look.item_time_format" */
struct t_hook *my_config_hook = weechat_hook_config ("weechat.look.item_time_format",
                                                     &my_config_cb, NULL, NULL);

Script (Python):

# prototipo
def hook_config(option: str, callback: str, callback_data: str) -> str: ...

# esempio
def my_config_cb(data: str, option: str, value: str) -> int:
    # ...
    return weechat.WEECHAT_RC_OK

# cattura le modifiche dell'opzione "weechat.look.item_time_format"
hook = weechat.hook_config("weechat.look.item_time_format", "my_config_cb", "")

hook_modifier

Updated in 1.5.

Hook su un modificatore.

Prototipo:

struct t_hook *weechat_hook_modifier (const char *modifier,
                                      char *(*callback)(const void *pointer,
                                                        void *data,
                                                        const char *modifier,
                                                        const char *modifier_data,
                                                        const char *string),
                                      const void *callback_pointer,
                                      void *callback_data);

Argomenti:

  • modifier: nome modificatore (a priority is allowed before the modifier, see note about priority) (see table below)

  • callback: funzione chiamata quando viene usato il modificatore, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • const char *modifier: nome del modificatore

    • const char *modifier_data: dati per il modificatore

    • const char *string: stringa da modificare

    • valore restituito: nuova stringa

  • callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_data: puntatore fornito alla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the hook is deleted

Valore restituito:

  • puntatore al nuovo hook, NULL in caso di errore

List of modifiers used by WeeChat and plugins:

Modificatore Min WeeChat Dati modificatore Stringa Output

irc_batch

4.0.0

Server name + "," + batch type + "," + batch parameters

Content of multiple messages, separated by a newline char ("\n").

New content of messages (number can be different), an empty string discards all messages in the batch.

irc_cap_sync_req

4.0.0

Server name + "," + supported capabilities on server (separated by spaces)

Capabilities to request (separated by spaces).

New content of capabilities to request (separated by spaces).

irc_in_xxx (1)

Nome server

Contenuto del messaggio ricevuto dal server IRC (prima della codifica del set caratteri).
Warning: the string may contain invalid UTF-8 data; use only for raw operations on a message. Modifier irc_in2_xxx is recommended instead.

Nuovo contenuto del messaggio.

irc_in2_xxx (1)

0.3.5

Nome server

Contenuto del messaggio ricevuto dal server IRC (dopo la codifica del set caratteri).

Nuovo contenuto del messaggio.

irc_out1_xxx (1)

0.3.7

Nome server

Content of message about to be sent to IRC server before automatic split (to fit in 512 bytes by default).

Nuovo contenuto del messaggio.

irc_out_xxx (1)

Nome server

Content of message about to be sent to IRC server after automatic split (to fit in 512 bytes by default).

Nuovo contenuto del messaggio.

relay_client_irc_in

4.0.0

String with relay client pointer (eg: "0x1234abcd")

Content of message received from relay IRC client.

New content of message.

relay_client_irc_out1

4.0.0

String with relay client pointer (eg: "0x1234abcd")

Content of message about to be sent to relay IRC client before automatic split (to fit in 512 bytes by default).

New content of message.

relay_client_irc_out

4.0.0

String with relay client pointer (eg: "0x1234abcd")

Content of message about to be sent to relay IRC client after automatic split (to fit in 512 bytes by default).

New content of message.

bar_condition_yyy (2)

Stringa con puntatore alla finestra (eg: "0x1234abcd")

Stringa vuota.

"1" per visualizzare la barra, "0" per nasconderla.

history_add

0.3.2

Stringa con puntatore al buffer (eg: "0x1234abcd")

Contenuto della riga di comando da aggiungere nella cronologia comandi (buffer e globale).

Stringa aggiunta alla cronologia comandi.

input_text_content

Stringa con puntatore al buffer (eg: "0x1234abcd")

Contenuto della riga di comando.

Nuovo contenuto della riga di comando.

input_text_display

Stringa con puntatore al buffer (eg: "0x1234abcd")

Contenuto della riga di comando, senza tag al cursore.

Nuova stringa, solo da mostrare (la riga di comando non viene modificata).

input_text_display_with_cursor

Stringa con puntatore al buffer (eg: "0x1234abcd")

Contenuto della riga di comando, con tag al cursore.

Nuova stringa, solo da mostrare (la riga di comando non viene modificata).

input_text_for_buffer

0.3.7

Stringa con puntatore al buffer (eg: "0x1234abcd")

Contenuto della riga di comando inviata al buffer (testo o comando).

Nuovo contenuto della riga di comando inviata al buffer.

weechat_print

buffer pointer (eg: "0x1234abcd") + ";" + tags (3)

Messaggio stampato.

Nuovo messaggio stampato.
For more information on the hooks called when a line is printed, see hook_line.

(1) xxx è il nome del comando IRC.
(2) yyy è il nome della barra.
(3) With WeeChat ≤ 2.8, the format was: plugin + ";" + buffer_name + ";" + tags.

Esempio in C:

char *
my_modifier_cb (const void *pointer, void *data, const char *modifier,
                const char *modifier_data,
                const char *string)
{
    char *result;
    int length;

    if (!string)
        return NULL;

    length = strlen (string) + 5;
    result = malloc (length);
    if (result)
    {
        /* aggiunge "xxx" ad ogni messaggio stampato */
        snprintf (result, length, "%s xxx", string);
    }

    return result;
}

struct t_hook *my_modifier_hook = weechat_hook_modifier ("weechat_print",
                                                         &my_modifier_cb, NULL, NULL);

Script (Python):

# prototipo
def hook_modifier(modifier: str, callback: str, callback_data: str) -> str: ...

# esempio
def my_modifier_cb(data: str, modifier: str, modifier_data: str, string: str) -> str:
    return "%s xxx" % string

hook = weechat.hook_modifier("weechat_print", "my_modifier_cb", "")

hook_modifier_exec

Esegue modificatore(i).

Prototipo:

char *weechat_hook_modifier_exec (const char *modifier,
                                  const char *modifier_data,
                                  const char *string);

Argomenti:

  • modifier: nome modificatore

  • modifier_data: dati modificatore

  • string: stringa da modificare

Valore restituito:

  • stringa modificata, NULL in caso di errore

List of modifiers defined by WeeChat and plugins that can be used:

Modificatore Min WeeChat Dati modificatore Stringa Output

charset_decode

plugin.buffer_name

Qualsiasi stringa.

Stringa codificata dal set caratteri trovato per plugin/buffer in UTF-8.

charset_encode

plugin.buffer_name

Qualsiasi stringa.

Stringa codificata da UTF-8 al set caratteri trovato per il plugin/buffer.

irc_color_decode

"1" per mantenere i colori, "0" per rimuovere i colori

Qualsiasi stringa.

String with IRC colors converted to WeeChat colors (or IRC colors removed).

irc_color_encode

"1" per mantenere i colori, "0" per rimuovere i colori

Qualsiasi stringa.

String with IRC colors (or IRC colors removed).

irc_color_decode_ansi

1.0

"1" per mantenere i colori, "0" per rimuovere i colori

Qualsiasi stringa.

String with ANSI colors converted to IRC colors (or ANSI colors removed).

irc_command_auth

0.4.1

Nome server

Authentication command (for example: /msg nickserv identify password).

Command with hidden password (for example: /msg nickserv identify ********).

irc_message_auth

0.4.1

Nome server

Message displayed after /msg sent to nickserv.

Message with hidden password.

irc_tag_escape_value

3.3

-

Any string.

String with IRC tag value escaped, see this page .

irc_tag_unescape_value

3.3

-

Any string.

String with IRC tag value unescaped, see this page .

color_decode_ansi

1.0

"1" per mantenere i colori, "0" per rimuovere i colori

Qualsiasi stringa.

String with ANSI colors converted to WeeChat colors (or ANSI colors removed).

color_encode_ansi

2.7

-

Any string.

String with WeeChat colors converted to ANSI colors.

eval_path_home

2.7

Optional: directory=xxx where xxx can be: config, data, cache, runtime

Any string.

Evaluated path, result of the function string_eval_path_home.

Esempio in C:

char *new_string = weechat_hook_modifier_exec ("my_modifier",
                                               my_data, my_string);

Script (Python):

# prototipo
def hook_modifier_exec(modifier: str, modifier_data: str, string: str) -> str: ...

# esempio
weechat.hook_modifier_exec("my_modifier", my_data, my_string)

hook_info

Updated in 1.5, 2.5.

Hook su una informazione (la callback prende e restituisce una stringa).

Prototipo:

struct t_hook *weechat_hook_info (const char *info_name,
                                  const char *description,
                                  const char *args_description,
                                  char *(*callback)(const void *pointer,
                                                    void *data,
                                                    const char *info_name,
                                                    const char *arguments),
                                  const void *callback_pointer,
                                  void *callback_data);

Argomenti:

  • info_name: nome della info (a priority is allowed before the info name, see note about priority)

  • description: descrizione

  • args_description: descrizione degli argomenti

  • callback: funzione chiamata alla richiesta di una info, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • const char *info_name: nome della info

    • const char *arguments: argomenti addizionali, dipendono dalle info

    • valore restituito: valore dell’info richiesta

  • callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_data: puntatore fornito alla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the hook is deleted

Valore restituito:

  • puntatore al nuovo hook, NULL in caso di errore

With WeeChat ≥ 2.5, the callback returns an allocated string (with WeeChat ≤ 2.4, it was a pointer to a static string).

Esempio in C:

char *
my_info_cb (const void *pointer, void *data, const char *info_name,
            const char *arguments)
{
    /* ... */
    return strdup ("some_info");
}

/* aggiunge informazione "my_info" */
struct t_hook *my_info_hook = weechat_hook_info ("my_info",
                                                 "Some info",
                                                 "Info about arguments",
                                                 &my_info_cb, NULL, NULL);

Script (Python):

# prototipo
def hook_info(info_name: str, description: str, args_description: str,
              callback: str, callback_data: str) -> str: ...

# esempio
def my_info_cb(data: str, info_name: str, arguments: str) -> str:
    return "some_info"

hook = weechat.hook_info("my_info", "Some info", "Info about arguments",
                         "my_info_cb", "")

hook_info_hashtable

WeeChat ≥ 0.3.4, updated in 1.5.

Hook su una informazione (la callback prende e restituisce una tabella hash).

Prototipo:

struct t_hook *weechat_hook_info_hashtable (const char *info_name,
                                            const char *description,
                                            const char *args_description,
                                            const char *output_description,
                                            struct t_hashtable *(*callback)(const void *pointer,
                                                                            void *data,
                                                                            const char *info_name,
                                                                            struct t_hashtable *hashtable),
                                            const void *callback_pointer,
                                            void *callback_data);

Argomenti:

  • info_name: nome della info (a priority is allowed before the info name, see note about priority)

  • description: descrizione

  • args_description: descrizione della tabella hash attesa (opzionale, può essere NULL)

  • output_description: descrizione della tabella hash restituita dalla callback (opzionale, può essere NULL)

  • callback: funzione chiamata alla richiesta della info, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • const char *info_name: nome della info

    • struct t_hashtable *hashtable: tabella hash, in base alla info

    • valore restituito: tabella hash richiesta

  • callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_data: puntatore fornito alla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the hook is deleted

Valore restituito:

  • puntatore al nuovo hook, NULL in caso di errore

Esempio in C:

struct t_hashtable *
my_info_hashtable_cb (const void *pointer, void *data, const char *info_name,
                      struct t_hashtable *hashtable)
{
    /* ... */
    return pointer_to_new_hashtable;
}

/* add info "my_info_hashtable" */
struct t_hook *my_info_hook = weechat_hook_info_hashtable ("my_info_hashtable",
                                                           "Some info",
                                                           "Info about input hashtable",
                                                           "Info about output hashtable",
                                                           &my_info_hashtable_cb, NULL, NULL);

Script (Python):

# prototipo
def hook_info_hashtable(info_name: str, description: str, args_description: str,
                        output_description: str, callback: str, callback_data: str) -> str: ...

# esempio
def my_info_hashtable_cb(data: str, info_name: str, hashtable: Dict[str, str]) -> Dict[str, str]:
    return {"test_key": "test_value"}

hook = weechat.hook_info_hashtable("my_info_hashtable", "Some info",
                                   "Info about input hashtable",
                                   "Info about output hashtable",
                                   "my_info_hashtable_cb", "")

hook_infolist

Updated in 1.5.

Hook su una lista info: la callback restituisce il puntatore alla lista info richiesta.

Prototipo:

struct t_hook *weechat_hook_infolist (const char *infolist_name,
                                      const char *description,
                                      const char *pointer_description,
                                      const char *args_description,
                                      struct t_infolist *(*callback)(const void *pointer,
                                                                     void *data,
                                                                     const char *infolist_name,
                                                                     void *obj_pointer,
                                                                     const char *arguments),
                                      const void *callback_pointer,
                                      void *callback_data);

Argomenti:

  • infolist_name: nome della lista info (a priority is allowed before the infolist name, see note about priority)

  • description: descrizione

  • pointer_description: descrizione del puntatore (opzionale, può essere NULL)

  • args_description: descrizione degli argomenti (opzionale, può essere NULL)

  • callback: funzione chiamata alla richiesta della lista info, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • const char *infolist_name: nome della lista info

    • void *pointer: puntatore ad un oggetto che la lista info deve restituire (per ricevere un solo elemento della lista info)

    • const char *arguments: argomento aggiuntivo, dipende dalla lista info

    • valore restituito: lista info richiesta

  • callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_data: puntatore fornito alla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the hook is deleted

Valore restituito:

  • puntatore al nuovo hook, NULL in caso di errore

Esempio in C:

struct t_infolist *
my_infolist_cb (const void *pointer, void *data, const char *infolist_name,
                void *obj_pointer, const char *arguments)
{
    struct t_infolist *my_infolist;

    /* compila lista info */
    /* ... */

    return my_infolist;
}

/* aggiunge lista info "my_infolist" */
struct t_hook *my_infolist = weechat_hook_infolist ("my_infolist",
                                                    "Infolist with some data",
                                                    "Info about pointer",
                                                    "Info about arguments",
                                                    &my_infolist_cb, NULL, NULL);

Script (Python):

# prototipo
def hook_infolist(infolist_name: str, description: str, pointer_description: str,
                  args_description: str, callback: str, callback_data: str) -> str: ...

# esempio
def my_infolist_cb(data: str, infolist_name: str, pointer: str, arguments: str) -> str:
    # build infolist
    # ...
    return my_infolist

hook = weechat.hook_infolist("my_infolist", "Infolist with some data",
                             "Info about pointer", "Info about arguments",
                             "my_infolist_cb", "")

hook_hdata

Updated in 1.5.

Hook di un hdata: la callback restituisce il puntatore all’hdata richiesto.

Prototipo:

struct t_hook *weechat_hook_hdata (const char *hdata_name,
                                   const char *description,
                                   struct t_hdata *(*callback)(const void *pointer,
                                                               void *data,
                                                               const char *hdata_name),
                                   const void *callback_pointer,
                                   void *callback_data);

Argomenti:

  • hdata_name: nome dell’hdata (a priority is allowed before the hdata name, see note about priority)

  • description: descrizione

  • callback: funzione chiamata alla richiesta di hdata, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • const char *hdata_name: nome dell’hdata

    • return value: hdata richiesto

  • callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_data: puntatore fornito alla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the hook is deleted

Valore restituito:

  • puntatore al nuovo hook, NULL in caso di errore

Esempio in C:

struct t_hdata *
my_hdata_cb (const void *pointer, void *data, const char *hdata_name)
{
    struct t_hdata *my_hdata;

    /* build hdata */
    /* ... */

    return my_hdata;
}

/* add hdata "my_hdata" */
struct t_hook *my_hdata = weechat_hook_hdata ("my_hdata",
                                              "Hdata for my structure",
                                              &my_hdata_cb, NULL, NULL);
Questa funzione non è disponibile nelle API per lo scripting.

hook_focus

Updated in 1.5, 4.0.0, 4.1.0.

Hook sul foucus: evento del mouse o tasto premuto nella modalità cursore (movimento libero del cursore).

Prototipo:

struct t_hook *weechat_hook_focus (const char *area,
                                   struct t_hashtable *(*callback)(const void *pointer,
                                                                   void *data,
                                                                   struct t_hashtable *info),
                                   const void *callback_pointer,
                                   void *callback_data);

Argomenti:

  • area: "chat" per la zona di chat, o il nome di un elemento barra (a priority is allowed before the area, see note about priority)

  • callback: funzione chiamata al momento del focus, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • struct t_hashtable *info: tabella hash con informazioni sul focus e stringhe restituite da altre chiamate alle callback sul focus (con la priorità più alta) (consultare la tabella in basso)

    • valore restituito: sia il puntatore "info" tabella hash completa), o il puntatore ad una nuova tabella hash (creata dalla callback, con chiavi e valori di tipo "string), questa nuovo contenuto della tabella hash verrà aggiunto ad info per le altre chiamate alle callback del focus

  • callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_data: puntatore fornito alla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the hook is deleted

Per l’azione di un mouse, la callback verrà chiamata due volte: la prima quando il pulsante viene premuto (qui la zona corrisponde sempre alla propria area), la seconda quando il pulsante viene rilasciato, e allora la zona potrà non corrispondere con la propria: per cui bisogna sempre verificare nella propria callback se l’area corrisponde prima di usare le informazioni nella tabella hash.

Contenuto della tabella hash inviata alla callback (tasti e valori sono di tipo "string"):

Key (1) Descrizione Valori di esempio Valore se N/D

_x

Colonna sullo schermo.

"0" …​ "n"

_y

Riga sullo schermo.

"0" …​ "n"

_key

Evento tasto o mouse.

"button1", "button2-gesture-left", …​

_window

Puntatore alla finestra.

"0x1234abcd"

""

_window_number

Numero della finestra.

"1" …​ "n"

"*"

_buffer

Puntatore al buffer.

"0x1234abcd"

""

_buffer_number

Numero del buffer.

"1" …​ "n"

"-1"

_buffer_plugin

Nome plugin del buffer.

"core", "irc", …​

""

_buffer_name

Nome del buffer.

"weechat", "libera.#weechat", …​

""

_buffer_full_name

Nome completo del buffer.

"core.weechat", "irc.libera.#weechat", …​

""

_buffer_localvar_XXX (2)

Variabili locali del buffer.

qualsiasi valore

non impostato

_chat

Indicatore area di chat.

"0" o "1"

"0"

_chat_line

Pointer to line (WeeChat ≥ 1.2).

"0x1234abcd"

""

_chat_line_x

Colonna nella riga (3).

"0" …​ "n"

"-1"

_chat_line_y

Numero della riga (3).

"0" …​ "n"

"-1"

_chat_line_date

Riga con data/ora.

"1313237175"

"0"

_chat_line_date_usec

Microseconds of line date/time.

"123456"

"0"

_chat_line_date_printed

Riga con data/ora (4).

"1313237175"

"0"

_chat_line_date_usec_printed

Microseconds of line printed date/time (4).

"123456"

"0"

_chat_line_time

Ora visualizzata.

"14:06:15"

""

_chat_line_tags

Tag della riga.

"irc_privmsg,nick_flashy,log1"

""

_chat_line_nick

Nick della riga.

"FlashCode"

""

_chat_line_prefix

Prefisso della riga.

"@FlashCode"

""

_chat_line_message

Messaggio della riga.

"Hello world!"

""

_chat_focused_line

Line at (x, y) (WeeChat ≥ 4.0.0).

"Hello world!"

""

_chat_focused_line_bol

Text from beginning of line to (x-1, y) (WeeChat ≥ 4.1.0).

"Hello"

""

_chat_focused_line_eol

Text from (x, y) to end of line (WeeChat ≥ 4.1.0).

"llo world!"

""

_chat_word

Parola a (x,y).

"Hello"

""

_chat_bol

Text from beginning of message to (x-1, y).

"He"

""

_chat_eol

Text from (x, y) to the end of message.

"llo world!"

""

_bar_name

Nome della barra.

"title", "nicklist", …​

""

_bar_filling

Riempimento della barra.

"horizontal", "vertical", …​

""

_bar_item_name

Nome dell’elemento barra.

"buffer_nicklist", "hotlist", …​

""

_bar_item_line

Riga nell’elemento barra.

"0" …​ "n"

"-1"

_bar_item_col

Colonna nell’elemento barra.

"0" …​ "n"

"-1"

_bar_window

Pointer to bar window (WeeChat ≥ 2.9).

"0x1234abcd"

""

(1) Ci sono alcune chiavi con il suffisso "2" (es: "_x2", "_y2", "_window2", …​) con informazioni sul secondo punto (utile solo per le azioni del mouse, per sapere dove il pulsante del mouse è stato rilasciato).
(2) XXX è il nome della variabile locale nel buffer.
(3) È impostato solo per l buffer con contenuto libero.
(4) Data/ora in cui WeeChat aggiunge una riga nel buffer (maggiore o uguale a "chat_line_date").

Informazioni aggiuntive per l’elemento barra "buffer_nicklist":

Plugin (1) Chiave Descrizione

irc

irc_nick

Pointer to IRC nick (WeeChat ≥ 3.0).

irc

irc_host

Host per il nick (se conosciuto).

weechat

nick

Nick.

weechat

prefix

Prefisso per il nick.

weechat

group

Nome gruppo.

(1) Il nome del plugin che definisce un hook_focus per restituire informazioni su questo elemento della barra (ad esempio se il plugin è "irc", tale informazione sarà disponibile solo sui buffer irc).

Valore restituito:

  • puntatore al nuovo hook, NULL in caso di errore

Esempio in C:

struct t_hashtable *
my_focus_nicklist_cb (const void *pointer, void *data, struct t_hashtable *info)
{
    /* add strings in hashtable */
    /* ... */

    return info;
}

/* add focus on nicklist */
struct t_hook *my_focus = weechat_hook_focus ("buffer_nicklist",
                                              &my_focus_nicklist_cb, NULL, NULL);

Script (Python):

# prototipo
def hook_focus(area: str, callback: str, callback_data: str) -> str: ...

# esempio
def my_focus_nicklist_cb(data: str, info: Dict[str, str]) -> Dict[str, str]:
    # build dict
    # ...
    return my_dict

hook = weechat.hook_focus("buffer_nicklist", "my_focus_nicklist_cb", "")

hook_set

WeeChat ≥ 0.3.9 (script: WeeChat ≥ 0.4.3).

Set string value of a hook property.

Prototipo:

void weechat_hook_set (struct t_hook *hook, const char *property,
                       const char *value);

Argomenti:

  • hook: qualcosa su cui è presente un hook con "weechat_hook_xxx()"

  • property: nome della proprietà (see table below)

  • value: new value for property

Properties:

Nome Min WeeChat Hook type Valore Descrizione

subplugin

any type

qualsiasi stringa

Name of sub plugin (commonly script name, which is displayed in /help command for a hook of type command).

stdin

0.4.3

process, process_hashtable

qualsiasi stringa

Send data on standard input (stdin) of child process.

stdin_close

0.4.3

process, process_hashtable

(not used)

Close pipe used to send data on standard input (stdin) of child process.

signal

1.0

process, process_hashtable

signal number or one of these names: hup, int, quit, kill, term, usr1, usr2

Send a signal to the child process.

Esempio in C:

struct t_hook *my_command_hook =
    weechat_hook_command ("abcd", "description",
                          "args", "description args",
                          "", &my_command_cb, NULL, NULL);
weechat_hook_set (my_command_hook, "subplugin", "test");

Script (Python):

# prototipo
def hook_set(hook: str, property: str, value: str) -> int: ...

# esempio
def my_process_cb(data: str, command: str, return_code: int, out: str, err: str) -> int:
    # ...
    return weechat.WEECHAT_RC_OK

hook = weechat.hook_process_hashtable("/path/to/command", {"stdin": "1"},
                                      20000, "my_process_cb", "")
weechat.hook_set(hook, "stdin", "data sent to stdin of child process")
weechat.hook_set(hook, "stdin_close", "")  # optional

unhook

Rimuove un hook.

Prototipo:

void weechat_unhook (struct t_hook *hook);

Argomenti:

  • hook: qualcosa su cui è presente un hook con "weechat_hook_xxx()"

Esempio in C:

struct t_hook *my_hook = weechat_hook_command ( /* ... */ );
/* ... */
weechat_unhook (my_hook);

Script (Python):

# prototipo
def unhook(hook: str) -> int: ...

# esempio
weechat.unhook(my_hook)

unhook_all

Updated in 1.5.

Rimuove l’hook in qualsiasi punto in cui è stato attivato dal plugin corrente.

Prototipo:

void weechat_unhook_all (const char *subplugin);

Argomenti:

  • subplugin: if not NULL, unhook only hooks with this "subplugin" set (this argument is not available in scripting API)

Esempio in C:

weechat_unhook_all (NULL);

Script (Python):

# prototipo
def unhook_all() -> int: ...

# esempio
weechat.unhook_all()

3.15. Buffer

Funzioni per creare/richiedere/chiudere buffer.

buffer_new

Updated in 1.5.

Apre un nuovo buffer.

If you want to immediately set buffer properties (buffer type, local variables, key bindings, etc.), then better use the function buffer_new_props which sets these properties during the buffer creation, before sending signal buffer_opened.

Prototipo:

struct t_gui_buffer *weechat_buffer_new (const char *name,
                                         int (*input_callback)(const void *pointer,
                                                               void *data,
                                                               struct t_gui_buffer *buffer,
                                                               const char *input_data),
                                         const void *input_callback_pointer,
                                         void *input_callback_data,
                                         int (*close_callback)(const void *pointer,
                                                               void *data,
                                                               struct t_gui_buffer *buffer),
                                         const void *close_callback_pointer,
                                         void *close_callback_data);

Argomenti:

  • name: nome del buffer (deve essere unico per il plugin)

  • input_callback: funzione chiamata quando il testo in input è stato inserito nel buffer, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • struct t_gui_buffer *buffer: puntatore al buffer

    • const char *input_data: dati in input

    • valore restituito:

      • WEECHAT_RC_OK

      • WEECHAT_RC_ERROR

  • input_callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • input_callback_data: puntatore fornito dalla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the buffer is closed

  • close_callback: funzione chiamata alla chiusura del buffer, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • struct t_gui_buffer *buffer: puntatore al buffer

    • valore restituito:

      • WEECHAT_RC_OK

      • WEECHAT_RC_ERROR

  • close_callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • close_callback_data: puntatore fornito dalla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the buffer is closed

Valore restituito:

  • puntatore al nuovo buffer, NULL in caso di errore

Esempio in C:

int
my_input_cb (const void *pointer, void *data,
             struct t_gui_buffer *buffer, const char *input_data)
{
    weechat_printf (buffer, "Testo: %s", input_data);
    return WEECHAT_RC_OK;
}

int
my_close_cb (const void *pointer, void *data, struct t_gui_buffer *buffer)
{
    weechat_printf (NULL, "Il buffer '%s' verrà chiuso!",
                    weechat_buffer_get_string (buffer, "name"));
    return WEECHAT_RC_OK;
}

struct t_gui_buffer *my_buffer = weechat_buffer_new ("my_buffer",
                                                     &my_input_cb, NULL, NULL,
                                                     &my_close_cb, NULL, NULL);

Script (Python):

# prototipo
def buffer_new(name: str, input_callback: str, input_callback_data: str,
               close_callback: str, close_callback_data: str) -> str: ...

# esempio
def my_input_cb(data: str, buffer: str, input_data: str) -> int:
    weechat.prnt(buffer, "Testo: %s" % input_data)
    return weechat.WEECHAT_RC_OK

def my_close_cb(data: str, buffer: str) -> int:
    weechat.prnt("", "Il buffer '%s' verrà chiuso!" % weechat.buffer_get_string(buffer, "name"))
    return weechat.WEECHAT_RC_OK

buffer = weechat.buffer_new("my_buffer", "my_input_cb", "", "my_close_cb", "")

buffer_new_props

WeeChat ≥ 3.5.

Open a new buffer and apply properties.

Prototipo:

struct t_gui_buffer *weechat_buffer_new_props (const char *name,
                                               struct t_hashtable *properties,
                                               int (*input_callback)(const void *pointer,
                                                                     void *data,
                                                                     struct t_gui_buffer *buffer,
                                                                     const char *input_data),
                                               const void *input_callback_pointer,
                                               void *input_callback_data,
                                               int (*close_callback)(const void *pointer,
                                                                     void *data,
                                                                     struct t_gui_buffer *buffer),
                                               const void *close_callback_pointer,
                                               void *close_callback_data);

Argomenti:

  • name: nome del buffer (deve essere unico per il plugin)

  • properties: properties to apply (see function buffer_set for the allowed properties)

  • input_callback: funzione chiamata quando il testo in input è stato inserito nel buffer, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • struct t_gui_buffer *buffer: puntatore al buffer

    • const char *input_data: dati in input

    • valore restituito:

      • WEECHAT_RC_OK

      • WEECHAT_RC_ERROR

  • input_callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • input_callback_data: puntatore fornito dalla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the buffer is closed

  • close_callback: funzione chiamata alla chiusura del buffer, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • struct t_gui_buffer *buffer: puntatore al buffer

    • valore restituito:

      • WEECHAT_RC_OK

      • WEECHAT_RC_ERROR

  • close_callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • close_callback_data: puntatore fornito dalla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the buffer is closed

Valore restituito:

  • puntatore al nuovo buffer, NULL in caso di errore

Esempio in C:

int
my_input_cb (const void *pointer, void *data,
             struct t_gui_buffer *buffer, const char *input_data)
{
    weechat_printf (buffer, "Testo: %s", input_data);
    return WEECHAT_RC_OK;
}

int
my_close_cb (const void *pointer, void *data, struct t_gui_buffer *buffer)
{
    weechat_printf (NULL, "Il buffer '%s' verrà chiuso!",
                    weechat_buffer_get_string (buffer, "name"));
    return WEECHAT_RC_OK;
}

struct t_hashtable *properties = weechat_hashtable_new (8,
                                                        WEECHAT_HASHTABLE_STRING,
                                                        WEECHAT_HASHTABLE_STRING,
                                                        NULL,
                                                        NULL);
/* buffer with free content */
weechat_hashtable_set (properties, "type", "free");
/* no logging on this buffer */
weechat_hashtable_set (properties, "localvar_set_no_log", "1");
/* bind key alt-c on this buffer */
weechat_hashtable_set (properties, "key_bind_meta-c", "/my_command");

struct t_gui_buffer *my_buffer = weechat_buffer_new_props ("my_buffer",
                                                           properties,
                                                           &my_input_cb, NULL, NULL,
                                                           &my_close_cb, NULL, NULL);

Script (Python):

# prototipo
def buffer_new_props(name: str, properties: Dict[str, str],
                     input_callback: str, input_callback_data: str,
                     close_callback: str, close_callback_data: str) -> str: ...

# esempio
def my_input_cb(data: str, buffer: str, input_data: str) -> int:
    weechat.prnt(buffer, "Testo: %s" % input_data)
    return weechat.WEECHAT_RC_OK

def my_close_cb(data: str, buffer: str) -> int:
    weechat.prnt("", "Il buffer '%s' verrà chiuso!" % weechat.buffer_get_string(buffer, "name"))
    return weechat.WEECHAT_RC_OK

properties = {
    "type": "free",                    # buffer with free content
    "localvar_set_no_log": "1",        # no logging on this buffer
    "key_bind_meta-c": "/my_command",  # bind key alt-c on this buffer
}
buffer = weechat.buffer_new_props("my_buffer", properties, "my_input_cb", "", "my_close_cb", "")

current_buffer

Restituisce il puntatore al buffer corrente (buffer visualizzato nella finestra corrente).

Prototipo:

struct t_gui_buffer *weechat_current_buffer ();

Valore restituito:

  • puntatore al buffer corrente

Esempio in C:

weechat_printf (weechat_current_buffer (), "Testo sul buffer corrente");

Script (Python):

# prototipo
def current_buffer() -> str: ...

# esempio
weechat.prnt(weechat.current_buffer(), "Testo sul buffer corrente")

Updated in 1.0.

Cerca un buffer tramite plugin e/o nome.

Prototipo:

struct t_gui_buffer *weechat_buffer_search (const char *plugin,
                                            const char *name);

Argomenti:

  • plugin: name of plugin, following special value is allowed:

    • ==: the name used is the buffer full name (for example: irc.libera.#weechat instead of libera.#weechat) (WeeChat ≥ 1.0)

  • name: name of buffer, if it is NULL or empty string, the current buffer is returned (buffer displayed by current window); if the name starts with (?i), the search is case insensitive (WeeChat ≥ 1.0)

Valore restituito:

  • puntatore al buffer trovato, NULL in caso contrario

Esempio in C:

struct t_gui_buffer *buffer1 = weechat_buffer_search ("irc", "libera.#weechat");
struct t_gui_buffer *buffer2 = weechat_buffer_search ("==", "irc.libera.#test");  /* WeeChat ≥ 1.0 */

Script (Python):

# prototipo
def buffer_search(plugin: str, name: str) -> str: ...

# esempio
buffer = weechat.buffer_search("my_plugin", "my_buffer")

buffer_search_main

Cerca nel buffer principale di WeeChat (per primo nel buffer core, il primo visualizzato all’avvio di WeeChat).

Prototipo:

struct t_gui_buffer *weechat_buffer_search_main ();

Valore restituito:

  • puntatore al buffer principale di WeeChat (buffer core)

Esempio in C:

struct t_gui_buffer *weechat_buffer = weechat_buffer_search_main ();

Script (Python):

# prototipo
def buffer_search_main() -> str: ...

# esempio
buffer = weechat.buffer_search_main()

buffer_clear

Pulisce il contenuto del buffer.

Prototipo:

void weechat_buffer_clear (struct t_gui_buffer *buffer);

Argomenti:

  • buffer: puntatore al buffer

Esempio in C:

struct t_gui_buffer *my_buffer = weechat_buffer_search ("my_plugin",
                                                        "my_buffer");
if (my_buffer)
{
    weechat_buffer_clear (my_buffer);
}

Script (Python):

# prototipo
def buffer_clear(buffer: str) -> int: ...

# esempio
buffer = weechat.buffer_search("my_plugin", "my_buffer")
if buffer:
    weechat.buffer_clear(buffer)

buffer_close

Chiude un buffer.

Prototipo:

void weechat_buffer_close (struct t_gui_buffer *buffer);

Argomenti:

  • buffer: puntatore al buffer

Esempio in C:

struct t_gui_buffer *my_buffer = weechat_buffer_new ("my_buffer",
                                                     &my_input_cb, NULL,
                                                     &my_close_cb, NULL);
/* ... */
weechat_buffer_close (my_buffer);

Script (Python):

# prototipo
def buffer_close(buffer: str) -> int: ...

# esempio
buffer = weechat.buffer_new("my_buffer", "my_input_cb", "", "my_close_cb", "")
# ...
weechat.buffer_close(buffer)

buffer_merge

Unisce un buffer in un altro: entrambi i buffer esistono separatamente, ma con lo stesso numero, e WeeChat visualizzerà le righe di entrambi i buffer (righe mischiate).

Prototipo:

void weechat_buffer_merge (struct t_gui_buffer *buffer,
                           struct t_gui_buffer *target_buffer);

Argomenti:

  • buffer: puntatore al buffer

  • target_buffer: buffer di destinazione, dove il buffer verrà unito

Esempio in C:

/* merge current buffer with weechat "core" buffer */
weechat_buffer_merge (weechat_current_buffer (),
                      weechat_buffer_search_main ());

Script (Python):

# prototipo
def buffer_merge(buffer: str, target_buffer: str) -> int: ...

# esempio
# merge current buffer with WeeChat "core" buffer
weechat.buffer_merge(weechat.current_buffer(), weechat.buffer_search_main())

buffer_unmerge

Stacca un buffer da un gruppo di buffer uniti.

Prototipo:

void weechat_buffer_unmerge (struct t_gui_buffer *buffer,
                             int number);

Argomenti:

  • buffer: puntatore al buffer

  • number: numero di destinazione per il buffer staccato, se è < 1, allora il buffer verrà spostato al numero di buffer +1

Esempio in C:

weechat_buffer_unmerge (weechat_current_buffer (), 1);

Script (Python):

# prototipo
def buffer_unmerge(buffer: str, number: int) -> int: ...

# esempio
weechat.buffer_unmerge(weechat.current_buffer(), 1)

buffer_get_integer

Restituisce il valore intero della proprietà di un buffer.

Prototipo:

int weechat_buffer_get_integer (struct t_gui_buffer *buffer,
                                const char *property);

Argomenti:

  • buffer: puntatore al buffer

  • property: nome della proprietà:

    • opening: 1 if buffer is opening, otherwise 0 (WeeChat ≥ 4.2.0)

    • number: numero del buffer (inizia da 1)

    • layout_number: numero del buffer salvato nel layout

    • layout_number_merge_order: ordine di unione per i layout

    • short_name_is_set: 1 se il nome breve è impostato, 0 in caso contrario

    • type: tipo dibuffer (0: formattato, 1: contenuto libero)

    • notify: livello di notifica per il buffer

    • num_displayed: numero delle finestre che visualizzano il buffer

    • active: 2 if buffer is the only active (merged), 1 se il buffer è attivo, 0 se il buffer è unito e non selezionato

    • hidden: 1 if buffer is hidden, otherwise 0 (WeeChat ≥ 1.0)

    • zoomed: 1 if buffer is merged and zoomed, otherwise 0 (WeeChat ≥ 1.0)

    • print_hooks_enabled: 1 se gli hook sulla stampa sono abilitati, altrimenti 0

    • day_change: 1 if messages for the day change are displayed, otherwise 0 (WeeChat ≥ 0.4.3)

    • clear: 1 if buffer can be cleared with command /buffer clear, otherwise 0 (WeeChat ≥ 1.0)

    • filter: 1 if filters are enabled on buffer, otherwise 0 (WeeChat ≥ 1.0)

    • closing: 1 if buffer is closing, otherwise 0 (WeeChat ≥ 1.0)

    • lines_hidden: 1 se almeno una riga è nascosta sul buffer (filtrata), oppure 0 se vengono visualizzate tutte le righe

    • prefix_max_length: lunghezza massima del prefisso in questo buffer

    • next_line_id: next line id in buffer (WeeChat ≥ 3.8)

    • time_for_each_line: 1 se l’ora è visualizzata per ogni riga nel buffer (predefinito), altrimenti 0

    • nicklist: 1 se la lista nick è abilitata, altrimenti 0

    • nicklist_case_sensitive: 1 se i nick sono sensibili alle maiuscole, altrimenti 0

    • nicklist_max_length: lunghezza massima per un nick

    • nicklist_display_groups: 1 se i gruppi vengono visualizzati, altrimenti 0

    • nicklist_count: number of nicks and groups in nicklist

    • nicklist_visible_count: numero di nick/gruppi visualizzati

    • nicklist_groups_count: number of groups in nicklist

    • nicklist_groups_visible_count: number of groups displayed

    • nicklist_nicks_count: number of nicks in nicklist

    • nicklist_nicks_visible_count: number of nicks displayed

    • input: 1 se l’input è abilitato, altrimenti 0

    • input_get_unknown_commands: 1 se i comandi sconosciuti vengono inviati alla callback di input, altrimenti 0

    • input_get_empty: 1 if empty input is sent to input callback, otherwise 0

    • input_multiline: 1 if multiple lines are sent as one message to input callback, otherwise 0

    • input_size: dimensione per l’input (in byte)

    • input_length: lunghezza dell’input (numero di caratteri)

    • input_pos: posizione del cursore nell’input del buffer

    • input_1st_display: primo carattere visualizzato su schermo

    • num_history: numero di comandi nella cronologia

    • text_search: tipo di ricerca nel testo:

      • 0: nessuna ricerca in questo momento

      • 1: search in buffer lines

      • 2: search in commands history

    • text_search_direction: direction for search:

      • 0: backward search (direction: oldest messages/commands)

      • 1: forward search (direction: newest messages/commands)

    • text_search_exact: 1 se la ricerca testo è esatta

    • text_search_regex: 1 if searching with a regular expression

    • text_search_where:

      • 0: nessuna ricerca in questo momento

      • 1: search in message

      • 2: search in prefix

      • 3: search in prefix and message

    • text_search_history:

      • 0: nessuna ricerca in questo momento

      • 1: search in buffer local history

      • 2: search in global history

    • text_search_found: 1 se il testo viene trovato, altrimenti 0

Valore restituito:

  • valore intero della proprietà

Esempio in C:

weechat_printf (NULL, "my buffer number is: %d",
                weechat_buffer_get_integer (my_buffer, "number"));

Script (Python):

# prototipo
def buffer_get_integer(buffer: str, property: str) -> int: ...

# esempio
weechat.prnt("", "my buffer number is: %d" % weechat.buffer_get_integer(my_buffer, "number"))

buffer_get_string

Restituisce il valore stringa di una proprietà del buffer.

Prototipo:

const char *weechat_buffer_get_string (struct t_gui_buffer *buffer,
                                       const char *property);

Argomenti:

  • buffer: puntatore al buffer

  • property: nome proprietà:

    • plugin: nome del plugin che ha creato questo buffer ("core" per il buffer principale di WeeChat)

    • name: nome del buffer

    • full_name: nome completo del buffer ("plugin.nome") (WeeChat ≥ 0.3.7)

    • old_full_name: old full name of buffer ("plugin.name"), set before the buffer is renamed (WeeChat ≥ 2.8)

    • short_name: nome breve del buffer (nota: usato solo per il display e può essere cambiato dall’utente, questo nome non va usato per trovare il nome del buffer, utilizzare invece name, fullname o la variabile locale channel)

    • type: type of buffer: "formatted" or "free" (WeeChat ≥ 4.2.0)

    • title: titolo del buffer

    • input: testo in ingresso

    • text_search_input: input salvato prima della ricerca nel testo

    • highlight_words: elenco di parole da evidenziare

    • highlight_disable_regex: POSIX extended regular expression for disabling highlight

    • highlight_regex: POSIX extended regular expression for highlight

    • highlight_tags_restrict: restrict highlights to messages with these tags

    • highlight_tags: force highlight on messages with these tags

    • hotlist_max_level_nicks: livello massimo della hotlist per alcuni nick

    • localvar_xxx: ottiene il contenuto della variabile locale "xxx" (sostituire "xxx" con il nome della variabile da leggere)

Valore restituito:

  • valore stringa della proprietà

Esempio in C:

weechat_printf (NULL, "name / short name of buffer are: %s / %s",
                weechat_buffer_get_string (my_buffer, "name"),
                weechat_buffer_get_string (my_buffer, "short_name"));

Script (Python):

# prototipo
def buffer_get_string(buffer: str, property: str) -> str: ...

# esempio
weechat.prnt("", "name / short name of buffer are: %s / %s"
    % (weechat.buffer_get_string(my_buffer, "name"),
    weechat.buffer_get_string(my_buffer, "short_name")))

buffer_get_pointer

Restituisce il valore puntatore della proprietà di un buffer.

Prototipo:

void *weechat_buffer_pointer (struct t_gui_buffer *buffer,
                              const char *property);

Argomenti:

  • buffer: puntatore al buffer

  • property: nome proprietà:

    • plugin: puntatore al plugin che ha creato questo buffer (NULL per il buffer principale di WeeChat)

    • text_search_regex_compiled: compiled regular expression

    • text_search_ptr_history: history found

    • highlight_disable_regex_compiled: espressione regolare highlight_disable_regex compilata

    • highlight_regex_compiled: espressione regolare highlight_regex compilata

Valore restituito:

  • valore puntatore della proprietà

Esempio in C:

weechat_printf (NULL, "plugin pointer of my buffer: %lx",
                weechat_buffer_get_pointer (my_buffer, "plugin"));

Script (Python):

# prototipo
def buffer_get_pointer(buffer: str, property: str) -> str: ...

# esempio
weechat.prnt("", "plugin pointer of my buffer: %s" % weechat.buffer_get_pointer(my_buffer, "plugin"))

buffer_set

Imposta il valore stringa della proprietà di un buffer.

Prototipo:

void weechat_buffer_set (struct t_gui_buffer *buffer, const char *property,
                         const char *value);

Argomenti:

  • buffer: puntatore al buffer

  • property: nome della proprietà (see table below)

  • value: new value for property

Properties:

Nome Min WeeChat Valore Descrizione

hotlist

"+", "-", WEECHAT_HOTLIST_LOW, WEECHAT_HOTLIST_MESSAGE, WEECHAT_HOTLIST_PRIVATE, WEECHAT_HOTLIST_HIGHLIGHT, "-1"

"+": abilita hotlist (impostazione globale , il puntatore al buffer pointer non è utilizzato)
"-": disabilita hotlist (impostazione globale, il puntatore al buffer non è utilizzato)
priorità: aggiunge il buffer alla hotlist con questa proprietà (conditions defined in option weechat.look.hotlist_add_conditions are NOT checked)
"-1": remove buffer from hotlist (WeeChat ≥ 1.0).

completion_freeze

"0" oppure "1"

"0": no freeze of completion (default value) (impostazione globale, il puntatore al buffer non è utilizzato)
"1": do not stop completion when command line is updated (impostazione globale, il puntatore al buffer non è utilizzato).

unread

empty string, "0", "+N", "-N" or "N" (N is integer)

empty string: set unread marker after last line of buffer
"0": remove unread marker from buffer
"N": move the unread marker N lines from the end towards the first line of buffer
"-N": move the unread marker N lines towards the first line of buffer
"+N": move the unread marker N lines towards the last line of buffer.

display

"1" oppure "auto"

"1": passa a questo buffer nella finestra corrente
"auto": passa a questo buffer nella finestra corrente, l’evidenziatore di lettura non viene resettato.

hidden

1.0

"0" oppure "1"

"0": unhide the buffer
"1": hide the buffer.

number

numero

Sposta buffer a questo numero.

name

qualsiasi stringa

Imposta nuovo nome per il buffer.

short_name

qualsiasi stringa

Imposta nuovo nome breve per il buffer.

type

"formatted" oppure "free"

Imposta tipo per il: "formatted" (per stampare i messaggi di chat), oppure "free" (per contenuto libero); when the value is "free", the property clear is forced to "0" (WeeChat ≥ 1.0).

notify

"0", "1", "2", "3"

Imposta il livello di notifica per il buffer: "0" = non aggiungere alla hotlist, "1" = aggiungere solo per gli eventi, "2" = aggiungere per eventi e messaggi, "3" = aggiungere per tutti i messaggi.

print_hooks_enabled

"0" oppure "1"

"0" to disable print hooks, "1" to enable them (default for a new buffer).

day_change

0.4.3

"0" oppure "1"

"0" to hide messages for the day change, "1" to see them (default for a new buffer).

clear

1.0

"0" or "1"

"0" to prevent user from clearing buffer with the command /buffer clear, "1" to let user clear the buffer (default for a new buffer) (note: even when it is set to "0", the buffer can still be cleared with the function buffer_clear).

filter

1.0

"0" or "1"

"0": disable filters on buffer
"1": enable filters on buffer.

title

qualsiasi stringa

Imposta nuovo titolo per il buffer.

time_for_each_line

"0" oppure "1"

"0" per nascondere l’orario in tutte le righe del buffer, "1" per visualizzarlo su tutte le righe (predefinito per un nuovo buffer).

nicklist

"0" oppure "1"

"0" per rimuovere la lista nick per il buffer, "1" per aggiungere la lista nick per il buffer.

nicklist_case_sensitive

"0" oppure "1"

"0" per avere una lista nick non sensibile alle maiuscole, "1" per una lista nick sensibile alle maiuscole.

nicklist_display_groups

"0" oppure "1"

"0" per nascondere i gruppi nella lista nick, "1" per visualizzare i gruppi della lista nick.

highlight_words

"-" oppure elenco di parole separato da virgole

"-" è un valore speciale per disabilitare qualsiasi evento su questo buffer, o un elenco di parole separate da virgole da evidenziare in questo buffer, ad esempio: "abc,def,ghi".

highlight_words_add

elenco di parole separate da virgole

Elenco di parole separate da virgole da evidenziare in questo buffer, queste parole vengono aggiunte alle parole evidenziate esistenti nel buffer.

highlight_words_del

elenco di parole separate da virgole

Elenco di parole separate da virgole da rimuovere dalle parole evidenziate nel buffer.

highlight_disable_regex

any string

POSIX extended regular expression for disabling highlight.

highlight_regex

qualsiasi stringa

POSIX extended regular expression for highlight.

highlight_tags_restrict

elenco separato da virgole di tag

Restrict highlights to messages with these tags in this buffer (it is possible to combine many tags as a logical "and" with separator "+", for example: "nick_toto+irc_action").

highlight_tags

elenco separato da virgole di tag

Force highlight on messages with these tags in this buffer (it is possible to combine many tags as a logical "and" with separator "+", for example: "nick_toto+irc_action").

hotlist_max_level_nicks

elenco separado da virgole di "nick:livello"

Elenco separato da virgole di nick con il livello massimo per la hotlist su questo buffer (il livello può essere: -1: mai nella hotlist, 0: basso, 1: messaggio, 2: privato, 3: evento), ad esempio: "joe:2,mike:-1,robert:-1" (joe non produce eventi sul buffer, mike e robert non modificano la hotlist).

hotlist_max_level_nicks_add

elenco separato da virgole di "nick:livello"

Elenco separato da virgole di nick con il livello per la hotlist, questi nick vengono aggiunti a quelli esistenti nel buffer.

hotlist_max_level_nicks_del

elenco separato da virgole di nick

Elenco separato da virgole di nick da rimuovere dai livelli massimi della hotlist.

key_bind_xxx

qualsiasi stringa

Assegna un nuovo tasto xxx, specifico per questo buffer, il valore è il comando da eseguire per questo tasto.

key_unbind_xxx

-

Rimuove l’assegnazione del tasto xxx per questo buffer.

input

qualsiasi stringa

Imposta un nuovo valore per l’input del buffer.

input_pos

posizione

Imposta la posizione del cursore per l’input del buffer.

input_get_unknown_commands

"0" oppure "1"

"0" per disabilitare i comandi sconosciuti per questo buffer (comportamento predefinito), "1" per ricevere i comandi sconosciuti, ad esempio se l’utente digita "/unknowncmd", verrà ricevuto dal buffer (nessun errore riguardo il comando sconosciuto).

input_get_empty

"0" oppure "1"

"0" to disable empty input on this buffer (default behavior), "1" to get empty input.

input_multiline

"0" or "1"

"0" to send each line separately to this buffer (default behavior), "1" to send multiple lines as a single message.

localvar_set_xxx

qualsiasi stringa

Imposta il nuovo valore per la variabile locale xxx (la variabile verrà creata se non esiste).

localvar_del_xxx

-

Rimuove la variabile locale xxx.

Esempio in C:

/* disabilita hotlist (per tutti i buffer) */
weechat_buffer_set (NULL, "hotlist", "-");

/* abilita nuovamente hotlist */
weechat_buffer_set (NULL, "hotlist", "+");

/* cambia il nome buffer */
weechat_buffer_set (my_buffer, "name", "my_new_name");

/* aggiunge una nuova variabile locale "tizio" con il valore "abc" */
weechat_buffer_set (my_buffer, "localvar_set_tizio", "abc");

/* rimuove la variabile locale "tizio" */
weechat_buffer_set (my_buffer, "localvar_del_tizio", "");

Script (Python):

# prototipo
def buffer_set(buffer: str, property: str, value: str) -> int: ...

# esempi

# disabilita hotlist (per tutti i buffer)
weechat.buffer_set("", "hotlist", "-")

# abilita nuovamente hotlist
weechat.buffer_set("", "hotlist", "+")

# cambia il nome buffer
weechat.buffer_set(my_buffer, "name", "my_new_name")

# aggiunge una nuova variabile locale "tizio" con il valore "abc"
weechat.buffer_set(my_buffer, "localvar_set_tizio", "abc")

# rimuove la variabile locale "tizio"
weechat.buffer_set(my_buffer, "localvar_del_tizio", "")

buffer_set_pointer

Imposta il valore puntatore per la proprietà di un buffer.

Prototipo:

void weechat_buffer_set_pointer (struct t_gui_buffer *buffer, const char *property,
                                 void *pointer);

Argomenti:

  • buffer: puntatore al buffer

  • property: nome della proprietà:

    • close_callback: set close callback function

    • close_callback_data: set close callback data

    • input_callback: set input callback function

    • input_callback_data: set input callback data

    • nickcmp_callback: set nick comparison callback function (this callback is called when searching nick in nicklist) (WeeChat ≥ 0.3.9)

    • nickcmp_callback_data: set nick comparison callback data (WeeChat ≥ 0.3.9)

  • pointer: new pointer value for property

Prototypes for callbacks:

int close_callback (const void *pointer, void *data,
                    struct t_gui_buffer *buffer);

int input_callback (const void *pointer, void *data,
                    struct t_gui_buffer *buffer, const char *input_data);

int nickcmp_callback (const void *pointer, void *data,
                      struct t_gui_buffer *buffer,
                      const char *nick1, const char *nick2);

Esempio in C:

int
my_close_cb (const void *pointer, void *data, struct t_gui_buffer *buffer)
{
    /* ... */
    return WEECHAT_RC_OK;
}

weechat_buffer_set_pointer (my_buffer, "close_callback", &my_close_cb);
Questa funzione non è disponibile nelle API per lo scripting.

buffer_string_replace_local_var

Sostituisce le variabili globali in una stringa con i loro valori, utilizzando le variabili del buffer locale.

Prototipo:

char *weechat_buffer_string_replace_local_var (struct t_gui_buffer *buffer,
                                               const char *string);

Argomenti:

  • buffer: puntatore al buffer

  • string: stringa con testo e variabili locali che utilizzano il formato "$var"

Valore restituito:

  • stringa con i valori delle variabili locali

Esempio in C:

weechat_buffer_set (my_buffer, "localvar_set_toto", "abc");

char *str = weechat_buffer_string_replace_local_var (my_buffer,
                                                     "test with $toto");
/* str contiene "test with abc" */

Script (Python):

# prototipo
def buffer_string_replace_local_var(buffer: str, string: str) -> str: ...

# esempio
weechat.buffer_set(my_buffer, "localvar_set_toto", "abc")
str = weechat.buffer_string_replace_local_var(my_buffer, "test with $toto")
# str contains "test with abc"

buffer_match_list

WeeChat ≥ 0.3.5, updated in 4.0.0.

Verifica se il buffer corrisponde ad una lista di buffer.

Prototipo:

int weechat_buffer_match_list (struct t_gui_buffer *buffer, const char *string);

Argomenti:

  • buffer: puntatore al buffer

  • string: elenco separato da virgole di buffer:

    • * indica tutti i buffer

    • il nome preceduto da ! viene escluso

    • wildcard * is allowed in name

Since version 4.0.0, comparison of buffer names is case sensitive.

Valore restituito:

  • 1 se il buffer coincide con la lista, altrimenti 0

Esempio in C:

struct t_gui_buffer *buffer = weechat_buffer_search ("irc", "libera.#weechat");
if (buffer)
{
    weechat_printf (NULL, "%d", weechat_buffer_match_list (buffer, "*"));                    /* 1 */
    weechat_printf (NULL, "%d", weechat_buffer_match_list (buffer, "*,!*#weechat*"));        /* 0 */
    weechat_printf (NULL, "%d", weechat_buffer_match_list (buffer, "irc.libera.*"));         /* 1 */
    weechat_printf (NULL, "%d", weechat_buffer_match_list (buffer, "irc.oftc.*,python.*"));  /* 0 */
}

Script (Python):

# prototipo
def buffer_match_list(buffer: str, string: str) -> int: ...

# esempio
buffer = weechat.buffer_search("irc", "libera.#weechat")
if buffer:
    weechat.prnt("", "%d" % weechat.buffer_match_list(buffer, "*"))                    # 1
    weechat.prnt("", "%d" % weechat.buffer_match_list(buffer, "*,!*#weechat*"))        # 0
    weechat.prnt("", "%d" % weechat.buffer_match_list(buffer, "irc.libera.*"))         # 1
    weechat.prnt("", "%d" % weechat.buffer_match_list(buffer, "irc.oftc.*,python.*"))  # 0

3.16. Finestre

Funzioni per richiedere finestre.

current_window

Restituisce il puntatore alla finestra corrente

Prototipo:

struct t_gui_window *weechat_current_window ();

Valore restituito:

  • puntatore alla finestra corrente

Esempio in C:

struct t_gui_window *current_window = weechat_current_window ();

Script (Python):

# prototipo
def current_window() -> str: ...

# esempio
current_window = weechat.current_window()

window_search_with_buffer

WeeChat ≥ 0.3.5.

Restituisce il puntatore alla finestra che mostra il buffer.

Prototipo:

struct t_gui_window *weechat_window_search_with_buffer (struct t_gui_buffer *buffer);

Argomenti:

  • buffer: puntatore al buffer

Valore restituito:

  • puntatore alla finestra che mostra il buffer (NULL se nessuna finestra sta mostrando il buffer)

Esempio in C:

weechat_printf (NULL,
                "window displaying core buffer: %lx",
                weechat_window_search_with_buffer (weechat_buffer_search_main ()));

Script (Python):

# prototipo
def window_search_with_buffer(buffer: str) -> str: ...

# esempio
weechat.prnt("", "window displaying core buffer: %s"
    % weechat.window_search_with_buffer(weechat.buffer_search_main()))

window_get_integer

Restituisce il valore intero della proprietà di una finestra.

Prototipo:

int weechat_window_get_integer (struct t_gui_window *window,
                                const char *property);

Argomenti:

  • window: puntatore alla finestra

  • property: nome della proprietà:

    • number: numero della finestra (inizia da 1)

    • win_x: posizione X della finestra nel terminale (la prima colonna è 0)

    • win_y: posizione Y della finestra nel terminale (la prima riga è 0)

    • win_width: larghezza della finestra, in caratteri

    • win_height: altezza della finestra, in caratteri

    • win_width_pct: misura percentuale, paragonata alla finestra genitore (ad esempio 50 indica metà grandezza)

    • win_height_pct: misura percentuale, paragonata alla finestra genitore (ad esempio 50 indica metà grandezza)

    • win_chat_x: posizione X della finestra di chat nel terminale (la prima colonna è 0)

    • win_chat_y: posizione Y della finestra di chat nel terminale (la prima riga è 0)

    • win_chat_width: larghezza della finestra di chat, in caratteri

    • win_chat_height: altezza della finestra di chat, in caratteri

    • first_line_displayed: 1 se la prima riga del buffer viene visualizzata su schermo, altrimenti 0

    • scrolling: 1 se lo scorrimento è attivo sulla finestra (ultima riga non visualizzata)

    • lines_after: numero di righe non visualizzate dopo l’ultima visualizzata (durante lo scorrimento)

Valore restituito:

  • valore intero della proprietà

Esempio in C:

weechat_printf (NULL, "current window is at position (x,y): (%d,%d)",
                weechat_window_get_integer (weechat_current_window (), "win_x"),
                weechat_window_get_integer (weechat_current_window (), "win_y"));

Script (Python):

# prototipo
def window_get_integer(window: str, property: str) -> int: ...

# esempio
weechat.prnt("", "current window is at position (x,y): (%d,%d)"
    % (weechat.window_get_integer(weechat.current_window(), "win_x"),
    weechat.window_get_integer(weechat.current_window(), "win_y")))

window_get_string

Restituisce il valore stringa della proprietà di una finestra.

La funzione non è utilizzata oggi, è riservata per una versione futura.

Prototipo:

const char *weechat_window_get_string (struct t_gui_window *window,
                                       const char *property);

Argomenti:

  • window: puntatore alla finestra

  • property: nome della proprietà

Valore restituito:

  • valore stringa della proprietà

Script (Python):

# prototipo
def window_get_string(window: str, property: str) -> str: ...

window_get_pointer

Restituisce il valore puntatore della proprietà di una finestra.

Prototipo:

void *weechat_window_get_pointer (struct t_gui_window *window,
                                  const char *property);

Argomenti:

  • window: puntatore alla finestra

  • property: nome della proprietà:

    • current: puntatore alla finestra corrente

    • buffer: puntatore al buffer visualizzato dalla finestra

Valore restituito:

  • valore puntatore della proprietà

Esempio in C:

weechat_printf (NULL,
                "buffer displayed in current window: %lx",
                weechat_window_get_pointer (weechat_current_window (), "buffer"));

Script (Python):

# prototipo
def window_get_pointer(window: str, property: str) -> str: ...

# esempio
weechat.prnt("", "buffer displayed in current window: %s"
    % weechat.window_get_pointer(weechat.current_window(), "buffer"))

window_set_title

Imposta il titolo per il terminale.

Prototipo:

void weechat_window_set_title (const char *title);

Argomenti:

  • title: nuovo titolo per il terminale (NULL per resettarlo); string is evaluated, so variables like ${info:version} can be used (see string_eval_expression)

Esempio in C:

weechat_window_set_title ("nuovo titolo qui");

Script (Python):

# prototipo
def window_set_title(title: str) -> int: ...

# esempio
weechat.window_set_title("nuovo titolo qui")

3.17. Lista nick

Funzioni per il buffer nicklist.

nicklist_add_group

Aggiunge un gruppo in una lista nick.

Prototipo:

struct t_gui_nick_group *weechat_nicklist_add_group (struct t_gui_buffer *buffer,
                                                     struct t_gui_nick_group *parent_group,
                                                     const char *name,
                                                     const char *color,
                                                     int visible);

Argomenti:

  • buffer: puntatore al buffer

  • parent_group: puntatore al genitore del gruppo, NULL se il gruppo non ha genitore (lista nick radice)

  • name: nome del gruppo

  • color: nome per l’opzione colore:

    • nome opzione per WeeChat, ad esempio weechat.color.nicklist_group

    • colore con sfondo opzionale, ad esempio yellow o yellow,red

    • nome colore per la barra:

      • bar_fg: colore di primo piando per la barra

      • bar_delim: colore dei delimitatori per la barra

      • bar_bg: colore di sfondo per la barra

  • visible:

    • 1: gruppi e sottogruppi/nick sono visibili

    • 0: gruppi e sottogruppi/nick sono nascosti

Il nome del gruppo può iniziare con uno o più numeri, seguiti da una pipe, e infine dal nome del gruppo. Quando questa stringa si trova all’inizio, viene utilizzata per ordinare i gruppi nella lista nick. Ad esempio i gruppi "1|test" e "2|abc" verranno visualizzati in quest’ordine: prima "test" poi "abc".

Valore restituito:

  • puntatore al nuovo gruppo, NULL in caso di errore

Esempio in C:

struct t_gui_nick_group *my_group =
    weechat_nicklist_add_group (my_buffer,
                                my_parent_group,
                                "test_group",
                                "weechat.color.nicklist_group",
                                1);

Script (Python):

# prototipo
def nicklist_add_group(buffer: str, parent_group: str, name: str, color: str, visible: int) -> str: ...

# esempio
group = weechat.nicklist_add_group(my_buffer, my_parent_group, "test_group",
    "weechat.color.nicklist_group", 1)

nicklist_search_group

Cerca un gruppo in una lista nick.

Prototipo:

struct t_gui_nick_group *weechat_nicklist_search_group (struct t_gui_buffer *buffer,
                                                        struct t_gui_nick_group *from_group,
                                                        const char *name);

Argomenti:

  • buffer: puntatore al buffer

  • from_group: ricerca solo da questo gruppo, se NULL, allora la cerca in tutta la lista nick

  • name: nome gruppo da cercare

Valore restituito:

  • puntatore al gruppo trovato, NULL se non trovato

Esempio in C:

struct t_gui_nick_group *ptr_group = weechat_nicklist_search_group (my_buffer,
                                                                    NULL, "test_group");

Script (Python):

# prototipo
def nicklist_search_group(buffer: str, from_group: str, name: str) -> str: ...

# esempio
group = weechat.nicklist_search_group(my_buffer, "", "test_group")

nicklist_add_nick

Aggiunge un nick in un gruppo.

Prototipo:

struct t_gui_nick_group *weechat_nicklist_add_nick (struct t_gui_buffer *buffer,
                                                    struct t_gui_nick_group *group,
                                                    const char *name,
                                                    const char *color,
                                                    const char *prefix,
                                                    const char *prefix_color,
                                                    int visible);

Argomenti:

  • buffer: puntatore al buffer

  • group: puntatore al gruppo

  • name: nome nick

  • color: nome dell’opzione per il colore:

    • nome opzione per WeeChat (da weechat.color.xxx), ad esempio chat_delimiters

    • colore con sfondo opzionale, ad esempio yellow o yellow,red

    • nome colore per la barra:

      • bar_fg: colore di primo piano per la barra

      • bar_delim: colore dei delimitatori per la barra

      • bar_bg: colore di sfondo per la barra

  • prefix: prefisso visualizzato prima del nick

  • prefix_color: nome dell’opzione per il colore:

    • nome opzione per WeeChat (da weechat.color.xxx), ad esempio chat_delimiters

    • colore con sfondo opzionale, ad esempio yellow o yellow,red

    • nome colore per la barra:

      • bar_fg: colore di primo piano per la barra

      • bar_delim: colore dei delimitatori per la barra

      • bar_bg: colore di sfondo per la barra

  • visible:

    • 1: il nick è visibile

    • 0: il nick è nascosto

Valore restituito:

  • puntatore al nuovo nick, NULL in caso di errore

Esempio in C:

struct t_gui_nick *my_nick =
    weechat_nicklist_add_nick (my_buffer, my_group,
                               "test_nick",
                               (nick_away) ? "weechat.color.nicklist_away" : "bar_fg",
                               "@", "lightgreen",
                               1);

Script (Python):

# prototipo
def nicklist_add_nick(buffer: str, group: str, name: str, color: str, prefix: str, prefix_color: str, visible: int) -> str: ...

# esempio
if nick_away:
    color = "weechat.color.nicklist_away"
else:
    color = "bar_fg"
nick = weechat.nicklist_add_nick(my_buffer, my_group, "test_nick", color, "@", "lightgreen", 1)

nicklist_search_nick

Cerca un nick nella lista nick.

Prototipo:

struct t_gui_nick *weechat_nicklist_search_nick (struct t_gui_buffer *buffer,
                                                 struct t_gui_nick_group *from_group,
                                                 const char *name);

Argomenti:

  • buffer: puntatore al buffer

  • from_group: cerca solo da questo gruppo, se NULL, allora cerca nell’intera lista nick

  • name: nick da cercare

Valore restituito:

  • puntatore al nuovo nick, NULL se non trovato

Esempio in C:

struct t_gui_nick *ptr_nick = weechat_nicklist_search_nick (my_buffer,
                                                            NULL, "test_nick");

Script (Python):

# prototipo
def nicklist_search_nick(buffer: str, from_group: str, name: str) -> str: ...

# esempio
nick = weechat.nicklist_search_nick(my_buffer, "", "test_nick")

nicklist_remove_group

Rimuove un gruppo da una lista nick.

Prototipo:

void weechat_nicklist_remove_group (struct t_gui_buffer *buffer,
                                    struct t_gui_nick_group *group);

Argomenti:

  • buffer: puntatore al buffer

  • group: puntatore al gruppo da rimuovere (verranno rimossi anhe i sottogruppi/nick)

Esempio in C:

weechat_nicklist_remove_group (my_buffer, my_group);

Script (Python):

# prototipo
def nicklist_remove_group(buffer: str, group: str) -> int: ...

# esempio
weechat.nicklist_remove_group(my_buffer, my_group)

nicklist_remove_nick

Rimuove un nick dalla lista nick.

Prototipo:

void weechat_nicklist_remove_nick (struct t_gui_buffer *buffer,
                                   struct t_gui_nick *nick);

Argomenti:

  • buffer: puntatore al buffer

  • nick: puntatore al nick da rimuovere

Esempio in C:

weechat_nicklist_remove_nick (my_buffer, my_nick);

Script (Python):

# prototipo
def nicklist_remove_nick(buffer: str, nick: str) -> int: ...

# esempio
weechat.nicklist_remove_nick(my_buffer, my_nick)

nicklist_remove_all

Rimuove tutti i gruppi/nick da una lista nick.

Prototipo:

void weechat_nicklist_remove_all (struct t_gui_buffer *buffer);

Argomenti:

  • buffer: puntatore al buffer

Esempio in C:

weechat_nicklist_remove_all (my_buffer);

Script (Python):

# prototipo
def nicklist_remove_all(buffer: str) -> int: ...

# esempio
weechat.nicklist_remove_all(my_buffer)

nicklist_get_next_item

WeeChat ≥ 0.3.7.

Ottiene il prossimo gruppo oppure il nick dalla lista nick (usato principalmente per mostrare la lista nick).

Prototipo:

void weechat_nicklist_get_next_item (struct t_gui_buffer *buffer,
                                     struct t_gui_nick_group **group,
                                     struct t_gui_nick **nick);

Argomenti:

  • buffer: puntatore al buffer

  • group: puntatore sul puntatore al gruppo

  • nick: puntatore sul puntatore al nick

Esempio in C:

struct t_gui_nick_group *ptr_group;
struct t_gui_nick *ptr_nick;

ptr_group = NULL;
ptr_nick = NULL;
weechat_nicklist_get_next_item (buffer, &ptr_group, &ptr_nick);
while (ptr_group || ptr_nick)
{
    if (ptr_nick)
    {
        /* nick */
        /* ... */
    }
    else
    {
        /* gruppo */
        /* ... */
    }
    weechat_nicklist_get_next_item (buffer, &ptr_group, &ptr_nick);
}
Questa funzione non è disponibile nelle API per lo scripting.

nicklist_group_get_integer

WeeChat ≥ 0.3.4.

Restituisce un valore intero della proprietà di un gruppo.

Prototipo:

int weechat_nicklist_group_get_integer (struct t_gui_buffer *buffer,
                                        struct t_gui_nick_group *group,
                                        const char *property);

Argomenti:

  • buffer: puntatore al buffer

  • group: puntatore al gruppo

  • property: nome della proprietà:

    • visible: 1 se il gruppo è visibile, altrimenti 0

    • level: livello del gruppo (root è 0)

Valore restituito:

  • valore intero della proprietà

Esempio in C:

int visible = weechat_nicklist_group_get_integer (buffer, group, "visible");

Script (Python):

# prototipo
def nicklist_group_get_integer(buffer: str, group: str, property: str) -> int: ...

# esempio
visible = weechat.nicklist_group_get_integer(buffer, group, "visible")

nicklist_group_get_string

WeeChat ≥ 0.3.4.

Restituisce il valore stringa della proprietà di un gruppo.

Prototipo:

const char *weechat_nicklist_group_get_string (struct t_gui_buffer *buffer,
                                               struct t_gui_nick_group *group,
                                               const char *property);

Argomenti:

  • buffer: puntatore al buffer

  • group: puntatore al gruppo

  • property: nome della proprietà:

    • name: nome del gruppo

    • color: colore del gruppo nella lista nick

Valore restituito:

  • valore stringa della proprietà

Esempio in C:

const char *color = weechat_nicklist_group_get_string (buffer, group, "color");

Script (Python):

# prototipo
def nicklist_group_get_string(buffer: str, group: str, property: str) -> str: ...

# esempio
color = weechat.nicklist_group_get_string(buffer, group, "color")

nicklist_group_get_pointer

WeeChat ≥ 0.3.4.

Restituisce il valore puntatore della proprietà di un gruppo.

Prototipo:

void *weechat_nicklist_group_get_pointer (struct t_gui_buffer *buffer,
                                          struct t_gui_nick_group *group,
                                          const char *property);

Argomenti:

  • buffer: puntatore al buffer

  • group: puntatore al gruppo

  • property: nome della proprietà:

    • parent: puntatore al gruppo genitore

Valore restituito:

  • valore puntatore della proprietà

Esempio in C:

struct t_gui_nick_group *parent = weechat_nicklist_group_get_pointer (buffer, group, "parent");

Script (Python):

# prototipo
def nicklist_group_get_pointer(buffer: str, group: str, property: str) -> str: ...

# esempio
parent = weechat.nicklist_group_get_pointer(buffer, group, "parent")

nicklist_group_set

WeeChat ≥ 0.3.4.

Imposta il valore stringa della proprietà di un gruppo.

Prototipo:

void weechat_nicklist_group_set (struct t_gui_buffer *buffer,
                                 struct t_gui_nick_group *group,
                                 const char *property,
                                 const char *value);

Argomenti:

  • buffer: puntatore al buffer

  • group: puntatore al gruppo

  • property: nome della proprietà (see table below)

  • value: new value for property

Properties:

Nome Valore Descrizione

color

nome per l’opzione del colore per WeeChat

Consultare l’argomento "color" della funzione nicklist_add_group.

visible

"0", "1"

"0" = gruppo nascosto, "1" = gruppo visibile.

Esempio in C:

/* cambia colore del gruppo a "bar_fg" */
weechat_nicklist_group_set (buffer, group, "color", "bar_fg");

/* cambia il colore del gruppo a giallo */
weechat_nicklist_group_set (buffer, group, "color", "yellow");

/* nasconde gruppo nella lista nick */
weechat_nicklist_group_set (buffer, group, "visible", "0");

Script (Python):

# prototipo
def nicklist_group_set(buffer: str, group: str, property: str, value: str) -> int: ...

# esempi

# cambia colore del gruppo a "bar_fg"
weechat.nicklist_group_set(buffer, group, "color", "bar_fg")

# cambia colore del gruppo a giallo
weechat.nicklist_group_set(buffer, group, "color", "yellow")

# nasconde gruppo nella lista nick
weechat.nicklist_group_set(buffer, group, "visible", "0")

nicklist_nick_get_integer

WeeChat ≥ 0.3.4.

Restituisce il valore intero della proprietà di un nick.

Prototipo:

int weechat_nicklist_nick_get_integer (struct t_gui_buffer *buffer,
                                       struct t_gui_nick *nick,
                                       const char *property);

Argomenti:

  • buffer: puntatore al buffer

  • nick: puntatore al nick

  • property: nome della proprietà:

    • visible: 1 se il nick è visibile, altrimenti 0

Valore restituito:

  • valore intero della proprietà

Esempio in C:

int visible = weechat_nicklist_nick_get_integer (buffer, nick, "visible");

Script (Python):

# prototipo
def nicklist_nick_get_integer(buffer: str, nick: str, property: str) -> int: ...

# esempio
visible = weechat.nicklist_nick_get_integer(buffer, nick, "visible")

nicklist_nick_get_string

WeeChat ≥ 0.3.4.

Restituisce il valore stringa della proprietà di un nick.

Prototipo:

const char *weechat_nicklist_nick_get_string (struct t_gui_buffer *buffer,
                                              struct t_gui_nick *nick,
                                              const char *property);

Argomenti:

  • buffer: puntatore al buffer

  • nick: puntatore al nick

  • property: nome della proprietà:

    • name: nome del nick

    • color: colore del nick nella lista nick

    • prefix: prefisso del nick

    • prefix_color: colore del prefisso nella lista nick

Valore restituito:

  • valore stringa della proprietà

Esempio in C:

const char *color = weechat_nicklist_nick_get_string (buffer, nick, "color");

Script (Python):

# prototipo
def nicklist_nick_get_string(buffer: str, nick: str, property: str) -> str: ...

# esempio
color = weechat.nicklist_nick_get_string(buffer, nick, "color")

nicklist_nick_get_pointer

WeeChat ≥ 0.3.4.

Restituisce il valore puntatore della proprietà di un nick.

Prototipo:

void *weechat_nicklist_nick_get_pointer (struct t_gui_buffer *buffer,
                                         struct t_gui_nick *nick,
                                         const char *property);

Argomenti:

  • buffer: puntatore al buffer

  • nick: puntatore al nick

  • property: nome proprietà:

    • group: puntatore al gruppo che contiene questo nick

Valore restituito:

  • valore puntatore della proprietà

Esempio in C:

struct t_gui_nick_group *group = weechat_nicklist_nick_get_pointer (buffer, nick, "group");

Script (Python):

# prototipo
def nicklist_nick_get_pointer(buffer: str, nick: str, property: str) -> str: ...

# esempio
group = weechat.nicklist_nick_get_pointer(buffer, nick, "group")

nicklist_nick_set

WeeChat ≥ 0.3.4.

Imposta il valore stringa della proprietà di un nick.

Prototipo:

void weechat_nicklist_nick_set (struct t_gui_buffer *buffer,
                                struct t_gui_nick *nick,
                                const char *property,
                                const char *value);

Argomenti:

  • buffer: puntatore al buffer

  • nick: puntatore al nick

  • property: nome della proprietà (see table below)

  • value: new value for property

Properties:

Nome Valore Descrizione

color

nome per l’opzione del colore di WeeChat

Consultare l’argomento "color" della funzione nicklist_add_nick.

prefix

qualsiasi stringa

Prefisso del nick.

prefix_color

nome per l’opzione del colore di WeeChat

Consultare l’argomento "prefix_color" della funzione nicklist_add_nick.

visible

"0", "1"

"0" = nick nascosto, "1" = nick visibile.

Esempi in C:

/* cambia colore del nick in azzurro */
weechat_nicklist_nick_set (buffer, nick, "color", "cyan");

/* cambia prefisso in "+" */
weechat_nicklist_nick_set (buffer, nick, "prefix", "+");

/* cambia colore del prefisso in giallo */
weechat_nicklist_nick_set (buffer, nick, "prefix_color", "yellow");

/* nascondi nick nella lista nick */
weechat_nicklist_nick_set (buffer, nick, "visible", "0");

Script (Python):

# prototipo
def nicklist_nick_set(buffer: str, nick: str, property: str, value: str) -> int: ...

# esempi

# cambia colore del nick in azzurro
weechat.nicklist_nick_set(buffer, nick, "color", "cyan")

# cambia prefisso in "+"
weechat.nicklist_nick_set(buffer, nick, "prefix", "+")

# cambia colore del prefisso in giallo
weechat.nicklist_nick_set(buffer, nick, "prefix_color", "yellow")

# nascondi nick nella lista nick
weechat.nicklist_nick_set(buffer, nick, "visible", "0")

3.18. Barre

Funzioni per le barre.

Cerca un elemento barra.

Prototipo:

struct t_gui_bar_item *weechat_bar_item_search (const char *name);

Argomenti:

  • name: nome dell’elemento barra

Valore restituito:

  • puntatore all’elemento barra trovato, NULL se non trovato

Esempio in C:

struct t_gui_bar_item *bar_item = weechat_bar_item_search ("myitem");

Script (Python):

# prototipo
def bar_item_search(name: str) -> str: ...

# esempio
bar_item = weechat.bar_item_search("myitem")

bar_item_new

Updated in 0.4.2, 1.5.

Crea un nuovo elemento barra.

Prototipo:

struct t_gui_bar_item *weechat_bar_item_new (const char *name,
                                             char *(*build_callback)(const void *pointer,
                                                                     void *data,
                                                                     struct t_gui_bar_item *item,
                                                                     struct t_gui_window *window,
                                                                     struct t_gui_buffer *buffer,
                                                                     struct t_hashtable *extra_info),
                                             const void *build_callback_pointer,
                                             void *build_callback_data);

Argomenti:

  • name: nome dell’elemento barra

  • build_callback: funzione chiamata quando l’elemento barra viene compilato, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • struct t_gui_bar_item *item: puntatore all’elemento barra

    • struct t_gui_window *window: puntatore alla finestra (NULL when called for a root bar)

    • struct t_gui_buffer *buffer: buffer displayed in window (if window is NULL, then it is current buffer) or buffer given in bar item with syntax: "@buffer:item" (WeeChat ≥ 0.4.2)

    • struct t_hashtable *extra_info: always NULL (argument is reserved for a future version) (WeeChat ≥ 0.4.2)

    • valore restituito: contenuto dell’elemento barra

  • build_callback_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • build_callback_data: puntatore fornito dalla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the bar item is removed

Valore restituito:

  • puntatore al nuovo elemento barra, NULL se non trovato

Esempio in C:

char *
my_build_callback (const void *pointer, void *data,
                   struct t_gui_bar_item *item,
                   struct t_gui_window *window,
                   struct t_gui_buffer *buffer,
                   struct t_hashtable *extra_info)
{
    return strdup ("my content");
}

struct t_gui_bar_item *my_item = weechat_bar_item_new ("myitem",
                                                       &my_build_callback,
                                                       NULL, NULL);

Script (Python):

For compatibility with versions ≤ 0.4.1, the default callback has only 3 arguments: data, item and window (no buffer and extra_info).
To use a callback with all arguments, you must add "(extra)" before the name, see example below (supported only in WeeChat ≥ 0.4.2).
# prototipo
def bar_item_new(name: str, build_callback: str, build_callback_data: str) -> str: ...

# esempio (callback without "buffer" and "extra_info")
def my_build_callback(data: str, item: str, window: str) -> str:
    return "my content"

bar_item = weechat.bar_item_new("myitem", "my_build_callback", "")

# example (callback with all arguments, for WeeChat ≥ 0.4.2)
def my_build_callback2(data: str, item: str, window: str, buffer: str, extra_info: Dict[str, str]) -> str:
    return "my content"

bar_item2 = weechat.bar_item_new("(extra)myitem2", "my_build_callback2", "")  # WeeChat ≥ 0.4.2

bar_item_update

Aggiorna il contenuto dell’elemento barra, chiamando la callback che lo ha compilato.

Prototipo:

void weechat_bar_item_update (const char *name);

Argomenti:

  • name: nome dell’elemento barra

Esempio in C:

weechat_bar_item_update ("myitem");

Script (Python):

# prototipo
def bar_item_update(name: str) -> int: ...

# esempio
weechat.bar_item_update("myitem")

bar_item_remove

Rimuove un elemento barra.

Prototipo:

void weechat_bar_item_remove (struct t_gui_bar_item *item);

Argomenti:

  • item: puntatore all’elemento barra

Esempio in C:

weechat_bar_item_remove (&my_item);

Script (Python):

# prototipo
def bar_item_remove(item: str) -> int: ...

# esempio
weechat.bar_item_remove(myitem)

Cerca una barra.

Prototipo:

struct t_gui_bar *weechat_bar_search (const char *name);

Argomenti:

  • name: nome della barra

Valore restituito:

  • puntatore alla barra trovata, NULL se non trovata

Esempio in C:

struct t_gui_bar *bar = weechat_bar_search ("mybar");

Script (Python):

# prototipo
def bar_search(name: str) -> str: ...

# esempio
bar = weechat.bar_search("mybar")

bar_new

Updated in 2.9, 4.0.0.

Crea una nuova barra.

Prototipo:

struct t_gui_bar *weechat_bar_new (const char *name,
                                   const char *hidden,
                                   const char *priority,
                                   const char *type,
                                   const char *condition,
                                   const char *position,
                                   const char *filling_top_bottom,
                                   const char *filling_left_right,
                                   const char *size,
                                   const char *size_max,
                                   const char *color_fg,
                                   const char *color_delim,
                                   const char *color_bg,
                                   const char *color_bg_inactive,
                                   const char *separator,
                                   const char *items);

Argomenti:

  • name: nome della barra

  • hidden:

    • on: la barra è nascosta

    • off: la barra è visibile

  • priority: priorità per la barra (intero)

  • type:

    • root: barra visualizzata una sola volta, al di fuori delle finestre

    • window: barra visualizzata in ogni finestra

  • condition: condizioni per la visualizzazione della barra:

    • active: la barra viene visualizzata solo nella finestra attiva

    • inactive: la barra viene visualizzata solo nelle finestre inattive

    • nicklist: la barra viene visualizzata nelle finestre con liste nick

    • evaluated expression: see the WeeChat user’s guide / Bar conditions 

  • position: top, bottom, left o right

  • filling_top_bottom:

    • horizontal: gli elementi sono posizionati in orizzontale (spazio dopo ogni elemento)

    • vertical: gli elementi sono posizionati in verticale (nuova riga dopo ogni elemento)

    • columns_horizontal: gli elementi sono posizionati in orizzontale, visualizzati su colonne

    • columns_vertical: gli elementi sono posizionati in verticale, visualizzati su colonne

  • filling_left_right:

    • horizontal: gli elementi sono posizionati in orizzontale (spazio dopo ogni elemento)

    • vertical: gli elementi sono posizionati in verticale (nuova riga dopo ogni elemento)

    • columns_horizontal: gli elementi sono posizionati in orizzontale, visualizzati su colonne

    • columns_vertical: gli elementi sono posizionati in verticale, visualizzati su colonne

  • size: dimensione della barra in caratteri (0 corrisponde a dimensione automatica)

  • size_max: dimensione massima per la barra (0 corrisponde a nessuna dimensione massima)

  • color_fg: colore per il testo nella barra

  • color_delim: colore per i delimitatori nella barra

  • color_bg: colore di sfondo per la barra

  • color_bg_inactive: background color for window bar which is not displayed in active window

  • separator:

    • on: la barra ha una riga di separazione con altre finestre/barre

    • off: nessun separatore

  • items: elenco di elemento nella barra, separati da virgola (spazio tra gli elementi), o "+" (elementi incollati)

Valore restituito:

  • puntatore alla nuova barra, NULL in caso di errore

Since version 4.0.0, if the bar already exists, WeeChat sets the values received as default values for bar options and returns the bar pointer instead of NULL.

Esempio in C:

struct t_gui_bar *my_bar = weechat_bar_new (
    "mybar", "off", "100", "window", "", "top", "horizontal", "vertical",
    "0", "5", "default", "cyan", "blue", "darkgray", "off",
    "time,buffer_number+buffer_name");

Script (Python):

# prototipo
def bar_new(name: str, hidden: str, priority: str, type: str, condition: str, position: str,
            filling_top_bottom: str, filling_left_right: str, size: str, size_max: str,
            color_fg: str, color_delim: str, color_bg: str, color_bg_inactive: str,
            separator: str, items: str) -> str: ...

# esempio
bar = weechat.bar_new("mybar", "off", "100", "window", "", "top", "horizontal", "vertical",
    "0", "5", "default", "cyan", "blue", "darkgray", "off", "time,buffer_number+buffer_name")
With WeeChat ≥ 2.9, in Ruby, the 4 colors (color_fg, color_delim, color_bg, color_bg_inactive) must be given in an array of 4 strings (due to a Ruby limitation of 15 arguments by function), see the WeeChat scripting guide  for more info.

bar_set

Imposta un nuovo valore per la proprietà di una barra.

Prototipo:

int weechat_bar_set (struct t_gui_bar *bar, const char *property,
                     const char *value);

Argomenti:

  • bar: puntatore alla barra

  • property: name, hidden, priority, conditions, position, filling_top_bottom, filling_left_right, size, size_max, color_fg, color_delim, color_bg, separator, items (consultare bar_new)

  • value: nuovo valore per la proprietà

Valore restituito:

  • 1 se il nuovo valore è stato impostato, 0 in caso di errore

Esempio in C:

weechat_bar_set (mybar, "position", "bottom");

Script (Python):

# prototipo
def bar_set(bar: str, property: str, value: str) -> int: ...

# esempio
weechat.bar_set(my_bar, "position", "bottom")

bar_update

Aggiorna il contenuto di una barra su schermo.

Prototipo:

void weechat_bar_update (const char *name);

Argomenti:

  • name: nome della barra

Esempio in C:

weechat_bar_update ("mybar");

Script (Python):

# prototipo
def bar_update(name: str) -> int: ...

# esempio
weechat.bar_update("mybar")

bar_remove

Rimuove una barra.

Prototipo:

void weechat_bar_remove (struct t_gui_bar *bar);

Argomenti:

  • bar: puntatore alla barra

Esempio in C:

weechat_bar_remove (mybar);

Script (Python):

# prototipo
def bar_remove(bar: str) -> int: ...

# esempio
weechat.bar_remove(my_bar)

3.19. Comandi

Funzioni per eseguire comandi di WeeChat.

command

Updated in 1.1.

Execute a command or send text to buffer.

Prototipo:

int weechat_command (struct t_gui_buffer *buffer, const char *command);

Argomenti:

  • buffer: puntatore al buffer (il comando viene eseguito su questo buffer, utilizzare NULL per il buffer corrente)

  • command: comando da eseguire (se preceduto da "/"), oppure il testo viene inviato sul buffer

Valori restituiti (WeeChat ≥ 1.1):

  • WEECHAT_RC_OK se l’operazione ha successo

  • WEECHAT_RC_ERROR se c’è un errore

Esempio in C:

int rc;
rc = weechat_command (weechat_buffer_search ("irc", "libera.#weechat"),
                      "/whois FlashCode");

Script (Python):

# prototipo
def command(buffer: str, command: str) -> int: ...

# esempio
rc = weechat.command(weechat.buffer_search("irc", "libera.#weechat"), "/whois FlashCode")

command_options

WeeChat ≥ 2.5.

Execute a command or send text to buffer with options.

Prototipo:

int weechat_command_options (struct t_gui_buffer *buffer, const char *command,
                             struct t_hashtable *options);

Argomenti:

  • buffer: puntatore al buffer (il comando viene eseguito su questo buffer, utilizzare NULL per il buffer corrente)

  • command: comando da eseguire (se preceduto da "/"), oppure il testo viene inviato sul buffer

  • options: a hashtable with some options (keys and values must be string) (can be NULL):

    • commands: a comma-separated list of commands allowed to be executed during this call; see function string_match_list for the format

    • delay: delay to execute command, in milliseconds

Valori restituiti:

  • WEECHAT_RC_OK se l’operazione ha successo

  • WEECHAT_RC_ERROR se c’è un errore

Esempio in C:

/* allow any command except /exec, run command in 2 seconds */
int rc;
struct t_hashtable *options = weechat_hashtable_new (8,
                                                     WEECHAT_HASHTABLE_STRING,
                                                     WEECHAT_HASHTABLE_STRING,
                                                     NULL,
                                                     NULL);
weechat_hashtable_set (options, "commands", "*,!exec");
weechat_hashtable_set (options, "delay", "2000");
rc = weechat_command_options (NULL, "/some_command arguments", options);

Script (Python):

# prototipo
def command_options(buffer: str, command: str, options: Dict[str, str]) -> int: ...

# example: allow any command except /exec
rc = weechat.command("", "/some_command arguments", {"commands": "*,!exec"})

3.20. Completion

Functions to complete a command line.

completion_new

WeeChat ≥ 2.9.

Create a new completion.

Prototipo:

struct t_gui_completion *weechat_completion_new (struct t_gui_buffer *buffer);

Argomenti:

  • buffer: buffer pointer

Valori restituiti:

  • pointer to new completion

Esempio in C:

struct t_gui_completion *completion = weechat_completion_new (weechat_buffer_search_main ());

Script (Python):

# prototipo
def completion_new(buffer: str) -> str: ...

# esempio
completion = weechat.completion_new(weechat.buffer_search_main())

WeeChat ≥ 2.9.

Search possible words at a given position of a string, in the completion context.

Prototipo:

int weechat_completion_search (struct t_gui_completion *completion, const char *data,
                               int position, int direction);

Argomenti:

  • completion: completion pointer

  • data: the string to complete

  • position: index of the char in string to complete (starts to 0)

  • direction: 1 for next completion, -1 for previous completion

Valore restituito:

  • 1 if OK, 0 if error

Esempio in C:

struct t_gui_completion *completion = weechat_completion_new (weechat_buffer_search_main ());
if (weechat_completion_search (completion, "/help filt", 10, 1))
{
    /* ... */
}

Script (Python):

# prototipo
def completion_search(completion: str, data: str, position: int, direction: int) -> int: ...

# esempio
completion = weechat.completion_new(weechat.buffer_search_main())
if weechat.completion_search(completion, "/help filt", 10, 1):
    # ...

completion_get_string

Novità nella versioe 2.9.

Ottiene il completamento di una proprietà come stringa.

Prototipo:

const char *weechat_completion_get_string (struct t_gui_completion *completion,
                                           const char *property);

Argomenti:

  • completion: puntatore al completamento

  • property: nome della proprietà:

    • base_command: comando usato per il completamento

    • base_word: parola che viene completata

    • args: argomenti del comando (inclusa la parola base)

Esempio in C:

int
my_completion_cb (const void *pointer, void *data, const char *completion_item,
                  struct t_gui_buffer *buffer,
                  struct t_gui_completion *completion)
{
    /* ottiene l'argomento del comando */
    const char *args = weechat_completion_get_string (completion, "args");

    /* completamento che dipende dagli argomenti */
    /* ... */

    return WEECHAT_RC_OK;
}

Script (Python):

# prototipo
def completion_get_string(completion: str, property: str) -> str: ...

# esempio
def my_completion_cb(data: str, completion_item: str, buffer: str, completion: str) -> int:
    # ottiene l'argomento del comando
    args = weechat.completion_get_string(completion, "args")
    # completamento che dipende dagli argomenti
    # ...
    return weechat.WEECHAT_RC_OK

completion_list_add

Novità nella versioe 2.9.

Aggiunge una parola per il completamento.

Prototipo:

void weechat_completion_list_add (struct t_gui_completion *completion,
                                  const char *word,
                                  int nick_completion,
                                  const char *where);

Argomenti:

  • completion: puntatore al completamento

  • word: parola da aggiungere

  • nick_completion: 1 se la parola è un nick, altrimenti 0

  • where: posizione in cui la parola sarà inserita nella lista:

    • WEECHAT_LIST_POS_SORT: qualunque posizione, per mantenere la lista ordinata

    • WEECHAT_LIST_POS_BEGINNING: inizio della lista

    • WEECHAT_LIST_POS_END: fine della lista

Esempio in C: consultare hook_completion.

Script (Python):

# prototipo
def completion_list_add(completion: str, word: str, nick_completion: int, where: str) -> int: ...

# esempio: consultare function hook_completion

completion_free

WeeChat ≥ 2.9.

Free a completion.

Prototipo:

void weechat_completion_free (struct t_gui_completion *completion);

Argomenti:

  • completion: completion pointer

Esempio in C:

weechat_completion_free (completion);

Script (Python):

# prototipo
def completion_free(completion: str) -> int: ...

# esempio
weechat.completion_free(completion)

3.21. Network

Funzioni di rete.

network_pass_proxy

Stabilisce una connessione/autenticazione con un proxy.

This function is blocking on call to connect(), so it must be called in a forked process only, to not block WeeChat.

Prototipo:

int weechat_network_pass_proxy (const char *proxy,
                                int sock,
                                const char *address,
                                int port);

Argomenti:

  • proxy: nome del proxy da utilizzare

  • sock: socket da utilizzare

  • address: indirizzo (nome host o indirizzo IP)

  • port: port

Valore restituito:

  • 1 se la connessione è andata a buon fine, 0 in caso di errore

Esempio in C:

if (weechat_network_pass_proxy ("my_proxy", sock, "irc.libera.chat", 6667))
{
    /* OK */
}
else
{
    /* errore */
}
Questa funzione non è disponibile nelle API per lo scripting.

network_connect_to

Updated in 0.4.3.

Stabilisce una connessione con un host remoto.

This function is blocking on call to connect(), so it must be called in a forked process only, to not block WeeChat.

Prototipo:

int weechat_network_connect_to (const char *proxy,
                                struct sockaddr *address,
                                socklen_t address_length);

Argomenti:

  • proxy: nome del proxy da utilizzare

  • address: address to connect to (with port)

  • address_length: length of argument address

Valore restituito:

  • socket number (≥ 0) if connection is OK, -1 if an error occurred

Esempio in C:

struct sockaddr *addr;
socklen_t length;
int sock;

/* allocate/set address and port in 'addr', set 'length' */
/* ... */

sock = weechat_network_connect_to (NULL, addr, length);
if (sock >= 0)
{
    /* OK */
}
else
{
    /* errore */
}
Questa funzione non è disponibile nelle API per lo scripting.

3.22. Info

Funzioni per ottenere info.

info_get

Updated in 2.5.

Restituisce la info, come stringa, da WeeChat o da un plugin.

Prototipo:

char *weechat_info_get (const char *info_name, const char *arguments);

Argomenti:

  • info_name: nome delle informazioni da leggere (see table below)

  • arguments: argomenti per l’informazione richiesta (opzionake, NULL se non è richiesto alcun argomento)

Valore restituito:

  • stringa con l’informazione richiesta, NULL in caso di errore (deve essere liberata richiamando "free" dopo l’utilizzo)

With WeeChat ≥ 2.5, the value returned is an allocated string (with WeeChat ≤ 2.4, it was a pointer to a static string).

Infos:

Plugin Nome Descrizione Argomenti

fifo

fifo_filename

nome della pipe FIFO

-

guile

guile_eval

evaluation of source code

source code to execute

guile

guile_interpreter

name of the interpreter used

-

guile

guile_version

version of the interpreter used

-

irc

irc_buffer

ottiene puntatore al buffer per un server/canale/nick IRC

server,canale,nick (canale e nick sono opzionali)

irc

irc_is_channel

1 se la stringa è il nome di un canale IRC valido per il server

server,canale (server è opzionale)

irc

irc_is_message_ignored

1 if the nick is ignored (message is not displayed)

server,message (message is the raw IRC message)

irc

irc_is_nick

1 se la stringa è un nick IRC valido

server,nickname (server is optional)

irc

irc_nick

ottiene nick corrente su un server

nome server

irc

irc_nick_color

get nick color code (deprecated since version 1.5, replaced by "nick_color")

nickname

irc

irc_nick_color_name

get nick color name (deprecated since version 1.5, replaced by "nick_color_name")

nickname

irc

irc_nick_from_host

ottiene nick dall’host IRC

host IRC (come :nick!nome@server.com)

irc

irc_server_cap

1 if capability is enabled in server

server,capability

irc

irc_server_cap_value

value of capability, if enabled in server

server,capability

irc

irc_server_isupport

1 se il server supporta questa caratteristica (dal messaggio IRC 005)

server,caratteristica

irc

irc_server_isupport_value

valore della caratteristica, se supportata dal servre (dal messaggio IRC 005)

server,caratteristica

logger

logger_log_file

path to current log filename for the buffer

buffer pointer ("0x12345678") or buffer full name ("irc.libera.#weechat")

lua

lua_eval

evaluation of source code

source code to execute

lua

lua_interpreter

name of the interpreter used

-

lua

lua_version

version of the interpreter used

-

perl

perl_eval

evaluation of source code

source code to execute

perl

perl_interpreter

name of the interpreter used

-

perl

perl_version

version of the interpreter used

-

php

php_eval

evaluation of source code

source code to execute

php

php_interpreter

name of the interpreter used

-

php

php_version

version of the interpreter used

-

python

python_eval

evaluation of source code

source code to execute

python

python_interpreter

name of the interpreter used

-

python

python_version

version of the interpreter used

-

relay

relay_client_count

number of clients for relay

protocol,status (both are optional, for each argument "*" means all; protocols: irc, weechat; statuses: connecting, waiting_auth, connected, auth_failed, disconnected)

ruby

ruby_eval

evaluation of source code

source code to execute

ruby

ruby_interpreter

name of the interpreter used

-

ruby

ruby_version

version of the interpreter used

-

spell

spell_dict

elenco separato da virgole di dizionari usati nel buffer

buffer pointer ("0x12345678") or buffer full name ("irc.libera.#weechat")

tcl

tcl_eval

evaluation of source code

source code to execute

tcl

tcl_interpreter

name of the interpreter used

-

tcl

tcl_version

version of the interpreter used

-

weechat

auto_connect

1 if automatic connection to servers is enabled, 0 if it has been disabled by the user (option "-a" or "--no-connect")

-

weechat

auto_load_scripts

1 if scripts are automatically loaded, 0 if the auto-load has been disabled by the user (option "-s" or "--no-script")

-

weechat

buffer

puntatore al buffer

buffer full name

weechat

charset_internal

set caratteri interno di WeeChat

-

weechat

charset_terminal

set caratteri terminale

-

weechat

color_ansi_regex

POSIX extended regular expression to search ANSI escape codes

-

weechat

color_rgb2term

RGB color converted to terminal color (0-255)

rgb,limit (limit is optional and is set to 256 by default)

weechat

color_term2rgb

terminal color (0-255) converted to RGB color

color (terminal color: 0-255)

weechat

cursor_mode

1 se la modalità cursore è abilitata

-

weechat

date

WeeChat compilation date/time

-

weechat

dir_separator

separatore directory

-

weechat

filters_enabled

1 se i filtri sono abilitati

-

weechat

inactivity

inattività della tastiera (secondi)

-

weechat

locale

locale usato per la traduzione dei messaggi

-

weechat

mouse

1 if mouse is enabled

-

weechat

nick_color

ottiene il codice del colore del nick

nickname;colors (colors is an optional comma-separated list of colors to use; background is allowed for a color with format text:background; if colors is present, WeeChat options with nick colors and forced nick colors are ignored)

weechat

nick_color_ignore_case

get nick color code, ignoring case

nickname;range;colors (range is a number of chars (see function strcasecmp_range, 0 = convert to lower case without using a range), colors is an optional comma-separated list of colors to use; background is allowed for a color with format text:background; if colors is present, WeeChat options with nick colors and forced nick colors are ignored)

weechat

nick_color_name

ottiene il nome del colore del nick

nickname;colors (colors is an optional comma-separated list of colors to use; background is allowed for a color with format text:background; if colors is present, WeeChat options with nick colors and forced nick colors are ignored)

weechat

nick_color_name_ignore_case

get nick color name, ignoring case

nickname;range;colors (range is a number of chars (see function strcasecmp_range, 0 = convert to lower case without using a range), colors is an optional comma-separated list of colors to use; background is allowed for a color with format text:background; if colors is present, WeeChat options with nick colors and forced nick colors are ignored)

weechat

pid

WeeChat PID (process ID)

-

weechat

term_color_pairs

number of color pairs supported in terminal

-

weechat

term_colors

number of colors supported in terminal

-

weechat

term_height

height of terminal

-

weechat

term_width

width of terminal

-

weechat

totp_generate

generate a Time-based One-Time Password (TOTP)

secret (in base32), timestamp (optional, current time by default), number of digits (optional, between 4 and 10, 6 by default)

weechat

totp_validate

validate a Time-based One-Time Password (TOTP): 1 if TOTP is correct, otherwise 0

secret (in base32), one-time password, timestamp (optional, current time by default), number of passwords before/after to test (optional, 0 by default)

weechat

uptime

WeeChat uptime (format: "days:hh:mm:ss")

"days" (number of days) or "seconds" (number of seconds) (optional)

weechat

uptime_current

WeeChat uptime for the current process only (upgrades with /upgrade command are ignored) (format: "days:hh:mm:ss")

"days" (number of days) or "seconds" (number of seconds) (optional)

weechat

version

versione di WeeChat

-

weechat

version_git

Versione git di weechat (output del comando "git describe" solo per la versione di sviluppo, vuoto per una release stabile)

-

weechat

version_number

versione di WeeChat (come numero)

version (optional, by default the version of the running WeeChat is returned)

weechat

weechat_cache_dir

WeeChat cache directory

-

weechat

weechat_config_dir

WeeChat config directory

-

weechat

weechat_daemon

1 if WeeChat is running in daemon mode (headless, in background)

-

weechat

weechat_data_dir

WeeChat data directory

-

weechat

weechat_dir

WeeChat directory (deprecated since version 3.2, replaced by "weechat_config_dir", "weechat_data_dir", "weechat_cache_dir" and "weechat_runtime_dir")

-

weechat

weechat_headless

1 if WeeChat is running headless

-

weechat

weechat_libdir

directory "lib" di WeeChat

-

weechat

weechat_localedir

directory "locale" di WeeChat

-

weechat

weechat_runtime_dir

WeeChat runtime directory

-

weechat

weechat_sharedir

directory "share" di WeeChat

-

weechat

weechat_site

sito di WeeChat

-

weechat

weechat_site_download

sito di WeeChat, pagina di download

-

weechat

weechat_upgrading

1 se si sta aggiornando WeeChat (comando /upgrade)

-

Esempio in C:

char *version = weechat_info_get ("version", NULL);
char *date = weechat_info_get ("date", NULL);
weechat_printf (NULL, "Current WeeChat version is: %s (compiled on %s)",
                version, date);
if (version)
    free (version);
if (date)
    free (date);

char *weechat_config_dir = weechat_info_get ("weechat_config_dir", NULL);
weechat_printf (NULL, "WeeChat config directory is: %s", weechat_config_dir);
if (weechat_config_dir)
    free (weechat_config_dir);

Script (Python):

# prototipo
def info_get(info_name: str, arguments: str) -> str: ...

# esempio
weechat.prnt("", "Current WeeChat version is: %s (compiled on %s)"
    % (weechat.info_get("version", ""), weechat.info_get("date", ""))
weechat.prnt("", "WeeChat config directory is: %s" % weechat.info_get("weechat_config_dir"))

info_get_hashtable

WeeChat ≥ 0.3.4.

Restituisce una info, come tabella hash, da WeeChat o da un plugin.

Prototipo:

struct t_hashtable *weechat_info_get_hashtable (const char *info_name,
                                                struct t_hashtable *hashtable);

Argomenti:

  • info_name: nome della info da leggere (see table below)

  • hashtable: tabella hash con argomenti (dipende dalla info richiesta)

  • (opzionale, NULL se l’argomento non viene richiesto)

Valore restituito:

  • tabella hash con la info richiesta, NULL in caso di errore (must be freed by calling hashtable_free after use)

Infos:

Plugin Nome Descrizione Tabella hash (input) Tabella hash (output)

irc

irc_message_parse

controlla un messaggio IRC

"message": messaggio IRC, "server": nome server (opzionale)

"tags": tags, "tag_xxx": unescaped value of tag "xxx" (one key per tag), "message_without_tags": message without the tags, "nick": nick, "user": user, "host": host, "command": command, "channel": channel, "arguments": arguments (includes channel), "text": text (for example user message), "param1" …​ "paramN": parsed command parameters, "num_params": number of parsed command parameters, "pos_command": index of "command" message ("-1" if "command" was not found), "pos_arguments": index of "arguments" message ("-1" if "arguments" was not found), "pos_channel": index of "channel" message ("-1" if "channel" was not found), "pos_text": index of "text" message ("-1" if "text" was not found)

irc

irc_message_split

split an IRC message (to fit in 512 bytes by default)

"message": messaggio IRC, "server": nome server (opzionale)

"msg1" …​ "msgN": messaggio da inviare (senza "\r\n" finale), "args1" …​ "argsN": argomenti dei messaggi, "count": numero di messaggi

weechat

focus_info

get focus info

"x": x coordinate (string with integer >= 0), "y": y coordinate (string with integer >= 0)

see function "hook_focus" in Plugin API reference

weechat

secured_data

secured data

-

secured data: names and values (be careful: the values are sensitive data: do NOT print/log them anywhere)

Esempio in C:

struct t_hashtable *hashtable_in, *hashtable_out;

hashtable_in = weechat_hashtable_new (8,
                                      WEECHAT_HASHTABLE_STRING,
                                      WEECHAT_HASHTABLE_STRING,
                                      NULL,
                                      NULL);
if (hashtable_in)
{
    weechat_hashtable_set (
        hashtable_in,
        "message",
        "@time=2015-06-27T16:40:35.000Z;tag2=value\\sspace :nick!user@host PRIVMSG #weechat :Hello world!");
    hashtable_out = weechat_info_get_hashtable ("irc_message_parse",
                                                hashtable_in);
    /*
     * now hashtable_out has following keys/values:
     *   "tags"                : "time=2015-06-27T16:40:35.000Z;tag2=value\\sspace"
     *   "tag_time"            : "2015-06-27T16:40:35.000Z"
     *   "tag_tag2"            : "value space"
     *   "message_without_tags": ":nick!user@host PRIVMSG #weechat :Hello world!"
     *   "nick"                : "nick"
     *   "user"                : "user"
     *   "host"                : "nick!user@host"
     *   "command"             : "PRIVMSG"
     *   "channel"             : "#weechat"
     *   "arguments"           : "#weechat :Hello world!"
     *   "text"                : "Hello world!"
     *   "param1"              : "#weechat"
     *   "param2"              : "Hello world!"
     *   "num_params"          : "2"
     *   "pos_command"         : "65"
     *   "pos_arguments"       : "73"
     *   "pos_channel"         : "73"
     *   "pos_text"            : "83"
     */
    weechat_hashtable_free (hashtable_in);
    weechat_hashtable_free (hashtable_out);
}
See the Guida allo Scripting di WeeChat / Verifica messaggio  for more info about "irc_message_parse" output.

Script (Python):

# prototipo
def info_get_hashtable(info_name: str, dict_in: Dict[str, str]) -> Dict[str, str]: ...

# esempio
dict_in = {"message": ":nick!user@host PRIVMSG #weechat :message here"}
weechat.prnt("", "message parsed: %s"
             % weechat.info_get_hashtable("irc_message_parse", dict_in))

3.23. Liste info

Una lista info è una lista di "elementi". Ciascun elemento contiene delle variabili.

Ad esempio, la lista info "irc_server" ha N elementi (N è il numero di server IRC definiti). Per ogni elemento, esistono variabili come "name", "buffer", "is connected",…​

Ogni variabile ha un tipo e un valore. I tipi possibili sono:

  • integer: qualunque valore intero

  • string: qualunque valore stringa

  • pointer: qualunque puntatore

  • buffer: buffer di lunghezza fissa, contenente qualunque dato

  • time: valore tempo

infolist_new

Crea una nuova lista info.

Prototipo:

struct t_infolist *weechat_infolist_new ();

Valore restituito:

  • puntatore alla nuova lista info

Esempio in C:

struct t_infolist *infolist = weechat_infolist_new ();

Script (Python):

# prototipo
def infolist_new() -> str: ...

# esempio
infolist = weechat.infolist_new()

infolist_new_item

Aggiunge un elemento alla lista info.

Prototipo:

struct t_infolist_item *weechat_infolist_new_item (struct t_infolist *infolist);

Argomenti:

  • infolist: puntatore alla lista info

Valore restituito:

  • puntatore al nuovo elemento

Esempio in C:

struct t_infolist_item *item = weechat_infolist_new_item (infolist);

Script (Python):

# prototipo
def infolist_new_item(infolist: str) -> str: ...

# esempio
item = weechat.infolist_new_item(infolist)

infolist_new_var_integer

Aggiunge una variabile intera ad un elemento della lista info.

Prototipo:

struct t_infolist_var *weechat_infolist_new_var_integer (struct t_infolist_item *item,
                                                         const char *name,
                                                         int value);

Argomenti:

  • item: puntatore all’elemento della lista info

  • name: nome variabile

  • value: valore intero

Valore restituito:

  • puntatore alla nuova variabile

Esempio in C:

struct t_infolist_var *var = weechat_infolist_new_var_integer (item,
                                                               "my_integer",
                                                               123);

Script (Python):

# prototipo
def infolist_new_var_integer(item: str, name: str, value: int) -> str: ...

# esempio
var = weechat.infolist_new_var_integer(item, "my_integer", 123)

infolist_new_var_string

Aggiunge una variabile stringa ad un elemento della lista info.

Prototipo:

struct t_infolist_var *weechat_infolist_new_var_string (struct t_infolist_item *item,
                                                        const char *name,
                                                        const char *value);

Argomenti:

  • item: puntatore all’elemento della lista info

  • name: nome variabile

  • value: valore stringa

Valore restituito:

  • puntatore alla nuova variabile

Esempio in C:

struct t_infolist_var *var = weechat_infolist_new_var_string (item,
                                                              "my_string",
                                                              "value");

Script (Python):

# prototipo
def infolist_new_var_string(item: str, name: str, value: str) -> str: ...

# esempio
var = weechat.infolist_new_var_string(item, "my_string", "value")

infolist_new_var_pointer

Aggiunge una variabile puntatore ad un elemento della lista info.

Prototipo:

struct t_infolist_var *weechat_infolist_new_var_pointer (struct t_infolist_item *item,
                                                         const char *name,
                                                         void *pointer);

Argomenti:

  • item: puntatore all’elemento della lista info

  • name: nome variabile

  • pointer: puntatore

Valore restituito:

  • puntatore alla nuova variabile

Esempio in C:

struct t_infolist_var *var = weechat_infolist_new_var_pointer (item,
                                                               "my_pointer",
                                                               &pointer);

Script (Python):

# prototipo
def infolist_new_var_pointer(item: str, name: str, pointer: str) -> str: ...

# esempio
var = weechat.infolist_new_var_pointer(item, "my_pointer", pointer)

infolist_new_var_buffer

Aggiunge una variabile puntatore ad un elemento della lista info.

Prototipo:

struct t_infolist_var *weechat_infolist_new_var_buffer (struct t_infolist_item *item,
                                                        const char *name,
                                                        void *pointer,
                                                        int size);

Argomenti:

  • item: puntatore all’elemento della lista info

  • name: nome della variabile

  • pointer: puntatore al buffer

  • size: dimensione del buffer

Valore restituito:

  • puntatore alla nuova variabile

Esempio in C:

char buffer[256];
/* ... */
struct t_infolist_var *var = weechat_infolist_new_var_buffer (item,
                                                              "my_buffer",
                                                              &buffer,
                                                              sizeof (buffer));
Questa funzione non è disponibile nelle API per lo scripting.

infolist_new_var_time

Aggiunge una variabile tempo ad un elemento della lista info.

Prototipo:

struct t_infolist_var *weechat_infolist_new_var_time (struct t_infolist_item *item,
                                                      const char *name,
                                                      time_t time);

Argomenti:

  • item: puntatore all’elemento della lista info

  • name: nome della variabile

  • time: valore tempo

Valore restituito:

  • puntatore alla nuova variabile

Esempio in C:

struct t_infolist_var *var = weechat_infolist_new_var_time (item,
                                                            "my_time",
                                                            time (NULL));

Script (Python):

# prototipo
def infolist_new_var_time(item: str, name: str, time: int) -> str: ...

# esempio
var = weechat.infolist_new_var_time(item, "my_time", int(time.time()))

infolist_get

Restituisce una lista info da WeeChat o da un plugin.

Il contenuto della lista info è un duplicato dei dati attuali. Se si sta richiedendo una lista info con molti dati (come "buffer_lines"), WeeChat allocherà memoria per duplicare tutti i dati, e potrebbe essere necessario un po' di tempo.
Invece di usare liste info più grandi, è preferibilie usare hdata (ma le liste info potrebbero avere più info di hdata, che sono dati raw), consultare hdata.

Prototipo:

struct t_infolist *weechat_infolist_get (const char *infolist_name,
                                         void *pointer,
                                         const char *arguments);

Argomenti:

  • infolist_name: nome della lista info da leggere (see table below)

  • pointer: puntatore ad un elemento, per ricevere solo questo elemento nella lista info (opzionale, può essere NULL)

  • arguments: argomenti per la lista info richiesta (opzionale, NULL se non è necessario alcun argomento)

Valore restituito:

  • puntatore alla lista info, NULL in caso di errore

Infolists:

Plugin Nome Descrizione Puntatore Argomenti

alias

alias

elenco di alias

puntatore all’alias (opzionale)

alias name (wildcard "*" is allowed) (optional)

alias

alias_default

list of default aliases

-

-

buflist

buflist

list of buffers in a buflist bar item

-

buflist bar item name (optional)

fset

fset_option

list of fset options

fset option pointer (optional)

option name (wildcard "*" is allowed) (optional)

guile

guile_script

elenco degli script

puntatore allo script (opzionale)

script name (wildcard "*" is allowed) (optional)

irc

irc_channel

elenco dei canali per un server IRC

puntatore al canale (opzionale)

server,canale (canale è opzionale)

irc

irc_color_weechat

mapping between IRC color codes and WeeChat color names

-

-

irc

irc_ignore

elenco di ignore IRC

puntatore all’ignore (opzionale)

-

irc

irc_modelist

list of channel mode lists for an IRC channel

mode list pointer (optional)

server,channel,type (type is optional)

irc

irc_modelist_item

list of items in a channel mode list

mode list item pointer (optional)

server,channel,type,number (number is optional)

irc

irc_nick

elenco dei nick per un canale IRC

puntatore al nick (opzionale)

server,channel,nick (nick is optional)

irc

irc_notify

elenco delle notifiche

puntatore alla notifica (opzionale)

server name (wildcard "*" is allowed) (optional)

irc

irc_server

elenco di server IRC

puntatore al server (opzionale)

server name (wildcard "*" is allowed) (optional)

logger

logger_buffer

elenco dei buffer logger

puntatore al logger (opzionale)

-

lua

lua_script

elenco degli script

puntatore allo script (opzionale)

script name (wildcard "*" is allowed) (optional)

perl

perl_script

elenco degli script

puntatore allo script (opzionale)

script name (wildcard "*" is allowed) (optional)

php

php_script

elenco degli script

puntatore allo script (opzionale)

script name (wildcard "*" is allowed) (optional)

python

python_script

elenco degli script

puntatore allo script (opzionale)

script name (wildcard "*" is allowed) (optional)

relay

relay

elenco di client relay

puntatore al relay (opzionale)

-

ruby

ruby_script

elenco degli script

puntatore allo script (opzionale)

script name (wildcard "*" is allowed) (optional)

script

script_script

elenco degli script

puntatore allo script (opzionale)

script name with extension (wildcard "*" is allowed) (optional)

tcl

tcl_script

elenco degli script

puntatore allo script (opzionale)

script name (wildcard "*" is allowed) (optional)

weechat

bar

elenco delle barre

puntatore alla barra (opzionale)

bar name (wildcard "*" is allowed) (optional)

weechat

bar_item

elenco degli elementi barra

puntatore all’elemento della barra (opzionale)

bar item name (wildcard "*" is allowed) (optional)

weechat

bar_window

elenco delle finestre barra

puntatore alla finestra della barra (opzionale)

-

weechat

buffer

elenco dei buffer

puntatore al buffer (opzionale)

buffer name (wildcard "*" is allowed) (optional)

weechat

buffer_lines

righe di un buffer

puntatore al buffer

-

weechat

filter

elenco dei filtri

-

filter name (wildcard "*" is allowed) (optional)

weechat

history

cronologia dei comandi

puntatore al buffer (se non impostato, restituisce la cronologia globale) (opzionale)

-

weechat

hook

elenco di hook

puntatore all’hook (opzionale)

type,arguments (type is command/timer/.., arguments to get only some hooks (wildcard "*" is allowed), both are optional)

weechat

hotlist

elenco dei buffer nella hotlist

-

-

weechat

key

elenco di tasti associati

-

contesto ("default", "search", "cursor" o "mouse") (opzionale)

weechat

layout

elenco dei layout

-

-

weechat

nicklist

nick nella lista nick per un buffer

puntatore al buffer

nick_xxx o group_xxx per ottenere solo xxx di nick/group (opzionale)

weechat

option

elenco delle opzioni

-

option name (wildcard "*" is allowed) (optional)

weechat

plugin

elenco dei plugin

puntatore al plugin (opzionale)

plugin name (wildcard "*" is allowed) (optional)

weechat

proxy

elenco dei proxy

puntatore al proxy (opzionale)

proxy name (wildcard "*" is allowed) (optional)

weechat

url_options

opzioni per la URL

-

-

weechat

window

elenco delle finestre

puntatore alla finestra (opzionale)

"current" per la finestra corrente o un numero della finestra (opzionale)

xfer

xfer

elenco di xfer

puntatore a xfer (opzionale)

-

Esempio in C:

struct t_infolist *infolist = weechat_infolist_get ("irc_server", NULL, NULL);

Script (Python):

# prototipo
def infolist_get(infolist_name: str, pointer: str, arguments: str) -> str: ...

# esempio
infolist = weechat.infolist_get("irc_server", "", "")

infolist_next

Sposta "cursor" all’elemento successivo nella lista info. La prima chiamata a questa funzione per una lista info sposta il cursore al primo elemento nella lista info.

Prototipo:

int weechat_infolist_next (struct t_infolist *infolist);

Argomenti:

  • infolist: puntatore alla lista info

Valore restituito:

  • 1 se il cursore è stato spostato sull’elemento successivo, 0 se è stata raggiunta la fine della lista

Esempio in C:

if (weechat_infolist_next (infolist))
{
    /* legge variabili nell'elemento... */
}
else
{
    /* nessun altro elemento disponibile */
}

Script (Python):

# prototipo
def infolist_next(infolist: str) -> int: ...

# esempio
rc = weechat.infolist_next(infolist)
if rc:
    # legge variabili nell'elemento...
else:
    # nessun altro elemento disponibile

infolist_prev

Sposta "cursor" all’elemento precedente nella lista info. La prima chiamata a questa funzione per una lista info sposta il cursore all’ultimo elemento.

Prototipo:

int weechat_infolist_prev (struct t_infolist *infolist);

Argomenti:

  • infolist: puntatore alla lista info

Valore restituito:

  • 1 se il cursore è stato spostato sull’elemento precedente, 0 se è stato raggiunto l’inizio della lista

Esempio in C:

if (weechat_infolist_prev (infolist))
{
    /* legge variabili nell'elemento... */
}
else
{
    /* nessun altro elemento disponibile */
}

Script (Python):

# prototipo
def infolist_prev(infolist: str) -> int: ...

# esempio
rc = weechat.infolist_prev(infolist)
if rc:
    # read variables in item...
else:
    # no more item available

infolist_reset_item_cursor

Ripristina "cursor" per la lista info.

Prototipo:

void weechat_infolist_reset_item_cursor (struct t_infolist *infolist);

Argomenti:

  • infolist: puntatore alla lista info

Esempio in C:

weechat_infolist_reset_item_cursor (infolist);

Script (Python):

# prototipo
def infolist_reset_item_cursor(infolist: str) -> int: ...

# esempio
weechat.infolist_reset_item_cursor(infolist)

infolist_search_var

WeeChat ≥ 0.4.3.

Search a variable in the current infolist item.

Prototipo:

struct t_infolist_var *weechat_infolist_search_var (struct t_infolist *infolist,
                                                    const char *name);

Argomenti:

  • infolist: puntatore alla lista info

  • name: nome della variabile

Valore restituito:

  • pointer to variable found, NULL if the variable was not found

Esempio in C:

if (weechat_infolist_search_var (infolist, "name"))
{
    /* variable "name" exists */
    /* ... */
}

Script (Python):

# prototipo
def infolist_search_var(infolist: str, name: str) -> str: ...

# esempio
if weechat.infolist_search_var(infolist, "name"):
    # variable "name" exists
    # ...

infolist_fields

Restituisce una lista di campi per l’elemento della lista info corrente.

Prototipo:

const char *weechat_infolist_fields (struct t_infolist *infolist);

Argomenti:

  • infolist: puntatore alla lista info

Valore restituito:

  • stringa con una lista di campi per l’elemento della lista info corrente. La lista è separata da virgole, e contiene lettere per tipo, seguite dal nome della variabile. I tipi sono: "i" (intero), "s" (stringa), "p" (puntatore), "b" (buffer), "t" (tempo).

Esempio in C:

const char *fields = weechat_infolist_fields (infolist);
/* i campi contengono qualcosa come:
   "i:my_integer,s:my_string,p:my_pointer,b:my_buffer,t:my_time" */

Script (Python):

# prototipo
def infolist_fields(infolist: str) -> str: ...

# esempio
fields = weechat.infolist_fields(infolist)
# i campi contengono qualcosa come:
# "i:my_integer,s:my_string,p:my_pointer,b:my_buffer,t:my_time"

infolist_integer

Restituisce il valore della variabile intera nell’elemento corrente della lista info.

Prototipo:

int weechat_infolist_integer (struct t_infolist *infolist, const char *var);

Argomenti:

  • infolist: puntatore alla lista info

  • var: nome della variabile (deve essere di tipo "integer")

Valore restituito:

  • valore intero della variabile

Esempio in C:

weechat_printf (NULL, "integer = %d",
                weechat_infolist_integer (infolist, "my_integer"));

Script (Python):

# prototipo
def infolist_integer(infolist: str, var: str) -> int: ...

# esempio
weechat.prnt("", "integer = %d" % weechat.infolist_integer(infolist, "my_integer"))

infolist_string

Restituisce il valore della variabile stringa nell’elemento della lista info corrente.

Prototipo:

const char *weechat_infolist_string (struct t_infolist *infolist, const char *var);

Argomenti:

  • infolist: puntatore alla lista info

  • var: nome della variabile (deve essere di tipo "string")

Valore restituito:

  • valore stringa della variabile

Esempio in C:

weechat_printf (NULL, "string = %s",
                weechat_infolist_string (infolist, "my_string"));

Script (Python):

# prototipo
def infolist_string(infolist: str, var: str) -> str: ...

# esempio
weechat.prnt("", "string = %s" % weechat.infolist_string(infolist, "my_string"))

infolist_pointer

Restituisce il valore della variabile puntatore nell’elemento della lista info corrente.

Prototipo:

void *weechat_infolist_pointer (struct t_infolist *infolist, const char *var);

Argomenti:

  • infolist: puntatore alla lista info

  • var: nome della variabile (deve essere di tipo "pointer")

Valore restituito:

  • puntatore al valore della variabile

Esempio in C:

weechat_printf (NULL, "pointer = 0x%lx",
                weechat_infolist_pointer (infolist, "my_pointer"));

Script (Python):

# prototipo
def infolist_pointer(infolist: str, var: str) -> str: ...

# esempio
weechat.prnt("", "pointer = 0x%s" % weechat.infolist_pointer(infolist, "my_pointer"))

infolist_buffer

Restituisce il valore della variabile buffer nell’elemento corrente della lista info.

Prototipo:

void *weechat_infolist_buffer (struct t_infolist *infolist, const char *var,
                               int *size);

Argomenti:

  • infolist: puntatore alla lista info

  • var: nome della variabile (deve essere di tipo "buffer")

  • size: puntatore ad una variabile intera, verrà impostata con la dimensione del buffer

Valore restituito:

  • puntatore al buffer

Esempio in C:

int size;
void *pointer = weechat_infolist_buffer (infolist, "my_buffer", &size);
weechat_printf (NULL, "buffer = 0x%lx, size = %d",
                pointer, size);
Questa funzione non è disponibile nelle API per lo scripting.

infolist_time

Restituisce il valore della variabile data/ora nell’elemento attivo della lista info.

Prototipo:

time_t weechat_infolist_time (struct t_infolist *infolist, const char *var);

Argomenti:

  • infolist: puntatore alla lista info

  • var: nome della variabile (deve essere di tipo "time")

Valore restituito:

  • valore della variabile nel formato data/ora

Esempio in C:

weechat_printf (NULL, "time = %ld",
                weechat_infolist_time (infolist, "my_time"));

Script (Python):

# prototipo
def infolist_time(infolist: str, var: str) -> int: ...

# esempio
weechat.prnt("", "time = %ld" % weechat.infolist_time(infolist, "my_time"))

infolist_free

Libera una lista info.

Prototipo:

void weechat_infolist_free (struct t_infolist *infolist);

Argomenti:

  • infolist: puntatore alla lista info

Esempio in C:

weechat_infolist_free (infolist);

Script (Python):

# prototipo
def infolist_free(infolist: str) -> int: ...

# esempio
weechat.infolist_free(infolist)

3.24. Hdata

Funzioni per hdata (accesso raw a WeeChat o ai dati dei plugin).

Hdata fornisce un accesso in sola lettura ai dati. È SEVERAMENTE VIETATO scrivere qualcosa in memoria puntato dalle variabili in hdata.
The only way to update data is to call function hdata_update.

hdata_new

WeeChat ≥ 0.3.6, updated in 0.3.9, 0.4.0.

Crea un nuovo hdata.

hdata vs infolist

Hdata è un metodo veloce per leggere i dati di WeeChat o dei plugin. È simile alle liste info, ma ci sono alcune differenze:

  • è più veloce ed usa meno memoria: lettura diretta dei dati senza duplicazione

  • può contenere informazioni differenti rispetto alle liste info: esso contiene solo dati raw in strutture (le liste info possono aggiungere alcuni dati extra per convenienza)

Prototipo:

struct t_hdata *weechat_hdata_new (const char *hdata_name, const char *var_prev, const char *var_next,
                                   int create_allowed, int delete_allowed,
                                   int (*callback_update)(void *data,
                                                          struct t_hdata *hdata,
                                                          void *pointer,
                                                          struct t_hashtable *hashtable),
                                   void *callback_update_data);

Argomenti:

  • hdata_name: nome di un hdata

  • var_prev: nome della variabile nella struttura che è puntatore all’elemento precedente nella lista (può essere NULL se non è disponibile tale variabile)

  • var_next: nome della variabile nella struttura che è puntatore all’elemento successivo nella lista (può essere NULL se non è disponibile tale variabile)

  • create_allowed: 1 if create of structure is allowed, otherwise 0 (WeeChat ≥ 0.4.0)

  • delete_allowed: 1 if delete of structure is allowed, otherwise 0 (WeeChat ≥ 0.3.9)

  • callback_update: callback to update data in hdata, can be NULL if no update is allowed (WeeChat ≥ 0.3.9), arguments and return value:

    • void *data: pointer

    • struct t_hdata *hdata: pointer to hdata

    • struct t_hashtable *hashtable: hashtable with variables to update (see hdata_update)

    • return value: number of variables updated

  • callback_update_data: pointer given to update callback when it is called by WeeChat (WeeChat ≥ 0.3.9)

Valore restituito:

  • puntatore al nuovo hdata

Esempio in C: source,c]

struct t_hdata *hdata = weechat_hdata_new ("myplugin_list", "prev", "next", 0, 0, &callback_update, NULL);
Questa funzione non è disponibile nelle API per lo scripting.

hdata_new_var

WeeChat ≥ 0.3.6, updated in 0.3.7, 0.3.9, 0.4.3, 3.4

Crea una nuova variabile in hdata.

Prototipo:

void weechat_hdata_new_var (struct t_hdata *hdata, const char *name, int offset, int type,
                            int update_allowed, const char *array_size, const char *hdata_name);

Argomenti:

  • hdata: puntatore ad hdata

  • name: nome della variabile

  • offset: offset della variabile nella struttura

  • type: tipo variabile, una di:

    • WEECHAT_HDATA_CHAR

    • WEECHAT_HDATA_INTEGER

    • WEECHAT_HDATA_LONG

    • WEECHAT_HDATA_STRING

    • WEECHAT_HDATA_SHARED_STRING (WeeChat ≥ 0.4.3)

    • WEECHAT_HDATA_POINTER

    • WEECHAT_HDATA_TIME

    • WEECHAT_HDATA_HASHTABLE (WeeChat ≥ 0.3.7)

    • WEECHAT_HDATA_OTHER

  • update_allowed: 1 if update of variable is allowed, otherwise 0 (WeeChat ≥ 0.3.9)

  • array_size: not NULL only if a variable is an array, and it can be: (WeeChat ≥ 0.3.9)

    • name of variable in hdata: this variable will be used as size of array (dynamic size for array)

    • integer (as string): fixed size for array

    • *: automatic size: the size of array is computed by looking at values, when the first NULL is found (only for type string, pointer or hashtable)

  • hdata_name: nome di un hdata (se è un puntatore ad una struttura con dati)

With WeeChat ≥ 3.4, the array_size parameter can be prefixed with *, for pointer to dynamically allocated array (without this prefix, the array is considered static).

Examples of variables and the corresponding array size (WeeChat ≥ 3.4):

Variable declaration in C Hdata type Array size Description

int *numbers;

WEECHAT_HDATA_INTEGER

*,2

Allocated array of 2 integers.

int *numbers;

WEECHAT_HDATA_INTEGER

*,array_size

Allocated array of integers, the size is stored in another variable called "array_size".

int numbers[3];

WEECHAT_HDATA_INTEGER

3

Static array of 3 integers.

char **words;

WEECHAT_HDATA_STRING

*,*

Allocated array of strings, dynamic size (NULL pointer must be present after last word).

char **words;

WEECHAT_HDATA_STRING

*,count_words

Allocated array of strings, the size is stored in another variable called "count_words".

Esempio in C:

struct t_myplugin_list
{
    char *name;
    struct t_gui_buffer *buffer;
    int numbers[3];
    int tags_count;
    char **tags_array;
    char **string_split;
    struct t_myplugin_list *prev;
    struct t_myplugin_list *next;
};

/* ... */

struct t_hdata *hdata = weechat_hdata_new ("myplugin_list", "prev", "next");
weechat_hdata_new_var (hdata, "name", offsetof (struct t_myplugin_list, name), WEECHAT_HDATA_STRING, 0, NULL, NULL);
weechat_hdata_new_var (hdata, "buffer", offsetof (struct t_myplugin_list, buffer), WEECHAT_HDATA_POINTER, 0, NULL, NULL);
weechat_hdata_new_var (hdata, "numbers", offsetof (struct t_myplugin_list, numbers), WEECHAT_HDATA_INTEGER, 0, "3", NULL);
weechat_hdata_new_var (hdata, "tags_count", offsetof (struct t_myplugin_list, tags_count), WEECHAT_HDATA_INTEGER, 0, NULL, NULL);
weechat_hdata_new_var (hdata, "tags_array", offsetof (struct t_myplugin_list, tags_array), WEECHAT_HDATA_STRING, 0, "*,tags_count", NULL);
weechat_hdata_new_var (hdata, "string_split", offsetof (struct t_myplugin_list, string_split), WEECHAT_HDATA_STRING, 0, "*,*", NULL);
weechat_hdata_new_var (hdata, "prev", offsetof (struct t_myplugin_list, prev), WEECHAT_HDATA_POINTER, 0, NULL, "myplugin_list");
weechat_hdata_new_var (hdata, "next", offsetof (struct t_myplugin_list, next), WEECHAT_HDATA_POINTER, 0, NULL, "myplugin_list");

La macro "WEECHAT_HDATA_VAR" può essere usata per accorciare il codice:

WEECHAT_HDATA_VAR(struct t_myplugin_list, name, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_myplugin_list, buffer, POINTER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_myplugin_list, numbers, INTEGER, 0, "3", NULL);
WEECHAT_HDATA_VAR(struct t_myplugin_list, tags_count, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_myplugin_list, tags_array, STRING, 0, "*,tags_count", NULL);
WEECHAT_HDATA_VAR(struct t_myplugin_list, string_split, STRING, 0, "*,*", NULL);
WEECHAT_HDATA_VAR(struct t_myplugin_list, prev, POINTER, 0, NULL, "myplugin_list");
WEECHAT_HDATA_VAR(struct t_myplugin_list, next, POINTER, 0, NULL, "myplugin_list");
Questa funzione non è disponibile nelle API per lo scripting.

hdata_new_list

WeeChat ≥ 0.3.6, updated in 1.0.

Crea una nuovo puntatore alla lista in hdata.

Prototipo:

void weechat_hdata_new_list (struct t_hdata *hdata, const char *name, void *pointer, int flags);

Argomenti:

  • hdata: puntatore hdata

  • name: nome delal variabile

  • pointer: puntatore alla lista

  • flags: combination of following values: (WeeChat ≥ 1.0)

    • WEECHAT_HDATA_LIST_CHECK_POINTERS: list used to check pointers

Esempio in C:

struct t_myplugin_list
{
    char *name;
    struct t_gui_buffer *buffer;
    int tags_count;
    char **tags_array;
    char **string_split;
    struct t_myplugin_list *prev;
    struct t_myplugin_list *next;
};

/* ... */

struct t_hdata *hdata = weechat_hdata_new ("myplugin_list", "prev", "next");
weechat_hdata_new_var (hdata, "name", offsetof (struct t_myplugin_list, name), WEECHAT_HDATA_STRING, NULL, NULL);
weechat_hdata_new_var (hdata, "buffer", offsetof (struct t_myplugin_list, buffer), WEECHAT_HDATA_POINTER, NULL, NULL);
weechat_hdata_new_var (hdata, "tags_count", offsetof (struct t_myplugin_list, tags_count), WEECHAT_HDATA_INTEGER, NULL, NULL);
weechat_hdata_new_var (hdata, "tags_array", offsetof (struct t_myplugin_list, tags_array), WEECHAT_HDATA_STRING, "tags_count", NULL);
weechat_hdata_new_var (hdata, "string_split", offsetof (struct t_myplugin_list, string_split), WEECHAT_HDATA_STRING, "*", NULL);
weechat_hdata_new_var (hdata, "prev", offsetof (struct t_myplugin_list, prev), WEECHAT_HDATA_POINTER, NULL, "myplugin_list");
weechat_hdata_new_var (hdata, "next", offsetof (struct t_myplugin_list, next), WEECHAT_HDATA_POINTER, NULL, "myplugin_list");

weechat_hdata_new_list (hdata, "buffers", &buffers, WEECHAT_HDATA_LIST_CHECK_POINTERS);
weechat_hdata_new_list (hdata, "last_buffer", &last_buffer, 0);

La macro "WEECHAT_HDATA_LIST" può essere usata per accorciare il codice:

WEECHAT_HDATA_LIST(buffers, WEECHAT_HDATA_LIST_CHECK_POINTERS);
WEECHAT_HDATA_LIST(last_buffer, 0);
Questa funzione non è disponibile nelle API per lo scripting.

hdata_get

WeeChat ≥ 0.3.6.

Restituisce hdata per una struttura di WeeChat o di un plugin.

Hdata non contiene dati, è una tabella hash con la posizione delle variabili nella struttura. Ciò indica che è necessario questo hdata ed un puntatore ad un oggetto di WeeChat/plugin per leggere dei dati.

Prototipo:

struct t_hdata *weechat_hdata_get (const char *hdata_name);

Argomenti:

  • hdata_name: nome di un hdata (see list below)

Valore restituito:

  • puntatore ad un hdata, NULL in caso di errore

List of hdata:

Plugin Nome Descrizione Lists Variables

fset

fset_option

fset options

-

index   (integer)
file   (string)
section   (string)
option   (string)
name   (string)
parent_name   (string)
type   (integer)
default_value   (string)
value   (string)
parent_value   (string)
min   (string)
max   (string)
description   (string)
string_values   (string)
marked   (integer)

guile

guile_script

elenco degli script

scripts
last_script

filename   (string)
interpreter   (pointer)
name   (string)
author   (string)
version   (string)
license   (string)
description   (string)
shutdown_func   (string)
charset   (string)
unloading   (integer)
prev_script   (pointer, hdata: "guile_script")
next_script   (pointer, hdata: "guile_script")

irc

irc_batch

irc batch

-

reference   (string)
parent_ref   (string)
type   (string)
parameters   (string)
start_time   (time)
messages   (pointer)
end_received   (integer)
messages_processed   (integer)
prev_batch   (pointer, hdata: "irc_batch")
next_batch   (pointer, hdata: "irc_batch")

irc

irc_channel

canale irc

-

type   (integer)
name   (string)
topic   (string)
modes   (string)
limit   (integer)
key   (string)
join_msg_received   (hashtable)
checking_whox   (integer)
away_message   (string)
has_quit_server   (integer)
cycle   (integer)
part   (integer)
nick_completion_reset   (integer)
pv_remote_nick_color   (string)
hook_autorejoin   (pointer)
nicks_count   (integer)
nicks   (pointer, hdata: "irc_nick")
last_nick   (pointer, hdata: "irc_nick")
nicks_speaking   (pointer)
nicks_speaking_time   (pointer, hdata: "irc_channel_speaking")
last_nick_speaking_time   (pointer, hdata: "irc_channel_speaking")
modelists   (pointer, hdata: "irc_modelist")
last_modelist   (pointer, hdata: "irc_modelist")
join_smart_filtered   (hashtable)
typing_state   (integer)
typing_status_sent   (time)
buffer   (pointer, hdata: "buffer")
buffer_as_string   (string)
prev_channel   (pointer, hdata: "irc_channel")
next_channel   (pointer, hdata: "irc_channel")

irc

irc_channel_speaking

channel_speaking irc

-

nick   (string)
time_last_message   (time)
prev_nick   (pointer, hdata: "irc_channel_speaking")
next_nick   (pointer, hdata: "irc_channel_speaking")

irc

irc_ignore

ignore irc

irc_ignore_list
last_irc_ignore

number   (integer)
mask   (string)
regex_mask   (pointer)
server   (string)
channel   (string)
prev_ignore   (pointer, hdata: "irc_ignore")
next_ignore   (pointer, hdata: "irc_ignore")

irc

irc_list

irc data for /list buffer

-

buffer   (pointer, hdata: "buffer")
channels   (pointer)
filter_channels   (pointer)
name_max_length   (integer)
filter   (string)
sort   (string)
sort_fields   (pointer)
sort_fields_count   (integer)
selected_line   (integer)

irc

irc_list_channel

irc channel on /list buffer

-

name   (string)
name2   (string)
users   (integer)
topic   (string)

irc

irc_modelist

irc modelist

-

type   (char)
state   (integer)
items   (pointer, hdata: "irc_modelist_item")
last_item   (pointer, hdata: "irc_modelist_item")
prev_modelist   (pointer, hdata: "irc_modelist")
next_modelist   (pointer, hdata: "irc_modelist")

irc

irc_modelist_item

irc modelist item

-

number   (integer)
mask   (string)
setter   (string)
datetime   (time)
prev_item   (pointer, hdata: "irc_modelist_item")
next_item   (pointer, hdata: "irc_modelist_item")

irc

irc_nick

nick irc

-

name   (string)
host   (string)
prefixes   (string)
prefix   (string)
away   (integer)
account   (string)
realname   (string)
color   (string)
prev_nick   (pointer, hdata: "irc_nick")
next_nick   (pointer, hdata: "irc_nick")

irc

irc_notify

notify irc

-

server   (pointer, hdata: "irc_server")
nick   (string)
check_away   (integer)
is_on_server   (integer)
away_message   (string)
ison_received   (integer)
prev_notify   (pointer, hdata: "irc_notify")
next_notify   (pointer, hdata: "irc_notify")

irc

irc_redirect

redirezione irc

-

server   (pointer, hdata: "irc_server")
pattern   (string)
signal   (string)
count   (integer)
current_count   (integer)
string   (string)
timeout   (integer)
command   (string)
assigned_to_command   (integer)
start_time   (time)
cmd_start   (hashtable)
cmd_stop   (hashtable)
cmd_extra   (hashtable)
cmd_start_received   (integer)
cmd_stop_received   (integer)
cmd_filter   (hashtable)
output   (string)
output_size   (integer)
prev_redirect   (pointer, hdata: "irc_redirect")
next_redirect   (pointer, hdata: "irc_redirect")

irc

irc_redirect_pattern

schema per la redirezione irc

irc_redirect_patterns
last_irc_redirect_pattern

name   (string)
temp_pattern   (integer)
timeout   (integer)
cmd_start   (string)
cmd_stop   (string)
cmd_extra   (string)
prev_redirect   (pointer, hdata: "irc_redirect_pattern")
next_redirect   (pointer, hdata: "irc_redirect_pattern")

irc

irc_server

server irc

irc_servers
last_irc_server

name   (string)
options   (pointer)
temp_server   (integer)
fake_server   (integer)
reloading_from_config   (integer)
reloaded_from_config   (integer)
addresses_eval   (string)
addresses_count   (integer)
addresses_array   (string, array_size: "addresses_count")
ports_array   (integer, array_size: "addresses_count")
retry_array   (integer, array_size: "addresses_count")
index_current_address   (integer)
current_address   (string)
current_ip   (string)
current_port   (integer)
current_retry   (integer)
sock   (integer)
hook_connect   (pointer, hdata: "hook")
hook_fd   (pointer, hdata: "hook")
hook_timer_connection   (pointer, hdata: "hook")
hook_timer_sasl   (pointer, hdata: "hook")
hook_timer_anti_flood   (pointer, hdata: "hook")
sasl_scram_client_first   (string)
sasl_scram_salted_pwd   (other)
sasl_scram_salted_pwd_size   (integer)
sasl_scram_auth_message   (string)
sasl_temp_username   (string)
sasl_temp_password   (string)
authentication_method   (integer)
sasl_mechanism_used   (integer)
is_connected   (integer)
tls_connected   (integer)
disconnected   (integer)
gnutls_sess   (pointer)
tls_cert   (pointer)
tls_cert_key   (pointer)
unterminated_message   (string)
nicks_count   (integer)
nicks_array   (string, array_size: "nicks_count")
nick_first_tried   (integer)
nick_alternate_number   (integer)
nick   (string)
nick_modes   (string)
host   (string)
checking_cap_ls   (integer)
cap_ls   (hashtable)
checking_cap_list   (integer)
cap_list   (hashtable)
multiline_max_bytes   (integer)
multiline_max_lines   (integer)
isupport   (string)
prefix_modes   (string)
prefix_chars   (string)
msg_max_length   (integer)
user_max_length   (integer)
host_max_length   (integer)
casemapping   (integer)
utf8mapping   (integer)
utf8only   (integer)
chantypes   (string)
chanmodes   (string)
monitor   (integer)
monitor_time   (time)
clienttagdeny   (string)
clienttagdeny_count   (integer)
clienttagdeny_array   (string, array_size: "clienttagdeny_count")
typing_allowed   (integer)
reconnect_delay   (integer)
reconnect_start   (time)
command_time   (time)
autojoin_done   (integer)
disable_autojoin   (integer)
is_away   (integer)
away_message   (string)
away_time   (time)
lag   (integer)
lag_displayed   (integer)
lag_check_time   (other)
lag_next_check   (time)
lag_last_refresh   (time)
cmd_list_regexp   (pointer)
list   (pointer, hdata: "irc_list")
last_away_check   (time)
last_data_purge   (time)
outqueue   (pointer)
last_outqueue   (pointer)
redirects   (pointer, hdata: "irc_redirect")
last_redirect   (pointer, hdata: "irc_redirect")
notify_list   (pointer, hdata: "irc_notify")
last_notify   (pointer, hdata: "irc_notify")
notify_count   (integer)
join_manual   (hashtable)
join_channel_key   (hashtable)
join_noswitch   (hashtable)
echo_msg_recv   (hashtable)
names_channel_filter   (hashtable)
batches   (pointer, hdata: "irc_batch")
last_batch   (pointer, hdata: "irc_batch")
buffer   (pointer, hdata: "buffer")
buffer_as_string   (string)
channels   (pointer, hdata: "irc_channel")
last_channel   (pointer, hdata: "irc_channel")
prev_server   (pointer, hdata: "irc_server")
next_server   (pointer, hdata: "irc_server")

lua

lua_script

elenco degli script

scripts
last_script

filename   (string)
interpreter   (pointer)
name   (string)
author   (string)
version   (string)
license   (string)
description   (string)
shutdown_func   (string)
charset   (string)
unloading   (integer)
prev_script   (pointer, hdata: "lua_script")
next_script   (pointer, hdata: "lua_script")

perl

perl_script

elenco degli script

scripts
last_script

filename   (string)
interpreter   (pointer)
name   (string)
author   (string)
version   (string)
license   (string)
description   (string)
shutdown_func   (string)
charset   (string)
unloading   (integer)
prev_script   (pointer, hdata: "perl_script")
next_script   (pointer, hdata: "perl_script")

php

php_script

elenco degli script

scripts
last_script

filename   (string)
interpreter   (pointer)
name   (string)
author   (string)
version   (string)
license   (string)
description   (string)
shutdown_func   (string)
charset   (string)
unloading   (integer)
prev_script   (pointer, hdata: "php_script")
next_script   (pointer, hdata: "php_script")

python

python_script

elenco degli script

scripts
last_script

filename   (string)
interpreter   (pointer)
name   (string)
author   (string)
version   (string)
license   (string)
description   (string)
shutdown_func   (string)
charset   (string)
unloading   (integer)
prev_script   (pointer, hdata: "python_script")
next_script   (pointer, hdata: "python_script")

ruby

ruby_script

elenco degli script

scripts
last_script

filename   (string)
interpreter   (pointer)
name   (string)
author   (string)
version   (string)
license   (string)
description   (string)
shutdown_func   (string)
charset   (string)
unloading   (integer)
prev_script   (pointer, hdata: "ruby_script")
next_script   (pointer, hdata: "ruby_script")

script

script_script

script dal repository

scripts_repo
last_script_repo

name   (string)
name_with_extension   (string)
language   (integer)
author   (string)
mail   (string)
version   (string)
license   (string)
description   (string)
tags   (string)
requirements   (string)
min_weechat   (string)
max_weechat   (string)
sha512sum   (string)
url   (string)
popularity   (integer)
date_added   (time)
date_updated   (time)
status   (integer)
version_loaded   (string)
displayed   (integer)
install_order   (integer)
prev_script   (pointer, hdata: "script_script")
next_script   (pointer, hdata: "script_script")

tcl

tcl_script

elenco degli script

scripts
last_script

filename   (string)
interpreter   (pointer)
name   (string)
author   (string)
version   (string)
license   (string)
description   (string)
shutdown_func   (string)
charset   (string)
unloading   (integer)
prev_script   (pointer, hdata: "tcl_script")
next_script   (pointer, hdata: "tcl_script")

weechat

bar

barra

gui_bars
last_gui_bar

name   (string)
options   (pointer)
items_count   (integer)
items_subcount   (pointer)
items_array   (pointer)
items_buffer   (pointer)
items_prefix   (pointer)
items_name   (pointer)
items_suffix   (pointer)
bar_window   (pointer, hdata: "bar_window")
bar_refresh_needed   (integer)
prev_bar   (pointer, hdata: "bar")
next_bar   (pointer, hdata: "bar")

weechat

bar_item

elemento barra

gui_bar_items
last_gui_bar_item

plugin   (pointer, hdata: "plugin")
name   (string)
build_callback   (pointer)
build_callback_pointer   (pointer)
build_callback_data   (pointer)
prev_item   (pointer, hdata: "bar_item")
next_item   (pointer, hdata: "bar_item")

weechat

bar_window

finestra della barra

-

bar   (pointer, hdata: "bar")
x   (integer)
y   (integer)
width   (integer)
height   (integer)
scroll_x   (integer)
scroll_y   (integer)
cursor_x   (integer)
cursor_y   (integer)
current_size   (integer)
items_count   (integer)
items_subcount   (pointer)
items_content   (pointer)
items_num_lines   (pointer)
items_refresh_needed   (pointer)
screen_col_size   (integer)
screen_lines   (integer)
coords_count   (integer)
coords   (pointer)
gui_objects   (pointer)
prev_bar_window   (pointer, hdata: "bar_window")
next_bar_window   (pointer, hdata: "bar_window")

Update allowed:
    scroll_x (integer)
    scroll_y (integer)

weechat

buffer

buffer

gui_buffer_last_displayed
gui_buffers
last_gui_buffer

opening   (integer)
plugin   (pointer, hdata: "plugin")
plugin_name_for_upgrade   (string)
number   (integer)
layout_number   (integer)
layout_number_merge_order   (integer)
name   (string)
full_name   (string)
old_full_name   (string)
short_name   (string)
type   (integer)
notify   (integer)
num_displayed   (integer)
active   (integer)
hidden   (integer)
zoomed   (integer)
print_hooks_enabled   (integer)
day_change   (integer)
clear   (integer)
filter   (integer)
close_callback   (pointer)
close_callback_pointer   (pointer)
close_callback_data   (pointer)
closing   (integer)
title   (string)
own_lines   (pointer, hdata: "lines")
mixed_lines   (pointer, hdata: "lines")
lines   (pointer, hdata: "lines")
next_line_id   (integer)
time_for_each_line   (integer)
chat_refresh_needed   (integer)
nicklist   (integer)
nicklist_case_sensitive   (integer)
nicklist_root   (pointer, hdata: "nick_group")
nicklist_max_length   (integer)
nicklist_display_groups   (integer)
nicklist_count   (integer)
nicklist_visible_count   (integer)
nicklist_groups_count   (integer)
nicklist_groups_visible_count   (integer)
nicklist_nicks_count   (integer)
nicklist_nicks_visible_count   (integer)
nickcmp_callback   (pointer)
nickcmp_callback_pointer   (pointer)
nickcmp_callback_data   (pointer)
input   (integer)
input_callback   (pointer)
input_callback_pointer   (pointer)
input_callback_data   (pointer)
input_get_unknown_commands   (integer)
input_get_empty   (integer)
input_multiline   (integer)
input_buffer   (string)
input_buffer_alloc   (integer)
input_buffer_size   (integer)
input_buffer_length   (integer)
input_buffer_pos   (integer)
input_buffer_1st_display   (integer)
input_undo_snap   (pointer, hdata: "input_undo")
input_undo   (pointer, hdata: "input_undo")
last_input_undo   (pointer, hdata: "input_undo")
ptr_input_undo   (pointer, hdata: "input_undo")
input_undo_count   (integer)
completion   (pointer, hdata: "completion")
history   (pointer, hdata: "history")
last_history   (pointer, hdata: "history")
ptr_history   (pointer, hdata: "history")
num_history   (integer)
text_search   (integer)
text_search_direction   (integer)
text_search_exact   (integer)
text_search_regex   (integer)
text_search_regex_compiled   (pointer)
text_search_where   (integer)
text_search_history   (integer)
text_search_found   (integer)
text_search_ptr_history   (pointer, hdata: "history")
text_search_input   (string)
highlight_words   (string)
highlight_regex   (string)
highlight_regex_compiled   (pointer)
highlight_disable_regex   (string)
highlight_disable_regex_compiled   (pointer)
highlight_tags_restrict   (string)
highlight_tags_restrict_count   (integer)
highlight_tags_restrict_array   (pointer, array_size: "highlight_tags_restrict_count")
highlight_tags   (string)
highlight_tags_count   (integer)
highlight_tags_array   (pointer, array_size: "highlight_tags_count")
hotlist   (pointer, hdata: "hotlist")
hotlist_max_level_nicks   (hashtable)
keys   (pointer, hdata: "key")
last_key   (pointer, hdata: "key")
keys_count   (integer)
local_variables   (hashtable)
prev_buffer   (pointer, hdata: "buffer")
next_buffer   (pointer, hdata: "buffer")

weechat

buffer_visited

visited buffer

gui_buffers_visited
last_gui_buffer_visited

buffer   (pointer, hdata: "buffer")
prev_buffer   (pointer, hdata: "buffer_visited")
next_buffer   (pointer, hdata: "buffer_visited")

weechat

completion

struttura con completamento

weechat_completions
last_weechat_completion

plugin   (pointer, hdata: "plugin")
buffer   (pointer, hdata: "buffer")
context   (integer)
base_command   (string)
base_command_arg_index   (integer)
base_word   (string)
base_word_pos   (integer)
position   (integer)
args   (string)
direction   (integer)
add_space   (integer)
force_partial_completion   (integer)
reverse_partial_completion   (integer)
list   (pointer)
word_found   (string)
word_found_is_nick   (integer)
position_replace   (integer)
diff_size   (integer)
diff_length   (integer)
partial_list   (pointer)
prev_completion   (pointer, hdata: "completion")
next_completion   (pointer, hdata: "completion")

weechat

completion_word

structure with word found for a completion

-

word   (string)
nick_completion   (char)
count   (integer)

weechat

config_file

file di configurazione

config_files
last_config_file

plugin   (pointer, hdata: "plugin")
priority   (integer)
name   (string)
filename   (string)
file   (pointer)
version   (integer)
callback_reload   (pointer)
callback_reload_pointer   (pointer)
callback_reload_data   (pointer)
sections   (pointer, hdata: "config_section")
last_section   (pointer, hdata: "config_section")
prev_config   (pointer, hdata: "config_file")
next_config   (pointer, hdata: "config_file")

weechat

config_option

opzione di configurazione

-

config_file   (pointer, hdata: "config_file")
section   (pointer, hdata: "config_section")
name   (string)
parent_name   (string)
type   (integer)
description   (string)
string_values   (string, array_size: "*")
min   (integer)
max   (integer)
default_value   (pointer)
value   (pointer)
null_value_allowed   (integer)
callback_check_value   (pointer)
callback_check_value_pointer   (pointer)
callback_check_value_data   (pointer)
callback_change   (pointer)
callback_change_pointer   (pointer)
callback_change_data   (pointer)
callback_delete   (pointer)
callback_delete_pointer   (pointer)
callback_delete_data   (pointer)
loaded   (integer)
prev_option   (pointer, hdata: "config_option")
next_option   (pointer, hdata: "config_option")

weechat

config_section

sezione di configurazione

-

config_file   (pointer, hdata: "config_file")
name   (string)
user_can_add_options   (integer)
user_can_delete_options   (integer)
callback_read   (pointer)
callback_read_pointer   (pointer)
callback_read_data   (pointer)
callback_write   (pointer)
callback_write_pointer   (pointer)
callback_write_data   (pointer)
callback_write_default   (pointer)
callback_write_default_pointer   (pointer)
callback_write_default_data   (pointer)
callback_create_option   (pointer)
callback_create_option_pointer   (pointer)
callback_create_option_data   (pointer)
callback_delete_option   (pointer)
callback_delete_option_pointer   (pointer)
callback_delete_option_data   (pointer)
options   (pointer, hdata: "config_option")
last_option   (pointer, hdata: "config_option")
prev_section   (pointer, hdata: "config_section")
next_section   (pointer, hdata: "config_section")

weechat

filter

filtro

gui_filters
last_gui_filter

enabled   (integer)
name   (string)
buffer_name   (string)
num_buffers   (integer)
buffers   (pointer)
tags   (string)
tags_count   (integer)
tags_array   (pointer, array_size: "tags_count")
regex   (string)
regex_prefix   (pointer)
regex_message   (pointer)
prev_filter   (pointer, hdata: "filter")
next_filter   (pointer, hdata: "filter")

weechat

history

cronologia dei comandi nel buffer

gui_history
last_gui_history

text   (string)
next_history   (pointer, hdata: "history")
prev_history   (pointer, hdata: "history")

Update allowed:
    __create
    __delete

weechat

hotlist

hotlist

gui_hotlist
last_gui_hotlist

priority   (integer)
creation_time.tv_sec   (time)
creation_time.tv_usec   (long)
buffer   (pointer)
count   (integer, array_size: "4")
prev_hotlist   (pointer, hdata: "hotlist")
next_hotlist   (pointer, hdata: "hotlist")

weechat

input_undo

struttura con "undo"per la riga di input

-

data   (string)
pos   (integer)
prev_undo   (pointer, hdata: "input_undo")
next_undo   (pointer, hdata: "input_undo")

weechat

key

un tasto (scorciatoia da tastiera)

gui_default_keys
gui_default_keys_cursor
gui_default_keys_histsearch
gui_default_keys_mouse
gui_default_keys_search
gui_keys
gui_keys_cursor
gui_keys_histsearch
gui_keys_mouse
gui_keys_search
last_gui_default_key
last_gui_default_key_cursor
last_gui_default_key_histsearch
last_gui_default_key_mouse
last_gui_default_key_search
last_gui_key
last_gui_key_cursor
last_gui_key_histsearch
last_gui_key_mouse
last_gui_key_search

key   (string)
area_type   (pointer)
area_name   (pointer)
area_key   (string)
command   (string)
score   (integer)
prev_key   (pointer, hdata: "key")
next_key   (pointer, hdata: "key")

weechat

layout

layout

gui_layout_current
gui_layouts
last_gui_layout

name   (string)
layout_buffers   (pointer, hdata: "layout_buffer")
last_layout_buffer   (pointer, hdata: "layout_buffer")
layout_windows   (pointer, hdata: "layout_window")
internal_id   (integer)
internal_id_current_window   (integer)
prev_layout   (pointer, hdata: "layout")
next_layout   (pointer, hdata: "layout")

weechat

layout_buffer

layout del buffer

-

plugin_name   (string)
buffer_name   (string)
number   (integer)
prev_layout   (pointer, hdata: "layout_buffer")
next_layout   (pointer, hdata: "layout_buffer")

weechat

layout_window

layout della finestra

-

internal_id   (integer)
parent_node   (pointer, hdata: "layout_window")
split_pct   (integer)
split_horiz   (integer)
child1   (pointer, hdata: "layout_window")
child2   (pointer, hdata: "layout_window")
plugin_name   (string)
buffer_name   (string)

weechat

line

struttura con una sola riga

-

data   (pointer, hdata: "line_data")
prev_line   (pointer, hdata: "line")
next_line   (pointer, hdata: "line")

weechat

line_data

struttura con una riga di dati

-

buffer   (pointer, hdata: "buffer")
id   (integer)
y   (integer)
date   (time)
date_usec   (integer)
date_printed   (time)
date_usec_printed   (integer)
str_time   (string)
tags_count   (integer)
tags_array   (shared_string, array_size: "tags_count")
displayed   (char)
notify_level   (char)
highlight   (char)
refresh_needed   (char)
prefix   (shared_string)
prefix_length   (integer)
message   (string)

Update allowed:
    date (time)
    date_usec (integer)
    date_printed (time)
    date_usec_printed (integer)
    tags_array (shared_string)
    prefix (shared_string)
    message (string)

weechat

lines

struttura con più righe

-

first_line   (pointer, hdata: "line")
last_line   (pointer, hdata: "line")
last_read_line   (pointer, hdata: "line")
lines_count   (integer)
first_line_not_read   (integer)
lines_hidden   (integer)
buffer_max_length   (integer)
buffer_max_length_refresh   (integer)
prefix_max_length   (integer)
prefix_max_length_refresh   (integer)

weechat

nick

nick nella lista nick

-

group   (pointer, hdata: "nick_group")
name   (shared_string)
color   (shared_string)
prefix   (shared_string)
prefix_color   (shared_string)
visible   (integer)
prev_nick   (pointer, hdata: "nick")
next_nick   (pointer, hdata: "nick")

weechat

nick_group

gruppo nella lista nick

-

name   (shared_string)
color   (shared_string)
visible   (integer)
level   (integer)
parent   (pointer, hdata: "nick_group")
children   (pointer, hdata: "nick_group")
last_child   (pointer, hdata: "nick_group")
nicks   (pointer, hdata: "nick")
last_nick   (pointer, hdata: "nick")
prev_group   (pointer, hdata: "nick_group")
next_group   (pointer, hdata: "nick_group")

weechat

plugin

plugin

weechat_plugins
last_weechat_plugin

filename   (string)
handle   (pointer)
name   (string)
description   (string)
author   (string)
version   (string)
license   (string)
charset   (string)
priority   (integer)
initialized   (integer)
debug   (integer)
upgrading   (integer)
variables   (hashtable)
prev_plugin   (pointer, hdata: "plugin")
next_plugin   (pointer, hdata: "plugin")

weechat

proxy

proxy

weechat_proxies
last_weechat_proxy

name   (string)
options   (pointer)
prev_proxy   (pointer, hdata: "proxy")
next_proxy   (pointer, hdata: "proxy")

weechat

window

finestra

gui_current_window
gui_windows
last_gui_window

number   (integer)
win_x   (integer)
win_y   (integer)
win_width   (integer)
win_height   (integer)
win_width_pct   (integer)
win_height_pct   (integer)
win_chat_x   (integer)
win_chat_y   (integer)
win_chat_width   (integer)
win_chat_height   (integer)
win_chat_cursor_x   (integer)
win_chat_cursor_y   (integer)
bar_windows   (pointer, hdata: "bar_window")
last_bar_window   (pointer, hdata: "bar_window")
refresh_needed   (integer)
gui_objects   (pointer)
buffer   (pointer, hdata: "buffer")
layout_plugin_name   (string)
layout_buffer_name   (string)
scroll   (pointer, hdata: "window_scroll")
ptr_tree   (pointer, hdata: "window_tree")
prev_window   (pointer, hdata: "window")
next_window   (pointer, hdata: "window")

weechat

window_scroll

scorrimento delle info nella finestra

-

buffer   (pointer, hdata: "buffer")
first_line_displayed   (integer)
start_line   (pointer, hdata: "line")
start_line_pos   (integer)
scrolling   (integer)
start_col   (integer)
lines_after   (integer)
text_search_start_line   (pointer, hdata: "line")
prev_scroll   (pointer, hdata: "window_scroll")
next_scroll   (pointer, hdata: "window_scroll")

weechat

window_tree

albero delle finestre

gui_windows_tree

parent_node   (pointer, hdata: "window_tree")
split_pct   (integer)
split_horizontal   (integer)
child1   (pointer, hdata: "window_tree")
child2   (pointer, hdata: "window_tree")
window   (pointer, hdata: "window")

Esempio in C:

struct t_hdata *hdata = weechat_hdata_get ("irc_server");

Script (Python):

# prototipo
def hdata_get(hdata_name: str) -> str: ...

# esempio
hdata = weechat.hdata_get("irc_server")

hdata_get_var_offset

WeeChat ≥ 0.3.6.

Restituisce l’offset della variabile in hdata.

Prototipo:

int weechat_hdata_get_var_offset (struct t_hdata *hdata, const char *name);

Argomenti:

  • hdata: puntatore hdata

  • name: nome della variabile

Valore restituito:

  • offset della variabile, -1 in caso di errore

Esempio in C:

int offset = weechat_hdata_get_var_offset (hdata, "name");

Script (Python):

# prototipo
def hdata_get_var_offset(hdata: str, name: str) -> int: ...

# esempio
offset = weechat.hdata_get_var_offset(hdata, "name")

hdata_get_var_type

WeeChat ≥ 0.3.6.

Restituisce il tipo di variabile in hdata (come intero).

Prototipo:

int weechat_hdata_get_var_type (struct t_hdata *hdata, const char *name);

Argomenti:

  • hdata: puntatore hdata

  • name: nome della variabile

Valore restituito:

  • tipo della variabile, -1 in caso di errore

Esempio in C:

int type = weechat_hdata_get_var_type (hdata, "name");
switch (type)
{
    case WEECHAT_HDATA_CHAR:
        /* ... */
        break;
    case WEECHAT_HDATA_INTEGER:
        /* ... */
        break;
    case WEECHAT_HDATA_LONG:
        /* ... */
        break;
    case WEECHAT_HDATA_STRING:
        /* ... */
        break;
    case WEECHAT_HDATA_SHARED_STRING:
        /* ... */
        break;
    case WEECHAT_HDATA_POINTER:
        /* ... */
        break;
    case WEECHAT_HDATA_TIME:
        /* ... */
        break;
    case WEECHAT_HDATA_HASHTABLE:
        /* ... */
        break;
    case WEECHAT_HDATA_OTHER:
        /* ... */
        break;
    default:
        /* variable not found */
        break;
}
Questa funzione non è disponibile nelle API per lo scripting.

hdata_get_var_type_string

WeeChat ≥ 0.3.6.

Restituisce il tipo di variabile in hdata (come stringa).

Prototipo:

const char *weechat_hdata_get_var_type_string (struct t_hdata *hdata, const char *name);

Argomenti:

  • hdata: puntatore hdata

  • name: nome della variabile

Valore restituito:

  • tipo della variabile, NULL in caso di errore

Esempio in C:

weechat_printf (NULL, "type = %s",
                weechat_hdata_get_var_type_string (hdata, "name"));

Script (Python):

# prototipo
def hdata_get_var_type_string(hdata: str, name: str) -> str: ...

# esempio
weechat.prnt("", "type = %s" % weechat.hdata_get_var_type_string(hdata, "name"))

hdata_get_var_array_size

WeeChat ≥ 0.3.9.

Return array size for variable in hdata.

Prototipo:

int weechat_hdata_get_var_array_size (struct t_hdata *hdata, void *pointer, const char *name);

Argomenti:

  • hdata: puntatore hdata

  • pointer: puntarore all’oggetto di WeeChat/plugin

  • name: nome della variabile

Valore restituito:

  • array size for variable, -1 if variable is not an array or if an error occurred

Esempio in C:

int array_size = weechat_hdata_get_var_array_size (hdata, pointer, "name");

Script (Python):

# prototipo
def hdata_get_var_array_size(hdata: str, pointer: str, name: str) -> int: ...

# esempio
array_size = weechat.hdata_get_var_array_size(hdata, pointer, "name")

hdata_get_var_array_size_string

WeeChat ≥ 0.3.9.

Return array size for variable in hdata (as string).

Prototipo:

const char *weechat_hdata_get_var_array_size_string (struct t_hdata *hdata, void *pointer,
                                                     const char *name);

Argomenti:

  • hdata: puntatore hdata

  • pointer: puntarore all’oggetto di WeeChat/plugin

  • name: nome della variabile

Valore restituito:

  • array size for variable as string, NULL if variable is not an array or if an error occurred

Esempio in C:

const char *array_size = weechat_hdata_get_var_array_size_string (hdata, pointer, "name");

Script (Python):

# prototipo
def hdata_get_var_array_size_string(hdata: str, pointer: str, name: str) -> str: ...

# esempio
array_size = weechat.hdata_get_var_array_size_string(hdata, pointer, "name")

hdata_get_var_hdata

WeeChat ≥ 0.3.6.

Restituisce hdata per la variabile in hdata.

Prototipo:

const char *weechat_hdata_get_var_hdata (struct t_hdata *hdata, const char *name);

Argomenti:

  • hdata: puntatore hdata

  • name: nome della variabile

Valore restituito:

  • hdata per la variabile, NULL in caso di nessun hdata presente o di errore

Esempio in C:

weechat_printf (NULL, "hdata = %s", weechat_hdata_get_var_hdata (hdata, "name"));

Script (Python):

# prototipo
def hdata_get_var_hdata(hdata: str, name: str) -> str: ...

# esempio
weechat.prnt("", "hdata = %s" % weechat.hdata_get_var_hdata(hdata, "name"))

hdata_get_var

WeeChat ≥ 0.3.6.

Restituisce il puntatore al contenuto della variabile in hdata.

Prototipo:

void *weechat_hdata_get_var (struct t_hdata *hdata, void *pointer, const char *name);

Argomenti:

  • hdata: puntatore hdata

  • pointer: puntarore all’oggetto di WeeChat/plugin

  • name: nome della variabile

Valore restituito:

  • puntatore al contenuto della variabile, NULL in caso di errore

Esempio in C:

struct t_hdata *hdata = weechat_hdata_get ("buffer");
struct t_gui_buffer *buffer = weechat_buffer_search_main ();
void *pointer = weechat_hdata_get_var (hdata, buffer, "name");
Questa funzione non è disponibile nelle API per lo scripting.

hdata_get_var_at_offset

WeeChat ≥ 0.3.6.

Restituisce il puntatore al contenuto della variabile in hdata, usando un offset.

Prototipo:

void *weechat_hdata_get_var_at_offset (struct t_hdata *hdata, void *pointer, int offset);

Argomenti:

  • hdata: puntatore hdata

  • pointer: puntatore ad un oggetto di WeeChat/plugin

  • offset: offset della variabile

Valore restituito:

  • puntatore al contenuto della variabile, NULL in caso di errore

Esempio in C:

struct t_hdata *hdata = weechat_hdata_get ("buffer");
struct t_gui_buffer *buffer = weechat_buffer_search_main ();
int offset = weechat_hdata_get_var_offset (hdata, "name");
void *pointer = weechat_hdata_get_var_at_offset (hdata, buffer, offset);
Questa funzione non è disponibile nelle API per lo scripting.

hdata_get_list

WeeChat ≥ 0.3.6.

Restituisce il puntatore alla lista da hdata.

Prototipo:

void *weechat_hdata_get_list (struct t_hdata *hdata, const char *name);

Argomenti:

  • hdata: puntatore hdata

  • name: nome della lista

Valore restituito:

  • puntatore alla lista, NULL in caso di errore

Esempio in C:

struct t_hdata *hdata = weechat_hdata_get ("buffer");
struct t_gui_buffer *buffers = weechat_hdata_get_list (hdata, "gui_buffers");

Script (Python):

# prototipo
def hdata_get_list(hdata: str, name: str) -> str: ...

# esempio
hdata = weechat.hdata_get("buffer")
buffers = weechat.hdata_get_list(hdata, "gui_buffers")

hdata_check_pointer

WeeChat ≥ 0.3.7, updated in 1.0.

Verifica se un puntatore è valido per un hdata e un puntatore della lista.

Prototipo:

int weechat_hdata_check_pointer (struct t_hdata *hdata, void *list, void *pointer);

Argomenti:

  • hdata: puntatore hdata

  • list: puntatore alla lista; if NULL (WeeChat ≥ 1.0), the pointer is checked with the lists in hdata that have flag "check pointers" (see hdata_new_list), and if no such list exists, the pointer is considered as valid

  • pointer: puntatore da verificare

Valore restituito:

  • 1 se il puntatore è in lista, 0 in caso contrario

Esempio in C:

/* check if a buffer pointer is valid */
struct t_hdata *hdata = weechat_hdata_get ("buffer");
if (weechat_hdata_check_pointer (hdata,
                                 weechat_hdata_get_list (hdata, "gui_buffers"),
                                 ptr_buffer))
{
    /* valid pointer */
}
else
{
    /* invalid pointer */
}

Script (Python):

# prototipo
def hdata_check_pointer(hdata: str, list: str, pointer: str) -> int: ...

# esempio
hdata = weechat.hdata_get("buffer")
if weechat.hdata_check_pointer(hdata, weechat.hdata_get_list(hdata, "gui_buffers"), ptr_buffer):
    # valid pointer
    # ...
else:
    # invalid pointer
    # ...

hdata_move

WeeChat ≥ 0.3.6.

Sposta il puntatore ad un altro elemento nella lista.

Prototipo:

void *weechat_hdata_move (struct t_hdata *hdata, void *pointer, int count);

Argomenti:

  • hdata: puntatore hdata

  • pointer: puntatore ad un oggetto di WeeChat/plugin

  • count: numero di salto(i) da eseguire (intero positivo o negativo, diverso da 0)

Valore restituito:

  • pointer to element reached, NULL if element is not found (for example end of list), or if an error occurred

Esempio in C:

struct t_hdata *hdata = weechat_hdata_get ("buffer");
struct t_gui_buffer *buffer = weechat_buffer_search_main ();

/* passa al buffer successivo, 2 volte */
buffer = weechat_hdata_move (hdata, buffer, 2);

/* passa al buffer precedente */
if (buffer)
    buffer = weechat_hdata_move (hdata, buffer, -1);

Script (Python):

# prototipo
def hdata_move(hdata: str, pointer: str, count: int) -> str: ...

# esempio
hdata = weechat.hdata_get("buffer")
buffer = weechat.buffer_search_main()

# passa al buffer successivo, 2 volte
buffer = weechat.hdata_move(hdata, buffer, 2)

# passa al buffer precedente
if buffer:
    buffer = weechat.hdata_move(hdata, buffer, -1)

WeeChat ≥ 0.4.1, updated in 3.4.

Search element in a list: the expression search is evaluated for each element in list, until element is found (or end of list).

Prototipo:

void *weechat_hdata_search (struct t_hdata *hdata, void *pointer, const char *search,
                            struct t_hashtable *pointers, struct t_hashtable *extra_vars,
                            struct t_hashtable *options, int move);

Argomenti:

  • hdata: puntatore hdata

  • pointer: puntatore ad un oggetto di WeeChat/plugin

  • search: expression to evaluate, default pointer in expression is the name of hdata (and this pointer changes for each element in list); for help on expression, see the WeeChat user’s guide / Command /eval 

  • pointers: hashtable for call to function string_eval_expression

  • extra_vars: hashtable for call to function string_eval_expression

  • options: hashtable for call to function string_eval_expression

  • move: number of jump(s) to execute after unsuccessful search (negative or positive integer, different from 0)

You must ensure the search expression is safe and does not include any user data. Such unsafe data must be given in the hashtable extra_vars and referenced by ${xxx} in the search expression (see the example below).

Valore restituito:

  • pointer to element found, NULL if not found

Esempio in C:

struct t_hdata *hdata = weechat_hdata_get ("irc_server");
void *servers = weechat_hdata_get_list (hdata, "irc_servers");
struct t_hashtable *extra_vars = weechat_hashtable_new (8,
                                                        WEECHAT_HASHTABLE_STRING,
                                                        WEECHAT_HASHTABLE_STRING,
                                                        NULL,
                                                        NULL);

/* search irc server with name "libera" */
weechat_hashtable_set (extra_vars, "server_name", "libera");
void *server = weechat_hdata_search (hdata, servers, "${irc_server.name} == ${server_name}",
                                     NULL, extra_vars, NULL, 1);
if (server)
{
    /* ... */
}
weechat_hashtable_free (extra_vars);

Script (Python):

# prototipo
def hdata_search(hdata: str, pointer: str, search: str,
                 pointers: Dict[str, str], extra_vars: Dict[str, str], options: Dict[str, str],
                 count: int) -> str: ...

# esempio
hdata = weechat.hdata_get("irc_server")
servers = weechat.hdata_get_list(hdata, "irc_servers")

# search irc server with name "libera"
server = weechat.hdata_search(hdata, servers, "${irc_server.name} == ${server_name}",
                              {}, {"server_name": "libera"}, {}, 1)
if server:
    # ...

hdata_char

WeeChat ≥ 0.3.7.

Restituisce il valore di una variabile char in una struttura dati usando hdata.

Prototipo:

char weechat_hdata_char (struct t_hdata *hdata, void *pointer, const char *name);

Argomenti:

  • hdata: puntatore hdata

  • pointer: puntatore all’oggetto di WeeChat/plugin

  • name: nome della variabile (deve essere di tipo "char"); for arrays, the name can be "N|name" where N is the index in array (starting at 0), for example: "2|name"

Valore restituito:

  • valore char della variabile

Esempio in C:

weechat_printf (NULL, "letter = %c", weechat_hdata_char (hdata, pointer, "letter"));

Script (Python):

# prototipo
def hdata_char(hdata: str, pointer: str, name: str) -> int: ...

# esempio
weechat.prnt("", "letter = %c" % weechat.hdata_char(hdata, pointer, "letter"))

hdata_integer

WeeChat ≥ 0.3.6.

Restituisce il valore di una variabile integer in una struttura dati usando hdata.

Prototipo:

int weechat_hdata_integer (struct t_hdata *hdata, void *pointer, const char *name);

Argomenti:

  • hdata: puntatore hdata

  • pointer: puntatore all’oggetto di WeeChat/plugin

  • name: nome della variabile (deve essere di tipo "integer"); for arrays, the name can be "N|name" where N is the index in array (starting at 0), for example: "2|name"

Valore restituito:

  • valore intero della variabile

Esempio in C:

struct t_hdata *hdata = weechat_hdata_get ("buffer");
struct t_gui_buffer *buffer = weechat_buffer_search_main ();
weechat_printf (NULL, "number = %d", weechat_hdata_integer (hdata, buffer, "number"));

Script (Python):

# prototipo
def hdata_integer(hdata: str, pointer: str, name: str) -> int: ...

# esempio
hdata = weechat.hdata_get("buffer")
buffer = weechat.buffer_search_main()
weechat.prnt("", "number = %d" % weechat.hdata_integer(hdata, buffer, "number"))

hdata_long

WeeChat ≥ 0.3.6.

Restituisce il valore della variabile long della struttura usando hdata.

Prototipo:

long weechat_hdata_long (struct t_hdata *hdata, void *pointer, const char *name);

Argomenti:

  • hdata: puntatore hdata

  • pointer: puntatore all’oggetto di WeeChat/plugin

  • name: nome della variabile (deve essere di tipo "long"); for arrays, the name can be "N|name" where N is the index in array (starting at 0), for example: "2|name"

Valore restituito:

  • valore long della variabile

Esempio in C:

weechat_printf (NULL, "longvar = %ld", weechat_hdata_long (hdata, pointer, "longvar"));

Script (Python):

# prototipo
def hdata_long(hdata: str, pointer: str, name: str) -> int: ...

# esempio
weechat.prnt("", "longvar = %ld" % weechat.hdata_long(hdata, pointer, "longvar"))

hdata_string

WeeChat ≥ 0.3.6.

Restituisce il valore della variabile string nella struttura usando hdata.

Prototipo:

const char *weechat_hdata_string (struct t_hdata *hdata, void *pointer, const char *name);

Argomenti:

  • hdata: puntatore hdata

  • pointer: puntatore all’oggetto di WeeChat/plugin

  • name: nome della variabile (deve essere di tipo "string"); for arrays, the name can be "N|name" where N is the index in array (starting at 0), for example: "2|name"

Valore restituito:

  • valore stringa della variabile

Esempio in C:

struct t_hdata *hdata = weechat_hdata_get ("buffer");
struct t_gui_buffer *buffer = weechat_buffer_search_main ();
weechat_printf (NULL, "name = %s", weechat_hdata_string (hdata, buffer, "name"));

Script (Python):

# prototipo
def hdata_string(hdata: str, pointer: str, name: str) -> str: ...

# esempio
hdata = weechat.hdata_get("buffer")
buffer = weechat.buffer_search_main()
weechat.prnt("", "name = %s" % weechat.hdata_string(hdata, buffer, "name"))

hdata_pointer

WeeChat ≥ 0.3.6.

Restituisce il valore della variabile puntatore nella struttura usando hdata.

Prototipo:

void *weechat_hdata_pointer (struct t_hdata *hdata, void *pointer, const char *name);

Argomenti:

  • hdata: hdata hdata

  • pointer: pointer all’oggetto di WeeChat/plugin

  • name: nome della variabile (deve essere di tipo "pointer"); for arrays, the name can be "N|name" where N is the index in array (starting at 0), for example: "2|name"

Valore restituito:

  • valore puntatore della variabile

Esempio in C:

struct t_hdata *hdata = weechat_hdata_get ("buffer");
struct t_gui_buffer *buffer = weechat_buffer_search_main ();
weechat_printf (NULL, "lines = %lx", weechat_hdata_pointer (hdata, buffer, "lines"));

Script (Python):

# prototipo
def hdata_pointer(hdata: str, pointer: str, name: str) -> str: ...

# esempio
hdata = weechat.hdata_get("buffer")
buffer = weechat.buffer_search_main()
weechat.prnt("", "lines = %lx" % weechat.hdata_pointer(hdata, buffer, "lines"))

hdata_time

WeeChat ≥ 0.3.6.

Restituisce il valore della variabile time nella struttura usando hdata.

Prototipo:

time_t weechat_hdata_time (struct t_hdata *hdata, void *pointer, const char *name);

Argomenti:

  • hdata: puntatore hdata

  • pointer: puntatore all’oggetto di WeeChat/plugin

  • name: nome della variabile (deve essere di tipo "time"); for arrays, the name can be "N|name" where N is the index in array (starting at 0), for example: "2|name"

Valore restituito:

  • valore time della variabile

Esempio in C:

struct t_hdata *hdata = weechat_hdata_get ("buffer");
struct t_gui_buffer *ptr = weechat_buffer_search_main ();
ptr = weechat_hdata_pointer (hdata, ptr, "lines");
if (ptr)
{
    hdata = weechat_hdata_get ("lines");
    ptr = weechat_hdata_pointer (hdata, ptr, "first_line");
    if (ptr)
    {
        hdata = weechat_hdata_get ("line");
        ptr = weechat_hdata_pointer (hdata, ptr, "data");
        if (ptr)
        {
            hdata = weechat_hdata_get ("line_data");
            time_t date = weechat_hdata_time (hdata, hdata, "date");
            weechat_printf (NULL, "time of last line displayed = %s", ctime (&date));
        }
    }
}

Script (Python):

# prototipo
def hdata_time(hdata: str, pointer: str, name: str) -> int: ...

# esempio
buf = weechat.buffer_search_main()
ptr = weechat.hdata_pointer(weechat.hdata_get("buffer"), buf, "lines")
if ptr:
    ptr = weechat.hdata_pointer(weechat.hdata_get("lines"), ptr, "first_line")
    if ptr:
        ptr = weechat.hdata_pointer(weechat.hdata_get("line"), ptr, "data")
        if ptr:
            date = weechat.hdata_time(weechat.hdata_get("line_data"), ptr, "date")
            weechat.prnt("", "time of first line displayed = %s" % time.strftime("%F %T", time.localtime(int(date))))

hdata_hashtable

WeeChat ≥ 0.3.7.

Restituisce il valore di una variabile nella tabella hash nella struttura usando hdata.

Prototipo:

struct t_hashtable *weechat_hdata_hashtable (struct t_hdata *hdata, void *pointer, const char *name);

Argomenti:

  • hdata: puntatore hdata

  • pointer: puntatore all’oggetto di WeeChat/plugin

  • name: nome della variabile (deve essere di tipo "hashtable"); for arrays, the name can be "N|name" where N is the index in array (starting at 0), for example: "2|name"

Valore restituito:

  • valore della tabella hash della variabile (puntatore alla tabella hash)

Esempio in C:

struct t_hdata *hdata = weechat_hdata_get ("buffer");
struct t_gui_buffer *buffer = weechat_buffer_search_main ();
struct t_hashtable *hashtable = weechat_hdata_hashtable (hdata, buffer, "local_variables");
weechat_printf (NULL, "%d local variables in core buffer",
                weechat_hashtable_get_integer (hashtable, "items_count"));

Script (Python):

# prototipo
def hdata_hashtable(hdata: str, pointer: str, name: str) -> Dict[str, str]: ...

# esempio
hdata = weechat.hdata_get("buffer")
buffer = weechat.buffer_search_main()
hash = weechat.hdata_hashtable(hdata, buffer, "local_variables")
weechat.prnt("", "local variables in core buffer:")
for key in hash:
    weechat.prnt("", "  %s == %s" % (key, hash[key]))

hdata_compare

WeeChat ≥ 1.9, updated in 4.1.0.

Compare a hdata variable of two objects.

Prototipo:

int weechat_hdata_compare (struct t_hdata *hdata, void *pointer1, void *pointer2, const char *name, int case_sensitive);

Argomenti:

  • hdata: hdata pointer

  • pointer1: pointer to first WeeChat/plugin object

  • pointer2: pointer to second WeeChat/plugin object

  • name: variable name or path to a variable name; for arrays, the name can be "N|name" where N is the index in array (starting at 0), for example: "2|name"

  • case_sensitive: 1 for case sensitive comparison of strings, otherwise 0

Valore restituito:

  • -1 if variable1 < variable2

  • 0 if variable1 == variable2

  • 1 if variable1 > variable2

Esempio in C:

struct t_hdata *hdata = weechat_hdata_get ("buffer");
struct t_gui_buffer *buffer1 = weechat_buffer_search ("irc", "libera.#weechat");
struct t_gui_buffer *buffer2 = weechat_buffer_search ("irc", "libera.#weechat-fr");
weechat_printf (NULL, "comparison of buffer number = %d",
                weechat_hdata_compare (hdata, buffer1, buffer2, "number", 0));
weechat_printf (NULL, "comparison of number of lines = %d",
                weechat_hdata_compare (hdata, buffer1, buffer2, "own_lines.lines_count", 0));
weechat_printf (NULL, "comparison of local variable = %d",
                weechat_hdata_compare (hdata, buffer1, buffer2, "local_variables.myvar", 0));

Script (Python):

# prototipo
def hdata_compare(hdata: str, pointer1: str, pointer2: str, name: str, case_sensitive: int) -> int: ...

# esempio
hdata = weechat.hdata_get("buffer")
buffer1 = weechat.buffer_search("irc", "libera.#weechat")
buffer2 = weechat.buffer_search("irc", "libera.#weechat-fr")
weechat.prnt("", "comparison of buffer number = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "number", 0))
weechat.prnt("", "comparison of number of lines = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "own_lines.lines_count", 0))
weechat.prnt("", "comparison of local variable = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "local_variables.myvar", 0))

hdata_set

WeeChat ≥ 0.3.9.

Set new value for variable in a hdata.

This function can be called only in an update callback (see hdata_new and hdata_update), if the variable can be updated.

Prototipo:

int weechat_hdata_set (struct t_hdata *hdata, void *pointer, const char *name, const char *value);

Argomenti:

  • hdata: hdata pointer

  • pointer: pointer to WeeChat/plugin object

  • name: variable name (types allowed: char, integer, long, string, pointer, time)

  • value: new value for variable

Valore restituito:

  • 1 if ok, 0 if error

Esempio in C:

weechat_hdata_set (hdata, pointer, "message", "test");
Questa funzione non è disponibile nelle API per lo scripting.

hdata_update

WeeChat ≥ 0.3.9.

Update data in a hdata.

Prototipo:

int weechat_hdata_update (struct t_hdata *hdata, void *pointer, struct t_hashtable *hashtable);

Argomenti:

  • hdata: hdata pointer

  • pointer: pointer to WeeChat/plugin object

  • hashtable: variables to update: keys are name of variables, values are new values for variables (keys and values are string), some special keys are allowed:

    • key __create_allowed (with any value): return 1 if create is allowed for structure, otherwise 0 (WeeChat ≥ 0.4.0)

    • key __delete_allowed (with any value): return 1 if delete is allowed for structure, otherwise 0

    • key __update_allowed, value is name of a variable: return 1 if update is allowed for this variable, otherwise 0

    • key __delete (with any value): delete structure (if allowed)

Valore restituito:

  • number of variables updated

Esempio in C:

/* subtract one hour on last message displayed in current buffer */

struct t_gui_lines *own_lines;
struct t_gui_line *line;
struct t_gui_line_data *line_data;
struct t_hdata *hdata;
struct t_hashtable *hashtable;
char str_date[64];

own_lines = weechat_hdata_pointer (weechat_hdata_get ("buffer"), weechat_current_buffer (), "own_lines");
if (own_lines)
{
    line = weechat_hdata_pointer (weechat_hdata_get ("lines"), own_lines, "last_line");
    if (line)
    {
        line_data = weechat_hdata_pointer (weechat_hdata_get ("line"), line, "data");
        hdata = weechat_hdata_get ("line_data");
        hashtable = weechat_hashtable_new (8,
                                           WEECHAT_HASHTABLE_STRING,
                                           WEECHAT_HASHTABLE_STRING,
                                           NULL,
                                           NULL);
        if (hashtable)
        {
            snprintf (str_date, sizeof (str_date), "%ld", ((long int)weechat_hdata_time (hdata, line_data, "date")) - 3600);
            weechat_hashtable_set (hashtable, "date", str_date);
            weechat_hdata_update (hdata, line_data, hashtable);
            weechat_hashtable_free (hashtable);
        }
    }
}

Script (Python):

# prototipo
def hdata_update(hdata: str, pointer: str, hashtable: Dict[str, str]) -> int: ...

# example: subtract one hour on last message displayed in current buffer
own_lines = weechat.hdata_pointer(weechat.hdata_get("buffer"), weechat.current_buffer(), "own_lines")
if own_lines:
    line = weechat.hdata_pointer(weechat.hdata_get("lines"), own_lines, "last_line")
    if line:
        line_data = weechat.hdata_pointer(weechat.hdata_get("line"), line, "data")
        hdata = weechat.hdata_get("line_data")
        weechat.hdata_update(hdata, line_data, {"date": str(weechat.hdata_time(hdata, line_data, "date") - 3600)})

hdata_get_string

WeeChat ≥ 0.3.6.

Restituisce il valore stringa di una proprietà di hdata.

Prototipo:

const char *weechat_hdata_get_string (struct t_hdata *hdata, const char *property);

Argomenti:

  • hdata: puntatore hdata

  • property: nome della proprietà:

    • var_keys: stringa con la lista di chiavi per le variabili in hdata (formato: "key1,key2,key3")

    • var_values: stringa con la lista di valori per le variabili in hdata (formato: "value1,value2,value3")

    • var_keys_values: stringa cona la lista di chiavi e valori per le variabili in hdata (formato: "key1:value1,key2:value2,key3:value3")

    • var_prev: nome della variabile nella struttura che fa da puntatore al precedente elemento nella lista

    • var_next: nome della variabile nella struttura che fa da puntatore al successivo elemento nella lista

    • list_keys: stringa con la lista di chiavi per le liste in hdata (formato: "key1,key2,key3")

    • list_values: stringa con la lista di valori per le liste in hdata (formato: "value1,value2,value3")

    • list_keys_values: stringa con la lista di chiavi e valori per le liste in hdata (formato: "key1:value1,key2:value2,key3:value3")

Valore restituito:

  • valore stringa della proprietà

Esempio in C:

weechat_printf (NULL, "variables in hdata: %s", weechat_hdata_get_string (hdata, "var_keys"));
weechat_printf (NULL, "lists in hdata: %s", weechat_hdata_get_string (hdata, "list_keys"));

Script (Python):

# prototipo
def hdata_get_string(hdata: str, property: str) -> str: ...

# esempio
weechat.prnt("", "variables in hdata: %s" % weechat.hdata_get_string(hdata, "var_keys"))
weechat.prnt("", "lists in hdata: %s" % weechat.hdata_get_string(hdata, "list_keys"))

3.25. Aggiornamento

Funzioni per l’aggiornamento di WeeChat (comando "/upgrade").

upgrade_new

Updated in 1.5.

Crea o legge un file per l’aggiornamento.

Prototipo:

struct t_upgrade_file *upgrade_file_new (const char *filename,
                                         int (*callback_read)(const void *pointer,
                                                              void *data,
                                                              struct t_upgrade_file *upgrade_file,
                                                              int object_id,
                                                              struct t_infolist *infolist),
                                         const void *callback_read_pointer,
                                         void *callback_read_data);

Argomenti:

  • filename: nome del file (l’estensione ".upgrade" verrà aggiunta a questo nome da WeeChat)

  • callback_read: funzione chiamata per ogni oggetto letto nel file di aggiornamento, argomenti e valore restituito:

    • const void *pointer: puntatore

    • void *data: puntatore

    • struct t_upgrade_file *upgrade_file: puntatore al file di aggiornamento

    • int object_id: id dell’oggetto

    • struct t_infolist *infolist: lista info con il contenuto dell’oggetto

    • valore restituito:

      • WEECHAT_RC_OK

      • WEECHAT_RC_ERROR

  • callback_read_pointer: puntatore fornito alla callback quando chiamata da WeeChat

  • callback_read_data: puntatore fornito dalla callback quando chiamata da WeeChat; if not NULL, it must have been allocated with malloc (or similar function) and it is automatically freed when the upgrade file is closed

Valore restituito:

  • puntatore al file di aggiornamento

Esempio in C:

struct t_upgrade_file *upgrade_file = weechat_upgrade_new ("my_file",
                                                           NULL, NULL, NULL);

Script (Python):

# prototipo
def upgrade_new(filename: str, callback_read: str, callback_read_data: str) -> str: ...

# esempio
upgrade_file = weechat.upgrade_new("my_file", "", "")

upgrade_write_object

Scrive un oggetto nel file di aggiornamento.

Prototipo:

int weechat_upgrade_write_object (struct t_upgrade_file *upgrade_file,
                                  int object_id,
                                  struct t_infolist *infolist);

Argomenti:

  • upgrade_file: puntatore al file di aggiornamento

  • object_id: id per l’oggetto

  • infolist: lista info da scrivere nel file

Valore restituito:

  • 1 se ok, 0 se errore

Esempio in C:

if (weechat_upgrade_write_object (upgrade_file, 1, &infolist))
{
    /* ok */
}
else
{
    /* errore */
}

Script (Python):

# prototipo
def upgrade_write_object(upgrade_file: str, object_id: int, infolist: str) -> int: ...

# esempio
weechat.upgrade_write_object(upgrade_file, 1, infolist)

upgrade_read

Updated in 1.5.

Legge un file di aggiornamento.

Prototipo:

int weechat_upgrade_read (struct t_upgrade_file *upgrade_file);

Argomenti:

  • upgrade_file: puntatore al file di aggiornamento

Valore restituito:

  • 1 se ok, 0 se errore

Esempio in C:

weechat_upgrade_read (upgrade_file);

Script (Python):

# prototipo
def upgrade_read(upgrade_file: str) -> int: ...

# esempio
weechat.upgrade_read(upgrade_file)

upgrade_close

Chiude un file di aggiornamento.

Prototipo:

void weechat_upgrade_close (struct t_upgrade_file *upgrade_file);

Argomenti:

  • upgrade_file: puntatore al file di aggiornamento

Esempio in C:

weechat_upgrade_close (upgrade_file);

Script (Python):

# prototipo
def upgrade_close(upgrade_file: str) -> int: ...

# esempio
weechat.upgrade_close(upgrade_file)