Add 256 colors support

Changes:
- new section "palette" in weechat.conf
- new API functions: list_search_pos and list_casesearch_pos
v2.8-utf8proc
Sebastien Helleu 2010-12-20 10:13:37 +01:00
parent e80d6b93a5
commit cd7a02bec5
35 changed files with 1650 additions and 139 deletions

View File

@ -1,12 +1,14 @@
WeeChat ChangeLog
=================
Sébastien Helleu <flashcode@flashtux.org>
v0.3.4-rc1, 2010-12-16
v0.3.4-rc1, 2010-12-20
Version 0.3.4 (under dev!)
--------------------------
* core: add 256 colors support, new section "palette" in weechat.conf
(task #6834)
* core: add support of python 2.7 in cmake and configure (debian #606989)
* core: add color support in option weechat.look.buffer_time_format
* core: call to hook_config when config option is created
@ -35,9 +37,9 @@ Version 0.3.4 (under dev!)
* core: use similar behaviour for keys bound to local or global history
(bug #30759)
* api: add priority for hooks (task #10550)
* api: add new functions: hashtable_get_string, hook_info_hashtable,
info_get_hashtable, hook_hsignal, hook_hsignal_send,
hook_completion_get_string, nicklist_group_get_integer,
* api: add new functions: list_search_pos, list_casesearch_pos,
hashtable_get_string, hook_info_hashtable, info_get_hashtable, hook_hsignal,
hook_hsignal_send, hook_completion_get_string, nicklist_group_get_integer,
nicklist_group_get_string, nicklist_group_get_pointer, nicklist_group_set,
nicklist_nick_get_integer, nicklist_nick_get_string, nicklist_nick_get_pointer,
nicklist_nick_set

View File

@ -85,6 +85,7 @@ my @ignore_options = ("aspell\\.dict\\..*",
"logger\\.mask\\..*",
"relay\\.port\\..*",
"rmodifier\\.modifier\\..*",
"weechat\\.palette\\..*",
"weechat\\.proxy\\..*",
"weechat\\.bar\\..*",
"weechat\\.debug\\..*",

View File

@ -2474,6 +2474,48 @@ item = weechat.list_search(list, data)
item = weechat.list_search(list, "my data")
----------------------------------------
weechat_list_search_pos
^^^^^^^^^^^^^^^^^^^^^^^
_New in version 0.3.4._
Search an item position in a list.
Prototype:
[source,C]
----------------------------------------
int weechat_list_search_pos (struct t_weelist *weelist,
const char *data);
----------------------------------------
Arguments:
* 'weelist': list pointer
* 'data': data to search in list
Return value:
* position of item found, -1 if item was not found
C example:
[source,C]
----------------------------------------
int pos_item = weechat_list_search_pos (list, "my data");
----------------------------------------
Script (Python):
[source,python]
----------------------------------------
# prototype
pos_item = weechat.list_search_pos(list, data)
# example
pos_item = weechat.list_search_pos(list, "my data")
----------------------------------------
weechat_list_casesearch
^^^^^^^^^^^^^^^^^^^^^^^
@ -2514,6 +2556,48 @@ item = weechat.list_casesearch(list, data)
item = weechat.list_casesearch(list, "my data")
----------------------------------------
weechat_list_casesearch_pos
^^^^^^^^^^^^^^^^^^^^^^^^^^^
_New in version 0.3.4._
Search an item position in a list, ignoring case.
Prototype:
[source,C]
----------------------------------------
int weechat_list_casesearch_pos (struct t_weelist *weelist,
const char *data);
----------------------------------------
Arguments:
* 'weelist': list pointer
* 'data': data to search in list
Return value:
* position of item found, -1 if item was not found
C example:
[source,C]
----------------------------------------
int pos_item = weechat_list_casesearch_pos (list, "my data");
----------------------------------------
Script (Python):
[source,python]
----------------------------------------
# prototype
pos_item = weechat.list_casesearch_pos(list, data)
# example
pos_item = weechat.list_casesearch_pos(list, "my data")
----------------------------------------
weechat_list_get
^^^^^^^^^^^^^^^^

View File

@ -2501,6 +2501,48 @@ item = weechat.list_search(list, data)
item = weechat.list_search(list, "ma donnée")
----------------------------------------
weechat_list_search_pos
^^^^^^^^^^^^^^^^^^^^^^^
_Nouveau dans la version 0.3.4._
Recherche la position d'un élément dans une liste.
Prototype :
[source,C]
----------------------------------------
int weechat_list_search_pos (struct t_weelist *weelist,
const char *data);
----------------------------------------
Paramètres :
* 'weelist' : pointeur vers la liste
* 'data' : donnée à chercher dans la liste
Valeur de retour :
* position de l'élément trouvé, -1 si aucun élément n'a été trouvé
Exemple en C :
[source,C]
----------------------------------------
int pos_item = weechat_list_search_pos (list, "ma donnée");
----------------------------------------
Script (Python) :
[source,python]
----------------------------------------
# prototype
pos_item = weechat.list_search_pos(list, data)
# exemple
pos_item = weechat.list_search_pos(list, "ma donnée")
----------------------------------------
weechat_list_casesearch
^^^^^^^^^^^^^^^^^^^^^^^
@ -2541,6 +2583,48 @@ item = weechat.list_casesearch(list, data)
item = weechat.list_casesearch(list, "ma donnée")
----------------------------------------
weechat_list_casesearch_pos
^^^^^^^^^^^^^^^^^^^^^^^^^^^
_Nouveau dans la version 0.3.4._
Recherche la position d'un élément dans la liste, sans tenir compte de la casse.
Prototype :
[source,C]
----------------------------------------
int weechat_list_casesearch_pos (struct t_weelist *weelist,
const char *data);
----------------------------------------
Paramètres :
* 'weelist' : pointeur vers la liste
* 'data' : données à chercher dans la liste
Valeur de retour :
* position l'élément trouvé, -1 si aucun élément n'a été trouvé
Exemple en C :
[source,C]
----------------------------------------
int pos_item = weechat_list_casesearch_pos (list, "ma donnée");
----------------------------------------
Script (Python) :
[source,python]
----------------------------------------
# prototype
pos_item = weechat.list_casesearch_pos(list, data)
# exemple
pos_item = weechat.list_casesearch_pos(list, "ma donnée")
----------------------------------------
weechat_list_get
^^^^^^^^^^^^^^^^

View File

@ -2461,6 +2461,49 @@ item = weechat.list_search(list, data)
item = weechat.list_search(list, "my data")
----------------------------------------
// TRANSLATION MISSING
weechat_list_search_pos
^^^^^^^^^^^^^^^^^^^^^^^
_New in version 0.3.4._
Search an item position in a list.
Prototype:
[source,C]
----------------------------------------
int weechat_list_search_pos (struct t_weelist *weelist,
const char *data);
----------------------------------------
Arguments:
* 'weelist': list pointer
* 'data': data to search in list
Return value:
* position of item found, -1 if item was not found
C example:
[source,C]
----------------------------------------
int pos_item = weechat_list_search_pos (list, "my data");
----------------------------------------
Script (Python):
[source,python]
----------------------------------------
# prototype
pos_item = weechat.list_search_pos(list, data)
# example
pos_item = weechat.list_search_pos(list, "my data")
----------------------------------------
weechat_list_casesearch
^^^^^^^^^^^^^^^^^^^^^^^
@ -2502,6 +2545,49 @@ item = weechat.list_casesearch(list, data)
item = weechat.list_casesearch(list, "my data")
----------------------------------------
// TRANSLATION MISSING
weechat_list_casesearch_pos
^^^^^^^^^^^^^^^^^^^^^^^^^^^
_New in version 0.3.4._
Search an item position in a list, ignoring case.
Prototype:
[source,C]
----------------------------------------
int weechat_list_casesearch_pos (struct t_weelist *weelist,
const char *data);
----------------------------------------
Arguments:
* 'weelist': list pointer
* 'data': data to search in list
Return value:
* position of item found, -1 if item was not found
C example:
[source,C]
----------------------------------------
int pos_item = weechat_list_casesearch_pos (list, "my data");
----------------------------------------
Script (Python):
[source,python]
----------------------------------------
# prototype
pos_item = weechat.list_casesearch_pos(list, data)
# example
pos_item = weechat.list_casesearch_pos(list, "my data")
----------------------------------------
weechat_list_get
^^^^^^^^^^^^^^^^

View File

@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.4-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-12-17 12:25+0100\n"
"POT-Creation-Date: 2010-12-20 09:52+0100\n"
"PO-Revision-Date: 2010-11-06 11:55+0100\n"
"Last-Translator: Jiri Golembiovsky <golemj@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1762,6 +1762,17 @@ msgstr "\t\tZměnil se den na %s"
msgid "debug level for plugin (\"core\" for WeeChat core)"
msgstr "úroveň ladění pro plugin (\"core\" pro jádro WeeChat)"
msgid ""
"custom color in palette, format is: \"alias;fg,bg;r/g/b\" where alias is "
"color name, fg,bg is \"foreground,background\" (example: \"200,-1\"), r/g/b "
"is redefinition of color (terminal must support it) (everything is optional "
"in this format)"
msgstr ""
#, fuzzy, c-format
msgid "%sError: palette option must be numeric"
msgstr "%sChyba: selhalo uložení voleb do %s"
msgid "Notify level for buffer"
msgstr "Úroveň upozornění pro buffer"

View File

@ -22,7 +22,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.3-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-12-17 12:25+0100\n"
"POT-Creation-Date: 2010-12-20 09:52+0100\n"
"PO-Revision-Date: 2010-12-07 23:21+0100\n"
"Last-Translator: Nils G.\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1821,6 +1821,17 @@ msgstr "\t\tEin neuer Tag bricht an. Heute ist %s"
msgid "debug level for plugin (\"core\" for WeeChat core)"
msgstr "Debug-Level für Erweiterung (\"core\" für den WeeChat Core)"
msgid ""
"custom color in palette, format is: \"alias;fg,bg;r/g/b\" where alias is "
"color name, fg,bg is \"foreground,background\" (example: \"200,-1\"), r/g/b "
"is redefinition of color (terminal must support it) (everything is optional "
"in this format)"
msgstr ""
#, fuzzy, c-format
msgid "%sError: palette option must be numeric"
msgstr "%sFehler: Optionen konnten nicht unter %s gesichert werden"
msgid "Notify level for buffer"
msgstr "Benachrichtigungsstufe für Buffer"

View File

@ -21,7 +21,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.4-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-12-17 12:25+0100\n"
"POT-Creation-Date: 2010-12-20 09:52+0100\n"
"PO-Revision-Date: 2010-11-06 11:56+0100\n"
"Last-Translator: Elián Hanisch <lambdae2@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1775,6 +1775,17 @@ msgstr "\t\tNuevo día, %s"
msgid "debug level for plugin (\"core\" for WeeChat core)"
msgstr "nivel de depurado para el plugin (\"core\" para el núcleo de WeeChat)"
msgid ""
"custom color in palette, format is: \"alias;fg,bg;r/g/b\" where alias is "
"color name, fg,bg is \"foreground,background\" (example: \"200,-1\"), r/g/b "
"is redefinition of color (terminal must support it) (everything is optional "
"in this format)"
msgstr ""
#, fuzzy, c-format
msgid "%sError: palette option must be numeric"
msgstr "%sError: no se pudo guardar las opciones en %s"
msgid "Notify level for buffer"
msgstr "Nivel de notificación para el buffer"

View File

@ -21,8 +21,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.4-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-12-17 12:25+0100\n"
"PO-Revision-Date: 2010-12-17 11:58+0100\n"
"POT-Creation-Date: 2010-12-20 09:52+0100\n"
"PO-Revision-Date: 2010-12-19 19:54+0100\n"
"Last-Translator: Sebastien Helleu <flashcode@flashtux.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
"Language: French\n"
@ -1791,6 +1791,21 @@ msgstr "\t\tJour changé: %s"
msgid "debug level for plugin (\"core\" for WeeChat core)"
msgstr "niveau de debug pour l'extension (\"core\" pour le coeur de WeeChat)"
msgid ""
"custom color in palette, format is: \"alias;fg,bg;r/g/b\" where alias is "
"color name, fg,bg is \"foreground,background\" (example: \"200,-1\"), r/g/b "
"is redefinition of color (terminal must support it) (everything is optional "
"in this format)"
msgstr ""
"couleur personnalisée dans la palette, le format est: \"alias;fg,bg;r/g/b\" "
"où alias est le nom de la couleur, fg,bg est \"texte,fond\" (par exemple: "
"\"200,-1\"), r/g/b est la redéfinition de la couleur (le terminal doit le "
"supporter) (tout est optionnel dans ce format)"
#, c-format
msgid "%sError: palette option must be numeric"
msgstr "%sErreur: l'option de palette doit être numérique"
msgid "Notify level for buffer"
msgstr "Niveau de notification pour le tampon"

View File

@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.4-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-12-17 12:25+0100\n"
"POT-Creation-Date: 2010-12-20 09:52+0100\n"
"PO-Revision-Date: 2010-11-05 17:17+0100\n"
"Last-Translator: Andras Voroskoi <voroskoi@frugalware.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1585,6 +1585,17 @@ msgstr "A mai dátum: %s\n"
msgid "debug level for plugin (\"core\" for WeeChat core)"
msgstr ""
msgid ""
"custom color in palette, format is: \"alias;fg,bg;r/g/b\" where alias is "
"color name, fg,bg is \"foreground,background\" (example: \"200,-1\"), r/g/b "
"is redefinition of color (terminal must support it) (everything is optional "
"in this format)"
msgstr ""
#, fuzzy, c-format
msgid "%sError: palette option must be numeric"
msgstr "%s nem sikerült a modul opciókat elmenteni\n"
#, fuzzy
msgid "Notify level for buffer"
msgstr "szobanév nem található a pufferhez"

View File

@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.4-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-12-17 12:25+0100\n"
"POT-Creation-Date: 2010-12-20 09:52+0100\n"
"PO-Revision-Date: 2010-12-10 14:11+0100\n"
"Last-Translator: Marco Paolone <marcopaolone@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1782,6 +1782,17 @@ msgstr "\t\tOggi è %s"
msgid "debug level for plugin (\"core\" for WeeChat core)"
msgstr "livello di debug per il plugin (\"core\" per il core di WeeChat)"
msgid ""
"custom color in palette, format is: \"alias;fg,bg;r/g/b\" where alias is "
"color name, fg,bg is \"foreground,background\" (example: \"200,-1\"), r/g/b "
"is redefinition of color (terminal must support it) (everything is optional "
"in this format)"
msgstr ""
#, fuzzy, c-format
msgid "%sError: palette option must be numeric"
msgstr "%sErrore: impossibile salvare le opzioni in %s"
msgid "Notify level for buffer"
msgstr "Livello di notifica per il buffer"

View File

@ -21,7 +21,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.4-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-12-17 12:25+0100\n"
"POT-Creation-Date: 2010-12-20 09:52+0100\n"
"PO-Revision-Date: 2010-11-06 11:56+0100\n"
"Last-Translator: Krzysztof Koroscik <soltys@szluug.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1783,6 +1783,17 @@ msgstr "\t\tDzień zmienił się na %s"
msgid "debug level for plugin (\"core\" for WeeChat core)"
msgstr "poziom debugowania dla wtyczki (\"core\" dla rdzenia WeeChat)"
msgid ""
"custom color in palette, format is: \"alias;fg,bg;r/g/b\" where alias is "
"color name, fg,bg is \"foreground,background\" (example: \"200,-1\"), r/g/b "
"is redefinition of color (terminal must support it) (everything is optional "
"in this format)"
msgstr ""
#, fuzzy, c-format
msgid "%sError: palette option must be numeric"
msgstr "%sBłąd: nie udało się zapisać ustawień do %s"
msgid "Notify level for buffer"
msgstr "Poziom powiadomień dla buforu"

View File

@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.4-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-12-17 12:25+0100\n"
"POT-Creation-Date: 2010-12-20 09:52+0100\n"
"PO-Revision-Date: 2010-11-13 09:26+0100\n"
"Last-Translator: Ivan Sichmann Freitas <ivansichfreitas@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1416,6 +1416,17 @@ msgstr ""
msgid "debug level for plugin (\"core\" for WeeChat core)"
msgstr ""
msgid ""
"custom color in palette, format is: \"alias;fg,bg;r/g/b\" where alias is "
"color name, fg,bg is \"foreground,background\" (example: \"200,-1\"), r/g/b "
"is redefinition of color (terminal must support it) (everything is optional "
"in this format)"
msgstr ""
#, fuzzy, c-format
msgid "%sError: palette option must be numeric"
msgstr "%sErro: falhou ao salvar as opções para %s"
msgid "Notify level for buffer"
msgstr ""

View File

@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.4-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-12-17 12:25+0100\n"
"POT-Creation-Date: 2010-12-20 09:52+0100\n"
"PO-Revision-Date: 2010-11-05 17:17+0100\n"
"Last-Translator: Pavel Shevchuk <stlwrt@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1594,6 +1594,17 @@ msgstr "Дата сменилась на %s\n"
msgid "debug level for plugin (\"core\" for WeeChat core)"
msgstr ""
msgid ""
"custom color in palette, format is: \"alias;fg,bg;r/g/b\" where alias is "
"color name, fg,bg is \"foreground,background\" (example: \"200,-1\"), r/g/b "
"is redefinition of color (terminal must support it) (everything is optional "
"in this format)"
msgstr ""
#, fuzzy, c-format
msgid "%sError: palette option must be numeric"
msgstr "%s не могу сохранить конфигурационный файл pluginов\n"
#, fuzzy
msgid "Notify level for buffer"
msgstr "не найдено имя канала для буфера"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-12-17 12:25+0100\n"
"POT-Creation-Date: 2010-12-20 09:52+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -1355,6 +1355,17 @@ msgstr ""
msgid "debug level for plugin (\"core\" for WeeChat core)"
msgstr ""
msgid ""
"custom color in palette, format is: \"alias;fg,bg;r/g/b\" where alias is "
"color name, fg,bg is \"foreground,background\" (example: \"200,-1\"), r/g/b "
"is redefinition of color (terminal must support it) (everything is optional "
"in this format)"
msgstr ""
#, c-format
msgid "%sError: palette option must be numeric"
msgstr ""
msgid "Notify level for buffer"
msgstr ""

View File

@ -37,6 +37,7 @@
#include "weechat.h"
#include "wee-config.h"
#include "wee-hashtable.h"
#include "wee-hook.h"
#include "wee-list.h"
#include "wee-proxy.h"
@ -705,6 +706,24 @@ completion_list_add_plugins_commands_cb (void *data,
return WEECHAT_RC_OK;
}
/*
* completion_list_add_color_alias_cb: add color alias in completion
*/
void
completion_list_add_color_alias_cb (void *data,
struct t_hashtable *hashtable,
const void *key, const void *value)
{
/* make C compiler happy */
(void) hashtable;
(void) value;
gui_completion_list_add ((struct t_gui_completion *)data,
(char *)key,
0, WEECHAT_LIST_POS_SORT);
}
/*
* completion_list_add_config_option_values_cb: add option value to completion
* list
@ -888,6 +907,12 @@ completion_list_add_config_option_values_cb (void *data,
color_name,
0, WEECHAT_LIST_POS_SORT);
}
if (gui_color_hash_palette_alias)
{
hashtable_map (gui_color_hash_palette_alias,
&completion_list_add_color_alias_cb,
completion);
}
gui_completion_list_add (completion, "++1",
0, WEECHAT_LIST_POS_END);
gui_completion_list_add (completion, "--1",

View File

@ -1260,12 +1260,9 @@ config_file_option_set (struct t_config_option *option, const char *value,
number = strtol (value + 2, &error, 10);
if (error && !error[0])
{
number = number % (num_colors + 1);
value_int = (old_value + number) %
(num_colors + 1);
if (value_int > num_colors - 1)
value_int -= num_colors;
if (value_int <= num_colors - 1)
if (gui_color_assign_by_diff (&value_int,
gui_color_get_name (old_value),
number))
new_value_ok = 1;
}
}
@ -1275,12 +1272,9 @@ config_file_option_set (struct t_config_option *option, const char *value,
number = strtol (value + 2, &error, 10);
if (error && !error[0])
{
number = number % (num_colors + 1);
value_int = (old_value + num_colors - number) %
num_colors;
if (value_int < 0)
value_int += num_colors;
if (value_int >= 0)
if (gui_color_assign_by_diff (&value_int,
gui_color_get_name (old_value),
-1 * number))
new_value_ok = 1;
}
}

View File

@ -61,6 +61,7 @@
struct t_config_file *weechat_config_file = NULL;
struct t_config_section *weechat_config_section_debug = NULL;
struct t_config_section *weechat_config_section_color = NULL;
struct t_config_section *weechat_config_section_proxy = NULL;
struct t_config_section *weechat_config_section_bar = NULL;
struct t_config_section *weechat_config_section_notify = NULL;
@ -660,6 +661,130 @@ config_weechat_debug_set (const char *plugin_name, const char *value)
value);
}
/*
* config_weechat_palette_change_cb: called when a palette option is changed
*/
void
config_weechat_palette_change_cb (void *data,
struct t_config_option *option)
{
char *error;
int number;
/* make C compiler happy */
(void) data;
(void) option;
error = NULL;
number = (int)strtol (option->name, &error, 10);
if (error && !error[0])
{
gui_color_palette_change (number, CONFIG_STRING(option));
}
}
/*
* config_weechat_palette_create_option_cb: create option in "palette" section
*/
int
config_weechat_palette_create_option_cb (void *data,
struct t_config_file *config_file,
struct t_config_section *section,
const char *option_name,
const char *value)
{
struct t_config_option *ptr_option;
char *error;
int rc, number;
/* make C compiler happy */
(void) data;
rc = WEECHAT_CONFIG_OPTION_SET_ERROR;
error = NULL;
number = (int)strtol (option_name, &error, 10);
if (error && !error[0])
{
if (option_name)
{
ptr_option = config_file_search_option (config_file, section,
option_name);
if (ptr_option)
{
if (value)
rc = config_file_option_set (ptr_option, value, 1);
else
{
config_file_option_free (ptr_option);
rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
}
}
else
{
if (value)
{
ptr_option = config_file_new_option (
config_file, section,
option_name, "string",
_("custom color in palette, format is: \"alias;fg,bg;r/g/b\" "
"where alias is color name, fg,bg is \"foreground,background\" "
"(example: \"200,-1\"), r/g/b is redefinition of color "
"(terminal must support it) (everything is optional "
"in this format)"),
NULL, 0, 0, "", value, 0, NULL, NULL,
&config_weechat_palette_change_cb, NULL,
NULL, NULL);
rc = (ptr_option) ?
WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR;
if (ptr_option)
gui_color_palette_add (number, value);
}
else
rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
}
}
}
else
{
gui_chat_printf (NULL,
_("%sError: palette option must be numeric"),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
}
return rc;
}
/*
* config_weechat_palette_delete_option_cb: delete option in "palette" section
*/
int
config_weechat_palette_delete_option_cb (void *data,
struct t_config_file *config_file,
struct t_config_section *section,
struct t_config_option *option)
{
char *error;
int number;
/* make C compiler happy */
(void) data;
(void) config_file;
(void) section;
error = NULL;
number = (int)strtol (option->name, &error, 10);
if (error && !error[0])
gui_color_palette_remove (number);
config_file_option_free (option);
return WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED;
}
/*
* config_weechat_proxy_read_cb: read proxy option in config file
*/
@ -1606,6 +1731,19 @@ config_weechat_init_options ()
"messages"),
NULL, 0, 0, "%a, %d %b %Y %T", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
/* palette */
ptr_section = config_file_new_section (weechat_config_file, "palette",
1, 1,
NULL, NULL, NULL, NULL,
NULL, NULL,
&config_weechat_palette_create_option_cb, NULL,
&config_weechat_palette_delete_option_cb, NULL);
if (!ptr_section)
{
config_file_free (weechat_config_file);
return 0;
}
/* colors */
ptr_section = config_file_new_section (weechat_config_file, "color",
0, 0,
@ -1617,6 +1755,8 @@ config_weechat_init_options ()
return 0;
}
weechat_config_section_color = ptr_section;
/* general color settings */
config_color_separator = config_file_new_option (
weechat_config_file, ptr_section,
@ -2232,9 +2372,9 @@ config_weechat_init ()
_("FATAL: error initializing configuration options"));
}
/* create timer to check if day has changed */
if (!config_day_change_timer)
{
/* create timer to check if day has changed */
gettimeofday (&tv_time, NULL);
local_time = localtime (&tv_time.tv_sec);
config_day_change_old_day = local_time->tm_mday;
@ -2244,8 +2384,9 @@ config_weechat_init ()
0,
&config_day_change_timer_cb,
NULL);
config_change_highlight_regex (NULL, NULL);
}
if (!config_highlight_regex)
config_change_highlight_regex (NULL, NULL);
return rc;
}

View File

@ -94,6 +94,7 @@ enum t_config_look_save_layout_on_exit
};
extern struct t_config_file *weechat_config_file;
extern struct t_config_section *weechat_config_section_color;
extern struct t_config_section *weechat_config_section_proxy;
extern struct t_config_section *weechat_config_section_bar;
extern struct t_config_section *weechat_config_section_notify;

View File

@ -182,6 +182,32 @@ weelist_search (struct t_weelist *weelist, const char *data)
return NULL;
}
/*
* weelist_search_pos: search data in a list (case sensitive), return position
* of item found, -1 if not found
*/
int
weelist_search_pos (struct t_weelist *weelist, const char *data)
{
struct t_weelist_item *ptr_item;
int i;
if (!weelist || !data)
return -1;
i = 0;
for (ptr_item = weelist->items; ptr_item;
ptr_item = ptr_item->next_item)
{
if (strcmp (data, ptr_item->data) == 0)
return i;
i++;
}
/* data not found in list */
return -1;
}
/*
* weelist_casesearch: search data in a list (case unsensitive)
*/
@ -204,6 +230,31 @@ weelist_casesearch (struct t_weelist *weelist, const char *data)
return NULL;
}
/*
* weelist_casesearch_pos: search data in a list (case unsensitive), return
* position of item found, -1 if not found
*/
int
weelist_casesearch_pos (struct t_weelist *weelist, const char *data)
{
struct t_weelist_item *ptr_item;
int i;
if (!weelist || !data)
return -1;
for (ptr_item = weelist->items; ptr_item;
ptr_item = ptr_item->next_item)
{
if (string_strcasecmp (data, ptr_item->data) == 0)
return i;
i++;
}
/* data not found in list */
return -1;
}
/*
* weelist_get: get an item in a list by position (0 is first element)
*/

