~ubuntu-branches/ubuntu/wily/weechat/wily

« back to all changes in this revision

Viewing changes to doc/it/weechat_scripting.it.txt

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bouthenot
  • Date: 2014-09-28 17:41:10 UTC
  • mfrom: (29.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20140928174110-bwlsn7gqmqfftnmb
Tags: 1.0.1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
= Guida allo Scripting di WeeChat
2
 
:author: Sébastien Helleu
3
 
:email: flashcode@flashtux.org
4
 
:lang: it
5
 
:toc:
6
 
:toclevels: 3
7
 
 
8
 
 
9
 
Questo manuale documenta il client di chat WeeChat, ed è parte
10
 
del programma stesso.
11
 
 
12
 
La versione più recente di questo documento si trova qui:
13
 
http://weechat.org/doc
14
 
 
15
 
 
16
 
[[introduction]]
17
 
== Introduzione
18
 
 
19
 
WeeChat (Wee Enhanced Environment for Chat) è un client di chat libero,
20
 
veloce e leggero, realizzato per molti sistemi operativi.
21
 
 
22
 
Questo manuale documenta come scrivere script per WeeChat, usando uno dei
23
 
linguaggi di scripting supportati:
24
 
 
25
 
* python
26
 
* perl
27
 
* ruby
28
 
* lua
29
 
* tcl
30
 
* guile (scheme)
31
 
 
32
 
[NOTE]
33
 
Quasi tutti gli esempi in questo manuale sono scritti in Python, ma l'API
34
 
è identica per gli altri linguaggi.
35
 
 
36
 
[[scripts_in_weechat]]
37
 
== Script in WeeChat
38
 
 
39
 
[[languages_specificities]]
40
 
=== Specifiche per i linguaggi
41
 
 
42
 
==== Python
43
 
 
44
 
* E necessario `import weechat`
45
 
* Le funzioni `print*` sono chiamate `prnt*` in python (dato che 'print'
46
 
  è una parola riservata)
47
 
* Le funzioni sono chiamate con `weechat.xxx(arg1, arg2, ...)`
48
 
 
49
 
==== Perl
50
 
 
51
 
* Le funzioni sono chiamate con `weechat::xxx(arg1, arg2, ...);`
52
 
 
53
 
==== Ruby
54
 
 
55
 
* E necessario definire 'weechat_init' e chiamare 'register' all'interno
56
 
* Le funzioni sono chiamate con `Weechat.xxx(arg1, arg2, ...)`
57
 
* A causa di una limitazione di Ruby (massimo 15 argomenti per funzione), la
58
 
  funzione `WeeChat.config_new_option` riceve le callback in un array di 6
59
 
  stringhe (3 callback + 3 stringhe di dati), così che una chiamata a questa
60
 
  funzione appare come:
61
 
 
62
 
[source,ruby]
63
 
----
64
 
Weechat.config_new_option(config, section, "name", "string", "description of option", "", 0, 0,
65
 
                          "value", "value", 0, ["check_cb", "", "change_cb", "", "delete_cb", ""])
66
 
----
67
 
 
68
 
==== Lua
69
 
 
70
 
* Le funzioni sono chiamate con `weechat.xxx(arg1, arg2, ...)`
71
 
 
72
 
==== Tcl
73
 
 
74
 
* Le funzioni sono chiamate con `weechat::xxx arg1 arg2 ...`
75
 
 
76
 
==== Guile (scheme)
77
 
 
78
 
* Le funzioni sono chiamate con `(weechat:xxx arg1 arg2 ...)`
79
 
* Le seguenti funzioni prendono un elenco di argomenti (invece di più argomenti
80
 
  come per le altre funzioni), poiché il numero di argomenti eccede il numero
81
 
  di argomenti consentiti in Guile:
82
 
** config_new_section
83
 
** config_new_option
84
 
** bar_new
85
 
 
86
 
[[register_function]]
87
 
=== Registrare una funzione
88
 
 
89
 
Tutti gli script WeeChat devono "registrare" loro stessi in WeeChat, e questo
90
 
deve essere la prima funzione chiamata nello script di WeeChat.
91
 
 
92
 
Prototipo:
93
 
 
94
 
[source,python]
95
 
----
96
 
weechat.register(name, author, version, license, description, shutdown_function, charset)
97
 
----
98
 
 
99
 
Argomenti:
100
 
 
101
 
* 'name': stringa, nome interno dello script
102
 
* 'author': stringa, nome dell'autore
103
 
* 'version': stringa, versione dello script
104
 
* 'license': stringa, licenza dello script
105
 
* 'description': stringa, breve descrizione dello script
106
 
* 'shutdown_function': stringa, nome della funzione chiamata quando lo script
107
 
  viene scaricato (può essere una stringa vuota)
108
 
* 'charset': stringa, set caratteri dello script (se il proprio script è in UTF-8,
109
 
  è possibile utilizzare un valore nullo qui, dato che UTF-8 è il set caratteri predefinito)
110
 
 
111
 
Esempio di script, per ogni linguaggio:
112
 
 
113
 
* python:
114
 
 
115
 
[source,python]
116
 
----
117
 
import weechat
118
 
 
119
 
weechat.register("test_python", "FlashCode", "1.0", "GPL3", "Test script", "", "")
120
 
weechat.prnt("", "Hello, from python script!")
121
 
----
122
 
 
123
 
* perl:
124
 
 
125
 
[source,perl]
126
 
----
127
 
weechat::register("test_perl", "FlashCode", "1.0", "GPL3", "Test script", "", "");
128
 
weechat::print("", "Hello, from perl script!");
129
 
----
130
 
 
131
 
* ruby:
132
 
 
133
 
[source,ruby]
134
 
----
135
 
def weechat_init
136
 
  Weechat.register("test_ruby", "FlashCode", "1.0", "GPL3", "Test script", "", "")
137
 
  Weechat.print("", "Hello, from ruby script!")
138
 
  return Weechat::WEECHAT_RC_OK
139
 
end
140
 
----
141
 
 
142
 
* lua:
143
 
 
144
 
[source,lua]
145
 
----
146
 
weechat.register("test_lua", "FlashCode", "1.0", "GPL3", "Test script", "", "")
147
 
weechat.print("", "Hello, from lua script!")
148
 
----
149
 
 
150
 
* tcl:
151
 
 
152
 
[source,tcl]
153
 
----
154
 
weechat::register "test_tcl" "FlashCode" "1.0" "GPL3" "Test script" "" ""
155
 
weechat::print "" "Hello, from tcl script!"
156
 
----
157
 
 
158
 
* guile (scheme):
159
 
 
160
 
[source,lisp]
161
 
----
162
 
(weechat:register "test_scheme" "FlashCode" "1.0" "GPL3" "Test script" "" "")
163
 
(weechat:print "" "Hello, from scheme script!")
164
 
----
165
 
 
166
 
[[load_script]]
167
 
=== Caricare uno script
168
 
 
169
 
Si raccomanda di usare il plugin "script" per caricare gli script, ad esempio:
170
 
 
171
 
----
172
 
/script load script.py
173
 
/script load script.pl
174
 
/script load script.rb
175
 
/script load script.lua
176
 
/script load script.tcl
177
 
/script load script.scm
178
 
----
179
 
 
180
 
Ogni linguaggio ha anche il suo comando specifico:
181
 
 
182
 
----
183
 
/python load python/script.py
184
 
/perl load perl/script.pl
185
 
/ruby load ruby/script.rb
186
 
/lua load lua/script.lua
187
 
/tcl load tcl/script.tcl
188
 
/guile load guile/script.scm
189
 
----
190
 
 
191
 
È possibile creare un link nella directory 'linguaggio/autoload' per caricare
192
 
automaticamente gli script all'avvio di WeeChat.
193
 
 
194
 
Ad esempio con Python:
195
 
 
196
 
----
197
 
$ cd ~/.weechat/python/autoload
198
 
$ ln -s ../script.py
199
 
----
200
 
 
201
 
[NOTE]
202
 
Quando viene installato un script con il comando `/script install` il link nella
203
 
directory 'autoload' viene creato automaticamente'.
204
 
 
205
 
[[differences_with_c_api]]
206
 
== Differenze con le API in C
207
 
 
208
 
Le API per gli script sono quasi identiche di quelle per i plugin C.
209
 
È possibile consultare '*' per i dettagli su ogni funzione nelle API:
210
 
prototipo, argomenti, valori restituiti, esempi.
211
 
 
212
 
È importante fare la differenza tra un 'plugin' ed uno 'script':
213
 
un plugin è un file binario compilato e caricato con il comando
214
 
`plugin`, mentre uno 'script' è un file di testo caricato tramite
215
 
un plugin come 'python' con il comando `python`.
216
 
 
217
 
Quando il proprio script 'test.py' chiama una funzione delle API di
218
 
Weechat, il path è simile a questo:
219
 
 
220
 
....
221
 
               ┌──────────────────────┐        ╔══════════════════╗
222
 
               │     python plugin    │        ║  WeeChat "core"  ║
223
 
               ├────────────┬─────────┤        ╟─────────┐        ║
224
 
test.py ─────► │ script API │  C API  │ ─────► ║  C API  │        ║
225
 
               └────────────┴─────────┘        ╚═════════╧════════╝
226
 
....
227
 
 
228
 
Quando WeeChat chiama una callback nel proprio script 'test.py', è
229
 
l'opposto del path precedente:
230
 
 
231
 
....
232
 
╔══════════════════╗        ┌──────────────────────┐
233
 
║  WeeChat "core"  ║        │     python plugin    │
234
 
║        ┌─────────╢        ├─────────┬────────────┤
235
 
║        │  C API  ║ ─────► │  C API  │ script API │ ─────► test.py
236
 
╚════════╧═════════╝        └─────────┴────────────┘
237
 
....
238
 
 
239
 
[[pointers]]
240
 
=== Puntatori
241
 
 
242
 
Come è già noto probabilmente, non esistono realmente i "puntatori"
243
 
negli script. Quando le funzioni API restituiscono un puntatore, viene
244
 
covertito in una stringa per lo script.
245
 
 
246
 
Ad esempio, se la funzione restituisce il puntatore 0x1234ab56, lo
247
 
script riceverà la stringa "0x1234ab56".
248
 
 
249
 
E quando una funzione API si aspetta un puntatore nell'argomento, lo script
250
 
deve fornire quel valore stringa. Il plugin C lo convertirà in un puntatore reale
251
 
prima di chiamare la funzione API in C.
252
 
 
253
 
Sono consentite stringhe vuote oppure "0x0", valgono come NULL in C.
254
 
Ad esempio, per stampare dei dati sul buffer core (il buffer principale di
255
 
WeeChat), è possibile fare questo:
256
 
 
257
 
[source,python]
258
 
----
259
 
weechat.prnt("", "hi!")
260
 
----
261
 
 
262
 
[WARNING]
263
 
In molte funzioni, per motivi legati alla velocità, WeeChat non verifica se
264
 
il puntatore è corretto oppure no. È il proprio lavoro controllare che si
265
 
stia fornendo un puntatore valido, altrimenti potrebbe comparire una
266
 
bella segnalazione per un errore ;)
267
 
 
268
 
