1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-29 14:26:39 +02:00

core: add themable flag to configuration options

Add an "int themable" field on struct t_config_option. The flag is set
automatically for every CONFIG_OPTION_TYPE_COLOR option, and may be set
explicitly on any other type by suffixing the type argument with
"|themable" in the call to config_file_new_option (e.g. "string|themable"
for a string option whose value contains "${color:...}" references).

Opt in the relevant string options in core (buffer_time_format,
day_change_message_*, item_time_format, nick_color_force, prefix_*,
chat_nick_colors, eval_syntax_colors, color palette aliases) and in the
buflist, fset, irc, relay plugins.

The flag is exposed via hdata, infolist, and print_log so scripts and
/debug can read it. This is the foundation for an upcoming /theme
command that will only be allowed to modify themable options.
This commit is contained in:
Sébastien Helleu
2026-05-25 22:55:12 +02:00
parent b802681230
commit 25495b6188
7 changed files with 74 additions and 38 deletions
+38 -4
View File
@@ -648,6 +648,7 @@ config_file_option_malloc (void)
new_option->name = NULL;
new_option->parent_name = NULL;
new_option->type = 0;
new_option->themable = 0;
new_option->description = NULL;
new_option->string_values = NULL;
new_option->min = 0;
@@ -704,16 +705,37 @@ config_file_new_option (struct t_config_file *config_file,
void *callback_delete_data)
{
struct t_config_option *new_option;
int var_type, int_value, argc, i, index_value, number;
char *pos, *option_name, *parent_name;
int var_type, int_value, argc, i, index_value, number, themable;
char *pos, *option_name, *parent_name, *type_name;
const char *ptr_type;
new_option = NULL;
option_name = NULL;
parent_name = NULL;
type_name = NULL;
themable = 0;
if (!name || !type)
goto error;
/*
* extract optional "|themable" suffix from type
* (e.g.: "string|themable" for a string option that contains color names)
*/
pos = strchr (type, '|');
if (pos && (strcmp (pos, "|themable") == 0))
{
type_name = string_strndup (type, pos - type);
if (!type_name)
goto error;
ptr_type = type_name;
themable = 1;
}
else
{
ptr_type = type;
}
pos = strstr (name, " << ");
if (pos)
{
@@ -734,7 +756,7 @@ config_file_new_option (struct t_config_file *config_file,
var_type = -1;
for (i = 0; i < CONFIG_NUM_OPTION_TYPES; i++)
{
if (strcmp (type, config_option_type_string[i]) == 0)
if (strcmp (ptr_type, config_option_type_string[i]) == 0)
{
var_type = i;
break;
@@ -744,10 +766,14 @@ config_file_new_option (struct t_config_file *config_file,
{
gui_chat_printf (NULL, "%sUnknown option type \"%s\"",
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
type);
ptr_type);
goto error;
}
/* color options are always themable */
if (var_type == CONFIG_OPTION_TYPE_COLOR)
themable = 1;
/*
* compatibility with versions < 4.1.0: force enum type for an integer
* with string values
@@ -784,6 +810,7 @@ config_file_new_option (struct t_config_file *config_file,
goto error;
new_option->parent_name = (parent_name) ? strdup (parent_name) : NULL;
new_option->type = var_type;
new_option->themable = themable;
if (description)
{
new_option->description = strdup (description);
@@ -969,6 +996,7 @@ error:
end:
free (option_name);
free (parent_name);
free (type_name);
return new_option;
}
@@ -2438,6 +2466,8 @@ config_file_option_get_pointer (struct t_config_option *option,
return option->parent_name;
else if (strcmp (property, "type") == 0)
return &option->type;
else if (strcmp (property, "themable") == 0)
return &option->themable;
else if (strcmp (property, "description") == 0)
return option->description;
else if (strcmp (property, "string_values") == 0)
@@ -4247,6 +4277,7 @@ config_file_hdata_config_option_cb (const void *pointer, void *data,
HDATA_VAR(struct t_config_option, name, STRING, 0, NULL, NULL);
HDATA_VAR(struct t_config_option, parent_name, STRING, 0, NULL, NULL);
HDATA_VAR(struct t_config_option, type, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_config_option, themable, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_config_option, description, STRING, 0, NULL, NULL);
HDATA_VAR(struct t_config_option, string_values, STRING, 0, "*,*", NULL);
HDATA_VAR(struct t_config_option, min, INTEGER, 0, NULL, NULL);
@@ -4359,6 +4390,8 @@ config_file_add_option_to_infolist (struct t_infolist *infolist,
{
goto error;
}
if (!infolist_new_var_integer (ptr_item, "themable", option->themable))
goto error;
if (option->value)
{
value = config_file_option_value_to_string (option, 0, 0, 0);
@@ -4523,6 +4556,7 @@ config_file_print_log (void)
log_printf (" name . . . . . . . . . . . . : '%s'", ptr_option->name);
log_printf (" parent_name. . . . . . . . . : '%s'", ptr_option->parent_name);
log_printf (" type . . . . . . . . . . . . : %d", ptr_option->type);
log_printf (" themable . . . . . . . . . . : %d", ptr_option->themable);
log_printf (" description. . . . . . . . . : '%s'", ptr_option->description);
log_printf (" string_values. . . . . . . . : %p", ptr_option->string_values);
log_printf (" min. . . . . . . . . . . . . : %d", ptr_option->min);
+2
View File
@@ -154,6 +154,8 @@ struct t_config_option
char *parent_name; /* parent name (to inherit the */
/* value from another option) */
enum t_config_option_type type; /* type */
int themable; /* 1 if option is themable */
/* (color, or string with color) */
char *description; /* description */
char **string_values; /* allowed string values */
int min, max; /* min and max for value */
+13 -13
View File
@@ -3446,7 +3446,7 @@ config_weechat_init_options (void)
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
config_look_buffer_time_format = config_file_new_option (
weechat_config_file, weechat_config_section_look,
"buffer_time_format", "string",
"buffer_time_format", "string|themable",
/* TRANSLATORS: string "${color:xxx}" must NOT be translated */
N_("time format for each line displayed in buffers (see man "
"strftime for date/time specifiers, extra specifiers are "
@@ -3470,7 +3470,7 @@ config_weechat_init_options (void)
NULL, NULL, NULL);
config_look_buffer_time_same = config_file_new_option (
weechat_config_file, weechat_config_section_look,
"buffer_time_same", "string",
"buffer_time_same", "string|themable",
/* TRANSLATORS: string "${color:xxx}" must NOT be translated */
N_("time displayed for a message with same time as previous message: "
"use a space \" \" to hide time, another string to display this "
@@ -3637,7 +3637,7 @@ config_weechat_init_options (void)
NULL, NULL, NULL);
config_look_day_change_message_1date = config_file_new_option (
weechat_config_file, weechat_config_section_look,
"day_change_message_1date", "string",
"day_change_message_1date", "string|themable",
/* TRANSLATORS: string "${color:xxx}" must NOT be translated */
N_("message displayed when the day has changed, with one date "
"displayed (for example at beginning of buffer) (see man "
@@ -3650,7 +3650,7 @@ config_weechat_init_options (void)
NULL, NULL, NULL);
config_look_day_change_message_2dates = config_file_new_option (
weechat_config_file, weechat_config_section_look,
"day_change_message_2dates", "string",
"day_change_message_2dates", "string|themable",
/* TRANSLATORS: string "${color:xxx}" must NOT be translated */
N_("message displayed when the day has changed, with two dates "
"displayed (between two messages); the second date specifiers "
@@ -3967,7 +3967,7 @@ config_weechat_init_options (void)
NULL, NULL, NULL);
config_look_item_time_format = config_file_new_option (
weechat_config_file, weechat_config_section_look,
"item_time_format", "string",
"item_time_format", "string|themable",
N_("time format for \"time\" bar item (see man strftime for "
"date/time specifiers) (note: content is evaluated, so you can "
"use colors with format \"${color:xxx}\", see /help eval)"),
@@ -4022,7 +4022,7 @@ config_weechat_init_options (void)
NULL, NULL, NULL);
config_look_nick_color_force = config_file_new_option (
weechat_config_file, weechat_config_section_look,
"nick_color_force", "string",
"nick_color_force", "string|themable",
N_("force color for some nicks: hash computed with nickname "
"to find color will not be used for these nicks (format is: "
"\"nick1:color1;nick2:color2\"); look up for nicks is with "
@@ -4114,7 +4114,7 @@ config_weechat_init_options (void)
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
config_look_prefix[GUI_CHAT_PREFIX_ERROR] = config_file_new_option (
weechat_config_file, weechat_config_section_look,
"prefix_error", "string",
"prefix_error", "string|themable",
/* TRANSLATORS: string "${color:xxx}" must NOT be translated */
N_("prefix for error messages (note: content is evaluated, so you "
"can use colors with format \"${color:xxx}\", see /help eval)"),
@@ -4124,7 +4124,7 @@ config_weechat_init_options (void)
NULL, NULL, NULL);
config_look_prefix[GUI_CHAT_PREFIX_NETWORK] = config_file_new_option (
weechat_config_file, weechat_config_section_look,
"prefix_network", "string",
"prefix_network", "string|themable",
/* TRANSLATORS: string "${color:xxx}" must NOT be translated */
N_("prefix for network messages (note: content is evaluated, so you "
"can use colors with format \"${color:xxx}\", see /help eval)"),
@@ -4134,7 +4134,7 @@ config_weechat_init_options (void)
NULL, NULL, NULL);
config_look_prefix[GUI_CHAT_PREFIX_ACTION] = config_file_new_option (
weechat_config_file, weechat_config_section_look,
"prefix_action", "string",
"prefix_action", "string|themable",
/* TRANSLATORS: string "${color:xxx}" must NOT be translated */
N_("prefix for action messages (note: content is evaluated, so you "
"can use colors with format \"${color:xxx}\", see /help eval)"),
@@ -4144,7 +4144,7 @@ config_weechat_init_options (void)
NULL, NULL, NULL);
config_look_prefix[GUI_CHAT_PREFIX_JOIN] = config_file_new_option (
weechat_config_file, weechat_config_section_look,
"prefix_join", "string",
"prefix_join", "string|themable",
/* TRANSLATORS: string "${color:xxx}" must NOT be translated */
N_("prefix for join messages (note: content is evaluated, so you "
"can use colors with format \"${color:xxx}\", see /help eval)"),
@@ -4154,7 +4154,7 @@ config_weechat_init_options (void)
NULL, NULL, NULL);
config_look_prefix[GUI_CHAT_PREFIX_QUIT] = config_file_new_option (
weechat_config_file, weechat_config_section_look,
"prefix_quit", "string",
"prefix_quit", "string|themable",
/* TRANSLATORS: string "${color:xxx}" must NOT be translated */
N_("prefix for quit messages (note: content is evaluated, so you "
"can use colors with format \"${color:xxx}\", see /help eval)"),
@@ -4643,7 +4643,7 @@ config_weechat_init_options (void)
NULL, NULL, NULL);
config_color_chat_nick_colors = config_file_new_option (
weechat_config_file, weechat_config_section_color,
"chat_nick_colors", "string",
"chat_nick_colors", "string|themable",
/* TRANSLATORS: please do not translate "lightred:blue" */
N_("text color for nicks (comma separated list of colors, "
"background is allowed with format: \"fg:bg\", for example: "
@@ -4914,7 +4914,7 @@ config_weechat_init_options (void)
/* eval syntax highlighting colors (for "${raw_hl:xxx}" and "${hl:xxx}") */
config_color_eval_syntax_colors = config_file_new_option (
weechat_config_file, weechat_config_section_color,
"eval_syntax_colors", "string",
"eval_syntax_colors", "string|themable",
/* TRANSLATORS: please do not translate "lightred:blue" */
N_("text color for syntax highlighting in evaluated strings, "
"with \"${raw_hl:...}\" and \"${hl:...}\" (comma separated "
+15 -15
View File
@@ -645,7 +645,7 @@ buflist_config_init (void)
{
buflist_config_format_buffer = weechat_config_new_option (
buflist_config_file, buflist_config_section_format,
"buffer", "string",
"buffer", "string|themable",
N_("format of each line with a buffer "
"(note: content is evaluated, see /help buflist); "
"example: standard format for bar item \"buflist\" and only the "
@@ -663,7 +663,7 @@ buflist_config_init (void)
NULL, NULL, NULL);
buflist_config_format_buffer_current = weechat_config_new_option (
buflist_config_file, buflist_config_section_format,
"buffer_current", "string",
"buffer_current", "string|themable",
N_("format for the line with current buffer "
"(note: content is evaluated, see /help buflist)"),
NULL, 0, 0, "${color:,17}${format_buffer}", NULL, 0,
@@ -672,7 +672,7 @@ buflist_config_init (void)
NULL, NULL, NULL);
buflist_config_format_hotlist = weechat_config_new_option (
buflist_config_file, buflist_config_section_format,
"hotlist", "string",
"hotlist", "string|themable",
N_("format for hotlist "
"(note: content is evaluated, see /help buflist)"),
NULL, 0, 0,
@@ -683,7 +683,7 @@ buflist_config_init (void)
NULL, NULL, NULL);
buflist_config_format_hotlist_level[3] = weechat_config_new_option (
buflist_config_file, buflist_config_section_format,
"hotlist_highlight", "string",
"hotlist_highlight", "string|themable",
N_("format for a buffer with hotlist level \"highlight\" "
"(note: content is evaluated, see /help buflist)"),
NULL, 0, 0, "${color:magenta}", NULL, 0,
@@ -692,7 +692,7 @@ buflist_config_init (void)
NULL, NULL, NULL);
buflist_config_format_hotlist_level[0] = weechat_config_new_option (
buflist_config_file, buflist_config_section_format,
"hotlist_low", "string",
"hotlist_low", "string|themable",
N_("format for a buffer with hotlist level \"low\" "
"(note: content is evaluated, see /help buflist)"),
NULL, 0, 0, "${color:white}", NULL, 0,
@@ -701,7 +701,7 @@ buflist_config_init (void)
NULL, NULL, NULL);
buflist_config_format_hotlist_level[1] = weechat_config_new_option (
buflist_config_file, buflist_config_section_format,
"hotlist_message", "string",
"hotlist_message", "string|themable",
N_("format for a buffer with hotlist level \"message\" "
"(note: content is evaluated, see /help buflist)"),
NULL, 0, 0, "${color:brown}", NULL, 0,
@@ -710,7 +710,7 @@ buflist_config_init (void)
NULL, NULL, NULL);
buflist_config_format_hotlist_level_none = weechat_config_new_option (
buflist_config_file, buflist_config_section_format,
"hotlist_none", "string",
"hotlist_none", "string|themable",
N_("format for a buffer not in hotlist "
"(note: content is evaluated, see /help buflist)"),
NULL, 0, 0, "${color:default}", NULL, 0,
@@ -719,7 +719,7 @@ buflist_config_init (void)
NULL, NULL, NULL);
buflist_config_format_hotlist_level[2] = weechat_config_new_option (
buflist_config_file, buflist_config_section_format,
"hotlist_private", "string",
"hotlist_private", "string|themable",
N_("format for a buffer with hotlist level \"private\" "
"(note: content is evaluated, see /help buflist)"),
NULL, 0, 0, "${color:green}", NULL, 0,
@@ -728,7 +728,7 @@ buflist_config_init (void)
NULL, NULL, NULL);
buflist_config_format_hotlist_separator = weechat_config_new_option (
buflist_config_file, buflist_config_section_format,
"hotlist_separator", "string",
"hotlist_separator", "string|themable",
N_("separator for counts in hotlist "
"(note: content is evaluated, see /help buflist)"),
NULL, 0, 0, "${color:default},", NULL, 0,
@@ -737,7 +737,7 @@ buflist_config_init (void)
NULL, NULL, NULL);
buflist_config_format_indent = weechat_config_new_option (
buflist_config_file, buflist_config_section_format,
"indent", "string",
"indent", "string|themable",
N_("string displayed to indent channel, private and list buffers "
"(note: content is evaluated, see /help buflist)"),
NULL, 0, 0, " ", NULL, 0,
@@ -746,7 +746,7 @@ buflist_config_init (void)
NULL, NULL, NULL);
buflist_config_format_lag = weechat_config_new_option (
buflist_config_file, buflist_config_section_format,
"lag", "string",
"lag", "string|themable",
N_("format for lag on an IRC server buffer "
"(note: content is evaluated, see /help buflist)"),
NULL, 0, 0,
@@ -757,7 +757,7 @@ buflist_config_init (void)
NULL, NULL, NULL);
buflist_config_format_name = weechat_config_new_option (
buflist_config_file, buflist_config_section_format,
"name", "string",
"name", "string|themable",
N_("format for buffer name "
"(note: content is evaluated, see /help buflist)"),
NULL, 0, 0, "${name}", NULL, 0,
@@ -766,7 +766,7 @@ buflist_config_init (void)
NULL, NULL, NULL);
buflist_config_format_nick_prefix = weechat_config_new_option (
buflist_config_file, buflist_config_section_format,
"nick_prefix", "string",
"nick_prefix", "string|themable",
N_("format for nick prefix on a channel "
"(note: content is evaluated, see /help buflist)"),
NULL, 0, 0, "${color_nick_prefix}${nick_prefix}", NULL, 0,
@@ -775,7 +775,7 @@ buflist_config_init (void)
NULL, NULL, NULL);
buflist_config_format_number = weechat_config_new_option (
buflist_config_file, buflist_config_section_format,
"number", "string",
"number", "string|themable",
N_("format for buffer number, ${number} is the indented number "
"(note: content is evaluated, see /help buflist)"),
NULL, 0, 0,
@@ -786,7 +786,7 @@ buflist_config_init (void)
NULL, NULL, NULL);
buflist_config_format_tls_version = weechat_config_new_option (
buflist_config_file, buflist_config_section_format,
"tls_version", "string",
"tls_version", "string|themable",
N_("format for TLS version on an IRC server buffer "
"(note: content is evaluated, see /help buflist)"),
NULL, 0, 0,
+1 -1
View File
@@ -572,7 +572,7 @@ fset_config_init (void)
NULL, NULL, NULL);
fset_config_format_option[1] = weechat_config_new_option (
fset_config_file, fset_config_section_format,
"option2", "string",
"option2", "string|themable",
N_("second format of each line, used when option "
"fset.look.format_number is set to 2 "
"(note: content is evaluated, see /help fset); "
+3 -3
View File
@@ -3959,7 +3959,7 @@ irc_config_init (void)
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
irc_config_color_mirc_remap = weechat_config_new_option (
irc_config_file, irc_config_section_color,
"mirc_remap", "string",
"mirc_remap", "string|themable",
/* TRANSLATORS: please do not translate the list of WeeChat color names at the end of string */
N_("remap mirc colors in messages using a hashtable (used only "
"for standard colors, not RGB colors): keys are \"fg,bg\" as "
@@ -3977,7 +3977,7 @@ irc_config_init (void)
NULL, NULL, NULL);
irc_config_color_nick_prefixes = weechat_config_new_option (
irc_config_file, irc_config_section_color,
"nick_prefixes", "string",
"nick_prefixes", "string|themable",
N_("color for nick prefixes using mode char (o=op, h=halfop, "
"v=voice, ..), format is: \"o:color1;h:color2;v:color3\" (if a "
"mode is not found, WeeChat will try with next modes received "
@@ -4008,7 +4008,7 @@ irc_config_init (void)
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
irc_config_color_term_remap = weechat_config_new_option (
irc_config_file, irc_config_section_color,
"term_remap", "string",
"term_remap", "string|themable",
N_("remap terminal color numbers in messages using a hashtable "
"(used only for RGB colors as hexadecimal, which are first "
"translated to terminal color numbers): keys are \"fg,bg\" as "
+2 -2
View File
@@ -1909,7 +1909,7 @@ relay_config_init (void)
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
relay_config_api_remote_input_cmd_local = weechat_config_new_option (
relay_config_file, relay_config_section_api,
"remote_input_cmd_local", "string",
"remote_input_cmd_local", "string|themable",
N_("text displayed after user input when the command would be "
"executed locally (NOT sent to the remote WeeChat) "
"(note: content is evaluated, see /help eval)"),
@@ -1917,7 +1917,7 @@ relay_config_init (void)
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
relay_config_api_remote_input_cmd_remote = weechat_config_new_option (
relay_config_file, relay_config_section_api,
"remote_input_cmd_remote", "string",
"remote_input_cmd_remote", "string|themable",
N_("text displayed after user input when the command would be "
"executed on the remote WeeChat (NOT executed locally) "
"(note: content is evaluated, see /help eval)"),