View File

@ -41,8 +41,10 @@ extern struct t_weelist_item *weelist_add (struct t_weelist *weelist,
void *user_data);
extern struct t_weelist_item *weelist_search (struct t_weelist *weelist,
const char *data);
extern int weelist_search_pos (struct t_weelist *weelist, const char *data);
extern struct t_weelist_item *weelist_casesearch (struct t_weelist *weelist,
const char *data);
extern int weelist_casesearch_pos (struct t_weelist *weelist, const char *data);
extern struct t_weelist_item *weelist_get (struct t_weelist *weelist,
int position);
extern void weelist_set (struct t_weelist_item *item, const char *value);

View File

@ -248,19 +248,19 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
case GUI_COLOR_BAR_FG_CHAR:
/* bar foreground */
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG]));
CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG]));
string += 2;
break;
case GUI_COLOR_BAR_DELIM_CHAR:
/* bar delimiter */
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_DELIM]));
CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_DELIM]));
string += 2;
break;
case GUI_COLOR_BAR_BG_CHAR:
/* bar background */
gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
string += 2;
break;
case GUI_COLOR_BAR_START_INPUT_CHAR:
@ -301,9 +301,9 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
break;
case GUI_COLOR_RESET_CHAR:
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG]));
CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG]));
gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
gui_window_remove_color_style (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
A_BOLD | A_UNDERLINE | A_REVERSE);
string++;
@ -672,7 +672,7 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
y = 0;
gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
CONFIG_COLOR(config_color_bar_more),
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
mvwprintw (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
y, x, "--");
}
@ -685,7 +685,7 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
y = (bar_window->height > 1) ? bar_window->height - 1 : 0;
gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
CONFIG_COLOR(config_color_bar_more),
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
mvwprintw (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
y, x, "++");
}