[[callbacks]]
269
 
=== Callback
270
 
 
271
 
Quasi tutte le callback di WeeChat devono restituire WEECHAT_RC_OK
272
 
oppure WEECHAT_RC_ERROR (l'eccezione è la callback modifier, che
273
 
restituisce una stringa).
274
 
 
275
 
Le callback in C utilizzano un argomento "data", che è un puntatore.
276
 
Nelle API per gli script, questo "data" è una stringa con un qualsiasi
277
 
valore (non è un puntatore).
278
 
 
279
 
Esempio di callback, per ogni linguaggio:
280
 
 
281
 
* python:
282
 
 
283
 
[source,python]
284
 
----
285
 
def timer_cb(data, remaining_calls):
286
 
    weechat.prnt("", "timer! data=%s" % data)
287
 
    return weechat.WEECHAT_RC_OK
288
 
 
289
 
weechat.hook_timer(1000, 0, 1, "timer_cb", "test")
290
 
----
291
 
 
292
 
* perl:
293
 
 
294
 
[source,perl]
295
 
----
296
 
sub timer_cb {
297
 
    my ($data, $remaining_calls) = @_;
298
 
    weechat::print("", "timer! data=$data");
299
 
    return weechat::WEECHAT_RC_OK;
300
 
}
301
 
 
302
 
