1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-04 16:53:14 +02:00

fset: add variable allowed_values in options, add two color options

New options:

- fset.color.allowed_values
- fset.color.allowed_values_selected
This commit is contained in:
Sébastien Helleu
2023-07-08 16:50:42 +02:00
parent 4c0c7d9adc
commit 1d5433485c
23 changed files with 360 additions and 88 deletions
+25 -2
View File
@@ -625,7 +625,9 @@ fset_buffer_display_option_eval (struct t_fset_option *fset_option)
}
/* min */
snprintf (str_field, length_field, "%s", fset_option->min);
snprintf (str_field, length_field,
"%s",
(fset_option->min) ? fset_option->min : "");
weechat_hashtable_set (fset_buffer_hashtable_extra_vars,
"__min", str_field);
snprintf (str_field, length_field,
@@ -642,7 +644,9 @@ fset_buffer_display_option_eval (struct t_fset_option *fset_option)
"empty_min", str_field2);
/* max */
snprintf (str_field, length_field, "%s", fset_option->max);
snprintf (str_field, length_field,
"%s",
(fset_option->max) ? fset_option->max : "");
weechat_hashtable_set (fset_buffer_hashtable_extra_vars,
"__max", str_field);
snprintf (str_field, length_field,
@@ -744,6 +748,25 @@ fset_buffer_display_option_eval (struct t_fset_option *fset_option)
weechat_hashtable_set (fset_buffer_hashtable_extra_vars,
"empty_string_values", str_field2);
/* allowed_values */
snprintf (str_field, length_field,
"%s",
(fset_option->allowed_values) ? fset_option->allowed_values : "");
weechat_hashtable_set (fset_buffer_hashtable_extra_vars,
"__allowed_values", str_field);
snprintf (str_field, length_field,
"%s%s",
weechat_color (weechat_config_string (fset_config_color_allowed_values[selected_line])),
(fset_option->allowed_values) ? fset_option->allowed_values : "");
weechat_hashtable_set (fset_buffer_hashtable_extra_vars,
"_allowed_values", str_field);
fset_buffer_fills_field (str_field, str_field2, length_field,
fset_option_max_length->allowed_values, 1, 1);
weechat_hashtable_set (fset_buffer_hashtable_extra_vars,
"allowed_values", str_field);
weechat_hashtable_set (fset_buffer_hashtable_extra_vars,
"empty_allowed_values", str_field2);
/* marked */
snprintf (str_field, length_field,
"%s",
+2 -1
View File
@@ -697,7 +697,7 @@ fset_command_init ()
"(bool/int/str/col/enum), type_tiny (b/i/s/c/e), default_value, "
"default_value_undef, value, quoted_value, value_undef, "
"value_changed, parent_value, min, max, description, description2, "
"description_en, description_en2, string_values\n"
"description_en, description_en2, string_values, allowed_values\n"
"\n"
"The lines with options are displayed using string evaluation "
"(see /help eval for the format), with these options:\n"
@@ -735,6 +735,7 @@ fset_command_init ()
"\"(no description)\" if there's no description\n"
" - ${string_values}: string values allowed for set of an enum "
"option\n"
" - ${allowed_values}: allowed values\n"
" - ${marked}: \"1\" if option is marked, otherwise \"0\"\n"
" - ${index}: index of option in list\n"
" - option data, with color but no spaces:\n"
+18 -1
View File
@@ -63,6 +63,7 @@ struct t_config_option *fset_config_format_option[2] = { NULL, NULL };
/* fset config, color section */
struct t_config_option *fset_config_color_allowed_values[2] = { NULL, NULL };
struct t_config_option *fset_config_color_color_name[2] = { NULL, NULL };
struct t_config_option *fset_config_color_default_value[2] = { NULL, NULL };
struct t_config_option *fset_config_color_description[2] = { NULL, NULL };
@@ -584,7 +585,7 @@ fset_config_init ()
NULL, 0, 0,
"${marked} ${name} ${type} ${value2}${newline}"
" ${empty_name} ${_default_value}${color:244} -- "
"${_min}..${_max}${newline}"
"${_allowed_values}${newline}"
" ${empty_name} ${_description}",
NULL, 0,
NULL, NULL, NULL,
@@ -603,6 +604,22 @@ fset_config_init ()
NULL, NULL, NULL);
if (fset_config_section_color)
{
fset_config_color_allowed_values[0] = weechat_config_new_option (
fset_config_file, fset_config_section_color,
"allowed_values", "color",
N_("color for allowed values"),
NULL, 0, 0, "default", NULL, 0,
NULL, NULL, NULL,
&fset_config_change_color_cb, NULL, NULL,
NULL, NULL, NULL);
fset_config_color_allowed_values[1] = weechat_config_new_option (
fset_config_file, fset_config_section_color,
"allowed_values_selected", "color",
N_("color for allowed values on the selected line"),
NULL, 0, 0, "white", NULL, 0,
NULL, NULL, NULL,
&fset_config_change_color_cb, NULL, NULL,
NULL, NULL, NULL);
fset_config_color_color_name[0] = weechat_config_new_option (
fset_config_file, fset_config_section_color,
"color_name", "color",
+1
View File
@@ -44,6 +44,7 @@ extern struct t_config_option *fset_config_format_export_option;
extern struct t_config_option *fset_config_format_export_option_null;
extern struct t_config_option *fset_config_format_option[2];
extern struct t_config_option *fset_config_color_allowed_values[2];
extern struct t_config_option *fset_config_color_color_name[2];
extern struct t_config_option *fset_config_color_default_value[2];
extern struct t_config_option *fset_config_color_description[2];
+1
View File
@@ -97,6 +97,7 @@ fset_mouse_focus_cb (const void *pointer, void *data, struct t_hashtable *info)
weechat_hashtable_set (info, "fset_option_max", ptr_fset_option->max);
weechat_hashtable_set (info, "fset_option_description", ptr_fset_option->description);
weechat_hashtable_set (info, "fset_option_string_values", ptr_fset_option->string_values);
weechat_hashtable_set (info, "fset_option_allowed_values", ptr_fset_option->allowed_values);
weechat_hashtable_set (info, "fset_option_marked", (ptr_fset_option->marked) ? "1" : "0");
return info;
+48 -1
View File
@@ -289,6 +289,8 @@ fset_option_add_option_in_hashtable (struct t_hashtable *hashtable,
fset_option->description : "(no description)");
weechat_hashtable_set (hashtable,
"string_values", fset_option->string_values);
weechat_hashtable_set (hashtable,
"allowed_values", fset_option->allowed_values);
weechat_hashtable_set (hashtable,
"default_value_undef",
(fset_option->default_value == NULL) ? "1" : "0");
@@ -435,7 +437,7 @@ fset_option_set_values (struct t_fset_option *fset_option,
void *ptr_default_value, *ptr_value;
struct t_config_option *ptr_parent_option;
int length, *ptr_type, *ptr_min, *ptr_max;
char str_value[64];
char str_value[64], str_allowed_values[4096];
/* file */
if (fset_option->file)
@@ -588,6 +590,40 @@ fset_option_set_values (struct t_fset_option *fset_option,
{
fset_option->string_values = strdup ("");
}
/* allowed_values */
if (fset_option->allowed_values)
{
free (fset_option->allowed_values);
fset_option->allowed_values = NULL;
}
str_allowed_values[0] = '\0';
switch (fset_option->type)
{
case FSET_OPTION_TYPE_BOOLEAN:
snprintf (str_allowed_values, sizeof (str_allowed_values),
"on,off");
break;
case FSET_OPTION_TYPE_INTEGER:
snprintf (str_allowed_values, sizeof (str_allowed_values),
"%d..%d", *ptr_min, *ptr_max);
break;
case FSET_OPTION_TYPE_STRING:
snprintf (str_allowed_values, sizeof (str_allowed_values),
_("any string"));
break;
case FSET_OPTION_TYPE_COLOR:
snprintf (str_allowed_values, sizeof (str_allowed_values),
_("any color"));
break;
case FSET_OPTION_TYPE_ENUM:
snprintf (str_allowed_values, sizeof (str_allowed_values),
"%s", fset_option->string_values);
break;
case FSET_OPTION_NUM_TYPES:
break;
}
fset_option->allowed_values = strdup (str_allowed_values);
}
/*
@@ -734,6 +770,11 @@ fset_option_set_max_length_fields_option (struct t_fset_option *fset_option)
if (length > fset_option_max_length->string_values)
fset_option_max_length->string_values = length;
/* allowed_values */
length = weechat_utf8_strlen_screen (fset_option->allowed_values);
if (length > fset_option_max_length->allowed_values)
fset_option_max_length->allowed_values = length;
/* marked */
length = weechat_utf8_strlen_screen (weechat_config_string (fset_config_look_marked_string));
if (length > fset_option_max_length->marked)
@@ -806,6 +847,7 @@ fset_option_alloc (struct t_config_option *option)
new_fset_option->max = NULL;
new_fset_option->description = NULL;
new_fset_option->string_values = NULL;
new_fset_option->allowed_values = NULL;
new_fset_option->marked = 0;
fset_option_set_values (new_fset_option, option);
@@ -927,6 +969,8 @@ fset_option_free (struct t_fset_option *fset_option)
free (fset_option->description);
if (fset_option->string_values)
free (fset_option->string_values);
if (fset_option->allowed_values)
free (fset_option->allowed_values);
free (fset_option);
}
@@ -1720,6 +1764,8 @@ fset_option_add_to_infolist (struct t_infolist *infolist,
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "string_values", fset_option->description))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "allowed_values", fset_option->allowed_values))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "marked", fset_option->marked))
return 0;
@@ -1760,6 +1806,7 @@ fset_option_print_log ()
weechat_log_printf (" max . . . . . . . . . : '%s'", ptr_fset_option->max);
weechat_log_printf (" description . . . . . : '%s'", ptr_fset_option->description);
weechat_log_printf (" string_values . . . . : '%s'", ptr_fset_option->string_values);
weechat_log_printf (" allowed_values. . . . : '%s'", ptr_fset_option->allowed_values);
weechat_log_printf (" marked. . . . . . . . : %d", ptr_fset_option->marked);
}
}
+2
View File
@@ -51,6 +51,7 @@ struct t_fset_option
char *max; /* max value */
char *description; /* option description */
char *string_values; /* string values for option */
char *allowed_values; /* allowed values (depends on type)*/
int marked; /* option marked for group oper. */
struct t_fset_option *prev_option; /* link to previous option */
struct t_fset_option *next_option; /* link to next option */
@@ -78,6 +79,7 @@ struct t_fset_option_max_length
int description_en;
int description_en2;
int string_values;
int allowed_values;
int marked;
};