View File

@ -31,8 +31,11 @@
#include "../../core/weechat.h"
#include "../../core/wee-config.h"
#include "../../core/wee-hashtable.h"
#include "../../core/wee-list.h"
#include "../../core/wee-string.h"
#include "../../core/wee-utf8.h"
#include "../../plugins/plugin.h"
#include "../gui-color.h"
#include "../gui-chat.h"
#include "gui-curses.h"
@ -84,6 +87,7 @@ gui_color_search (const char *color_name)
/*
* gui_color_assign: assign a WeeChat color (read from config)
* return 1 if ok, 0 if error
*/
int
@ -92,15 +96,26 @@ gui_color_assign (int *color, const char *color_name)
int color_index, pair;
char *error;
/* search for color alias */
pair = gui_color_palette_get_alias (color_name);
if (pair >= 0)
{
*color = GUI_COLOR_PAIR_FLAG | pair;
return 1;
}
/* is it pair number? */
error = NULL;
pair = (int)strtol (color_name, &error, 10);
if (error && !error[0] && (pair >= 0))
{
*color = 0x10000 | pair;
/* color_name is a number, use this pair number */
*color = GUI_COLOR_PAIR_FLAG | pair;
return 1;
}
else
{
/* search for basic WeeChat color */
color_index = gui_color_search (color_name);
if (color_index >= 0)
{
@ -113,6 +128,57 @@ gui_color_assign (int *color, const char *color_name)
return 0;
}
/*
* gui_color_assign_by_diff: assign color by difference
* It is called when a color option is
* set with value ++X or --X, to search
* another color (for example ++1 is
* next color/alias in list)
* return 1 if ok, 0 if error
*/
int
gui_color_assign_by_diff (int *color, const char *color_name, int diff)
{
int index, list_size;
struct t_weelist_item *ptr_item;
const char *name;
index = weelist_search_pos (gui_color_list_with_alias, color_name);
if (index < 0)
index = 0;
list_size = weelist_size (gui_color_list_with_alias);
diff = diff % (list_size + 1);
if (diff > 0)
{
index = (index + diff) % (list_size + 1);
while (index > list_size - 1)
{
index -= list_size;
}
}
else
{
index = (index + list_size + diff) % list_size;
while (index < 0)
{
index += list_size;
}
}
ptr_item = weelist_get (gui_color_list_with_alias, index);
if (!ptr_item)
return 0;
name = weelist_string (ptr_item);
if (name)
return gui_color_assign (color, name);
return 0;
}
/*
* gui_color_get_number: get number of available colors
*/
@ -132,13 +198,17 @@ gui_color_get_name (int num_color)
{
static char color[32][16];
static int index_color = 0;
struct t_gui_color_palette *ptr_color_palette;
if (num_color & 0x10000)
if (num_color & GUI_COLOR_PAIR_FLAG)
{
ptr_color_palette = gui_color_palette_get (num_color & GUI_COLOR_PAIR_MASK);
if (ptr_color_palette && ptr_color_palette->alias)
return ptr_color_palette->alias;
index_color = (index_color + 1) % 32;
color[index_color][0] = '\0';
snprintf (color[index_color], sizeof (color[index_color]),
"%d", num_color & 0xFFFF);
"%d", num_color & GUI_COLOR_PAIR_MASK);
return color[index_color];
}
@ -163,7 +233,7 @@ gui_color_build (int number, int foreground, int background)
gui_color[number]->string = malloc (4);
}
if (foreground & 0x10000)
if (foreground & GUI_COLOR_PAIR_FLAG)
{
gui_color[number]->foreground = foreground;
gui_color[number]->background = 0;
@ -171,7 +241,7 @@ gui_color_build (int number, int foreground, int background)
}
else
{
if (background & 0x10000)
if (background & GUI_COLOR_PAIR_FLAG)
background = 0;
gui_color[number]->foreground = gui_weechat_colors[foreground].foreground;
gui_color[number]->background = gui_weechat_colors[background].foreground;
@ -200,6 +270,9 @@ gui_color_get_pair (int num_color)
fg = gui_color[num_color]->foreground;
bg = gui_color[num_color]->background;
if ((fg > 0) && (fg & GUI_COLOR_PAIR_FLAG))
return fg & GUI_COLOR_PAIR_MASK;
if (((fg == -1) || (fg == 99))
&& ((bg == -1) || (bg == 99)))
return gui_color_last_pair;
@ -211,6 +284,34 @@ gui_color_get_pair (int num_color)
return (bg * gui_color_num_bg) + fg + 1;
}
/*
* gui_color_init_pair: init a color pair
*/
void
gui_color_init_pair (int number)
{
struct t_gui_color_palette *ptr_color_palette;
int fg, bg;
if ((number >= 1) && (number <= COLOR_PAIRS - 1))
{
ptr_color_palette = gui_color_palette_get (number);
if (ptr_color_palette)
{
init_pair (number,
ptr_color_palette->foreground,
ptr_color_palette->background);
}
else
{
fg = (number - 1) % gui_color_num_bg;
bg = ((number - 1) < gui_color_num_bg) ? -1 : (number - 1) / gui_color_num_bg;
init_pair (number, fg, bg);
}
}
}
/*
* gui_color_init_pairs: init color pairs
*/
@ -218,7 +319,8 @@ gui_color_get_pair (int num_color)
void
gui_color_init_pairs ()
{
int i, fg, bg, num_colors;
int i, num_colors;
struct t_gui_color_palette *ptr_color_palette;
/*
* depending on terminal and $TERM value, we can have for example:
@ -235,23 +337,29 @@ gui_color_init_pairs ()
{
gui_color_num_bg = (COLOR_PAIRS >= 256) ? 16 : 8;
num_colors = (COLOR_PAIRS >= 256) ? 256 : COLOR_PAIRS;
for (i = 1; i < num_colors; i++)
{
fg = (i - 1) % gui_color_num_bg;
bg = ((i - 1) < gui_color_num_bg) ? -1 : (i - 1) / gui_color_num_bg;
init_pair (i, fg, bg);
}
gui_color_last_pair = num_colors - 1;
/* WeeChat pairs */
for (i = 1; i < num_colors; i++)
{
gui_color_init_pair (i);
}
/* disable white on white, replaced by black on white */
init_pair (gui_color_last_pair, -1, -1);
ptr_color_palette = gui_color_palette_get (gui_color_last_pair);
if (!ptr_color_palette)
init_pair (gui_color_last_pair, -1, -1);
/*
* white on default bg is default (-1) (for terminals with white/light
* background)
*/
if (!CONFIG_BOOLEAN(config_look_color_real_white))
init_pair (COLOR_WHITE + 1, -1, -1);
{
ptr_color_palette = gui_color_palette_get (COLOR_WHITE);
if (!ptr_color_palette)
init_pair (COLOR_WHITE + 1, -1, -1);
}
}
}
@ -395,6 +503,167 @@ gui_color_display_terminal_colors ()
printf ("\n");
}
/*
* gui_color_palette_add_alias_cb: add an alias in hashtable with aliases
*/
void
gui_color_palette_add_alias_cb (void *data,
struct t_hashtable *hashtable,
const void *key, const void *value)
{
struct t_gui_color_palette *color_palette;
char *error;
int number;
/* make C compiler happy */
(void) data;
(void) hashtable;
color_palette = (struct t_gui_color_palette *)value;
if (color_palette && color_palette->alias)
{
error = NULL;
number = (int)strtol ((char *)key, &error, 10);
if (error && !error[0])
{
hashtable_set (gui_color_hash_palette_alias,
color_palette->alias,
&number);
}
weelist_add (gui_color_list_with_alias, color_palette->alias,
WEECHAT_LIST_POS_END, NULL);
}
}
/*
* gui_color_palette_build_aliases: build aliases for palette
*/
void
gui_color_palette_build_aliases ()
{
int i;
hashtable_remove_all (gui_color_hash_palette_alias);
weelist_remove_all (gui_color_list_with_alias);
for (i = 0; i < GUI_CURSES_NUM_WEECHAT_COLORS; i++)
{
weelist_add (gui_color_list_with_alias,
gui_weechat_colors[i].string,
WEECHAT_LIST_POS_END,
NULL);
}
hashtable_map (gui_color_hash_palette_color,
&gui_color_palette_add_alias_cb, NULL);
}
/*
* gui_color_palette_new: create a new color in palette
*/
struct t_gui_color_palette *
gui_color_palette_new (int number, const char *value)
{
struct t_gui_color_palette *new_color_palette;
char **items, *pos, *pos2, *error1, *error2, *error3, str_number[64];
int num_items, fg, bg, r, g, b;
if (!value)
return NULL;
new_color_palette = malloc (sizeof (*new_color_palette));
if (new_color_palette)
{
new_color_palette->alias = NULL;
new_color_palette->foreground = number;
new_color_palette->background = -1;
new_color_palette->r = -1;
new_color_palette->g = -1;
new_color_palette->b = -1;
items = string_split (value, ";", 0, 0, &num_items);
if (items)
{
if ((num_items >= 1) && items[0][0])
{
new_color_palette->alias = strdup (items[0]);
}
if ((num_items >= 2) && items[1][0])
{
pos = strchr (items[1], ',');
if (pos)
{
pos[0] = '\0';
error1 = NULL;
fg = (int)strtol (items[1], &error1, 10);
error2 = NULL;
bg = (int)strtol (pos + 1, &error2, 10);
if (error1 && !error1[0] && error2 && !error2[0]
&& (fg >= -1) && (bg >= -1))
{
new_color_palette->foreground = fg;
new_color_palette->background = bg;
}
}
}
if ((num_items >= 3) && items[2][0])
{
pos = strchr (items[2], '/');
if (pos)
{
pos[0] = '\0';
pos2 = strchr (pos + 1, '/');
if (pos2)
{
pos2[0] = '\0';
error1 = NULL;
r = (int)strtol (items[2], &error1, 10);
error2 = NULL;
g = (int)strtol (pos + 1, &error2, 10);
error3 = NULL;
b = (int)strtol (pos2 + 1, &error3, 10);
if (error1 && !error1[0] && error2 && !error2[0]
&& error3 && !error3[0]
&& (r >= 0) && (r <= 1000)
&& (g >= 0) && (g <= 1000)
&& (b >= 0) && (b <= 1000))
{
new_color_palette->r = r;
new_color_palette->g = g;
new_color_palette->b = b;
}
}
}
}
string_free_split (items);
}
if (!new_color_palette->alias)
{
snprintf (str_number, sizeof (str_number), "%d", number);
new_color_palette->alias = strdup (str_number);
}
}
return new_color_palette;
}
/*
* gui_color_palette_free: free a color in palette
*/
void
gui_color_palette_free (struct t_gui_color_palette *color_palette)
{
if (!color_palette)
return;
if (color_palette->alias)
free (color_palette->alias);
free (color_palette);
}
/*
* gui_color_end: end GUI colors
*/