weechat::hook_timer(1000, 0, 1, "timer_cb", "test");
303
 
----
304
 
 
305
 
* ruby:
306
 
 
307
 
[source,ruby]
308
 
----
309
 
def timer_cb(data, remaining_calls)
310
 
  Weechat.print("", "timer! data=#{data}");
311
 
  return Weechat::WEECHAT_RC_OK
312
 
end
313
 
 
314
 
Weechat.hook_timer(1000, 0, 1, "timer_cb", "test");
315
 
----
316
 
 
317
 
* lua:
318
 
 
319
 
[source,lua]
320
 
----
321
 
function timer_cb(data, remaining_calls)
322
 
    weechat.print("", "timer! data="..data)
323
 
    return weechat.WEECHAT_RC_OK
324
 
end
325
 
 
326
 
weechat.hook_timer(1000, 0, 1, "timer_cb", "test")
327
 
----
328
 
 
329
 
* tcl:
330
 
 
331
 
[source,tcl]
332
 
----
333
 
proc timer_cb { data remaining_calls } {
334
 
    weechat::print {} "timer! data=$data"
335
 
    return $::weechat::WEECHAT_RC_OK
336
 
}
337
 
 
338
 
weechat::hook_timer 1000 0 1 timer_cb test
339
 
----
340
 
 
341
 
* guile (scheme):
342
 
 
343
 
[source,lisp]
344
 
----
345
 
(define (timer_cb data remaining_calls)
346
 
  (weechat:print "" (string-append "timer! data=" data))
347
 
  weechat:WEECHAT_RC_OK
348
 
)
349
 
 
350
 
(weechat:hook_timer 1000 0 1 "timer_cb" "test")
351
 
----
352
 
 
353
 
[[script_api]]
354
 
== Script API
355
 
 
356
 
Per maggiori informazioni sulle funzioni nelle API,
357
 
consultare 'Referenze API per Plugin di WeeChat'.
358
 
 
359
 
[[script_api_functions]]
360
 
=== Funzioni
361
 
 
362
 
Elenco di funzioni nelle API per gli script:
363
 
 
364
 
[width="100%",cols="^1,10",options="header"]
365
 
|===
366
 
| Categoria              | Funzioni
367
 
| generale               |
368
 
  register
369
 
| plugin                 |
370
 
  plugin_get_name
371
 
| stringhe               |
372
 
  charset_set, iconv_to_internal, iconv_from_internal, gettext, ngettext, +
373
 
  strlen_screen, string_match, string_has_highlight, string_has_highlight_regex,
374
 
  string_mask_to_regex, string_remove_color, string_is_command_char,
375
 
  string_input_for_buffer, string_eval_expression
376
 
| directory              |
377
 
  mkdir_home, mkdir, mkdir_parents
378
 
| liste ordinate         |
379
 
  list_new, list_add, list_search, list_search_pos, list_casesearch,
380
 
  list_casesearch_pos, list_get, list_set, list_next, list_prev, list_string,
381
 
  list_size, list_remove, list_remove_all, list_free
382
 
| file di configurazione |
383
 
  config_new, config_new_section, config_search_section, config_new_option,
384
 
  config_search_option, +
385
 
  config_string_to_boolean, config_option_reset, config_option_set,
386
 
  config_option_set_null, config_option_unset, config_option_rename,
387
 
  config_option_is_null, config_option_default_is_null, +
388
 
  config_boolean, config_boolean_default, config_integer, config_integer_default,
389
 
  config_string, config_string_default, config_color, config_color_default, +
390
 
  config_write_option, config_write_line, config_write, config_read,
