From d322389e0437f5ce68e6b7301d36068214f3db32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sun, 26 Apr 2015 10:28:59 +0200 Subject: [PATCH] core: add support of full color option name in command /eval and API function string_eval_expression() --- ChangeLog.asciidoc | 4 +++- doc/en/weechat_plugin_api.en.asciidoc | 3 ++- doc/fr/weechat_plugin_api.fr.asciidoc | 3 ++- doc/it/weechat_plugin_api.it.asciidoc | 3 ++- doc/ja/weechat_plugin_api.ja.asciidoc | 4 +++- src/core/wee-eval.c | 3 +++ src/gui/gui-color.h | 3 +++ tests/unit/core/test-eval.cpp | 17 +++++++++++++++++ 8 files changed, 35 insertions(+), 5 deletions(-) diff --git a/ChangeLog.asciidoc b/ChangeLog.asciidoc index cf2d2113b..90f423ce9 100644 --- a/ChangeLog.asciidoc +++ b/ChangeLog.asciidoc @@ -19,6 +19,7 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] === New features +* core: add support of full color option name in command /eval * core: use environment variable WEECHAT_HOME on startup (closes #391) * core: remove WeeChat version from config files (closes #407) * core: add options weechat.look.quote_{nick_prefix|nick_suffix|time_format} to @@ -32,7 +33,8 @@ 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 support of full color option name in functions color() and + string_eval_expression() * 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 e40cf6e47..5718a4dc6 100644 --- a/doc/en/weechat_plugin_api.en.asciidoc +++ b/doc/en/weechat_plugin_api.en.asciidoc @@ -1922,7 +1922,8 @@ expanded to last): `test` | `${color:name}` | - WeeChat color code (the name of color has optional attributes) | + WeeChat color code (the name of color has optional attributes), + see function <<_color,weechat_color>> for supported formats | `${color:red}red text` + `${color:*214}bold orange text` | `red text` (in red) + diff --git a/doc/fr/weechat_plugin_api.fr.asciidoc b/doc/fr/weechat_plugin_api.fr.asciidoc index 8fdc66e24..71aac857b 100644 --- a/doc/fr/weechat_plugin_api.fr.asciidoc +++ b/doc/fr/weechat_plugin_api.fr.asciidoc @@ -1962,7 +1962,8 @@ première étendue à la dernière) : `test` | `${color:nom}` | - Code couleur WeeChat (le nom de couleur a des attributs facultatifs) | + Code couleur WeeChat (le nom de couleur a des attributs facultatifs), + voir la fonction <<_color,weechat_color>> pour les formats supportés | `${color:red}texte rouge` + `${color:*214}texte orange gras` | `texte rouge` (en rouge) + diff --git a/doc/it/weechat_plugin_api.it.asciidoc b/doc/it/weechat_plugin_api.it.asciidoc index 5f61b239a..63a746e09 100644 --- a/doc/it/weechat_plugin_api.it.asciidoc +++ b/doc/it/weechat_plugin_api.it.asciidoc @@ -1990,7 +1990,8 @@ expanded to last): `test` | `${color:name}` | - WeeChat color code (the name of color has optional attributes) | + WeeChat color code (the name of color has optional attributes), + see function <<_color,weechat_color>> for supported formats | `${color:red}red text` + `${color:*214}bold orange text` | `red text` (in red) + diff --git a/doc/ja/weechat_plugin_api.ja.asciidoc b/doc/ja/weechat_plugin_api.ja.asciidoc index 2896d74cc..5857713cd 100644 --- a/doc/ja/weechat_plugin_api.ja.asciidoc +++ b/doc/ja/weechat_plugin_api.ja.asciidoc @@ -1922,8 +1922,10 @@ char *weechat_string_eval_expression (const char *expr, `${re:1}` | `test` +// TRANSLATION MISSING | `${color:name}` | - WeeChat 色コード (色名部分はオプション属性をとることも可能です) | + WeeChat 色コード (色名部分はオプション属性をとることも可能です), + see function <<_color,weechat_color>> for supported formats | `${color:red}red text` + `${color:*214}bold orange text` | `red text` (赤色で) + diff --git a/src/core/wee-eval.c b/src/core/wee-eval.c index 346d16c11..acf03aa89 100644 --- a/src/core/wee-eval.c +++ b/src/core/wee-eval.c @@ -325,6 +325,9 @@ eval_replace_vars_cb (void *data, const char *text) /* 5. color code */ if (strncmp (text, "color:", 6) == 0) { + ptr_value = gui_color_search_config (text + 6); + if (ptr_value) + return strdup (ptr_value); ptr_value = gui_color_get_custom (text + 6); return strdup ((ptr_value) ? ptr_value : ""); } diff --git a/src/gui/gui-color.h b/src/gui/gui-color.h index f8682385b..b67d2876d 100644 --- a/src/gui/gui-color.h +++ b/src/gui/gui-color.h @@ -22,6 +22,8 @@ #include +struct t_config_option; + /* * Color from configuration options. * When changing some colors below: @@ -173,6 +175,7 @@ extern struct t_weelist *gui_color_list_with_alias; /* color functions */ +extern const char *gui_color_from_option (struct t_config_option *option); extern const char *gui_color_search_config (const char *color_name); extern int gui_color_attr_get_flag (char c); extern void gui_color_attr_build_string (int color, char *str_attr); diff --git a/tests/unit/core/test-eval.cpp b/tests/unit/core/test-eval.cpp index 185d17231..39deb4e0c 100644 --- a/tests/unit/core/test-eval.cpp +++ b/tests/unit/core/test-eval.cpp @@ -27,6 +27,7 @@ extern "C" #include #include "src/core/wee-eval.h" #include "src/core/wee-config.h" +#include "src/core/wee-config-file.h" #include "src/core/wee-hashtable.h" #include "src/core/wee-string.h" #include "src/core/wee-version.h" @@ -38,6 +39,7 @@ extern "C" value = eval_expression (__expr, pointers, extra_vars, options); \ STRCMP_EQUAL(__result, value); \ free (value); + TEST_GROUP(Eval) { }; @@ -171,6 +173,7 @@ TEST(Eval, EvalCondition) TEST(Eval, EvalExpression) { struct t_hashtable *pointers, *extra_vars, *options; + struct t_config_option *ptr_option; char *value, str_value[256]; pointers = NULL; @@ -209,6 +212,20 @@ TEST(Eval, EvalExpression) /* test color */ WEE_CHECK_EVAL(gui_color_get_custom ("green"), "${color:green}"); WEE_CHECK_EVAL(gui_color_get_custom ("*214"), "${color:*214}"); + snprintf (str_value, sizeof (str_value), + "%s-test-", + gui_color_from_option (config_color_chat_delimiters)); + WEE_CHECK_EVAL(str_value, "${color:chat_delimiters}-test-"); + config_file_search_with_string ("irc.color.message_join", NULL, NULL, + &ptr_option, NULL); + if (!ptr_option) + { + FAIL("ERROR: option irc.color.message_join not found."); + } + snprintf (str_value, sizeof (str_value), + "%s-test-", gui_color_from_option (ptr_option)); + WEE_CHECK_EVAL(str_value, "${color:irc.color.message_join}-test-"); + WEE_CHECK_EVAL("test", "${option.not.found}test"); /* test info */ WEE_CHECK_EVAL(version_get_version (), "${info:version}");