View File

@ -235,9 +235,9 @@ gui_window_reset_style (WINDOW *window, int num_color)
window_current_style_attr = 0;
window_current_color_attr = 0;
wattroff (window, A_BOLD | A_UNDERLINE | A_REVERSE);
wattron (window, COLOR_PAIR(gui_color_get_pair (num_color)) |
gui_color[num_color]->attributes);
wattroff (window, A_BOLD | A_UNDERLINE | A_REVERSE);
}
/*
@ -297,9 +297,9 @@ gui_window_set_weechat_color (WINDOW *window, int num_color)
gui_window_reset_style (window, num_color);
wattron (window, gui_color[num_color]->attributes);
if ((gui_color[num_color]->foreground > 0)
&& (gui_color[num_color]->foreground & 0x10000))
&& (gui_color[num_color]->foreground & GUI_COLOR_PAIR_FLAG))
{
wattron (window, COLOR_PAIR(gui_color[num_color]->foreground & 0xFFFF));
wattron (window, COLOR_PAIR(gui_color[num_color]->foreground & GUI_COLOR_PAIR_MASK));
}
else
{
@ -354,15 +354,22 @@ void
gui_window_set_custom_color_fg (WINDOW *window, int fg)
{
int current_bg;
if ((fg >= 0) && (fg < GUI_CURSES_NUM_WEECHAT_COLORS))
if (fg >= 0)
{
current_bg = window_current_style_bg;
gui_window_remove_color_style (window, A_BOLD);
gui_window_set_color_style (window, gui_weechat_colors[fg].attributes);
gui_window_set_color (window,
gui_weechat_colors[fg].foreground,
current_bg);
if (fg & GUI_COLOR_PAIR_FLAG)
{
gui_window_set_custom_color_pair (window, fg & GUI_COLOR_PAIR_MASK);
}
else if (fg < GUI_CURSES_NUM_WEECHAT_COLORS)
{
current_bg = window_current_style_bg;
gui_window_remove_color_style (window, A_BOLD);
gui_window_set_color_style (window, gui_weechat_colors[fg].attributes);
gui_window_set_color (window,
gui_weechat_colors[fg].foreground,
current_bg);
}
}
}
@ -376,14 +383,21 @@ gui_window_set_custom_color_bg (WINDOW *window, int bg)
{
int current_attr, current_fg;
if ((bg >= 0) && (bg < GUI_CURSES_NUM_WEECHAT_COLORS))
if (bg >= 0)
{
current_attr = window_current_style_attr;
current_fg = window_current_style_fg;
gui_window_set_color_style (window, current_attr);
gui_window_set_color (window, current_fg,
(gui_color_num_bg > 8) ?
gui_weechat_colors[bg].background : gui_weechat_colors[bg].foreground);
if (bg & GUI_COLOR_PAIR_FLAG)
{
gui_window_set_custom_color_pair (window, bg & GUI_COLOR_PAIR_MASK);
}
else if (bg < GUI_CURSES_NUM_WEECHAT_COLORS)
{
current_attr = window_current_style_attr;
current_fg = window_current_style_fg;
gui_window_set_color_style (window, current_attr);
gui_window_set_color (window, current_fg,
(gui_color_num_bg > 8) ?
gui_weechat_colors[bg].background : gui_weechat_colors[bg].foreground);
}
}
}

View File

@ -101,6 +101,26 @@ gui_color_assign (int *color, const char *color_name)
return 0;
}
/*
* gui_color_assign_by_diff: assign color by difference
* It is called when a color option is
* set with value ++X or --X, to search
* another color (for example ++1 is
* next color/alias in list)
* return 1 if ok, 0 if error
*/
int
gui_color_assign_by_diff (int *color, const char *color_name, int diff)
{
/* TODO: write this function for Gtk */
(void) color;
(void) color_name;
(void) diff;
return 1;
}
/*
* gui_color_get_number: get number of available colors
*/
@ -147,6 +167,17 @@ gui_color_get_pair (int num_color)
return (bg * 8) + fg;
}
/*
* gui_color_init_pair: init a color pair
*/
void
gui_color_init_pair (int number)
{
/* This function does nothing in Gtk GUI */
(void) number;
}
/*
* gui_color_init_pairs: init color pairs
*/
@ -227,6 +258,41 @@ gui_color_display_terminal_colors ()
/* This function does nothing in Gtk GUI */
}
/*
* gui_color_palette_build_aliases: build aliases for palette
*/
void
gui_color_palette_build_aliases ()
{
/* This function does nothing in Gtk GUI */
}
/*
* gui_color_palette_new: create a new color in palette
*/
struct t_gui_color_palette *
gui_color_palette_new (int number, const char *value)
{
/* This function does nothing in Gtk GUI */
(void) number;
(void) value;
return NULL;
}
/*
* gui_color_palette_free: free a color in palette
*/
void
gui_color_palette_free (struct t_gui_color_palette *color_palette)
{
/* This function does nothing in Gtk GUI */
(void) color_palette;
}
/*
* gui_color_end: end GUI colors
*/