391
 
  config_reload, +
392
 
  config_option_free, config_section_free_options, config_section_free,
393
 
  config_free, +
394
 
  config_get, config_get_plugin, config_is_set_plugin, config_set_plugin,
395
 
  config_set_desc_plugin, config_unset_plugin
396
 
| combinazione tasti     |
397
 
  key_bind, key_unbind
398
 
| visualizzazione        |
399
 
  prefix, color, print (for python: prnt), print_date_tags (for python:
400
 
  prnt_date_tags), print_y (for python: prnt_y), log_print
401
 
| hook                   |
402
 
  hook_command, hook_command_run, hook_timer, hook_fd, hook_process,
403
 
  hook_process_hashtable, hook_connect, hook_print, hook_signal,
404
 
  hook_signal_send, hook_hsignal, hook_hsignal_send, hook_config,
405
 
  hook_completion, hook_completion_list_add, hook_modifier, hook_modifier_exec,
406
 
  hook_info, hook_info_hashtable, hook_infolist, hook_focus, hook_set, unhook,
407
 
  unhook_all
408
 
| buffer                 |
409
 
  buffer_new, current_buffer, buffer_search, buffer_search_main, buffer_clear,
410
 
  buffer_close, buffer_merge, buffer_unmerge, buffer_get_integer,
411
 
  buffer_get_string, buffer_get_pointer, buffer_set,
412
 
  buffer_string_replace_local_var, buffer_match_list
413
 
| finestre               |
414
 
  current_window, window_search_with_buffer, window_get_integer,
415
 
  window_get_string, window_get_pointer, window_set_title
416
 
| lista nick             |
417
 
  nicklist_add_group, nicklist_search_group, nicklist_add_nick,
418
 
  nicklist_search_nick, nicklist_remove_group, nicklist_remove_nick,
419
 
  nicklist_remove_all, nicklist_group_get_integer, nicklist_group_get_string,
420
 
  nicklist_group_get_pointer, nicklist_group_set, nicklist_nick_get_integer,
421
 
  nicklist_nick_get_string, nicklist_nick_get_pointer, nicklist_nick_set
422
 
| barre                  |
423
 
  bar_item_search, bar_item_new, bar_item_update, bar_item_remove, bar_search,
424
 
  bar_new, bar_set, bar_update, bar_remove
425
 
| comandi                |
426
 
  comando
427
 
| info                   |
428
 
  info_get, info_get_hashtable
429
 
| liste info             |
430
 
  infolist_new, infolist_new_item, infolist_new_var_integer,
431
 
  infolist_new_var_string, infolist_new_var_pointer, infolist_new_var_time, +
432
 
  infolist_get, infolist_next, infolist_prev, infolist_reset_item_cursor, +
433
 
  infolist_fields, infolist_integer, infolist_string, infolist_pointer, +
434
 
  infolist_time, infolist_free
435
 
| hdata                  |
436
 
  hdata_get, hdata_get_var_offset, hdata_get_var_type_string,
437
 
  hdata_get_var_array_size, hdata_get_var_array_size_string,
438
 
  hdata_get_var_hdata, hdata_get_list, hdata_check_pointer, hdata_move,
439
 
  hdata_search, hdata_char, hdata_integer, hdata_long, hdata_string,
440
 
  hdata_pointer, hdata_time, hdata_hashtable, hdata_update, hdata_get_string
441
 
| aggiornamento          |
442
 
  upgrade_new, upgrade_write_object, upgrade_read, upgrade_close
443
 
|===
444
 
 
445
 
[[script_api_constants]]
446
 
=== Costanti
447
 
 
448
 
Elenco di costanti nelle API per gli script:
449
 
 
450
 
[width="100%",cols="^1,10",options="header"]
451
 
|===
452
 
| Categoria              | Costanti
453
 
| codici restituiti      |
454
 
  WEECHAT_RC_OK, WEECHAT_RC_OK_EAT, WEECHAT_RC_ERROR
455
 
| file di configurazione |
456
 
  WEECHAT_CONFIG_READ_OK, WEECHAT_CONFIG_READ_MEMORY_ERROR,
457
 
  WEECHAT_CONFIG_READ_FILE_NOT_FOUND, WEECHAT_CONFIG_WRITE_OK,
458
 
  WEECHAT_CONFIG_WRITE_ERROR, WEECHAT_CONFIG_WRITE_MEMORY_ERROR, +
459
 
  WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE,
460
 
  WEECHAT_CONFIG_OPTION_SET_ERROR, WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND,
461
 
  WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET, WEECHAT_CONFIG_OPTION_UNSET_OK_RESET,
462
 
  WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED, WEECHAT_CONFIG_OPTION_UNSET_ERROR
463
 
| liste ordinate         |
464
 
  WEECHAT_LIST_POS_SORT, WEECHAT_LIST_POS_BEGINNING, WEECHAT_LIST_POS_END
465
 
| hotlist                |
466
 
  WEECHAT_HOTLIST_LOW, WEECHAT_HOTLIST_MESSAGE, WEECHAT_HOTLIST_PRIVATE,
467
 
  WEECHAT_HOTLIST_HIGHLIGHT
468
 
| hook su processo       |
469
 
  WEECHAT_HOOK_PROCESS_RUNNING, WEECHAT_HOOK_PROCESS_ERROR
470
 
| hook su connessione    |
471
 
  WEECHAT_HOOK_CONNECT_OK, WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND,
