1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-01 15:26:37 +02:00

api: add support of full color option name in function color()

This commit is contained in:
Sébastien Helleu
2015-04-26 09:31:22 +02:00
parent ccc6cdace1
commit 0f333ee630
6 changed files with 69 additions and 18 deletions
+48 -14
View File
@@ -112,6 +112,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.
*
@@ -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 */