summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2015-04-26 09:31:22 +0200
committerSébastien Helleu <flashcode@flashtux.org>2015-04-26 10:29:22 +0200
commit0f333ee63018169a7e4e85d469fb3fa9c9df0ab3 (patch)
tree2f452d457e125fce22e44a4e7f964dcd0debd5f7
parentccc6cdace144eebfc1459cf5722689e35374c859 (diff)
downloadweechat-0f333ee63018169a7e4e85d469fb3fa9c9df0ab3.zip
api: add support of full color option name in function color()
-rw-r--r--ChangeLog.asciidoc1
-rw-r--r--doc/en/weechat_plugin_api.en.asciidoc5
-rw-r--r--doc/fr/weechat_plugin_api.fr.asciidoc5
-rw-r--r--doc/it/weechat_plugin_api.it.asciidoc7
-rw-r--r--doc/ja/weechat_plugin_api.ja.asciidoc7
-rw-r--r--src/gui/gui-color.c62
6 files changed, 69 insertions, 18 deletions
diff --git a/ChangeLog.asciidoc b/ChangeLog.asciidoc
index 5c5ec4b37..cf2d2113b 100644
--- a/ChangeLog.asciidoc
+++ b/ChangeLog.asciidoc
@@ -32,6 +32,7 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]
* core: add option "-s" in command /eval to split expression before evaluating
it (no more split by default) (closes #324)
* core: add priority in plugins to initialize them in order
+* api: add support of full option name in function color()
* api: add "_chat_line" (line pointer) in hashtable of hook_focus
* irc: add support of SHA-256 and SHA-512 algorithms in server option
"ssl_fingerprint" (closes #281)
diff --git a/doc/en/weechat_plugin_api.en.asciidoc b/doc/en/weechat_plugin_api.en.asciidoc
index 5ef3e91d1..e40cf6e47 100644
--- a/doc/en/weechat_plugin_api.en.asciidoc
+++ b/doc/en/weechat_plugin_api.en.asciidoc
@@ -6491,7 +6491,10 @@ const char *weechat_color (const char *color_name);
Arguments:
* 'color_name': name of color, one of:
-** WeeChat option name (from weechat.color.xxx), for example 'chat_delimiters'
+** WeeChat color option name (from weechat.color.xxx), for example
+ 'chat_delimiters'
+** option name (format: file.section.option), for example
+ 'irc.color.message_quit' (_WeeChat ≥ 1.2_)
** color with optional attributes/background (see below)
** attribute:
*** 'bold': set bold
diff --git a/doc/fr/weechat_plugin_api.fr.asciidoc b/doc/fr/weechat_plugin_api.fr.asciidoc
index 3c1ea1e45..8fdc66e24 100644
--- a/doc/fr/weechat_plugin_api.fr.asciidoc
+++ b/doc/fr/weechat_plugin_api.fr.asciidoc
@@ -6587,7 +6587,10 @@ const char *weechat_color (const char *color_name);
Paramètres :
* 'color_name' : nom de la couleur, parmi :
-** une option WeeChat (de weechat.color.xxx), par exemple 'chat_delimiters'
+** le nom d'une option de couleur WeeChat (de weechat.color.xxx), par exemple
+ 'chat_delimiters'
+** le nom d'une option (format: fichier.section.option), par exemple
+ 'irc.color.message_quit' (_WeeChat ≥ 1.2_)
** une couleur avec des attributs/fond optionnels (voir ci-dessous)
** un attribut :
*** 'bold' : activer le gras
diff --git a/doc/it/weechat_plugin_api.it.asciidoc b/doc/it/weechat_plugin_api.it.asciidoc
index f3e223d4e..5f61b239a 100644
--- a/doc/it/weechat_plugin_api.it.asciidoc
+++ b/doc/it/weechat_plugin_api.it.asciidoc
@@ -6614,7 +6614,12 @@ const char *weechat_color (const char *color_name);
Argomenti:
* 'color_name': nome del colore, uno di:
-** nome opzione di WeeChat (da weechat.color.xxx), ad esempio 'chat_delimiters'
+// TRANSLATION MISSING
+** WeeChat color option name (from weechat.color.xxx), for example
+ 'chat_delimiters'
+// TRANSLATION MISSING
+** option name (format: file.section.option), for example
+ 'irc.color.message_quit' (_WeeChat ≥ 1.2_)
** colore con attributi/sfondo opzionali (vedi sotto)
** attributo:
*** 'bold': imposta grassetto
diff --git a/doc/ja/weechat_plugin_api.ja.asciidoc b/doc/ja/weechat_plugin_api.ja.asciidoc
index 90406fe81..2896d74cc 100644
--- a/doc/ja/weechat_plugin_api.ja.asciidoc
+++ b/doc/ja/weechat_plugin_api.ja.asciidoc
@@ -6492,7 +6492,12 @@ const char *weechat_color (const char *color_name);
引数:
* 'color_name': 色の名前、以下の中から 1 つ:
-** WeeChat オプション名 (weechat.color.xxx の xxx)、例えば 'chat_delimiters'
+// TRANSLATION MISSING
+** WeeChat color option name (from weechat.color.xxx), for example
+ 'chat_delimiters'
+// TRANSLATION MISSING
+** option name (format: file.section.option), for example
+ 'irc.color.message_quit' (_WeeChat ≥ 1.2_)
** 任意で属性や背景色を指定した色 (以下を参照)
** 属性:
*** 'bold': 太字を有効
diff --git a/src/gui/gui-color.c b/src/gui/gui-color.c
index 72f324592..5b8792ac9 100644
--- a/src/gui/gui-color.c
+++ b/src/gui/gui-color.c
@@ -113,6 +113,37 @@ char *gui_color_ansi[16] =
/*
+ * Returns a color code from an option, which can be a color or a string.
+ *
+ * Returns NULL if the option has a wrong type.
+ */
+
+const char *
+gui_color_from_option (struct t_config_option *option)
+{
+ if (!option)
+ return NULL;
+
+ switch (option->type)
+ {
+ case CONFIG_OPTION_TYPE_COLOR:
+ if (option->min < 0)
+ {
+ return gui_color_get_custom (
+ gui_color_get_name (CONFIG_COLOR(option)));
+ }
+ return GUI_COLOR(option->min);
+ case CONFIG_OPTION_TYPE_STRING:
+ return gui_color_get_custom (CONFIG_STRING(option));
+ default:
+ return NULL;
+ }
+
+ /* never executed */
+ return NULL;
+}
+
+/*
* Searches for a color with configuration option name.
*
* Returns color string, NULL if not found.
@@ -123,21 +154,24 @@ gui_color_search_config (const char *color_name)
{
struct t_config_option *ptr_option;
- if (color_name)
+ if (!color_name)
+ return NULL;
+
+ /* search in weechat.conf colors (example: "chat_delimiters") */
+ for (ptr_option = weechat_config_section_color->options;
+ ptr_option; ptr_option = ptr_option->next_option)
{
- for (ptr_option = weechat_config_section_color->options;
- ptr_option; ptr_option = ptr_option->next_option)
- {
- if (string_strcasecmp (ptr_option->name, color_name) == 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);
- }
- }
+ if (string_strcasecmp (ptr_option->name, color_name) == 0)
+ return gui_color_from_option (ptr_option);
+ }
+
+ /* search in any configuration file (example: "irc.color.message_quit") */
+ if (strchr (color_name, '.'))
+ {
+ config_file_search_with_string (color_name, NULL, NULL, &ptr_option,
+ NULL);
+ if (ptr_option)
+ return gui_color_from_option (ptr_option);
}
/* color not found */