472
 
  WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND, WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED,
473
 
  WEECHAT_HOOK_CONNECT_PROXY_ERROR, WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR,
474
 
  WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR, WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR,
475
 
  WEECHAT_HOOK_CONNECT_MEMORY_ERROR, WEECHAT_HOOK_CONNECT_TIMEOUT,
476
 
  WEECHAT_HOOK_CONNECT_SOCKET_ERROR
477
 
| hook su segnale        |
478
 
  WEECHAT_HOOK_SIGNAL_STRING, WEECHAT_HOOK_SIGNAL_INT, WEECHAT_HOOK_SIGNAL_POINTER
479
 
|===
480
 
 
481
 
[[common_tasks]]
482
 
== Compiti comuni
483
 
 
484
 
Questo capitolo spiega alcuni compiti comuni, con degli esempi.
485
 
Verranno utilizzati soltanto degli elementi parziali contenuti
486
 
nelle API, per un riferimento completo consultare
487
 
'Referenze API per Plugin di WeeChat'.
488
 
 
489
 
[[buffers]]
490
 
=== Buffer
491
 
 
492
 
[[buffers_display_messages]]
493
 
==== Visualizzare messaggi
494
 
 
495
 
Una stringa vuota è utilizzata spesso per lavorare con il buffer core di
496
 
WeeChat. Per gli altri buffer, è necessario fornire un puntatore (come
497
 
stringa, consultare <<pointers,pointers>>).
498
 
 
499
 
Esempi:
500
 
 
501
 
[source,python]
502
 
----
503
 
# visualizza "hello" sul buffer core
504
 
weechat.prnt("", "hello")
505
 
 
506
 
# visualizza "hello" sul buffer core, ma non salva sul file di log
507
 
# (solo versioni >= 0.3.3)
508
 
weechat.prnt_date_tags("", 0, "no_log", "hello")
509
 
 
510
 
# visualizza il prefisso "==>" ed il messaggio "hello" sul buffer corrente
511
 
# (prefisso e messaggio vanno separati da una tabulazione)
512
 
weechat.prnt(weechat.current_buffer(), "==>\thello")
513
 
 
514
 
# visualizza un messaggio di errore sul buffer core (con il prefisso di errore)
515
 
weechat.prnt("", "%swrong arguments" % weechat.prefix("error"))
516
 
 
517
 
# visualizza messaggio con il colore sul buffer core
518
 
weechat.prnt("", "text %syellow on blue" % weechat.color("yellow,blue"))
519
 
 
520
 
# cerca buffer e visualizza messaggiosearch buffer and display message
521
 
# (il nome completo del buffer è plugin.nome, ad esempio: "irc.freenode.#weechat")
522
 
buffer = weechat.buffer_search("irc", "freenode.#weechat")
523
 
weechat.prnt(buffer, "message on #weechat channel")
524
 
 
525
 
# altra soluzione per cercare un buffer IRC (migliore)
526
 
# (nota: server e canale sono separati da virgola)
527
 
buffer = weechat.info_get("irc_buffer", "freenode,#weechat")
528
 
weechat.prnt(buffer, "message on #weechat channel")
529
 
----
530
 
 
531
 
[NOTE]
532
 
La funzione print si chiama `print` in Perl/Ruby/Lua/Tcl e `prnt` in Python.
533
 
 
534
 
[[buffers_send_text]]
535
 
==== Invia testo al buffer
536
 
 
537
 
È possibile inviare del testo o un comando ad un buffer. È esattamente come
538
 
se si digitasse del testo o un comando, seguiti da [Enter].
539
 
 
540
 
Esempi:
541
 
 
542
 
// TRANSLATION MISSING
543
 
[source,python]
544
 
----
545
 
# execute command "/help" on current buffer (result is on core buffer)
546
 
weechat.command("", "/help")
547
 
 
548
 
# invia "hello" sul canale IRC #weechat  (gli utenti sul canale vedranno il messaggio)
549
 
buffer = weechat.info_get("irc_buffer", "freenode,#weechat")
550
 
weechat.command(buffer, "hello")
551
 
----
552
 
 
553
 
[[buffers_new]]
554
 
==== Creare un nuovo buffer
555
 
 
556
 
È possibile creare un nuovo buffer nel proprio script, per poi utilizzarlo per
557
 
visualizzare i messaggi.
558
 
 
559
 
Possono essere chiamate due callback (sono opzionali): una per i dati in
560
 
input (quando viene digitato del testo e premuto [Enter] sul buffer), l'altra
561
 
quando il buffer viene chiuso (ad esempio con `/buffer close`).
562
 
 
563
 
Esempio:
564
 
 
565
 
[source,python]
566
 
----
567
 
# callback per i dati ricevuti in input
568
 
def buffer_input_cb(data, buffer, input_data):
569
 
    # ...
570
 
    return weechat.WEECHAT_RC_OK
571
 
 
572
 
# callback chiamata alla chiusura del buffer
573
 
def buffer_close_cb(data, buffer):
574
 
    # ...
575
 
    return weechat.WEECHAT_RC_OK
576
 
 
577
 
# crea un buffer
578
 
buffer = weechat.buffer_new("mybuffer", "buffer_input_cb", "", "buffer_close_cb", "")
579
 
 
580
 
# imposta titolo
581
 
weechat.buffer_set(buffer, "title", "Questo titolo è per il mio buffer.")
582
 
 
583
 
