1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-09 19:23:13 +02:00

core: add option type "enum" (closes #1973)

The type "enum" replaces type "integer" when used with string values.

For compatibility, any option created with type "integer" and string values is
automatically created to "enum" on creation, with no error.
This commit is contained in:
Sébastien Helleu
2023-07-06 19:00:16 +02:00
parent 8f9d88edd0
commit 66cb9f6ea2
30 changed files with 1665 additions and 921 deletions
+44 -39
View File
@@ -123,8 +123,42 @@ fset_bar_item_fset_cb (const void *pointer, void *data,
-1);
}
if ((ptr_fset_option->string_values && ptr_fset_option->string_values[0])
|| (ptr_fset_option->type == FSET_OPTION_TYPE_INTEGER))
if (ptr_fset_option->type == FSET_OPTION_TYPE_INTEGER)
{
ptr_option = weechat_config_get (ptr_fset_option->name);
if (ptr_option)
{
weechat_string_dyn_concat (default_and_values,
weechat_color ("bar_fg"),
-1);
weechat_string_dyn_concat (default_and_values, ", ", -1);
weechat_string_dyn_concat (default_and_values, _("values:"), -1);
weechat_string_dyn_concat (default_and_values, " ", -1);
weechat_string_dyn_concat (
default_and_values,
weechat_color (
weechat_config_string (
fset_config_color_help_values)),
-1);
weechat_string_dyn_concat (default_and_values,
ptr_fset_option->min,
-1);
weechat_string_dyn_concat (default_and_values,
weechat_color ("bar_fg"),
-1);
weechat_string_dyn_concat (default_and_values, " ... ", -1);
weechat_string_dyn_concat (
default_and_values,
weechat_color (
weechat_config_string (
fset_config_color_help_values)),
-1);
weechat_string_dyn_concat (default_and_values,
ptr_fset_option->max,
-1);
}
}
else if (ptr_fset_option->type == FSET_OPTION_TYPE_ENUM)
{
ptr_option = weechat_config_get (ptr_fset_option->name);
if (ptr_option)
@@ -135,8 +169,7 @@ fset_bar_item_fset_cb (const void *pointer, void *data,
ptr_string_values = weechat_config_option_get_pointer (
ptr_option, "string_values");
}
if (ptr_string_values
|| (ptr_fset_option->type == FSET_OPTION_TYPE_INTEGER))
if (ptr_string_values)
{
weechat_string_dyn_concat (default_and_values,
weechat_color ("bar_fg"),
@@ -144,32 +177,17 @@ fset_bar_item_fset_cb (const void *pointer, void *data,
weechat_string_dyn_concat (default_and_values, ", ", -1);
weechat_string_dyn_concat (default_and_values, _("values:"), -1);
weechat_string_dyn_concat (default_and_values, " ", -1);
if (ptr_string_values)
for (i = 0; ptr_string_values[i]; i++)
{
for (i = 0; ptr_string_values[i]; i++)
if (i > 0)
{
if (i > 0)
{
weechat_string_dyn_concat (default_and_values,
weechat_color ("bar_fg"),
-1);
weechat_string_dyn_concat (default_and_values,
", ",
-1);
}
weechat_string_dyn_concat (
default_and_values,
weechat_color (
weechat_config_string (
fset_config_color_help_values)),
-1);
weechat_string_dyn_concat (default_and_values,
ptr_string_values[i],
weechat_color ("bar_fg"),
-1);
weechat_string_dyn_concat (default_and_values,
", ",
-1);
}
}
else
{
weechat_string_dyn_concat (
default_and_values,
weechat_color (
@@ -177,20 +195,7 @@ fset_bar_item_fset_cb (const void *pointer, void *data,
fset_config_color_help_values)),
-1);
weechat_string_dyn_concat (default_and_values,
ptr_fset_option->min,
-1);
weechat_string_dyn_concat (default_and_values,
weechat_color ("bar_fg"),
-1);
weechat_string_dyn_concat (default_and_values, " ... ", -1);
weechat_string_dyn_concat (
default_and_values,
weechat_color (
weechat_config_string (
fset_config_color_help_values)),
-1);
weechat_string_dyn_concat (default_and_values,
ptr_fset_option->max,
ptr_string_values[i],
-1);
}
}
+13 -12
View File
@@ -282,7 +282,8 @@ fset_command_fset (const void *pointer, void *data,
fset_command_get_option (&ptr_fset_option, &ptr_option);
if (ptr_fset_option &&
((ptr_fset_option->type == FSET_OPTION_TYPE_INTEGER)
|| (ptr_fset_option->type == FSET_OPTION_TYPE_COLOR)))
|| (ptr_fset_option->type == FSET_OPTION_TYPE_COLOR)
|| (ptr_fset_option->type == FSET_OPTION_TYPE_ENUM)))
{
fset_option_add_value (ptr_fset_option, ptr_option, value);
}
@@ -651,7 +652,7 @@ fset_command_init ()
"(\"end\" to select the last line)\n"
" -toggle: toggle the boolean value\n"
" -add: add \"value\" (which can be a negative number) "
"for integers and colors, set/append to value for other types "
"for integers, colors and enums, set/append to value for other types "
"(set for a negative value, append for a positive value)\n"
" -reset: reset the value of option\n"
" -unset: unset the option\n"
@@ -675,7 +676,7 @@ fset_command_init ()
" * show all options (no filter)\n"
" xxx show only options with \"xxx\" in name\n"
" f:xxx show only configuration file \"xxx\"\n"
" t:xxx show only type \"xxx\" (bool/int/str/col)\n"
" t:xxx show only type \"xxx\" (bool/int/str/col/enum)\n"
" d show only changed options\n"
" d:xxx show only changed options with \"xxx\" in "
"name\n"
@@ -692,7 +693,7 @@ fset_command_init ()
" c:xxx show only options matching the evaluated "
"condition \"xxx\", using following variables: file, section, "
"option, name, parent_name, type, type_en, type_short "
"(bool/int/str/col), type_tiny (b/i/s/c), default_value, "
"(bool/int/str/col/enum), type_tiny (b/i/s/c), 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"
@@ -712,7 +713,7 @@ fset_command_init ()
" - ${parent_name}: parent option name\n"
" - ${type}: option type (translated)\n"
" - ${type_en}: option type (in English)\n"
" - ${type_short}: short option type (bool/int/str/col)\n"
" - ${type_short}: short option type (bool/int/str/col/enum)\n"
" - ${type_tiny}: tiny option type (b/i/s/c)\n"
" - ${default_value}: option default value\n"
" - ${default_value_undef}: \"1\" if default value is null, "
@@ -731,8 +732,8 @@ fset_command_init ()
" - ${description_en}: option description (in English)\n"
" - ${description_en2}: option description (in English), "
"\"(no description)\" if there's no description\n"
" - ${string_values}: string values allowed for set of an "
"integer option using strings\n"
" - ${string_values}: string values allowed for set of an enum "
"option\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"
@@ -762,10 +763,10 @@ fset_command_init ()
"\n"
"Keys and input to set options on fset buffer:\n"
" alt+space t toggle boolean value\n"
" alt+'-' - subtract 1 from value for integer/color, "
"set value for other types\n"
" alt+'+' + add 1 to value for integer/color, append "
"to value for other types\n"
" alt+'-' - subtract 1 from value for "
"integer/color/enum, set value for other types\n"
" alt+'+' + add 1 to value for integer/color/enum, "
"append to value for other types\n"
" alt+f, alt+r r reset value\n"
" alt+f, alt+u u unset value\n"
" alt+enter s set value\n"
@@ -805,7 +806,7 @@ fset_command_init ()
" right button toggle boolean (on/off) or "
"edit the option value\n"
" right button + drag left/right increase/decrease value "
"for integer/color, set/append to value for other types\n"
"for integer/color/enum, set/append to value for other types\n"
" right button + drag up/down mark/unmark multiple options\n"
"\n"
"Note: if input has one or more leading spaces, the following text "
+5 -3
View File
@@ -98,7 +98,7 @@ fset_mouse_focus_cb (const void *pointer, void *data, struct t_hashtable *info)
}
/*
* Get distance between x and x2 (as a positive integer);
* Get distance between x and x2 (as a positive integer).
*/
int
@@ -224,7 +224,8 @@ fset_mouse_hsignal_cb (const void *pointer, void *data, const char *signal,
{
distance = fset_mouse_get_distance_x (hashtable);
if ((ptr_fset_option->type == FSET_OPTION_TYPE_INTEGER)
|| (ptr_fset_option->type == FSET_OPTION_TYPE_COLOR))
|| (ptr_fset_option->type == FSET_OPTION_TYPE_COLOR)
|| (ptr_fset_option->type == FSET_OPTION_TYPE_ENUM))
{
snprintf (str_command, sizeof (str_command),
"/fset -add -%d",
@@ -240,7 +241,8 @@ fset_mouse_hsignal_cb (const void *pointer, void *data, const char *signal,
{
distance = fset_mouse_get_distance_x (hashtable);
if ((ptr_fset_option->type == FSET_OPTION_TYPE_INTEGER)
|| (ptr_fset_option->type == FSET_OPTION_TYPE_COLOR))
|| (ptr_fset_option->type == FSET_OPTION_TYPE_COLOR)
|| (ptr_fset_option->type == FSET_OPTION_TYPE_ENUM))
{
snprintf (str_command, sizeof (str_command),
"/fset -add %d",
+19 -15
View File
@@ -48,11 +48,11 @@ struct t_hook *fset_option_timer_hook = NULL;
/* types */
char *fset_option_type_string[FSET_OPTION_NUM_TYPES] =
{ N_("boolean"), N_("integer"), N_("string"), N_("color") };
{ N_("boolean"), N_("integer"), N_("string"), N_("color"), N_("enum") };
char *fset_option_type_string_short[FSET_OPTION_NUM_TYPES] =
{ "bool", "int", "str", "col" };
{ "bool", "int", "str", "col", "enum" };
char *fset_option_type_string_tiny[FSET_OPTION_NUM_TYPES] =
{ "b", "i", "s", "c" };
{ "b", "i", "s", "c", "e" };
/*
@@ -170,6 +170,18 @@ fset_option_set_value_string (struct t_config_option *option,
*value_string = strdup (*((int *)value) ? "on" : "off");
break;
case FSET_OPTION_TYPE_INTEGER:
snprintf (str_value, sizeof (str_value), "%d", *((int *)value));
*value_string = strdup (str_value);
break;
case FSET_OPTION_TYPE_STRING:
*value_string = strdup (
(default_value) ? weechat_config_string_default (option) : weechat_config_string (option));
break;
case FSET_OPTION_TYPE_COLOR:
*value_string = strdup (
(default_value) ? weechat_config_color_default (option) : weechat_config_color (option));
break;
case FSET_OPTION_TYPE_ENUM:
ptr_string_values = weechat_config_option_get_pointer (
option, "string_values");
if (ptr_string_values)
@@ -179,18 +191,9 @@ fset_option_set_value_string (struct t_config_option *option,
}
else
{
snprintf (str_value, sizeof (str_value), "%d", *((int *)value));
*value_string = strdup (str_value);
*value_string = strdup ("");
}
break;
case FSET_OPTION_TYPE_STRING:
*value_string = strdup (
(default_value) ? weechat_config_string_default (option) : weechat_config_string (option));
break;
case FSET_OPTION_TYPE_COLOR:
*value_string = strdup (
(default_value) ? weechat_config_color_default (option) : weechat_config_color (option));
break;
case FSET_OPTION_NUM_TYPES:
break;
}
@@ -1114,7 +1117,7 @@ fset_option_toggle_value (struct t_fset_option *fset_option,
}
/*
* Adds a value to an integer/color option.
* Adds a value to an integer/enum/color option.
*/
void
@@ -1126,7 +1129,8 @@ fset_option_add_value (struct t_fset_option *fset_option,
if (!fset_option || !option
|| ((fset_option->type != FSET_OPTION_TYPE_INTEGER)
&& (fset_option->type != FSET_OPTION_TYPE_COLOR)))
&& (fset_option->type != FSET_OPTION_TYPE_COLOR)
&& (fset_option->type != FSET_OPTION_TYPE_ENUM)))
return;
snprintf (str_value, sizeof (str_value),
+1
View File
@@ -30,6 +30,7 @@ enum t_fset_option_type
FSET_OPTION_TYPE_INTEGER,
FSET_OPTION_TYPE_STRING,
FSET_OPTION_TYPE_COLOR,
FSET_OPTION_TYPE_ENUM,
/* number of option types */
FSET_OPTION_NUM_TYPES,
};