View File

@ -377,16 +377,38 @@ gui_bar_item_get_value (const char *name, struct t_gui_bar *bar,
bar_color[0] = '\0';
if (prefix || suffix)
{
snprintf (delimiter_color, sizeof (delimiter_color),
"%c%c%02d",
GUI_COLOR_COLOR_CHAR,
GUI_COLOR_FG_CHAR,
CONFIG_COLOR(bar->options[GUI_BAR_OPTION_COLOR_DELIM]));
snprintf (bar_color, sizeof (bar_color),
"%c%c%02d",
GUI_COLOR_COLOR_CHAR,
GUI_COLOR_FG_CHAR,
CONFIG_COLOR(bar->options[GUI_BAR_OPTION_COLOR_FG]));
if (CONFIG_COLOR(bar->options[GUI_BAR_OPTION_COLOR_DELIM]) & GUI_COLOR_PAIR_FLAG)
{
snprintf (delimiter_color, sizeof (delimiter_color),
"%c%c%05d",
GUI_COLOR_COLOR_CHAR,
GUI_COLOR_PAIR_CHAR,
CONFIG_COLOR(bar->options[GUI_BAR_OPTION_COLOR_DELIM]) & GUI_COLOR_PAIR_MASK);
}
else
{
snprintf (delimiter_color, sizeof (delimiter_color),
"%c%c%02d",
GUI_COLOR_COLOR_CHAR,
GUI_COLOR_FG_CHAR,
CONFIG_COLOR(bar->options[GUI_BAR_OPTION_COLOR_DELIM]));
}
if (CONFIG_COLOR(bar->options[GUI_BAR_OPTION_COLOR_FG]) & GUI_COLOR_PAIR_FLAG)
{
snprintf (bar_color, sizeof (bar_color),
"%c%c%05d",
GUI_COLOR_COLOR_CHAR,
GUI_COLOR_PAIR_CHAR,
CONFIG_COLOR(bar->options[GUI_BAR_OPTION_COLOR_FG]) & GUI_COLOR_PAIR_MASK);
}
else
{
snprintf (bar_color, sizeof (bar_color),
"%c%c%02d",
GUI_COLOR_COLOR_CHAR,
GUI_COLOR_FG_CHAR,
CONFIG_COLOR(bar->options[GUI_BAR_OPTION_COLOR_FG]));
}
}
snprintf (result, length,
"%s%s%s%s%s%s",

View File

@ -36,13 +36,22 @@
#include "../core/weechat.h"
#include "../core/wee-config.h"
#include "../core/wee-hashtable.h"
#include "../core/wee-list.h"
#include "../core/wee-string.h"
#include "../core/wee-utf8.h"
#include "../plugins/plugin.h"
#include "gui-color.h"
#include "gui-window.h"
struct t_gui_color *gui_color[GUI_COLOR_NUM_COLORS]; /* GUI colors */
/* palette colors and aliases */
struct t_hashtable *gui_color_hash_palette_color = NULL;
struct t_hashtable *gui_color_hash_palette_alias = NULL;
struct t_weelist *gui_color_list_with_alias = NULL;
/*
* gui_color_search_config: search a color with configuration option name
@ -52,27 +61,21 @@ struct t_gui_color *gui_color[GUI_COLOR_NUM_COLORS]; /* GUI colors */
const char *
gui_color_search_config (const char *color_name)
{
struct t_config_section *ptr_section;
struct t_config_option *ptr_option;
if (color_name)
{
ptr_section = config_file_search_section (weechat_config_file,
"color");
if (ptr_section)
for (ptr_option = weechat_config_section_color->options;
ptr_option; ptr_option = ptr_option->next_option)
{
for (ptr_option = ptr_section->options; ptr_option;
ptr_option = ptr_option->next_option)
if (string_strcasecmp (ptr_option->name, color_name) == 0)
{
if (string_strcasecmp (ptr_option->name, color_name) == 0)
if (ptr_option->min < 0)
{
if (ptr_option->min < 0)
{
return gui_color_get_custom (
gui_color_get_name (CONFIG_COLOR(ptr_option)));
}
return GUI_COLOR(ptr_option->min);
return gui_color_get_custom (
gui_color_get_name (CONFIG_COLOR(ptr_option)));
}
return GUI_COLOR(ptr_option->min);
}
}
}
@ -189,9 +192,8 @@ gui_color_get_custom (const char *color_name)
else
{
/* custom color name (GUI dependent) */
error = NULL;
pair = (int)strtol (color_name, &error, 10);
if (error && !error[0])
pair = gui_color_palette_get_alias (color_name);
if (pair >= 0)
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s%05d",
@ -201,61 +203,74 @@ gui_color_get_custom (const char *color_name)
}
else
{
pos_comma = strchr (color_name, ',');
if (pos_comma)
error = NULL;
pair = (int)strtol (color_name, &error, 10);
if (error && !error[0])
{
if (pos_comma == color_name)
str_fg = NULL;
else
str_fg = string_strndup (color_name, pos_comma - color_name);
pos_bg = pos_comma + 1;
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s%05d",
GUI_COLOR_COLOR_STR,
GUI_COLOR_PAIR_STR,
pair);
}
else
{
str_fg = strdup (color_name);
pos_bg = NULL;
}
if (str_fg && pos_bg)
{
fg = gui_color_search (str_fg);
bg = gui_color_search (pos_bg);
if ((fg >= 0) && (bg >= 0))
pos_comma = strchr (color_name, ',');
if (pos_comma)
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s%02d,%02d",
GUI_COLOR_COLOR_STR,
GUI_COLOR_FG_BG_STR,
fg, bg);
if (pos_comma == color_name)
str_fg = NULL;
else
str_fg = string_strndup (color_name, pos_comma - color_name);
pos_bg = pos_comma + 1;
}
}
else if (str_fg && !pos_bg)
{
fg = gui_color_search (str_fg);
if (fg >= 0)
else
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s%02d",
GUI_COLOR_COLOR_STR,
GUI_COLOR_FG_STR,
fg);
str_fg = strdup (color_name);
pos_bg = NULL;
}
}
else if (!str_fg && pos_bg)
{
bg = gui_color_search (pos_bg);
if (bg >= 0)
if (str_fg && pos_bg)
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s%02d",
GUI_COLOR_COLOR_STR,
GUI_COLOR_BG_STR,
bg);
fg = gui_color_search (str_fg);
bg = gui_color_search (pos_bg);
if ((fg >= 0) && (bg >= 0))
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s%02d,%02d",
GUI_COLOR_COLOR_STR,
GUI_COLOR_FG_BG_STR,
fg, bg);
}
}
else if (str_fg && !pos_bg)
{
fg = gui_color_search (str_fg);
if (fg >= 0)
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s%02d",
GUI_COLOR_COLOR_STR,
GUI_COLOR_FG_STR,
fg);
}
}
else if (!str_fg && pos_bg)
{
bg = gui_color_search (pos_bg);
if (bg >= 0)
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s%02d",
GUI_COLOR_COLOR_STR,
GUI_COLOR_BG_STR,
bg);
}
}
if (str_fg)
free (str_fg);
}
if (str_fg)
free (str_fg);
}
}
@ -463,3 +478,144 @@ gui_color_free (struct t_gui_color *color)
free (color);
}
}
/*
* gui_color_palette_alloc: allocate hashtables and lists for palette
*/
void
gui_color_palette_alloc ()
{
if (!gui_color_hash_palette_color)
{
gui_color_hash_palette_color = hashtable_new (16,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_POINTER,
NULL,
NULL);
}
if (!gui_color_hash_palette_alias)
{
gui_color_hash_palette_alias = hashtable_new (16,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_INTEGER,
NULL,
NULL);
}
if (!gui_color_list_with_alias)
{
gui_color_list_with_alias = weelist_new ();
}
}
/*
* gui_color_palette_get_alias: get color pair number with alias
* return -1 if alias is not found
*/
int
gui_color_palette_get_alias (const char *alias)
{
int *ptr_number;
if (gui_color_hash_palette_alias)
{
ptr_number = hashtable_get (gui_color_hash_palette_alias, alias);
if (ptr_number)
return *ptr_number;
}
/* alias not found */
return -1;
}
/*
* gui_color_palette_get: get a color palette with number
*/
struct t_gui_color_palette *
gui_color_palette_get (int number)
{
char str_number[64];
snprintf (str_number, sizeof (str_number), "%d", number);
return hashtable_get (gui_color_hash_palette_color,
str_number);
}
/*
* gui_color_palette_add: add a color in palette
*/
void
gui_color_palette_add (int number, const char *value)
{
struct t_gui_color_palette *new_color_palette, *ptr_color_palette;
char str_number[64];
gui_color_palette_alloc ();
new_color_palette = gui_color_palette_new (number, value);
if (!new_color_palette)
return;
snprintf (str_number, sizeof (str_number), "%d", number);
ptr_color_palette = hashtable_get (gui_color_hash_palette_color,
str_number);
if (ptr_color_palette)
gui_color_palette_free (ptr_color_palette);
hashtable_set (gui_color_hash_palette_color,
str_number, new_color_palette);
gui_color_palette_build_aliases ();
if (gui_init_ok)
gui_color_init_pair (number);
}
/*
* gui_color_palette_remove: remove a color in palette
*/
void
gui_color_palette_remove (int number)
{
struct t_gui_color_palette *ptr_color_palette;
char str_number[64];
gui_color_palette_alloc ();
snprintf (str_number, sizeof (str_number), "%d", number);
ptr_color_palette = hashtable_get (gui_color_hash_palette_color,
str_number);
if (ptr_color_palette)
{
gui_color_palette_free (ptr_color_palette);
hashtable_remove (gui_color_hash_palette_color, str_number);
gui_color_palette_build_aliases ();
if (gui_init_ok)
gui_color_init_pair (number);
}
}
/*
* gui_color_palette_change: change a color in palette
*/
void
gui_color_palette_change (int number, const char *value)
{
struct t_gui_color_palette *ptr_color_palette;
char str_number[64];
gui_color_palette_alloc ();
snprintf (str_number, sizeof (str_number), "%d", number);
ptr_color_palette = hashtable_get (gui_color_hash_palette_color,
str_number);
if (ptr_color_palette)
{
gui_color_palette_free (ptr_color_palette);
hashtable_remove (gui_color_hash_palette_color, str_number);
gui_color_palette_add (number, value);
}
}