# disabilita il logging, impostando la variabile locale "no_log" ad "1"
584
 
weechat.buffer_set(buffer, "localvar_set_no_log", "1")
585
 
----
586
 
 
587
 
[[buffers_properties]]
588
 
==== Proprietà dei buffer
589
 
 
590
 
Si possono leggere le proprietà del buffer, come stringa, intero o puntatore.
591
 
 
592
 
Esempi:
593
 
 
594
 
[source,python]
595
 
----
596
 
buffer = weechat.current_buffer()
597
 
 
598
 
number     = weechat.buffer_get_integer(buffer, "number")
599
 
name       = weechat.buffer_get_string(buffer, "name")
600
 
short_name = weechat.buffer_get_string(buffer, "short_name")
601
 
----
602
 
 
603
 
È possibile aggiungere, leggere o eliminare le variabili locali nel buffer:
604
 
 
605
 
[source,python]
606
 
----
607
 
# aggiunge la variabile locale
608
 
weechat.buffer_set(buffer, "localvar_set_myvar", "my_value")
609
 
 
610
 
# legge la variabile locale
611
 
myvar = weechat.buffer_get_string(buffer, "localvar_myvar")
612
 
 
613
 
# elimina la variabile locale
614
 
weechat.buffer_set(buffer, "localvar_del_myvar", "")
615
 
----
616
 
 
617
 
Per impostare le variabili locali di un buffer, digitare questo comando
618
 
in WeeChat:
619
 
 
620
 
----
621
 
/buffer localvar
622
 
----
623
 
 
624
 
[[hooks]]
625
 
=== Hook
626
 
 
627
 
[[hook_command]]
628
 
==== Aggiungere un nuovo comando
629
 
 
630
 
Aggiunge un comando personalizzato con `hook_command`. Si può fare uso di
631
 
un template di completamento personalizzato per completare gli argomenti
632
 
del proprio comando.
633
 
 
634
 
Esempio:
635
 
 
636
 
[source,python]
637
 
----
638
 
def my_command_cb(data, buffer, args):
639
 
    # ...
640
 
    return weechat.WEECHAT_RC_OK
641
 
 
642
 
hook = weechat.hook_command("myfilter", "descrizione di myfilter",
643
 
    "[list] | [enable|disable|toggle [name]] | [add name plugin.buffer tags regex] | [del name|-all]",
644
 
    "descrizione degli argomenti...",
645
 
    "list"
646
 
    " || enable %(filters_names)"
647
 
    " || disable %(filters_names)"
648
 
    " || toggle %(filters_names)"
649
 
    " || add %(filters_names) %(buffers_plugins_names)|*"
650
 
    " || del %(filters_names)|-all",
651
 
    "my_command_cb", "")
652
 
----
653
 
 
654
 
E poi in WeeChat:
655
 
 
656
 
----
657
 
/help myfilter
658
 
 
659
 
/myfilter arguments...
660
 
----
661
 
 
662
 
[[hook_timer]]
663
 
==== Aggiungere un timer
664
 
 
665
 
Aggiungere un timer con `hook_timer`.
666
 
 
667
 
Esempio:
668
 
 
669
 
[source,python]
670
 
----
671
 
def timer_cb(data, remaining_calls):
672
 
    # ...
673
 
    return weechat.WEECHAT_RC_OK
674
 
 
675
 
# timer chiamato ogni minuto quandi i secondi sono 00
676
 
weechat.hook_timer(60 * 1000, 60, 0, "timer_cb", "")
677
 
----
678
 
 
679
 
[[hook_process]]
680
 
==== Eseguire un processo in background
681
 
 
682
 
È possibile eseguire un processo in background con `hook_process`. La
683
 
callback verrà chiamata quando i dati sono pronti. Può essere chiamata
684
 
più volte.
685
 
 
686
 
Per l'ultima chiamata alla callback, 'rc' è impostato a zero o su un
687
 
valore positivo, è il codice restituito dal comando.
688
 
 
689
 
Esempio:
690
 
 
691
 
[source,python]
692
 
----
693
 
process_output = ""
694
 
 
695
 
def my_process_cb(data, command, rc, out, err):
696
 
    global process_output
697
 
    if out != "":
698
 
        process_output += out
699
 
    if int(rc) >= 0:
700
 
        weechat.prnt("", process_output)
701
 
    return weechat.WEECHAT_RC_OK
702
 
 
703
 
weechat.hook_process("/bin/ls -l /etc", 10 * 1000, "my_process_cb", "")
704
 
----
705
 
 
706
 
[[url_transfer]]
707
 
==== Trasferimento URL
708
 
 
709
 
_Novità nella versione 0.3.7._
710
 
 
711
 
Per scaricare un URL (o inviare verso un URL), è necessario usare la funzione
712
 
`hook_process` oppure `hook_process_hashtable` se ci fosse bisogno di impostare
713
 
delle opzioni per il trasferimento dell'URL.
714
 
 
715
 
Esempio di trasferimento di un URL senza opzioni: la pagina HTML verrà
716
 
ricevuta come "out" nella callback (output standard di un processo):
717
 
 
718
 
[source,python]
719
 
----
720
 
# Mostra la versione stabile corrente di WeeChat.
721
 
weechat_version = ""
722
 
 
723
 
def weechat_process_cb(data, command, rc, out, err):
724
 
    global weechat_version
725
 
    if out != "":
726
 
        weechat_version += out
