diff --git a/ChangeLog.adoc b/ChangeLog.adoc index afb33ed26..32fbfc6d1 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -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) diff --git a/doc/de/includes/autogen_api_infos.de.adoc b/doc/de/includes/autogen_api_infos.de.adoc index 7b125e77c..d85f90b6a 100644 --- a/doc/de/includes/autogen_api_infos.de.adoc +++ b/doc/de/includes/autogen_api_infos.de.adoc @@ -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) | - diff --git a/doc/en/includes/autogen_api_infos.en.adoc b/doc/en/includes/autogen_api_infos.en.adoc index e8a926693..6d8015437 100644 --- a/doc/en/includes/autogen_api_infos.en.adoc +++ b/doc/en/includes/autogen_api_infos.en.adoc @@ -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) | - diff --git a/doc/fr/includes/autogen_api_infos.fr.adoc b/doc/fr/includes/autogen_api_infos.fr.adoc index 3d1077b6a..7ca361116 100644 --- a/doc/fr/includes/autogen_api_infos.fr.adoc +++ b/doc/fr/includes/autogen_api_infos.fr.adoc @@ -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 | - diff --git a/doc/it/includes/autogen_api_infos.it.adoc b/doc/it/includes/autogen_api_infos.it.adoc index 1878e2276..39c99079f 100644 --- a/doc/it/includes/autogen_api_infos.it.adoc +++ b/doc/it/includes/autogen_api_infos.it.adoc @@ -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) | - diff --git a/doc/ja/includes/autogen_api_infos.ja.adoc b/doc/ja/includes/autogen_api_infos.ja.adoc index 4cc6389dd..900f8d1f4 100644 --- a/doc/ja/includes/autogen_api_infos.ja.adoc +++ b/doc/ja/includes/autogen_api_infos.ja.adoc @@ -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) | - diff --git a/doc/pl/includes/autogen_api_infos.pl.adoc b/doc/pl/includes/autogen_api_infos.pl.adoc index 74de8a42d..87726354e 100644 --- a/doc/pl/includes/autogen_api_infos.pl.adoc +++ b/doc/pl/includes/autogen_api_infos.pl.adoc @@ -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) | - diff --git a/po/cs.po b/po/cs.po index 307352f42..93e9e0e0e 100644 --- a/po/cs.po +++ b/po/cs.po @@ -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 \n" "Language-Team: weechat-dev \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" diff --git a/po/de.po b/po/de.po index 7809c2bc8..4b060a79a 100644 --- a/po/de.po +++ b/po/de.po @@ -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 \n" "Language-Team: German \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" diff --git a/po/es.po b/po/es.po index 4ab5336f9..452206b0a 100644 --- a/po/es.po +++ b/po/es.po @@ -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 \n" "Language-Team: weechat-dev \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" diff --git a/po/fr.po b/po/fr.po index 9a8ad96c1..6fb8af641 100644 --- a/po/fr.po +++ b/po/fr.po @@ -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 \n" "Language-Team: weechat-dev \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" diff --git a/po/hu.po b/po/hu.po index 4b496064a..883e9d6fc 100644 --- a/po/hu.po +++ b/po/hu.po @@ -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 \n" "Language-Team: weechat-dev \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" diff --git a/po/it.po b/po/it.po index 248ad1759..2a06562a7 100644 --- a/po/it.po +++ b/po/it.po @@ -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 \n" "Language-Team: weechat-dev \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" diff --git a/po/ja.po b/po/ja.po index d2ddb59dd..e95eb88fe 100644 --- a/po/ja.po +++ b/po/ja.po @@ -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 \n" "Language-Team: Japanese \n" "Language-Team: Polish \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" diff --git a/po/pt.po b/po/pt.po index 6a4c5688a..2da9637ba 100644 --- a/po/pt.po +++ b/po/pt.po @@ -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 \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" diff --git a/po/pt_BR.po b/po/pt_BR.po index 0e4506d92..f2ef652e1 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -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 \n" "Language-Team: weechat-dev \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" diff --git a/po/ru.po b/po/ru.po index 9576439f6..912de4a38 100644 --- a/po/ru.po +++ b/po/ru.po @@ -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 \n" "Language-Team: weechat-dev \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 "цвет чата" diff --git a/po/tr.po b/po/tr.po index 970e6297a..19eb88ebe 100644 --- a/po/tr.po +++ b/po/tr.po @@ -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 \n" "Language-Team: weechat-dev \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" diff --git a/po/weechat.pot b/po/weechat.pot index 2d592e3e5..950a4914d 100644 --- a/po/weechat.pot +++ b/po/weechat.pot @@ -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 \n" "Language-Team: weechat-dev \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 "" diff --git a/src/gui/gui-nick.c b/src/gui/gui-nick.c index db1f825c8..bcf26b119 100644 --- a/src/gui/gui-nick.c +++ b/src/gui/gui-nick.c @@ -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; } diff --git a/src/gui/gui-nick.h b/src/gui/gui-nick.h index 560c03549..ff8bb6a29 100644 --- a/src/gui/gui-nick.h +++ b/src/gui/gui-nick.h @@ -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 */ diff --git a/src/plugins/plugin-api-info.c b/src/plugins/plugin-api-info.c index 429ceafd7..b37fcc44e 100644 --- a/src/plugins/plugin-api-info.c +++ b/src/plugins/plugin-api-info.c @@ -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\")"), diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index e2ba4cec2..8a6f7c3b7 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -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) \ diff --git a/tests/unit/gui/test-gui-nick.cpp b/tests/unit/gui/test-gui-nick.cpp index 6423635e9..b275dfd7c 100644 --- a/tests/unit/gui/test-gui-nick.cpp +++ b/tests/unit/gui/test-gui-nick.cpp @@ -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); }