View File

@ -114,6 +114,9 @@ enum t_gui_color_enum
#define GUI_COLOR_BAR_MOVE_CURSOR_CHAR '#'
#define GUI_COLOR_BAR_MOVE_CURSOR_STR "#"
#define GUI_COLOR_PAIR_FLAG 0x10000
#define GUI_COLOR_PAIR_MASK 0xFFFF
/* color structure */
struct t_gui_color
@ -124,9 +127,22 @@ struct t_gui_color
char *string; /* WeeChat color: "\x19??", ?? is #color*/
};
/* custom color in palette */
struct t_gui_color_palette
{
char *alias; /* alias name for this color pair */
int foreground; /* foreground color */
int background; /* background color */
int r, g, b; /* red/green/blue values for color */
};
/* color variables */
extern struct t_gui_color *gui_color[];
extern struct t_hashtable *gui_color_hash_palette_color;
extern struct t_hashtable *gui_color_hash_palette_alias;
extern struct t_weelist *gui_color_list_with_alias;
/* color functions */
@ -135,15 +151,27 @@ extern const char *gui_color_get_custom (const char *color_name);
extern char *gui_color_decode (const char *string, const char *replacement);
extern char *gui_color_string_replace_colors (const char *string);
extern void gui_color_free (struct t_gui_color *color);
extern int gui_color_palette_get_alias (const char *alias);
extern struct t_gui_color_palette *gui_color_palette_get (int number);
extern void gui_color_palette_add (int number, const char *value);
extern void gui_color_palette_remove (int number);
extern void gui_color_palette_change (int number, const char *value);
/* color functions (GUI dependent) */
extern int gui_color_search (const char *color_name);
extern int gui_color_assign (int *color, char const *color_name);
extern int gui_color_assign_by_diff (int *color, const char *color_name,
int diff);
extern int gui_color_get_number ();
extern const char *gui_color_get_name (int num_color);
extern void gui_color_init_pair (int number);
extern void gui_color_init_pairs ();
extern void gui_color_init_weechat ();
extern void gui_color_display_terminal_colors ();
extern void gui_color_palette_build_aliases ();
extern struct t_gui_color_palette *gui_color_palette_new (int number,
const char *value);
extern void gui_color_palette_free (struct t_gui_color_palette *color_palette);
#endif /* __WEECHAT_GUI_COLOR_H */