727
 
    if int(rc) >= 0:
728
 
        weechat.prnt("", "Current WeeChat stable is: %s" % weechat_version)
729
 
    return weechat.WEECHAT_RC_OK
730
 
 
731
 
weechat.hook_process("url:http://weechat.org/dev/info/stable/",
732
 
                     30 * 1000, "weechat_process_cb", "")
733
 
----
734
 
 
735
 
[TIP]
736
 
Tutte le informazioni disponibili su Weechat sono sulla pagina
737
 
http://weechat.org/dev/info
738
 
 
739
 
Esempio di trasferimento di un URL con un'opzione: scaricare l'ultimo pacchetto
740
 
di sviluppo di WeeChat nel file '/tmp/weechat-devel.tar.gz':
741
 
 
742
 
[source,python]
743
 
----
744
 
def my_process_cb(data, command, rc, out, err):
745
 
    if int(rc) >= 0:
746
 
        weechat.prnt("", "End of transfer (rc=%s)" % rc)
747
 
    return weechat.WEECHAT_RC_OK
748
 
 
749
 
weechat.hook_process_hashtable("url:http://weechat.org/files/src/weechat-devel.tar.gz",
750
 
                               { "file_out": "/tmp/weechat-devel.tar.gz" },
751
 
                               30 * 1000, "my_process_cb", "")
752
 
----
753
 
 
754
 
Per maggiori informazioni sul trasferimento degli URL e le opzioni disponibili,
755
 
consultare le funzioni `hook_process` e `hook_process_hashtable` in 'Referenze
756
 
API per Plugin'.
757
 
 
758
 
[[config_options]]
759
 
=== Configurazione / opzioni
760
 
 
761
 
[[config_options_set_script]]
762
 
==== Impostare l'opzione per lo script
763
 
 
764
 
La funzione `config_is_set_plugin` viene utilizzare per verificare se un'opzione
765
 
è impostata oppure no, e `config_set_plugin` per impostare l'opzione.
766
 
 
767
 
Esempio:
768
 
 
769
 
[source,python]
770
 
----
771
 
script_options = {
772
 
    "option1" : "value1",
773
 
    "option2" : "value2",
774
 
    "option3" : "value3",
775
 
}
776
 
for option, default_value in script_options.items():
777
 
    if not weechat.config_is_set_plugin(option):
778
 
        weechat.config_set_plugin(option, default_value)
779
 
----
780
 
 
781
 
[[config_options_detect_changes]]
782
 
==== Rilevare le modifiche
783
 
 
784
 
È necessario utilizzare `hook_config` per essere notificati se l'utente dovesse
785
 
modificare alcune opzioni dello script.
786
 
 
787
 
Esempio:
788
 
 
789
 
[source,python]
790
 
----
791
 
SCRIPT_NAME = "myscript"
792
 
 
793
 
# ...
794
 
 
795
 
def config_cb(data, option, value):
796
 
    """Callback called when a script option is changed."""
797
 
    # for example, read all script options to script variables...
798
 
    # ...
799
 
    return weechat.WEECHAT_RC_OK
800
 
 
801
 
# ...
802
 
 
803
 
weechat.hook_config("plugins.var.python." + SCRIPT_NAME + ".*", "config_cb", "")
804
 
# for other languages, change "python" with your language ("perl", "ruby", "lua" or "tcl")
805
 
----
806
 
 
807
 
[[config_options_weechat]]
808
 
==== Leggere le opzioni di WeeChat
809
 
 
810
 
La funzione `config_get` restituisce il puntatore all'opzione. Poi, in base al tipo
811
 
di opzione, è necessario chiamare `config_string`, `config_boolean`,
812
 
`config_integer` oppure `config_color`.
813
 
 
814
 
[source,python]
815
 
----
816
 
# stringa
817
 
weechat.prnt("", "value of option weechat.look.item_time_format is: %s"
818
 
                 % (weechat.config_string(weechat.config_get("weechat.look.item_time_format"))))
819
 
 
820
 
# bool
821
 
weechat.prnt("", "value of option weechat.look.day_change is: %d"
822
 
                 % (weechat.config_boolean(weechat.config_get("weechat.look.day_change"))))
823
 
 
824
 
# intero
825
 
weechat.prnt("", "value of option weechat.look.scroll_page_percent is: %d"
826
 
                 % (weechat.config_integer(weechat.config_get("weechat.look.scroll_page_percent"))))
827
 
 
828
 
# colore
829
 
weechat.prnt("", "value of option weechat.color.chat_delimiters is: %s"
830
 
                 % (weechat.config_color(weechat.config_get("weechat.color.chat_delimiters"))))
831
 
----
832
 
 
833
 
[[irc]]
834
 
=== IRC
835
 
 
836
 
[[irc_catch_messages]]
837
 
==== Catturare messaggi
838
 
 
839
 
Il plugin IRC invia due segnali per un messaggio ricevuto (`xxx` è il nome
840
 
interno del server IRC, `yyy` è il nome del comando IRC come JOIN, QUIT,
841
 
PRIVMSG, 301, ..):
842
 
 
843
 
xxxx,irc_in_yyy::
844
 
    segnale inviato prima di esaminare il messaggio
845
 
 
846
 
xxx,irc_in2_yyy::
847
 
    segnale inviato dopo aver esaminato il messaggio
848
 
 
849
 
[source,python]
850
 
----
851
 
