api: add optional list of colors in infos "nick_color" and "nick_color_name" (closes #1565)

This commit is contained in:
Sébastien Helleu 2020-10-04 08:45:03 +02:00
parent 657e659c42
commit f8403c76db
25 changed files with 288 additions and 133 deletions

View File

@ -20,6 +20,7 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]
New features::
* api: add optional list of colors in infos "nick_color" and "nick_color_name" (issue #1565)
* api: add argument "bytes" in function string_dyn_concat
* api: add function string_color_code_size (issue #1547)
* fset: add option fset.look.auto_refresh (issue #1553)

View File

@ -106,9 +106,9 @@
| weechat | locale | Spracheinstellung die für die übersetzten Nachrichten verwendet werden soll | -
| weechat | nick_color | zeigt Farbecode des Nick | Nickname
| weechat | nick_color | zeigt Farbecode des Nick | nickname;colors (colors is an optional comma-separated list of colors to use; background is allowed for a color with format text:background; if colors is present, WeeChat options with nick colors and forced nick colors are ignored)
| weechat | nick_color_name | zeigt Farbnamen des Nick | Nickname
| weechat | nick_color_name | zeigt Farbnamen des Nick | nickname;colors (colors is an optional comma-separated list of colors to use; background is allowed for a color with format text:background; if colors is present, WeeChat options with nick colors and forced nick colors are ignored)
| weechat | pid | WeeChat PID (Prozess-ID) | -

View File

@ -106,9 +106,9 @@
| weechat | locale | locale used for translating messages | -
| weechat | nick_color | get nick color code | nickname
| weechat | nick_color | get nick color code | nickname;colors (colors is an optional comma-separated list of colors to use; background is allowed for a color with format text:background; if colors is present, WeeChat options with nick colors and forced nick colors are ignored)
| weechat | nick_color_name | get nick color name | nickname
| weechat | nick_color_name | get nick color name | nickname;colors (colors is an optional comma-separated list of colors to use; background is allowed for a color with format text:background; if colors is present, WeeChat options with nick colors and forced nick colors are ignored)
| weechat | pid | WeeChat PID (process ID) | -

View File

@ -106,9 +106,9 @@
| weechat | locale | locale utilisée pour la traduction des messages | -
| weechat | nick_color | retourne le code couleur du pseudo | pseudo
| weechat | nick_color | retourne le code couleur du pseudo | pseudo;couleurs (couleurs est une liste de couleurs facultative, séparée par des virgules ; un fond est autorisé pour la couleur avec le format texte:fond ; si couleurs est présent, les options WeeChat avec les couleurs de pseudos et couleurs forcées de pseudos sons ignorées)
| weechat | nick_color_name | retourne le nom de la couleur du pseudo | pseudo
| weechat | nick_color_name | retourne le nom de la couleur du pseudo | pseudo;couleurs (couleurs est une liste de couleurs facultative, séparée par des virgules ; un fond est autorisé pour la couleur avec le format texte:fond ; si couleurs est présent, les options WeeChat avec les couleurs de pseudos et couleurs forcées de pseudos sons ignorées)
| weechat | pid | PID (ID de processus) de WeeChat | -

View File

@ -106,9 +106,9 @@
| weechat | locale | locale usato per la traduzione dei messaggi | -
| weechat | nick_color | ottiene il codice del colore del nick | nick
| weechat | nick_color | ottiene il codice del colore del nick | nickname;colors (colors is an optional comma-separated list of colors to use; background is allowed for a color with format text:background; if colors is present, WeeChat options with nick colors and forced nick colors are ignored)
| weechat | nick_color_name | ottiene il nome del colore del nick | nick
| weechat | nick_color_name | ottiene il nome del colore del nick | nickname;colors (colors is an optional comma-separated list of colors to use; background is allowed for a color with format text:background; if colors is present, WeeChat options with nick colors and forced nick colors are ignored)
| weechat | pid | WeeChat PID (process ID) | -

View File

@ -106,9 +106,9 @@
| weechat | locale | 翻訳メッセージに利用するロケール | -
| weechat | nick_color | ニックネームの色コードを取得 | ニックネーム
| weechat | nick_color | ニックネームの色コードを取得 | nickname;colors (colors is an optional comma-separated list of colors to use; background is allowed for a color with format text:background; if colors is present, WeeChat options with nick colors and forced nick colors are ignored)
| weechat | nick_color_name | ニックネームの色名を取得 | ニックネーム
| weechat | nick_color_name | ニックネームの色名を取得 | nickname;colors (colors is an optional comma-separated list of colors to use; background is allowed for a color with format text:background; if colors is present, WeeChat options with nick colors and forced nick colors are ignored)
| weechat | pid | WeeChat の PID (プロセス ID) | -

View File

@ -106,9 +106,9 @@
| weechat | locale | zestaw znaków użyty do tłumaczenia wiadomości | -
| weechat | nick_color | pobiera kod koloru nicka | nazwa użytkownika
| weechat | nick_color | pobiera kod koloru nicka | nickname;colors (colors is an optional comma-separated list of colors to use; background is allowed for a color with format text:background; if colors is present, WeeChat options with nick colors and forced nick colors are ignored)
| weechat | nick_color_name | pobiera nazwę koloru nicka | nazwa użytkownika
| weechat | nick_color_name | pobiera nazwę koloru nicka | nickname;colors (colors is an optional comma-separated list of colors to use; background is allowed for a color with format text:background; if colors is present, WeeChat options with nick colors and forced nick colors are ignored)
| weechat | pid | WeeChat PID (ID procesu) | -

View File

@ -21,7 +21,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2020-09-12 18:48+0200\n"
"POT-Creation-Date: 2020-10-04 08:26+0200\n"
"PO-Revision-Date: 2020-04-28 16:40+0200\n"
"Last-Translator: Ondřej Súkup <mimi.vx@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -10332,6 +10332,16 @@ msgstr "rgb,limit (limit je volitelný a nastaven na výchozí hodnotu 256)"
msgid "get nick color code"
msgstr "získat kód barvy přezdívky"
#, fuzzy
msgid ""
"nickname;colors (colors is an optional comma-separated list of colors to "
"use; background is allowed for a color with format text:background; if "
"colors is present, WeeChat options with nick colors and forced nick colors "
"are ignored)"
msgstr ""
"barva textu pro přezdívky (čárkou oddělený seznam barev, pozadí je povoleno "
"ve formátu: \"fg:bg\", například: \"lightred:blue\")"
msgid "get nick color name"
msgstr "získat jméno barvy přezdívky"

View File

@ -24,7 +24,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2020-09-12 18:48+0200\n"
"POT-Creation-Date: 2020-10-04 08:26+0200\n"
"PO-Revision-Date: 2020-09-08 13:14+0200\n"
"Last-Translator: Nils Görs <weechatter@arcor.de>\n"
"Language-Team: German <kde-i18n-de@kde.org>\n"
@ -12241,6 +12241,17 @@ msgstr "RGB,limit (Obergrenze ist optional und ist Standardmäßig 256)"
msgid "get nick color code"
msgstr "zeigt Farbecode des Nick"
#, fuzzy
msgid ""
"nickname;colors (colors is an optional comma-separated list of colors to "
"use; background is allowed for a color with format text:background; if "
"colors is present, WeeChat options with nick colors and forced nick colors "
"are ignored)"
msgstr ""
"Textfarbe für Nicks (durch Kommata getrennte Liste von Farben. Eine "
"Hintergrundfarbe kann durch das folgende Format genutzt werden: \"fg:bg\". "
"Zum Beispiel: \"lightred:blue\")"
msgid "get nick color name"
msgstr "zeigt Farbnamen des Nick"

View File

@ -22,7 +22,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2020-09-12 18:48+0200\n"
"POT-Creation-Date: 2020-10-04 08:26+0200\n"
"PO-Revision-Date: 2020-04-28 16:40+0200\n"
"Last-Translator: Elián Hanisch <lambdae2@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -10644,6 +10644,16 @@ msgstr ""
msgid "get nick color code"
msgstr "obtiene el código del color del apodo"
#, fuzzy
msgid ""
"nickname;colors (colors is an optional comma-separated list of colors to "
"use; background is allowed for a color with format text:background; if "
"colors is present, WeeChat options with nick colors and forced nick colors "
"are ignored)"
msgstr ""
"color para los apodos (lista de colores separadas por comas, color de fondo "
"es permitido siguiendo el formato \"fg:bg\", por ejemplo: \"lightred:blue\")"
msgid "get nick color name"
msgstr "obtiene el nombre del color del apodo"

View File

@ -21,8 +21,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2020-09-12 18:48+0200\n"
"PO-Revision-Date: 2020-09-12 18:49+0200\n"
"POT-Creation-Date: 2020-10-04 08:26+0200\n"
"PO-Revision-Date: 2020-10-04 08:27+0200\n"
"Last-Translator: Sébastien Helleu <flashcode@flashtux.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
"Language: fr\n"
@ -11967,6 +11967,17 @@ msgstr "rgb,limite (la limite est optionnelle et vaut 256 par défaut)"
msgid "get nick color code"
msgstr "retourne le code couleur du pseudo"
msgid ""
"nickname;colors (colors is an optional comma-separated list of colors to "
"use; background is allowed for a color with format text:background; if "
"colors is present, WeeChat options with nick colors and forced nick colors "
"are ignored)"
msgstr ""
"pseudo;couleurs (couleurs est une liste de couleurs facultative, séparée par "
"des virgules ; un fond est autorisé pour la couleur avec le format texte:"
"fond ; si couleurs est présent, les options WeeChat avec les couleurs de "
"pseudos et couleurs forcées de pseudos sons ignorées)"
msgid "get nick color name"
msgstr "retourne le nom de la couleur du pseudo"

View File

@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2020-09-12 18:48+0200\n"
"POT-Creation-Date: 2020-10-04 08:26+0200\n"
"PO-Revision-Date: 2020-04-28 16:40+0200\n"
"Last-Translator: Andras Voroskoi <voroskoi@frugalware.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -9686,6 +9686,14 @@ msgstr ""
msgid "get nick color code"
msgstr "üzenetek színe"
#, fuzzy
msgid ""
"nickname;colors (colors is an optional comma-separated list of colors to "
"use; background is allowed for a color with format text:background; if "
"colors is present, WeeChat options with nick colors and forced nick colors "
"are ignored)"
msgstr "idő színe a beszédablakban"
#, fuzzy
msgid "get nick color name"
msgstr "üzenetek színe"

View File

@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2020-09-12 18:48+0200\n"
"POT-Creation-Date: 2020-10-04 08:26+0200\n"
"PO-Revision-Date: 2020-04-28 16:40+0200\n"
"Last-Translator: Esteban I. Ruiz Moreno <exio4.com@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -10830,6 +10830,16 @@ msgstr ""
msgid "get nick color code"
msgstr "ottiene il codice del colore del nick"
#, fuzzy
msgid ""
"nickname;colors (colors is an optional comma-separated list of colors to "
"use; background is allowed for a color with format text:background; if "
"colors is present, WeeChat options with nick colors and forced nick colors "
"are ignored)"
msgstr ""
"colore del testo per i nick (elenco separato da virgole di colori, quello di "
"sfondo è consentito con il formato \"fg:bg\", ad esempio: \"lightred:blue\")"
msgid "get nick color name"
msgstr "ottiene il nome del colore del nick"

View File

@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2020-09-12 18:48+0200\n"
"POT-Creation-Date: 2020-10-04 08:26+0200\n"
"PO-Revision-Date: 2020-04-28 16:40+0200\n"
"Last-Translator: AYANOKOUZI, Ryuunosuke <i38w7i3@yahoo.co.jp>\n"
"Language-Team: Japanese <https://github.com/l/weechat/tree/master/"
@ -11465,6 +11465,16 @@ msgstr "rgb,limit (limit は任意でデフォルトでは 256 に設定)"
msgid "get nick color code"
msgstr "ニックネームの色コードを取得"
#, fuzzy
msgid ""
"nickname;colors (colors is an optional comma-separated list of colors to "
"use; background is allowed for a color with format text:background; if "
"colors is present, WeeChat options with nick colors and forced nick colors "
"are ignored)"
msgstr ""
"ニックネームのテキスト色 (コンマ区切りの色リスト、背景色は以下の書式で指定: "
"\"fg:bg\"、例: \"lightred:blue\")"
msgid "get nick color name"
msgstr "ニックネームの色名を取得"

View File

@ -22,7 +22,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2020-09-12 18:48+0200\n"
"POT-Creation-Date: 2020-10-04 08:26+0200\n"
"PO-Revision-Date: 2020-04-28 16:40+0200\n"
"Last-Translator: Krzysztof Korościk <soltys@soltys.info>\n"
"Language-Team: Polish <kde-i18n-doc@kde.org>\n"
@ -11679,6 +11679,16 @@ msgstr "rgb,limit (limit jest opcjonalny i ustawiony domyślnie na 256)"
msgid "get nick color code"
msgstr "pobiera kod koloru nicka"
#, fuzzy
msgid ""
"nickname;colors (colors is an optional comma-separated list of colors to "
"use; background is allowed for a color with format text:background; if "
"colors is present, WeeChat options with nick colors and forced nick colors "
"are ignored)"
msgstr ""
"kolor tekstu nicków (oddzielona przecinkami lista kolorów, tło jest "
"dozwolone za pomocą formatu: \"fg:bg\" na przykład: \"lightred:blue\")"
msgid "get nick color name"
msgstr "pobiera nazwę koloru nicka"

View File

@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2020-09-12 18:48+0200\n"
"POT-Creation-Date: 2020-10-04 08:26+0200\n"
"PO-Revision-Date: 2020-04-28 16:40+0200\n"
"Last-Translator: Vasco Almeida <vascomalmeida@sapo.pt>\n"
"Language-Team: Portuguese <>\n"
@ -11291,6 +11291,16 @@ msgstr "rgb,limite (o limite é opcional e está definido como 256 por omissão)
msgid "get nick color code"
msgstr "obter código de cor do nick"
#, fuzzy
msgid ""
"nickname;colors (colors is an optional comma-separated list of colors to "
"use; background is allowed for a color with format text:background; if "
"colors is present, WeeChat options with nick colors and forced nick colors "
"are ignored)"
msgstr ""
"cor do texto dos nicks (lista de cores separadas por vírgula, o fundo pode "
"ser indicado com o formato: \"texto:fundo\", por exemplo: \"lightred:blue\")"
msgid "get nick color name"
msgstr "obter nome da cor do nick"

View File

@ -21,7 +21,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2020-09-12 18:48+0200\n"
"POT-Creation-Date: 2020-10-04 08:26+0200\n"
"PO-Revision-Date: 2020-04-18 11:34+0200\n"
"Last-Translator: Eduardo Elias <camponez@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -10131,6 +10131,16 @@ msgstr ""
msgid "get nick color code"
msgstr "obter código de cor do apelido"
#, fuzzy
msgid ""
"nickname;colors (colors is an optional comma-separated list of colors to "
"use; background is allowed for a color with format text:background; if "
"colors is present, WeeChat options with nick colors and forced nick colors "
"are ignored)"
msgstr ""
"cor do texto para apelidos (lista de cores separada por vírgulas, fundo é "
"permitido com o formato: \"fg:bg\", por exemplo: \"lightred:blue\")"
msgid "get nick color name"
msgstr "obter nome da cor do apelido"

View File

@ -21,7 +21,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2020-09-12 18:48+0200\n"
"POT-Creation-Date: 2020-10-04 08:26+0200\n"
"PO-Revision-Date: 2020-04-28 16:40+0200\n"
"Last-Translator: Aleksey V Zapparov AKA ixti <ixti@member.fsf.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -9722,6 +9722,14 @@ msgstr ""
msgid "get nick color code"
msgstr "цвет чата"
#, fuzzy
msgid ""
"nickname;colors (colors is an optional comma-separated list of colors to "
"use; background is allowed for a color with format text:background; if "
"colors is present, WeeChat options with nick colors and forced nick colors "
"are ignored)"
msgstr "цвет времени в окне чата"
#, fuzzy
msgid "get nick color name"
msgstr "цвет чата"

View File

@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2020-09-12 18:48+0200\n"
"POT-Creation-Date: 2020-10-04 08:26+0200\n"
"PO-Revision-Date: 2019-11-03 08:38+0100\n"
"Last-Translator: Hasan Kiran <sunder67@hotmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -8842,6 +8842,13 @@ msgstr ""
msgid "get nick color code"
msgstr "rumuz renk kodu al"
msgid ""
"nickname;colors (colors is an optional comma-separated list of colors to "
"use; background is allowed for a color with format text:background; if "
"colors is present, WeeChat options with nick colors and forced nick colors "
"are ignored)"
msgstr ""
msgid "get nick color name"
msgstr "rumuz renk ismi al"

View File

@ -21,7 +21,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2020-09-12 18:48+0200\n"
"POT-Creation-Date: 2020-10-04 08:26+0200\n"
"PO-Revision-Date: 2014-08-16 10:27+0200\n"
"Last-Translator: Sébastien Helleu <flashcode@flashtux.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -8702,6 +8702,13 @@ msgstr ""
msgid "get nick color code"
msgstr ""
msgid ""
"nickname;colors (colors is an optional comma-separated list of colors to "
"use; background is allowed for a color with format text:background; if "
"colors is present, WeeChat options with nick colors and forced nick colors "
"are ignored)"
msgstr ""
msgid "get nick color name"
msgstr ""

View File

@ -242,97 +242,106 @@ gui_nick_strdup_for_color (const char *nickname)
}
/*
* Finds a color code for a nick (according to nick letters).
* Finds a color name for a nick (according to nick letters).
*
* Returns a WeeChat color code (that can be used for display).
* If colors is NULL (most common case), the color returned is either a forced
* color (from option "weechat.look.nick_color_force") or a color from option
* "weechat.color.chat_nick_colors".
*
* If colors is set and not empty, a color from this list is returned
* (format of argument: comma-separated list of colors, a background is
* allowed with format "fg:bg", for example: "blue,yellow:red" for blue and
* yellow on red).
*
* Returns the name of a color (for example: "green").
*
* Note: result must be freed after use.
*/
const char *
gui_nick_find_color (const char *nickname)
char *
gui_nick_find_color_name (const char *nickname, const char *colors)
{
int color;
char *nickname2;
const char *forced_color, *str_color;
int color, num_colors;
char *nickname2, **list_colors, *result;
const char *forced_color, *ptr_result;
static char *default_color = "default";
list_colors = NULL;
num_colors = 0;
nickname2 = NULL;
ptr_result = NULL;
if (!nickname || !nickname[0])
return gui_color_get_custom ("default");
goto end;
if (!config_nick_colors)
config_set_nick_colors ();
if (config_num_nick_colors == 0)
return gui_color_get_custom ("default");
if (colors && colors[0])
{
list_colors = string_split (colors, ",", NULL, 0, 0, &num_colors);
if (!list_colors || (num_colors == 0))
goto end;
}
nickname2 = gui_nick_strdup_for_color (nickname);
/* look if color is forced */
forced_color = gui_nick_get_forced_color (
(nickname2) ? nickname2 : nickname);
if (forced_color)
if (!list_colors)
{
forced_color = gui_color_get_custom (forced_color);
if (forced_color && forced_color[0])
/* look if color is forced for the nick */
forced_color = gui_nick_get_forced_color (
(nickname2) ? nickname2 : nickname);
if (forced_color)
{
if (nickname2)
free (nickname2);
return forced_color;
ptr_result = forced_color;
goto end;
}
/* ensure nick colors are properly set */
if (!config_nick_colors)
config_set_nick_colors ();
if (config_num_nick_colors == 0)
goto end;
}
/* hash nickname to get color */
color = gui_nick_hash_color ((nickname2) ? nickname2 : nickname,
config_num_nick_colors);
color = gui_nick_hash_color (
(nickname2) ? nickname2 : nickname,
(list_colors) ? num_colors : config_num_nick_colors);
ptr_result = (list_colors) ?
list_colors[color] : config_nick_colors[color];
end:
result = strdup ((ptr_result) ? ptr_result : default_color);
if (list_colors)
string_free_split (list_colors);
if (nickname2)
free (nickname2);
/* return color */
str_color = gui_color_get_custom (config_nick_colors[color]);
return (str_color[0]) ? str_color : gui_color_get_custom ("default");
return result;
}
/*
* Finds a color name for a nick (according to nick letters).
* Finds a color code for a nick (according to nick letters).
*
* Returns the name of a color (for example: "green").
* If colors is NULL (most common case), the color returned is either a forced
* color (from option "weechat.look.nick_color_force") or a color from option
* "weechat.color.chat_nick_colors".
*
* If colors is set and not empty, a color from this list is returned
* (format of argument: comma-separated list of colors, a background is
* allowed with format "fg:bg", for example: "blue,yellow:red" for blue and
* yellow on red).
*
* Returns a WeeChat color code (that can be used for display).
*
* Note: result must be freed after use.
*/
const char *
gui_nick_find_color_name (const char *nickname)
char *
gui_nick_find_color (const char *nickname, const char *colors)
{
int color;
char *nickname2;
const char *forced_color;
static char *default_color = "default";
char *color;
const char *ptr_result;
if (!nickname || !nickname[0])
return default_color;
if (!config_nick_colors)
config_set_nick_colors ();
if (config_num_nick_colors == 0)
return default_color;
nickname2 = gui_nick_strdup_for_color (nickname);
/* look if color is forced */
forced_color = gui_nick_get_forced_color (
(nickname2) ? nickname2 : nickname);
if (forced_color)
{
if (nickname2)
free (nickname2);
return forced_color;
}
/* hash nickname to get color */
color = gui_nick_hash_color ((nickname2) ? nickname2 : nickname,
config_num_nick_colors);
if (nickname2)
free (nickname2);
/* return color name */
return config_nick_colors[color];
color = gui_nick_find_color_name (nickname, colors);
ptr_result = gui_color_get_custom (color);
if (color)
free (color);
return (ptr_result) ? strdup (ptr_result) : NULL;
}

View File

@ -20,7 +20,9 @@
#ifndef WEECHAT_GUI_NICK_H
#define WEECHAT_GUI_NICK_H
extern const char *gui_nick_find_color (const char *nickname);
extern const char *gui_nick_find_color_name (const char *nickname);
extern char *gui_nick_find_color_name (const char *nickname,
const char *colors);
extern char *gui_nick_find_color (const char *nickname,
const char *colors);
#endif /* WEECHAT_GUI_NICK_H */

View File

@ -665,15 +665,24 @@ plugin_api_info_nick_color_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
const char *ptr_color;
char **items, *result;
int num_items;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) info_name;
ptr_color = gui_nick_find_color (arguments);
return (ptr_color) ? strdup (ptr_color) : NULL;
items = string_split (arguments, ";", NULL, 0, 2, &num_items);
result = gui_nick_find_color (
(num_items >= 1) ? items[0] : NULL,
(num_items >= 2) ? items[1] : NULL);
if (items)
string_free_split (items);
return result;
}
/*
@ -685,15 +694,24 @@ plugin_api_info_nick_color_name_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
const char *ptr_color;
char **items, *result;
int num_items;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) info_name;
ptr_color = gui_nick_find_color_name (arguments);
return (ptr_color) ? strdup (ptr_color) : NULL;
items = string_split (arguments, ";", NULL, 0, 2, &num_items);
result = gui_nick_find_color_name (
(num_items >= 1) ? items[0] : NULL,
(num_items >= 2) ? items[1] : NULL);
if (items)
string_free_split (items);
return result;
}
/*
@ -1835,11 +1853,19 @@ plugin_api_info_init ()
&plugin_api_info_color_rgb2term_cb, NULL, NULL);
hook_info (NULL, "nick_color",
N_("get nick color code"),
N_("nickname"),
N_("nickname;colors (colors is an optional comma-separated "
"list of colors to use; background is allowed for a color "
"with format text:background; if colors is present, WeeChat "
"options with nick colors and forced nick colors are "
"ignored)"),
&plugin_api_info_nick_color_cb, NULL, NULL);
hook_info (NULL, "nick_color_name",
N_("get nick color name"),
N_("nickname"),
N_("nickname;colors (colors is an optional comma-separated "
"list of colors to use; background is allowed for a color "
"with format text:background; if colors is present, WeeChat "
"options with nick colors and forced nick colors are "
"ignored)"),
&plugin_api_info_nick_color_name_cb, NULL, NULL);
hook_info (NULL, "uptime",
N_("WeeChat uptime (format: \"days:hh:mm:ss\")"),

View File

@ -67,7 +67,7 @@ struct timeval;
* please change the date with current one; for a second change at same
* date, increment the 01, otherwise please keep 01.
*/
#define WEECHAT_PLUGIN_API_VERSION "20200823-01"
#define WEECHAT_PLUGIN_API_VERSION "20201004-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \

View File

@ -61,6 +61,16 @@ extern char *gui_nick_strdup_for_color (const char *nickname);
if (nick) \
free (nick);
#define WEE_FIND_COLOR(__result, __nickname, __colors) \
color = gui_nick_find_color_name (__nickname, __colors); \
STRCMP_EQUAL(__result, color); \
free (color); \
result_color = gui_color_get_custom (__result); \
color = gui_nick_find_color (__nickname, __colors); \
STRCMP_EQUAL(result_color, color); \
free (color);
TEST_GROUP(GuiNick)
{
};
@ -341,50 +351,35 @@ TEST(GuiNick, StrdupForColor)
/*
* Tests functions:
* gui_nick_find_color
* gui_nick_find_color_name
*/
TEST(GuiNick, FindColor)
{
const char *color_default, *color_lightgreen, *color_brown;
const char *color_green, *color_cyan;
const char *result_color;
char *color;
color_default = gui_color_get_custom ("default");
color_lightgreen = gui_color_get_custom ("lightgreen");
color_brown = gui_color_get_custom ("brown");
color_green = gui_color_get_custom ("green");
color_cyan = gui_color_get_custom ("cyan");
WEE_FIND_COLOR("default", NULL, NULL);
WEE_FIND_COLOR("default", "", NULL);
STRCMP_EQUAL(color_default, gui_nick_find_color (NULL));
STRCMP_EQUAL(color_default, gui_nick_find_color (""));
STRCMP_EQUAL(color_lightgreen, gui_nick_find_color ("abcdef"));
STRCMP_EQUAL(color_brown, gui_nick_find_color ("abcdefghi"));
WEE_FIND_COLOR("lightgreen", "abcdef", NULL);
WEE_FIND_COLOR("brown", "abcdefghi", NULL);
/* with forced color */
config_file_option_set (config_look_nick_color_force,
"abcdef:green;abcdefghi:cyan", 1);
STRCMP_EQUAL(color_green, gui_nick_find_color ("abcdef"));
STRCMP_EQUAL(color_cyan, gui_nick_find_color ("abcdefghi"));
WEE_FIND_COLOR("green", "abcdef", NULL);
WEE_FIND_COLOR("cyan", "abcdefghi", NULL);
config_file_option_reset (config_look_nick_color_force, 1);
}
/*
* Tests functions:
* gui_nick_find_color_name
*/
/* with custom colors */
WEE_FIND_COLOR("yellow", "abcdef", "red,blue,yellow,magenta");
WEE_FIND_COLOR("blue", "abcdefghi", "red,blue,yellow,magenta");
TEST(GuiNick, FindColorName)
{
STRCMP_EQUAL("default", gui_nick_find_color_name (NULL));
STRCMP_EQUAL("default", gui_nick_find_color_name (""));
STRCMP_EQUAL("lightgreen", gui_nick_find_color_name ("abcdef"));
STRCMP_EQUAL("brown", gui_nick_find_color_name ("abcdefghi"));
/* with forced color */
/* with forced color and custom colors (forced color is ignored) */
config_file_option_set (config_look_nick_color_force,
"abcdef:green;abcdefghi:cyan", 1);
STRCMP_EQUAL("green", gui_nick_find_color_name ("abcdef"));
STRCMP_EQUAL("cyan", gui_nick_find_color_name ("abcdefghi"));
WEE_FIND_COLOR("yellow", "abcdef", "red,blue,yellow,magenta");
WEE_FIND_COLOR("blue", "abcdefghi", "red,blue,yellow,magenta");
config_file_option_reset (config_look_nick_color_force, 1);
}