View File

@ -511,7 +511,9 @@ plugin_load (const char *filename)
new_plugin->list_new = &weelist_new;
new_plugin->list_add = &weelist_add;
new_plugin->list_search = &weelist_search;
new_plugin->list_search_pos = &weelist_search_pos;
new_plugin->list_casesearch = &weelist_casesearch;
new_plugin->list_casesearch_pos = &weelist_casesearch_pos;
new_plugin->list_get = &weelist_get;
new_plugin->list_set = &weelist_set;
new_plugin->list_next = &weelist_next;

View File

@ -816,6 +816,41 @@ weechat_lua_api_list_search (lua_State *L)
LUA_RETURN_STRING_FREE(result);
}
/*
* weechat_lua_api_list_search_pos: search position of a string in list
*/
static int
weechat_lua_api_list_search_pos (lua_State *L)
{
const char *weelist, *data;
int n, pos;
/* make C compiler happy */
(void) L;
if (!lua_current_script || !lua_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(LUA_CURRENT_SCRIPT_NAME, "list_search_pos");
LUA_RETURN_INT(-1);
}
n = lua_gettop (lua_current_interpreter);
if (n < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, "list_search_pos");
LUA_RETURN_INT(-1);
}
weelist = lua_tostring (lua_current_interpreter, -2);
data = lua_tostring (lua_current_interpreter, -1);
pos = weechat_list_search_pos (script_str2ptr (weelist), data);
LUA_RETURN_INT(pos);
}
/*
* weechat_lua_api_list_casesearch: search a string in list (ignore case)
*/
@ -853,6 +888,42 @@ weechat_lua_api_list_casesearch (lua_State *L)
LUA_RETURN_STRING_FREE(result);
}
/*
* weechat_lua_api_list_casesearch_pos: search position of a string in list
* (ignore case)
*/
static int
weechat_lua_api_list_casesearch_pos (lua_State *L)
{
const char *weelist, *data;
int n, pos;
/* make C compiler happy */
(void) L;
if (!lua_current_script || !lua_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(LUA_CURRENT_SCRIPT_NAME, "list_casesearch_pos");
LUA_RETURN_INT(-1);
}
n = lua_gettop (lua_current_interpreter);
if (n < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, "list_casesearch_pos");
LUA_RETURN_INT(-1);
}
weelist = lua_tostring (lua_current_interpreter, -2);
data = lua_tostring (lua_current_interpreter, -1);
pos = weechat_list_casesearch_pos (script_str2ptr (weelist), data);
LUA_RETURN_INT(pos);
}
/*
* weechat_lua_api_list_get: get item by position
*/
@ -7612,7 +7683,9 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
{ "list_new", &weechat_lua_api_list_new },
{ "list_add", &weechat_lua_api_list_add },
{ "list_search", &weechat_lua_api_list_search },
{ "list_search_pos", &weechat_lua_api_list_search_pos },
{ "list_casesearch", &weechat_lua_api_list_casesearch },
{ "list_casesearch_pos", &weechat_lua_api_list_casesearch_pos },
{ "list_get", &weechat_lua_api_list_get },
{ "list_set", &weechat_lua_api_list_set },
{ "list_next", &weechat_lua_api_list_next },

View File

@ -728,6 +728,39 @@ XS (XS_weechat_api_list_search)
PERL_RETURN_STRING_FREE(result);
}
/*
* weechat::list_search_pos: search position of a string in list
*/
XS (XS_weechat_api_list_search_pos)
{
char *weelist, *data;
int pos;
dXSARGS;
/* make C compiler happy */
(void) cv;
if (!perl_current_script || !perl_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(PERL_CURRENT_SCRIPT_NAME, "list_search_pos");
PERL_RETURN_INT(-1);
}
if (items < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PERL_CURRENT_SCRIPT_NAME, "list_search_pos");
PERL_RETURN_INT(-1);
}
weelist = SvPV (ST (0), PL_na);
data = SvPV (ST (1), PL_na);
pos = weechat_list_search_pos (script_str2ptr (weelist), data);
PERL_RETURN_INT(pos);
}
/*
* weechat::list_casesearch: search a string in list (ignore case)
*/
@ -761,6 +794,40 @@ XS (XS_weechat_api_list_casesearch)
PERL_RETURN_STRING_FREE(result);
}
/*
* weechat::list_casesearch_pos: search position of a string in list
* (ignore case)
*/
XS (XS_weechat_api_list_casesearch_pos)
{
char *weelist, *data;
int pos;
dXSARGS;
/* make C compiler happy */
(void) cv;
if (!perl_current_script || !perl_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(PERL_CURRENT_SCRIPT_NAME, "list_casesearch_pos");
PERL_RETURN_INT(-1);
}
if (items < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PERL_CURRENT_SCRIPT_NAME, "list_casesearch_pos");
PERL_RETURN_INT(-1);
}
weelist = SvPV (ST (0), PL_na);
data = SvPV (ST (1), PL_na);
pos = weechat_list_casesearch_pos (script_str2ptr (weelist), data);
PERL_RETURN_INT(pos);
}
/*
* weechat::list_get: get item by position
*/
@ -6553,7 +6620,9 @@ weechat_perl_api_init (pTHX)
newXS ("weechat::list_new", XS_weechat_api_list_new, "weechat");
newXS ("weechat::list_add", XS_weechat_api_list_add, "weechat");
newXS ("weechat::list_search", XS_weechat_api_list_search, "weechat");
newXS ("weechat::list_search_pos", XS_weechat_api_list_search_pos, "weechat");
newXS ("weechat::list_casesearch", XS_weechat_api_list_casesearch, "weechat");
newXS ("weechat::list_casesearch_pos", XS_weechat_api_list_casesearch_pos, "weechat");
newXS ("weechat::list_get", XS_weechat_api_list_get, "weechat");
newXS ("weechat::list_set", XS_weechat_api_list_set, "weechat");
newXS ("weechat::list_next", XS_weechat_api_list_next, "weechat");

View File