def join_cb(data, signal, signal_data):
852
 
    # signal è per esempio: "freenode,irc_in2_join"
853
 
    # signal_data è il messaggio IRC message, ad esempio: ":nick!user@host JOIN :#channel"
854
 
    nick = weechat.info_get("irc_nick_from_host", signal_data)
855
 
    server = signal.split(",")[0]
856
 
    channel = signal_data.split(":")[-1]
857
 
    buffer = weechat.info_get("irc_buffer", "%s,%s" % (server, channel))
858
 
    if buffer:
859
 
        weechat.prnt(buffer, "Eheh, %s has joined this channel!" % nick)
860
 
    return weechat.WEECHAT_RC_OK
861
 
 
862
 
# può essere utile qui utilizzare "*" come server, per catturare
863
 
# i messaggi JOIN su tutti i server IRC
864
 
weechat.hook_signal("*,irc_in2_join", "join_cb", "")
865
 
----
866
 
 
867
 
[[irc_modify_messages]]
868
 
==== Modificare i messaggi
869
 
 
870
 
Il plugin IRC invia un "modificatore" chiamato "irc_in_xxx" ("xxx" è il comando
871
 
IRC) per un messaggio ricevuto, in modo da poterlo modificare.
872
 
 
873
 
[source,python]
874
 
----
875
 
def modifier_cb(data, modifier, modifier_data, string):
876
 
    # aggiunge il nome del server a tutti i messaggi ricevuti
877
 
    # (ok non è molto utile, ma è solo un esempio!)
878
 
    return "%s %s" % (string, modifier_data)
879
 
 
880
 
weechat.hook_modifier("irc_in_privmsg", "modifier_cb", "")
881
 
----
882
 
 
883
 
[WARNING]
884
 
A malformed message could crash WeeChat or cause severe problems!
885
 
Un messaggio errato può mandare in crash WeeChat o causare seri problemi!
886
 
 
887
 
[[irc_message_parse]]
888
 
==== Verifica messaggio
889
 
 
890
 
_Novità nella versione 0.3.4._
891
 
 
892
 
È possibile verificare un messaggio irc con una info_hashtable chiamata
893
 
"irc_message_parse".
894
 
 
895
 
[source,python]
896
 
----
897
 
dict = weechat.info_get_hashtable("irc_message_parse",
898
 
                                  { "message": ":nick!user@host PRIVMSG #weechat :message here" })
899
 
weechat.prnt("", "dict: %s" % dict)
900
 
 
901
 
# output:
902
 
#   dict: {'nick': 'nick', 'host': 'nick!user@host', 'command': 'PRIVMSG', 'arguments': '#weechat :message here', 'channel': '#weechat'}
903
 
----
904
 
 
905
 
[[infos]]
906
 
=== Info
907
 
 
908
 
[[infos_weechat_version]]
909
 
==== Versione di WeeChat
910
 
 
911
 
Il modo migliore per verificare la versione è richiedere "version_number" e
912
 
comparare l'intero con il numero di versione esadecimale.
913
 
 
914
 
Esempio:
915
 
 
916
 
[source,python]
917
 
----
918
 
version = weechat.info_get("version_number", "") or 0
919
 
if int(version) >= 0x00030200:
920
 
    weechat.prnt("", "This is WeeChat 0.3.2 or newer")
921
 
else:
922
 
    weechat.prnt("", "This is WeeChat 0.3.1 or older")
923
 
----
924
 
 
925
 
[NOTE]
926
 
Le versioni ≤ 0.3.1.1 restituiscono una stringa vuota per
927
 
'info_get("version_number")', per cui bisogna verificare che
928
 
il valore restituito *non* sia vuoto.
929
 
 
930
 
To get version as string:
931
 
 
932
 
[source,python]
933
 
----
934
 
# this will display for example "Version 0.3.2"
935
 
weechat.prnt("", "Version %s" % weechat.info_get("version", ""))
936
 
----
937
 
 
938
 
[[infos_other]]
939
 
==== Altre informazioni
940
 
 
941
 
[source,python]
942
 
----
943
 
# la directory home di WeeChat, ad esempio: "/home/xxxx/.weechat"
944
 
weechat.prnt("", "WeeChat home dir: %s" % weechat.info_get("weechat_dir", ""))
945
 
 
946
 
# inattività della tastiera
947
 
weechat.prnt("", "Inactivity since %s seconds" % weechat.info_get("inactivity", ""))
948
 
----
949
 
 
950
 
[[infolists]]
951
 
=== Liste info
952
 
 
953
 
[[infolists_read]]
954
 
==== Leggere una lista info
955
 
 
956
 
È possibile leggere una lista info compilata da WeeChat
957
 
o da altri plugin.
958
 
 
959
 
Esempio:
960
 
 
961
 
[source,python]
962
 
----
963
 
# legge la lista info "buffer", per ottenere la lista dei buffer
964
 
infolist = weechat.infolist_get("buffer", "", "")
965
 
if infolist:
966
 
    while weechat.infolist_next(infolist):
967
 
        name = weechat.infolist_string(infolist, "name")
968
 
        weechat.prnt("", "buffer: %s" % name)
969
 
    weechat.infolist_free(infolist)
970
 
----
971
 
 
972
 
[IMPORTANT]
973
 
Non dimenticare di chiamare `infolist_free` per liberare la memoria
974
 
utilizzata dalla lista info, perché WeeChat non libererà automaticamente
975
 
la memoria.