@ -768,6 +768,39 @@ weechat_python_api_list_search (PyObject *self, PyObject *args)
PYTHON_RETURN_STRING_FREE(result);
}
/*
* weechat_python_api_list_search_pos: search position of a string in list
*/
static PyObject *
weechat_python_api_list_search_pos (PyObject *self, PyObject *args)
{
char *weelist, *data;
int pos;
/* make C compiler happy */
(void) self;
if (!python_current_script || !python_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "list_search_pos");
PYTHON_RETURN_INT(-1);
}
weelist = NULL;
data = NULL;
if (!PyArg_ParseTuple (args, "ss", &weelist, &data))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "list_search_pos");
PYTHON_RETURN_INT(-1);
}
pos = weechat_list_search_pos (script_str2ptr (weelist), data);
PYTHON_RETURN_INT(pos);
}
/*
* weechat_python_api_list_casesearch: search a string in list (ignore case)
*/
@ -802,6 +835,40 @@ weechat_python_api_list_casesearch (PyObject *self, PyObject *args)
PYTHON_RETURN_STRING_FREE(result);
}
/*
* weechat_python_api_list_casesearch_pos: search position of a string in list
* (ignore case)
*/
static PyObject *
weechat_python_api_list_casesearch_pos (PyObject *self, PyObject *args)
{
char *weelist, *data;
int pos;
/* make C compiler happy */
(void) self;
if (!python_current_script || !python_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "list_casesearch_pos");
PYTHON_RETURN_INT(-1);
}
weelist = NULL;
data = NULL;
if (!PyArg_ParseTuple (args, "ss", &weelist, &data))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "list_casesearch_pos");
PYTHON_RETURN_INT(-1);
}
pos = weechat_list_casesearch_pos (script_str2ptr (weelist), data);
PYTHON_RETURN_INT(pos);
}
/*
* weechat_python_api_list_get: get item by position
*/
@ -6886,7 +6953,9 @@ PyMethodDef weechat_python_funcs[] =
{ "list_new", &weechat_python_api_list_new, METH_VARARGS, "" },
{ "list_add", &weechat_python_api_list_add, METH_VARARGS, "" },
{ "list_search", &weechat_python_api_list_search, METH_VARARGS, "" },
{ "list_search_pos", &weechat_python_api_list_search_pos, METH_VARARGS, "" },
{ "list_casesearch", &weechat_python_api_list_casesearch, METH_VARARGS, "" },
{ "list_casesearch_pos", &weechat_python_api_list_casesearch_pos, METH_VARARGS, "" },
{ "list_get", &weechat_python_api_list_get, METH_VARARGS, "" },
{ "list_set", &weechat_python_api_list_set, METH_VARARGS, "" },
{ "list_next", &weechat_python_api_list_next, METH_VARARGS, "" },

View File

@ -830,6 +830,42 @@ weechat_ruby_api_list_search (VALUE class, VALUE weelist, VALUE data)
RUBY_RETURN_STRING(result);
}
/*
* weechat_ruby_api_list_search_pos: search position of a string in list
*/
static VALUE
weechat_ruby_api_list_search_pos (VALUE class, VALUE weelist, VALUE data)
{
char *c_weelist, *c_data;
int pos;
/* make C compiler happy */
(void) class;
if (!ruby_current_script || !ruby_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, "list_search_pos");
RUBY_RETURN_INT(-1);
}
if (NIL_P (weelist) || NIL_P (data))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, "list_search_pos");
RUBY_RETURN_INT(-1);
}
Check_Type (weelist, T_STRING);
Check_Type (data, T_STRING);
c_weelist = StringValuePtr (weelist);
c_data = StringValuePtr (data);
pos = weechat_list_search_pos (script_str2ptr(c_weelist), c_data);
RUBY_RETURN_INT(pos);
}
/*
* weechat_ruby_api_list_casesearch: search a string in list (ignore case)
*/
@ -866,6 +902,43 @@ weechat_ruby_api_list_casesearch (VALUE class, VALUE weelist, VALUE data)
RUBY_RETURN_STRING(result);
}
/*
* weechat_ruby_api_list_casesearch_pos: search position of a string in list
* (ignore case)
*/
static VALUE
weechat_ruby_api_list_casesearch_pos (VALUE class, VALUE weelist, VALUE data)
{
char *c_weelist, *c_data;
int pos;
/* make C compiler happy */
(void) class;
if (!ruby_current_script || !ruby_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, "list_casesearch_pos");
RUBY_RETURN_INT(-1);
}
if (NIL_P (weelist) || NIL_P (data))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, "list_casesearch_pos");
RUBY_RETURN_INT(-1);
}
Check_Type (weelist, T_STRING);
Check_Type (data, T_STRING);
c_weelist = StringValuePtr (weelist);
c_data = StringValuePtr (data);
pos = weechat_list_casesearch_pos (script_str2ptr(c_weelist), c_data);
RUBY_RETURN_INT(pos);
}
/*
* weechat_ruby_api_list_get: get item by position
*/
@ -7546,7 +7619,9 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
rb_define_module_function (ruby_mWeechat, "list_new", &weechat_ruby_api_list_new, 0);
rb_define_module_function (ruby_mWeechat, "list_add", &weechat_ruby_api_list_add, 4);
rb_define_module_function (ruby_mWeechat, "list_search", &weechat_ruby_api_list_search, 2);
rb_define_module_function (ruby_mWeechat, "list_search_pos", &weechat_ruby_api_list_search_pos, 2);
rb_define_module_function (ruby_mWeechat, "list_casesearch", &weechat_ruby_api_list_casesearch, 2);
rb_define_module_function (ruby_mWeechat, "list_casesearch_pos", &weechat_ruby_api_list_casesearch_pos, 2);
rb_define_module_function (ruby_mWeechat, "list_get", &weechat_ruby_api_list_get, 2);
rb_define_module_function (ruby_mWeechat, "list_set", &weechat_ruby_api_list_set, 2);
rb_define_module_function (ruby_mWeechat, "list_next", &weechat_ruby_api_list_next, 1);

View File

@ -931,6 +931,41 @@ weechat_tcl_api_list_search (ClientData clientData, Tcl_Interp *interp,
TCL_RETURN_STRING_FREE(result);
}
/*
* weechat_tcl_api_list_search_pos: search position of a string in list
*/
static int
weechat_tcl_api_list_search_pos (ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj* objp;
char *weelist, *data;
int i, pos;
/* make C compiler happy */
(void) clientData;
if (!tcl_current_script || !tcl_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(TCL_CURRENT_SCRIPT_NAME, "list_search_pos");
TCL_RETURN_INT(-1);
}
if (objc < 3)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "list_search_pos");
TCL_RETURN_INT(-1);
}
weelist = Tcl_GetStringFromObj (objv[1], &i);
data = Tcl_GetStringFromObj (objv[2], &i);
pos = weechat_list_search_pos (script_str2ptr (weelist), data);
TCL_RETURN_INT(pos);
}
/*
* weechat_tcl_api_list_casesearch: search a string in list (ignore case)
*/
@ -967,6 +1002,42 @@ weechat_tcl_api_list_casesearch (ClientData clientData, Tcl_Interp *interp,
TCL_RETURN_STRING_FREE(result);
}
/*
* weechat_tcl_api_list_casesearch_pos: search position of a string in list
* (ignore case)
*/
static int
weechat_tcl_api_list_casesearch_pos (ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj* objp;
char *weelist, *data;
int i, pos;
/* make C compiler happy */
(void) clientData;
if (!tcl_current_script || !tcl_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(TCL_CURRENT_SCRIPT_NAME, "list_casesearch_pos");
TCL_RETURN_INT(-1);
}
if (objc < 3)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "list_casesearch_pos");
TCL_RETURN_INT(-1);
}
weelist = Tcl_GetStringFromObj (objv[1], &i);
data = Tcl_GetStringFromObj (objv[2], &i);
pos = weechat_list_casesearch_pos (script_str2ptr (weelist), data);
TCL_RETURN_INT(pos);
}
/*
* weechat_tcl_api_list_get: get item by position
*/
@ -7405,8 +7476,12 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
weechat_tcl_api_list_add, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::list_search",
weechat_tcl_api_list_search, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::list_search_pos",
weechat_tcl_api_list_search_pos, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::list_casesearch",
weechat_tcl_api_list_casesearch, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::list_casesearch_pos",
weechat_tcl_api_list_casesearch_pos, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::list_get",
weechat_tcl_api_list_get, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::list_set",

View File

@ -45,7 +45,7 @@ struct timeval;
*/
/* API version (used to check that plugin has same API and can be loaded) */
#define WEECHAT_PLUGIN_API_VERSION "20101125-01"
#define WEECHAT_PLUGIN_API_VERSION "20101220-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@ -237,8 +237,12 @@ struct t_weechat_plugin
void *user_data);
struct t_weelist_item *(*list_search) (struct t_weelist *weelist,
const char *data);
int (*list_search_pos) (struct t_weelist *weelist,
const char *data);
struct t_weelist_item *(*list_casesearch) (struct t_weelist *weelist,
const char *data);
int (*list_casesearch_pos) (struct t_weelist *weelist,
const char *data);
struct t_weelist_item *(*list_get) (struct t_weelist *weelist,
int position);
void (*list_set) (struct t_weelist_item *item, const char *value);
@ -899,8 +903,12 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
weechat_plugin->list_add(__list, __string, __where, __user_data)
#define weechat_list_search(__list, __string) \
weechat_plugin->list_search(__list, __string)
#define weechat_list_search_pos(__list, __string) \
weechat_plugin->list_search_pos(__list, __string)
#define weechat_list_casesearch(__list, __string) \
weechat_plugin->list_casesearch(__list, __string)
#define weechat_list_casesearch_pos(__list, __string) \
weechat_plugin->list_casesearch_pos(__list, __string)
#define weechat_list_get(__list, __index) \
weechat_plugin->list_get(__list, __index)
#define weechat_list_set(__item, __value) \