diff --git a/ChangeLog.adoc b/ChangeLog.adoc index e31a4ad3a..fc8131c2f 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -15,6 +15,7 @@ For a list of important changes that require manual actions, please look at rele New features:: + * core: add option type "enum" (issue #1973) * core: add variables "_chat_focused_line_bol" and "_chat_focused_line_eol" in focus data (issue #1955) * api: add info "buffer" (issue #1962) * buflist: increase max number of buflist items from 3 to 5 (issue #1703) diff --git a/doc/de/weechat_user.de.adoc b/doc/de/weechat_user.de.adoc index fcd9eca68..ae2593b0c 100644 --- a/doc/de/weechat_user.de.adoc +++ b/doc/de/weechat_user.de.adoc @@ -1725,8 +1725,10 @@ wurde (Befehl: `+/mouse toggle+`). | kbd:[▼] | - | chat: fset buffer | Auswahl wird fünf Einträge nach unten bewegt, im fset Buffer. | `+/fset -down 5+` | ◾◽◽ | - | chat: fset buffer | springt zu einem Eintrag im fset Buffer. | `+/window ${_window_number};/fset -go ${_chat_line_y}+` | ◽◽◾ | - | chat: fset buffer | Boolean-Wert wird umgeschaltet (an/aus) oder editiere den Wert einer Option. | `+hsignal:fset_mouse+` -| ◽◽◾ | left | chat: fset buffer | Integer/Farbwerte werden verringert, andere Variabletypen werden in die Eingabezeile kopiert. | `+hsignal:fset_mouse+` -| ◽◽◾ | right | chat: fset buffer | Integer/Farbwerte werden erhöht, andere Variabletypen werden in die Eingabezeile kopiert. | `+hsignal:fset_mouse+` +// TRANSLATION MISSING +| ◽◽◾ | left | chat: fset buffer | Integer/Farbwerte/enum werden verringert, andere Variabletypen werden in die Eingabezeile kopiert. | `+hsignal:fset_mouse+` +// TRANSLATION MISSING +| ◽◽◾ | right | chat: fset buffer | Integer/Farbwerte/enum werden erhöht, andere Variabletypen werden in die Eingabezeile kopiert. | `+hsignal:fset_mouse+` | ◽◽◾ | up / down | chat: fset buffer | markieren/demarkieren von mehreren Optionen. | `+hsignal:fset_mouse+` | kbd:[▲] | - | chat: script buffer | fünf Zeilen nach oben blättern, im Script-Buffer. | `+/script up 5+` | kbd:[▼] | - | chat: script buffer | fünf Zeilen nach unten blättern, im Script-Buffer. | `+/script down 5+` @@ -1773,8 +1775,10 @@ Diese Tasten und Aktionen werden im fset-Buffer verwendet (siehe <]` | scrollt horizontal nach rechts. | `+/fset -right+` | kbd:[Alt+Space] | `t` | Boolean Wert ein/ausschalten. | `+/fset -toggle+` -| kbd:[Alt+-] | `-` | subtrahiert 1 vom Wert bei Integer/Farboptionen, bei anderen Typen kann der Wert editiert werden. | `+/fset -add -1+` -| kbd:[Alt++] | `+` | addiert 1 zum Wert bei Integer/Farboptionen, bei anderen Typen kann der Wert editiert werden. | `+/fset -add 1+` +// TRANSLATION MISSING +| kbd:[Alt+-] | `-` | subtrahiert 1 vom Wert bei Integer/Farboptionen/enum, bei anderen Typen kann der Wert editiert werden. | `+/fset -add -1+` +// TRANSLATION MISSING +| kbd:[Alt++] | `+` | addiert 1 zum Wert bei Integer/Farboptionen/enum, bei anderen Typen kann der Wert editiert werden. | `+/fset -add 1+` | kbd:[Alt+f], kbd:[Alt+r] | `r` | Wert resetten. | `+/fset -reset+` | kbd:[Alt+f], kbd:[Alt+u] | `u` | Wert zurücksetzen. | `+/fset -unset+` | kbd:[Alt+Enter] | `s` | Wert setzen. | `+/fset -set+` @@ -1844,7 +1848,7 @@ Beispiel des fset-Buffer, der Optionen anzeigt, die mit `weechat.look` beginnen │2.fset │weechat.look.bare_display_exit_on_input: exit the bare display mode on any c│ │ │hanges in input [default: on] │ │ │----------------------------------------------------------------------------│ -│ │ weechat.look.align_end_of_lines integer message │ +│ │ weechat.look.align_end_of_lines enum message │ │ │ weechat.look.align_multiline_words boolean on │ │ │ weechat.look.bar_more_down string "++" │ │ │ weechat.look.bar_more_left string "<<" │ @@ -1853,12 +1857,12 @@ Beispiel des fset-Buffer, der Optionen anzeigt, die mit `weechat.look` beginnen │ │## weechat.look.bare_display_exit_on_input boolean on ##│ │ │ weechat.look.bare_display_time_format string "%H:%M" │ │ │ weechat.look.buffer_auto_renumber boolean on │ -│ │ weechat.look.buffer_notify_default integer all │ -│ │ weechat.look.buffer_position integer end │ +│ │ weechat.look.buffer_notify_default enum all │ +│ │ weechat.look.buffer_position enum end │ │ │ weechat.look.buffer_search_case_sensitive boolean off │ │ │ weechat.look.buffer_search_force_default boolean off │ │ │ weechat.look.buffer_search_regex boolean off │ -│ │ weechat.look.buffer_search_where integer prefix_message │ +│ │ weechat.look.buffer_search_where enum prefix_message │ │ │ weechat.look.buffer_time_format string "%H:%M:%S" │ │ │ weechat.look.buffer_time_same string "" │ │ │[12:55] [2] [fset] 2:fset │ @@ -3325,7 +3329,7 @@ irc.server.libera.autorejoin_delay integer null -> 30 irc.server.libera.away_check integer null -> 0 irc.server.libera.away_check_max_nicks integer null -> 25 irc.server.libera.capabilities string null -> "*" -irc.server.libera.charset_message integer null -> message +irc.server.libera.charset_message enum null -> message irc.server.libera.command string null -> "" irc.server.libera.command_delay integer null -> 0 irc.server.libera.connection_timeout integer null -> 60 @@ -3341,9 +3345,9 @@ irc.server.libera.notify string null -> "" irc.server.libera.password string null -> "" irc.server.libera.proxy string null -> "" irc.server.libera.realname string null -> "" -irc.server.libera.sasl_fail integer null -> reconnect +irc.server.libera.sasl_fail enum null -> reconnect irc.server.libera.sasl_key string null -> "" -irc.server.libera.sasl_mechanism integer null -> plain +irc.server.libera.sasl_mechanism enum null -> plain irc.server.libera.sasl_password string "${sec.data.libera}" irc.server.libera.sasl_timeout integer null -> 15 irc.server.libera.sasl_username string "alice" diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index d6d264fa5..ac6b91643 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -6880,7 +6880,7 @@ section = weechat.config_search_section(config_file, "section") ==== config_new_option -_Updated in 1.5._ +_Updated in 1.5, 4.1.0._ Create a new option in a section of a configuration file. @@ -6928,12 +6928,13 @@ Arguments: "name << file.section.option" * _type_: type of option: ** _boolean_: boolean value (on/off) -** _integer_: integer value (with optional strings for values) +** _integer_: integer value ** _string_: string value ** _color_: color +** _enum_: list of string values (stored as integer internally) * _description_: description of option -* _string_values_: values as string (separated by `+|+`), used for type - _integer_ (optional) +* _string_values_: values as string (separated by `+|+`) (optional, required + for type _enum_) * _min_: minimum value (for type _integer_) * _max_: maximum value (for type _integer_) * _default_value_: default value for option (used when option is reset) @@ -6984,8 +6985,8 @@ C example: [source,c] ---- /* boolean */ -struct t_config_option *option1 = - weechat_config_new_option (config_file, section, "option1", "boolean", +struct t_config_option *option_bool = + weechat_config_new_option (config_file, section, "option_bool", "boolean", "My option, type boolean", NULL, 0, 0, @@ -6997,8 +6998,8 @@ struct t_config_option *option1 = NULL, NULL, NULL); /* integer */ -struct t_config_option *option2 = - weechat_config_new_option (config_file, section, "option2", "integer", +struct t_config_option *option_int = + weechat_config_new_option (config_file, section, "option_int", "integer", "My option, type integer", NULL, 0, 100, @@ -7009,22 +7010,9 @@ struct t_config_option *option2 = NULL, NULL, NULL, NULL, NULL, NULL); -/* integer (with string values) */ -struct t_config_option *option3 = - weechat_config_new_option (config_file, section, "option3", "integer", - "My option, type integer (with string values)", - "top|bottom|left|right", - 0, 0, - "bottom", - "bottom", - 0, - NULL, NULL, NULL, - NULL, NULL, NULL, - NULL, NULL, NULL); - /* string */ -struct t_config_option *option4 = - weechat_config_new_option (config_file, section, "option4", "string", +struct t_config_option *option_str = + weechat_config_new_option (config_file, section, "option_str", "string", "My option, type string", NULL, 0, 0, @@ -7036,8 +7024,8 @@ struct t_config_option *option4 = NULL, NULL, NULL); /* color */ -struct t_config_option *option5 = - weechat_config_new_option (config_file, section, "option5", "color", +struct t_config_option *option_col = + weechat_config_new_option (config_file, section, "option_col", "color", "My option, type color", NULL, 0, 0, @@ -7047,6 +7035,19 @@ struct t_config_option *option5 = NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + +/* enum */ +struct t_config_option *option_enum = + weechat_config_new_option (config_file, section, "option_enum", "enum", + "My option, type enum", + "top|bottom|left|right", + 0, 0, + "bottom", + "bottom", + 0, + NULL, NULL, NULL, + NULL, NULL, NULL, + NULL, NULL, NULL); ---- Script (Python): @@ -7062,49 +7063,49 @@ def config_new_option(config_file: str, section: str, name: str, type: str, desc callback_delete: str, callback_delete_data: str) -> str: ... # example -def option4_check_value_cb(data: str, option: str, value: str) -> int: +def option_str_check_value_cb(data: str, option: str, value: str) -> int: # ... return 1 # return 0 -def option4_change_cb(data: str, option: str) -> None: +def option_str_change_cb(data: str, option: str) -> None: # ... -def option4_delete_cb(data: str, option: str) -> None: +def option_str_delete_cb(data: str, option: str) -> None: # ... -option1 = weechat.config_new_option(config_file, section, "option1", "boolean", +option_bool = weechat.config_new_option(config_file, section, "option_bool", "boolean", "My option, type boolean", "", 0, 0, "on", "on", 0, "", "", "", "", "", "") -option2 = weechat.config_new_option(config_file, section, "option2", "integer", +option_int = weechat.config_new_option(config_file, section, "option_int", "integer", "My option, type integer", "", 0, 100, "15", "15", 0, "", "", "", "", "", "") -option3 = weechat.config_new_option(config_file, section, "option3", "integer", - "My option, type integer (with string values)", - "top|bottom|left|right", - 0, 0, "bottom", "bottom", 0, +option_str = weechat.config_new_option(config_file, section, "option_str", "string", + "My option, type string", + "", 0, 0, "test", "test", 1, + "option_str_check_value_cb", "", + "option_str_change_cb", "", + "option_str_delete_cb", "") + +option_col = weechat.config_new_option(config_file, section, "option_col", "color", + "My option, type color", + "", 0, 0, "lightblue", "lightblue", 0, "", "", "", "", "", "") -option4 = weechat.config_new_option(config_file, section, "option4", "string", - "My option, type string", - "", 0, 0, "test", "test", 1, - "option4_check_value_cb", "", - "option4_change_cb", "", - "option4_delete_cb", "") - -option5 = weechat.config_new_option(config_file, section, "option5", "color", - "My option, type color", - "", 0, 0, "lightblue", "lightblue", 0, +option_enum = weechat.config_new_option(config_file, section, "option_enum", "enum", + "My option, type enum", + "top|bottom|left|right", + 0, 0, "bottom", "bottom", 0, "", "", "", "", "", "") @@ -7387,7 +7388,7 @@ Arguments: type of option: ** _boolean_: *** `toggle`: toggle the current value -** _integer_ or _color_: +** _integer_, _color_ or _enum_: *** `++N`: add `N` (any integer) to the current value *** `--N`: subtract `N` (any integer) from the current value * _run_callback_: 1 for calling change callback if value of option is changed, @@ -7621,6 +7622,7 @@ Arguments: *** _integer_ *** _string_ *** _color_ +*** _enum_ ** _description_: option description Return value: @@ -7794,6 +7796,7 @@ Return value, depending on the option type: * _integer_: 0 * _string_: 0 * _color_: 0 +* _enum_: 0 C example: @@ -7844,6 +7847,7 @@ Return value, depending on the option type: * _integer_: 0 * _string_: 0 * _color_: 0 +* _enum_: 0 C example: @@ -7894,6 +7898,7 @@ Return value, depending on the option type: * _integer_: integer value of option * _string_: 0 * _color_: color index +* _enum_: integer value of option (index of enum value) C example: @@ -7936,6 +7941,7 @@ Return value, depending on the option type: * _integer_: default integer value of option * _string_: 0 * _color_: default color index +* _enum_: default integer value of option (index of enum value) C example: @@ -7975,10 +7981,10 @@ Arguments: Return value, depending on the option type: * _boolean_: "on" if value is true, otherwise "off" -* _integer_: string value if the option is an integer with string values, - otherwise NULL +* _integer_: NULL * _string_: string value of option * _color_: name of color +* _enum_: string value of option C example: @@ -8018,10 +8024,10 @@ Arguments: Return value, depending on the option type: * _boolean_: "on" if default value is true, otherwise "off" -* _integer_: default string value if the option is an integer with string - values, otherwise NULL +* _integer_: NULL * _string_: default string value of option * _color_: name of default color +* _enum_: default string value of option C example: @@ -8064,6 +8070,7 @@ Return value, depending on the option type: * _integer_: NULL * _string_: NULL * _color_: name of color +* _enum_: NULL C example: @@ -8106,6 +8113,7 @@ Return value, depending on the option type: * _integer_: NULL * _string_: NULL * _color_: name of default color +* _enum_: NULL C example: @@ -8127,6 +8135,96 @@ option = weechat.config_get("plugin.section.option") value = weechat.config_color_default(option) ---- +==== config_enum + +_WeeChat ≥ 4.1.0._ + +Return enum value of option, as integer. + +Prototype: + +[source,c] +---- +int weechat_config_enum (struct t_config_option *option); +---- + +Arguments: + +* _option_: option pointer + +Return value, depending on the option type: + +* _boolean_: boolean value of option (0 or 1) +* _integer_: integer value of option +* _string_: 0 +* _color_: color index +* _enum_: integer value of option (index of enum value) + +C example: + +[source,c] +---- +struct t_config_option *option = weechat_config_get ("plugin.section.option"); +int value = weechat_config_enum (option); +---- + +Script (Python): + +[source,python] +---- +# prototype +def config_enum(option: str) -> int: ... + +# example +option = weechat.config_get("plugin.section.option") +value = weechat.config_enum(option) +---- + +==== config_enum_default + +_WeeChat ≥ 4.1.0._ + +Return default enum value of option, as integer. + +Prototype: + +[source,c] +---- +int weechat_config_enum_default (struct t_config_option *option); +---- + +Arguments: + +* _option_: option pointer + +Return value, depending on the option type: + +* _boolean_: default boolean value of option (0 or 1) +* _integer_: default integer value of option +* _string_: 0 +* _color_: default color index +* _enum_: integer value of option (index of enum value) + +C example: + +[source,c] +---- +struct t_config_option *option = weechat_config_get ("plugin.section.option"); +int value = weechat_config_enum_default (option); +---- + +Script (Python): + +[source,python] +---- +# prototype +def config_enum_default(option: str) -> int: ... + +# example +option = weechat.config_get("plugin.section.option") +value = weechat.config_enum_default(option) +---- + ==== config_write_option Write a line in a configuration file with option and its value (this function diff --git a/doc/en/weechat_user.en.adoc b/doc/en/weechat_user.en.adoc index d8fbb43c4..cb1496868 100644 --- a/doc/en/weechat_user.en.adoc +++ b/doc/en/weechat_user.en.adoc @@ -1710,8 +1710,8 @@ These mouse actions are possible only if mouse is enabled with key kbd:[Alt+m] | kbd:[▼] | - | chat: fset buffer | Move five lines down in fset buffer. | `+/fset -down 5+` | ◾◽◽ | - | chat: fset buffer | Select line in fset buffer. | `+/window ${_window_number};/fset -go ${_chat_line_y}+` | ◽◽◾ | - | chat: fset buffer | Toggle boolean (on/off) or edit the option value. | `+hsignal:fset_mouse+` -| ◽◽◾ | left | chat: fset buffer | Decrease value for integer/color, set/append to value for other types. | `+hsignal:fset_mouse+` -| ◽◽◾ | right | chat: fset buffer | Increase value for integer/color, set/append to value for other types. | `+hsignal:fset_mouse+` +| ◽◽◾ | left | chat: fset buffer | Decrease value for integer/color/enum, set/append to value for other types. | `+hsignal:fset_mouse+` +| ◽◽◾ | right | chat: fset buffer | Increase value for integer/color/enum, set/append to value for other types. | `+hsignal:fset_mouse+` | ◽◽◾ | up / down | chat: fset buffer | Mark/unmark multiple options. | `+hsignal:fset_mouse+` | kbd:[▲] | - | chat: script buffer | Move five lines up in script buffer. | `+/script up 5+` | kbd:[▼] | - | chat: script buffer | Move five lines down in script buffer. | `+/script down 5+` @@ -1758,8 +1758,8 @@ These keys and actions are used on the fset buffer (see <>). | kbd:[F11] | `pass:[<]` | Scroll horizontally on the left. | `+/fset -left+` | kbd:[F12] | `pass:[>]` | Scroll horizontally on the right. | `+/fset -right+` | kbd:[Alt+Space] | `t` | Toggle boolean value. | `+/fset -toggle+` -| kbd:[Alt+-] | `-` | Subtract 1 from value for integer/color, set value for other types. | `+/fset -add -1+` -| kbd:[Alt++] | `+` | Add 1 to value for integer/color, append to value for other types. | `+/fset -add 1+` +| kbd:[Alt+-] | `-` | Subtract 1 from value for integer/color/enum, set value for other types. | `+/fset -add -1+` +| kbd:[Alt++] | `+` | Add 1 to value for integer/color/enum, append to value for other types. | `+/fset -add 1+` | kbd:[Alt+f], kbd:[Alt+r] | `r` | Reset value. | `+/fset -reset+` | kbd:[Alt+f], kbd:[Alt+u] | `u` | Unset value. | `+/fset -unset+` | kbd:[Alt+Enter] | `s` | Set value. | `+/fset -set+` @@ -1829,7 +1829,7 @@ Example of fset buffer displaying options starting with `weechat.look` : │2.fset │weechat.look.bare_display_exit_on_input: exit the bare display mode on any c│ │ │hanges in input [default: on] │ │ │----------------------------------------------------------------------------│ -│ │ weechat.look.align_end_of_lines integer message │ +│ │ weechat.look.align_end_of_lines enum message │ │ │ weechat.look.align_multiline_words boolean on │ │ │ weechat.look.bar_more_down string "++" │ │ │ weechat.look.bar_more_left string "<<" │ @@ -1838,12 +1838,12 @@ Example of fset buffer displaying options starting with `weechat.look` : │ │## weechat.look.bare_display_exit_on_input boolean on ##│ │ │ weechat.look.bare_display_time_format string "%H:%M" │ │ │ weechat.look.buffer_auto_renumber boolean on │ -│ │ weechat.look.buffer_notify_default integer all │ -│ │ weechat.look.buffer_position integer end │ +│ │ weechat.look.buffer_notify_default enum all │ +│ │ weechat.look.buffer_position enum end │ │ │ weechat.look.buffer_search_case_sensitive boolean off │ │ │ weechat.look.buffer_search_force_default boolean off │ │ │ weechat.look.buffer_search_regex boolean off │ -│ │ weechat.look.buffer_search_where integer prefix_message │ +│ │ weechat.look.buffer_search_where enum prefix_message │ │ │ weechat.look.buffer_time_format string "%H:%M:%S" │ │ │ weechat.look.buffer_time_same string "" │ │ │[12:55] [2] [fset] 2:fset │ @@ -3264,7 +3264,7 @@ irc.server.libera.autorejoin_delay integer null -> 30 irc.server.libera.away_check integer null -> 0 irc.server.libera.away_check_max_nicks integer null -> 25 irc.server.libera.capabilities string null -> "*" -irc.server.libera.charset_message integer null -> message +irc.server.libera.charset_message enum null -> message irc.server.libera.command string null -> "" irc.server.libera.command_delay integer null -> 0 irc.server.libera.connection_timeout integer null -> 60 @@ -3280,9 +3280,9 @@ irc.server.libera.notify string null -> "" irc.server.libera.password string null -> "" irc.server.libera.proxy string null -> "" irc.server.libera.realname string null -> "" -irc.server.libera.sasl_fail integer null -> reconnect +irc.server.libera.sasl_fail enum null -> reconnect irc.server.libera.sasl_key string null -> "" -irc.server.libera.sasl_mechanism integer null -> plain +irc.server.libera.sasl_mechanism enum null -> plain irc.server.libera.sasl_password string "${sec.data.libera}" irc.server.libera.sasl_timeout integer null -> 15 irc.server.libera.sasl_username string "alice" diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc index d2a4b001b..df4e6b1ea 100644 --- a/doc/fr/weechat_plugin_api.fr.adoc +++ b/doc/fr/weechat_plugin_api.fr.adoc @@ -6995,7 +6995,7 @@ section = weechat.config_search_section(config_file, "section") ==== config_new_option -_Mis à jour dans la 1.5._ +_Mis à jour dans la 1.5, 4.1.0._ Créer une nouvelle option dans une section d'un fichier de configuration. @@ -7043,12 +7043,14 @@ Paramètres : "name << file.section.option" * _type_ : type de l'option : ** _boolean_ : valeur booléenne (on/off) -** _integer_ : valeur entière (avec en option une chaîne pour chaque valeur) +** _integer_ : valeur entière ** _string_ : une chaîne de caractères ** _color_ : une couleur +** _enum_ : liste de valeurs sous forme de chaînes (stocké comme nombre entier + en interne) * _description_ : description de l'option -* _string_values_ : valeurs sous forme de chaîne (séparées par `+|+`), utilisées - pour le type _integer_ (optionnel) +* _string_values_ : valeurs sous forme de chaîne (séparées par `+|+`) (optionnel, + requis pour le type _enum_) * _min_ : valeur minimum (pour le type _integer_) * _max_ : valeur maximum (pour le type _integer_) * _default_value_ : valeur par défaut de l'option (utilisée quand l'option est @@ -7103,8 +7105,8 @@ Exemple en C : [source,c] ---- /* booléen */ -struct t_config_option *option1 = - weechat_config_new_option (config_file, section, "option1", "boolean", +struct t_config_option *option1_bool = + weechat_config_new_option (config_file, section, "option_bool", "boolean", "Mon option, type booléen", NULL, 0, 0, @@ -7116,8 +7118,8 @@ struct t_config_option *option1 = NULL, NULL, NULL); /* entier */ -struct t_config_option *option2 = - weechat_config_new_option (config_file, section, "option2", "integer", +struct t_config_option *option_int = + weechat_config_new_option (config_file, section, "option_int", "integer", "Mon option, type entier", NULL, 0, 100, @@ -7128,23 +7130,9 @@ struct t_config_option *option2 = NULL, NULL, NULL, NULL, NULL, NULL); -/* entier (avec valeurs sous forme de chaînes) */ -struct t_config_option *option3 = - weechat_config_new_option (config_file, section, "option3", "integer", - "Mon option, type entier " - "(avec valeurs sous forme de chaînes)", - "top|bottom|left|right", - 0, 0, - "bottom", - "bottom", - 0, - NULL, NULL, NULL, - NULL, NULL, NULL, - NULL, NULL, NULL); - /* chaîne */ -struct t_config_option *option4 = - weechat_config_new_option (config_file, section, "option4", "string", +struct t_config_option *option_str = + weechat_config_new_option (config_file, section, "option_str", "string", "Mon option, type chaîne", NULL, 0, 0, @@ -7156,8 +7144,8 @@ struct t_config_option *option4 = NULL, NULL, NULL); /* couleur */ -struct t_config_option *option5 = - weechat_config_new_option (config_file, section, "option5", "color", +struct t_config_option *option_col = + weechat_config_new_option (config_file, section, "option_col", "color", "Mon option, type couleur", NULL, 0, 0, @@ -7167,6 +7155,19 @@ struct t_config_option *option5 = NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + +/* énuméré */ +struct t_config_option *option_enum = + weechat_config_new_option (config_file, section, "option_enum", "enum", + "Mon option, type énuméré", + "top|bottom|left|right", + 0, 0, + "bottom", + "bottom", + 0, + NULL, NULL, NULL, + NULL, NULL, NULL, + NULL, NULL, NULL); ---- Script (Python) : @@ -7182,49 +7183,49 @@ def config_new_option(config_file: str, section: str, name: str, type: str, desc callback_delete: str, callback_delete_data: str) -> str: ... # exemple -def option4_check_value_cb(data: str, option: str, value: str) -> int: +def option_str_check_value_cb(data: str, option: str, value: str) -> int: # ... return 1 # return 0 -def option4_change_cb(data: str, option: str) -> None: +def option_str_change_cb(data: str, option: str) -> None: # ... -def option4_delete_cb(data: str, option: str) -> None: +def option_str_delete_cb(data: str, option: str) -> None: # ... -option1 = weechat.config_new_option(config_file, section, "option1", "boolean", +option_bool = weechat.config_new_option(config_file, section, "option_bool", "boolean", "Mon option, type booléen", "", 0, 0, "on", "on", 0, "", "", "", "", "", "") -option2 = weechat.config_new_option(config_file, section, "option2", "integer", +option_int = weechat.config_new_option(config_file, section, "option_int", "integer", "Mon option, type entier", "", 0, 100, "15", "15", 0, "", "", "", "", "", "") -option3 = weechat.config_new_option(config_file, section, "option3", "integer", - "Mon option, type entier (avec valeurs sous forme de chaînes)", - "top|bottom|left|right", - 0, 0, "bottom", "bottom", 0, +option_str = weechat.config_new_option(config_file, section, "option_str", "string", + "Mon option, type chaîne", + "", 0, 0, "test", "test", 1, + "option_str_check_value_cb", "", + "option_str_change_cb", "", + "option_str_delete_cb", "") + +option_col = weechat.config_new_option(config_file, section, "option_col", "color", + "Mon option, type couleur", + "", 0, 0, "lightblue", "lightblue", 0, "", "", "", "", "", "") -option4 = weechat.config_new_option(config_file, section, "option4", "string", - "Mon option, type chaîne", - "", 0, 0, "test", "test", 1, - "option4_check_value_cb", "", - "option4_change_cb", "", - "option4_delete_cb", "") - -option5 = weechat.config_new_option(config_file, section, "option5", "color", - "Mon option, type couleur", - "", 0, 0, "lightblue", "lightblue", 0, +option_enum = weechat.config_new_option(config_file, section, "option_enum", "enum", + "Mon option, type énuméré", + "top|bottom|left|right", + 0, 0, "bottom", "bottom", 0, "", "", "", "", "", "") @@ -7512,7 +7513,7 @@ Paramètres : selon le type de l'option : ** _boolean_ : *** `toggle` : basculer la valeur courante -** _integer_ ou _color_ : +** _integer_, _color_ ou _enum_ : *** `++N` : ajouter `N` (un entier) à la valeur courante *** `--N` : soustraire `N` (un entier) de la valeur courante * _run_callback_ : 1 pour appeler la fonction de rappel si la valeur de @@ -7748,6 +7749,7 @@ Paramètres : *** _integer_ *** _string_ *** _color_ +*** _enum_ ** _description_ : description de l'option Valeur de retour : @@ -7924,6 +7926,7 @@ Valeur de retour, selon le type de l'option : * _integer_ : 0 * _string_ : 0 * _color_ : 0 +* _enum_ : 0 Exemple en C : @@ -7974,6 +7977,7 @@ Valeur de retour, selon le type de l'option : * _integer_ : 0 * _string_ : 0 * _color_ : 0 +* _enum_ : 0 Exemple en C : @@ -8024,6 +8028,7 @@ Valeur de retour, selon le type de l'option : * _integer_ : valeur entière de l'option * _string_ : 0 * _color_ : index de la couleur +* _enum_ : valeur entière de l'option (index de la valeur de l'énuméré) Exemple en C : @@ -8066,6 +8071,7 @@ Valeur de retour, selon le type de l'option : * _integer_ : valeur entière par défaut de l'option * _string_ : 0 * _color_ : index de la couleur par défaut +* _enum_ : valeur entière par défaut de l'option (index de la valeur de l'énuméré) Exemple en C : @@ -8105,10 +8111,10 @@ Paramètres : Valeur de retour, selon le type de l'option : * _boolean_ : "on" si la valeur est vraie, sinon "off" -* _integer_ : valeur de l'option sous forme de chaîne si l'option est un entier - avec des valeurs sous forme de chaînes, sinon NULL +* _integer_ : NULL * _string_ : valeur de l'option sous forme de chaîne * _color_ : nom de la couleur +* _enum_ : valeur de l'option sous forme de chaîne Exemple en C : @@ -8148,10 +8154,10 @@ Paramètres : Valeur de retour, selon le type de l'option : * _boolean_ : "on" si la valeur par défaut est vraie, sinon "off" -* _integer_ : valeur par défaut de l'option sous forme de chaîne si l'option - est un entier avec des valeurs sous forme de chaînes, sinon NULL +* _integer_ : NULL * _string_ : valeur par défaut de l'option sous forme de chaîne * _color_ : nom de la couleur par défaut +* _enum_ : valeur par défaut de l'option sous forme de chaîne Exemple en C : @@ -8194,6 +8200,7 @@ Valeur de retour, selon le type de l'option : * _integer_ : NULL * _string_ : NULL * _color_ : nom de la couleur +* _enum_ : NULL Exemple en C : @@ -8236,6 +8243,7 @@ Valeur de retour, selon le type de l'option : * _integer_ : NULL * _string_ : NULL * _color_ : nom de la couleur par défaut +* _enum_ : NULL Exemple en C : @@ -8257,6 +8265,96 @@ option = weechat.config_get("plugin.section.option") value = weechat.config_color_default(option) ---- +==== config_enum + +_WeeChat ≥ 4.1.0._ + +Retourner la valeur de l'option, sous forme d'entier. + +Prototype : + +[source,c] +---- +int weechat_config_enum (struct t_config_option *option); +---- + +Paramètres : + +* _option_ : pointeur vers l'option + +Valeur de retour, selon le type de l'option : + +* _boolean_ : valeur booléenne de l'option (0 ou 1) +* _integer_ : valeur entière de l'option +* _string_ : 0 +* _color_ : index de la couleur +* _enum_ : valeur entière de l'option (index de la valeur de l'énuméré) + +Exemple en C : + +[source,c] +---- +struct t_config_option *option = weechat_config_get ("plugin.section.option"); +int value = weechat_config_enum (option); +---- + +Script (Python) : + +[source,python] +---- +# prototype +def config_enum(option: str) -> int: ... + +# exemple +option = weechat.config_get("plugin.section.option") +value = weechat.config_enum(option) +---- + +==== config_enum_default + +_WeeChat ≥ 4.1.0._ + +Retourner la valeur par défaut de l'option, sous forme d'entier. + +Prototype : + +[source,c] +---- +int weechat_config_enum_default (struct t_config_option *option); +---- + +Paramètres : + +* _option_ : pointeur vers l'option + +Valeur de retour, selon le type de l'option : + +* _boolean_ : valeur booléenne par défaut de l'option (0 ou 1) +* _integer_ : valeur entière par défaut de l'option +* _string_ : 0 +* _color_ : index de la couleur par défaut +* _enum_ : valeur entière par défaut de l'option (index de la valeur de l'énuméré) + +Exemple en C : + +[source,c] +---- +struct t_config_option *option = weechat_config_get ("plugin.section.option"); +int value = weechat_config_enum_default (option); +---- + +Script (Python) : + +[source,python] +---- +# prototype +def config_enum_default(option: str) -> int: ... + +# example +option = weechat.config_get("plugin.section.option") +value = weechat.config_enum_default(option) +---- + ==== config_write_option Écrire une ligne dans le fichier de configuration avec l'option et sa valeur diff --git a/doc/fr/weechat_user.fr.adoc b/doc/fr/weechat_user.fr.adoc index d38c28b12..830144b95 100644 --- a/doc/fr/weechat_user.fr.adoc +++ b/doc/fr/weechat_user.fr.adoc @@ -1747,8 +1747,8 @@ avec la touche kbd:[Alt+m] (commande : `+/mouse toggle+`). | kbd:[▼] | - | chat : tampon fset | Descendre de cinq lignes dans le tampon fset. | `+/fset -down 5+` | ◾◽◽ | - | chat : tampon fset | Sélectionner la ligne dans le tampon fset. | `+/window ${_window_number};/fset -go ${_chat_line_y}+` | ◽◽◾ | - | chat : tampon fset | Basculer le booléen (on/off) ou éditer la valeur de l'option. | `+hsignal:fset_mouse+` -| ◽◽◾ | left | chat : tampon fset | Décrémenter la valeur de l'entier/couleur, définir/ajouter à la valeur pour les autres types. | `+hsignal:fset_mouse+` -| ◽◽◾ | right | chat : tampon fset | Incrémenter la valeur de l'entier/couleur, définir/ajouter à la valeur pour les autres types. | `+hsignal:fset_mouse+` +| ◽◽◾ | left | chat : tampon fset | Décrémenter la valeur de l'entier/couleur/énuméré, définir/ajouter à la valeur pour les autres types. | `+hsignal:fset_mouse+` +| ◽◽◾ | right | chat : tampon fset | Incrémenter la valeur de l'entier/couleur/énuméré, définir/ajouter à la valeur pour les autres types. | `+hsignal:fset_mouse+` | ◽◽◾ | up / down | chat : tampon fset | Marquer/démarquer de multiples options. | `+hsignal:fset_mouse+` | kbd:[▲] | - | chat : tampon script | Monter de 5 lignes dans le tampon script. | `+/script up 5+` | kbd:[▼] | - | chat : tampon script | Descendre de 5 lignes dans le tampon script. | `+/script down 5+` @@ -1796,8 +1796,8 @@ Ces touches et actions sont utilisées sur le tampon fset | kbd:[F11] | `pass:[<]` | Faire défiler horizontalement vers la gauche. | `+/fset -left+` | kbd:[F12] | `pass:[>]` | Faire défiler horizontalement vers la droite. | `+/fset -right+` | kbd:[Alt+Space] | `t` | Basculer la valeur booléenne. | `+/fset -toggle+` -| kbd:[Alt+-] | `-` | Soustraire 1 de la valeur de l'entier/couleur, définir la valeur pour les autres types. | `+/fset -add -1+` -| kbd:[Alt++] | `+` | Ajouter 1 à la valeur de l'entier/couleur, ajouter à la valeur pour les autres types. | `+/fset -add 1+` +| kbd:[Alt+-] | `-` | Soustraire 1 de la valeur de l'entier/couleur/énuméré, définir la valeur pour les autres types. | `+/fset -add -1+` +| kbd:[Alt++] | `+` | Ajouter 1 à la valeur de l'entier/couleur/énuméré, ajouter à la valeur pour les autres types. | `+/fset -add 1+` | kbd:[Alt+f], kbd:[Alt+r] | `r` | Réinitialiser la valeur. | `+/fset -reset+` | kbd:[Alt+f], kbd:[Alt+u] | `u` | Supprimer/réinitialiser la valeur. | `+/fset -unset+` | kbd:[Alt+Enter] | `s` | Définir la valeur. | `+/fset -set+` @@ -1868,7 +1868,7 @@ Exemple de tampon fset affichant les options commençant par `weechat.look` : │2.fset │weechat.look.bare_display_exit_on_input: exit the bare display mode on any c│ │ │hanges in input [default: on] │ │ │----------------------------------------------------------------------------│ -│ │ weechat.look.align_end_of_lines integer message │ +│ │ weechat.look.align_end_of_lines enum message │ │ │ weechat.look.align_multiline_words boolean on │ │ │ weechat.look.bar_more_down string "++" │ │ │ weechat.look.bar_more_left string "<<" │ @@ -1877,12 +1877,12 @@ Exemple de tampon fset affichant les options commençant par `weechat.look` : │ │## weechat.look.bare_display_exit_on_input boolean on ##│ │ │ weechat.look.bare_display_time_format string "%H:%M" │ │ │ weechat.look.buffer_auto_renumber boolean on │ -│ │ weechat.look.buffer_notify_default integer all │ -│ │ weechat.look.buffer_position integer end │ +│ │ weechat.look.buffer_notify_default enum all │ +│ │ weechat.look.buffer_position enum end │ │ │ weechat.look.buffer_search_case_sensitive boolean off │ │ │ weechat.look.buffer_search_force_default boolean off │ │ │ weechat.look.buffer_search_regex boolean off │ -│ │ weechat.look.buffer_search_where integer prefix_message │ +│ │ weechat.look.buffer_search_where enum prefix_message │ │ │ weechat.look.buffer_time_format string "%H:%M:%S" │ │ │ weechat.look.buffer_time_same string "" │ │ │[12:55] [2] [fset] 2:fset │ @@ -3366,7 +3366,7 @@ irc.server.libera.autorejoin_delay integer null -> 30 irc.server.libera.away_check integer null -> 0 irc.server.libera.away_check_max_nicks integer null -> 25 irc.server.libera.capabilities string null -> "*" -irc.server.libera.charset_message integer null -> message +irc.server.libera.charset_message enum null -> message irc.server.libera.command string null -> "" irc.server.libera.command_delay integer null -> 0 irc.server.libera.connection_timeout integer null -> 60 @@ -3382,9 +3382,9 @@ irc.server.libera.notify string null -> "" irc.server.libera.password string null -> "" irc.server.libera.proxy string null -> "" irc.server.libera.realname string null -> "" -irc.server.libera.sasl_fail integer null -> reconnect +irc.server.libera.sasl_fail enum null -> reconnect irc.server.libera.sasl_key string null -> "" -irc.server.libera.sasl_mechanism integer null -> plain +irc.server.libera.sasl_mechanism enum null -> plain irc.server.libera.sasl_password string "${sec.data.libera}" irc.server.libera.sasl_timeout integer null -> 15 irc.server.libera.sasl_username string "alice" diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc index 4e0d4960d..9ba5c30f0 100644 --- a/doc/it/weechat_plugin_api.it.adoc +++ b/doc/it/weechat_plugin_api.it.adoc @@ -7157,7 +7157,7 @@ section = weechat.config_search_section(config_file, "section") ==== config_new_option // TRANSLATION MISSING -_Updated in 1.5._ +_Updated in 1.5, 4.1.0._ Crea una nuova opzione nella sezione di un file di configurazione. @@ -7206,12 +7206,15 @@ Argomenti: "name << file.section.option" * _type_: tipo dell'opzione: ** _boolean_: valore booleano (on/off) -** _integer_: valore intero (con stringhe opzionali per i valori) +** _integer_: valore intero ** _string_: valore stringa ** _color_: colore +// TRANSLATION MISSING +** _enum_: list of string values (stored as integer internally) * _description_: descrizione dell'opzione -* _string_values_: valori come stringa (separati da `+|+`), usato dal tipo _integer_ - (opzionale) +// TRANSLATION MISSING +* _string_values_: valori come stringa (separati da `+|+`) (optional, required + for type _enum_) * _min_: valore minimo (per il tipo _integer_) * _max_: valore massimo (per il tipo _integer_) * _default_value_: valore predefinito per l'opzione (usato per il reset dell'opzione) @@ -7265,8 +7268,8 @@ Esempio in C: [source,c] ---- /* booleano */ -struct t_config_option *option1 = - weechat_config_new_option (config_file, section, "option1", "boolean", +struct t_config_option *option_bool = + weechat_config_new_option (config_file, section, "option_bool", "boolean", "My option, type boolean", NULL, 0, 0, @@ -7278,8 +7281,8 @@ struct t_config_option *option1 = NULL, NULL, NULL); /* intero */ -struct t_config_option *option2 = - weechat_config_new_option (config_file, section, "option2", "integer", +struct t_config_option *option_int = + weechat_config_new_option (config_file, section, "option_int", "integer", "My option, type integer", NULL, 0, 100, @@ -7290,22 +7293,9 @@ struct t_config_option *option2 = NULL, NULL, NULL, NULL, NULL, NULL); -/* intero (con valori stringa) */ -struct t_config_option *option3 = - weechat_config_new_option (config_file, section, "option3", "integer", - "My option, type integer (with string values)", - "top|bottom|left|right", - 0, 0, - "bottom", - "bottom", - 0, - NULL, NULL, NULL, - NULL, NULL, NULL, - NULL, NULL, NULL); - /* stringa */ -struct t_config_option *option4 = - weechat_config_new_option (config_file, section, "option4", "string", +struct t_config_option *option_str = + weechat_config_new_option (config_file, section, "option_str", "string", "My option, type string", NULL, 0, 0, @@ -7317,8 +7307,8 @@ struct t_config_option *option4 = NULL, NULL, NULL); /* colore */ -struct t_config_option *option5 = - weechat_config_new_option (config_file, section, "option5", "color", +struct t_config_option *option_col = + weechat_config_new_option (config_file, section, "option_col", "color", "My option, type color", NULL, 0, 0, @@ -7328,6 +7318,19 @@ struct t_config_option *option5 = NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + +/* enum */ +struct t_config_option *option_enum = + weechat_config_new_option (config_file, section, "option_enum", "enum", + "My option, type enum", + "top|bottom|left|right", + 0, 0, + "bottom", + "bottom", + 0, + NULL, NULL, NULL, + NULL, NULL, NULL, + NULL, NULL, NULL); ---- Script (Python): @@ -7343,49 +7346,49 @@ def config_new_option(config_file: str, section: str, name: str, type: str, desc callback_delete: str, callback_delete_data: str) -> str: ... # esempio -def option4_check_value_cb(data: str, option: str, value: str) -> int: +def option_str_check_value_cb(data: str, option: str, value: str) -> int: # ... return 1 # return 0 -def option4_change_cb(data: str, option: str) -> None: +def option_str_change_cb(data: str, option: str) -> None: # ... -def option4_delete_cb(data: str, option: str) -> None: +def option_str_delete_cb(data: str, option: str) -> None: # ... -option1 = weechat.config_new_option(config_file, section, "option1", "boolean", +option_bool = weechat.config_new_option(config_file, section, "option_bool", "boolean", "My option, type boolean", "", 0, 0, "on", "on", 0, "", "", "", "", "", "") -option2 = weechat.config_new_option(config_file, section, "option2", "integer", +option_int = weechat.config_new_option(config_file, section, "option_int", "integer", "My option, type integer", "", 0, 100, "15", "15", 0, "", "", "", "", "", "") -option3 = weechat.config_new_option(config_file, section, "option3", "integer", - "My option, type integer (with string values)", - "top|bottom|left|right", - 0, 0, "bottom", "bottom", 0, +option_str = weechat.config_new_option(config_file, section, "option_str", "string", + "My option, type string", + "", 0, 0, "test", "test", 1, + "option_str_check_value_cb", "", + "option_str_change_cb", "", + "option_str_delete_cb", "") + +option_col = weechat.config_new_option(config_file, section, "option_col", "color", + "My option, type color", + "", 0, 0, "lightblue", "lightblue", 0, "", "", "", "", "", "") -option4 = weechat.config_new_option(config_file, section, "option4", "string", - "My option, type string", - "", 0, 0, "test", "test", 1, - "option4_check_value_cb", "", - "option4_change_cb", "", - "option4_delete_cb", "") - -option5 = weechat.config_new_option(config_file, section, "option5", "color", - "My option, type color", - "", 0, 0, "lightblue", "lightblue", 0, +option_enum = weechat.config_new_option(config_file, section, "option_enum", "enum", + "My option, type enum", + "top|bottom|left|right", + 0, 0, "bottom", "bottom", 0, "", "", "", "", "", "") @@ -7677,7 +7680,7 @@ Argomenti: // TRANSLATION MISSING *** `toggle`: toggle the current value // TRANSLATION MISSING -** _integer_ or _color_: +** _integer_, _color_ or _enum_: // TRANSLATION MISSING *** `++N`: add `N` (any integer) to the current value // TRANSLATION MISSING @@ -7919,6 +7922,7 @@ Argomenti: *** _integer_ *** _string_ *** _color_ +*** _enum_ ** _description_: option description Valore restituito: @@ -8095,6 +8099,7 @@ Return value, depending on the option type: * _integer_: 0 * _string_: 0 * _color_: 0 +* _enum_: 0 Esempio in C: @@ -8146,6 +8151,7 @@ Return value, depending on the option type: * _integer_: 0 * _string_: 0 * _color_: 0 +* _enum_: 0 Esempio in C: @@ -8197,6 +8203,7 @@ Return value, depending on the option type: * _integer_: integer value of option * _string_: 0 * _color_: color index +* _enum_: integer value of option (index of enum value) Esempio in C: @@ -8240,6 +8247,7 @@ Return value, depending on the option type: * _integer_: default integer value of option * _string_: 0 * _color_: default color index +* _enum_: default integer value of option (index of enum value) Esempio in C: @@ -8280,10 +8288,10 @@ Argomenti: Return value, depending on the option type: * _boolean_: "on" if value is true, otherwise "off" -* _integer_: string value if the option is an integer with string values, - otherwise NULL +* _integer_: NULL * _string_: string value of option * _color_: name of color +* _enum_: string value of option Esempio in C: @@ -8324,10 +8332,10 @@ Argomenti: Return value, depending on the option type: * _boolean_: "on" if default value is true, otherwise "off" -* _integer_: default string value if the option is an integer with string - values, otherwise NULL +* _integer_: NULL * _string_: default string value of option * _color_: name of default color +* _enum_: default string value of option Esempio in C: @@ -8371,6 +8379,7 @@ Return value, depending on the option type: * _integer_: NULL * _string_: NULL * _color_: name of color +* _enum_: NULL Esempio in C: @@ -8414,6 +8423,7 @@ Return value, depending on the option type: * _integer_: NULL * _string_: NULL * _color_: name of default color +* _enum_: NULL Esempio in C: @@ -8435,6 +8445,98 @@ option = weechat.config_get("plugin.section.option") value = weechat.config_color_default(option) ---- +// TRANSLATION MISSING +==== config_enum + +_WeeChat ≥ 4.1.0._ + +Return enum value of option, as integer. + +Prototype: + +[source,c] +---- +int weechat_config_enum (struct t_config_option *option); +---- + +Arguments: + +* _option_: option pointer + +Return value, depending on the option type: + +* _boolean_: boolean value of option (0 or 1) +* _integer_: integer value of option +* _string_: 0 +* _color_: color index +* _enum_: integer value of option (index of enum value) + +C example: + +[source,c] +---- +struct t_config_option *option = weechat_config_get ("plugin.section.option"); +int value = weechat_config_enum (option); +---- + +Script (Python): + +[source,python] +---- +# prototype +def config_enum(option: str) -> int: ... + +# example +option = weechat.config_get("plugin.section.option") +value = weechat.config_enum(option) +---- + +// TRANSLATION MISSING +==== config_enum_default + +_WeeChat ≥ 4.1.0._ + +Return default enum value of option, as integer. + +Prototype: + +[source,c] +---- +int weechat_config_enum_default (struct t_config_option *option); +---- + +Arguments: + +* _option_: option pointer + +Return value, depending on the option type: + +* _boolean_: default boolean value of option (0 or 1) +* _integer_: default integer value of option +* _string_: 0 +* _color_: default color index +* _enum_: integer value of option (index of enum value) + +C example: + +[source,c] +---- +struct t_config_option *option = weechat_config_get ("plugin.section.option"); +int value = weechat_config_enum_default (option); +---- + +Script (Python): + +[source,python] +---- +# prototype +def config_enum_default(option: str) -> int: ... + +# example +option = weechat.config_get("plugin.section.option") +value = weechat.config_enum_default(option) +---- + ==== config_write_option Scrive una riga nel file di configurazione con l'opzione ed il suo valore diff --git a/doc/it/weechat_user.it.adoc b/doc/it/weechat_user.it.adoc index 7c4d864f6..a2c5925e6 100644 --- a/doc/it/weechat_user.it.adoc +++ b/doc/it/weechat_user.it.adoc @@ -1892,9 +1892,9 @@ These mouse actions are possible only if mouse is enabled with key kbd:[Alt+m] // TRANSLATION MISSING | ◽◽◾ | - | chat: fset buffer | Toggle boolean (on/off) or edit the option value. | `+hsignal:fset_mouse+` // TRANSLATION MISSING -| ◽◽◾ | left | chat: fset buffer | Decrease value for integer/color, set/append to value for other types. | `+hsignal:fset_mouse+` +| ◽◽◾ | left | chat: fset buffer | Decrease value for integer/color/enum, set/append to value for other types. | `+hsignal:fset_mouse+` // TRANSLATION MISSING -| ◽◽◾ | right | chat: fset buffer | Increase value for integer/color, set/append to value for other types. | `+hsignal:fset_mouse+` +| ◽◽◾ | right | chat: fset buffer | Increase value for integer/color/enum, set/append to value for other types. | `+hsignal:fset_mouse+` // TRANSLATION MISSING | ◽◽◾ | up / down | chat: fset buffer | Mark/unmark multiple options. | `+hsignal:fset_mouse+` // TRANSLATION MISSING @@ -1956,8 +1956,8 @@ These keys and actions are used on the fset buffer (see <>). | kbd:[F11] | `pass:[<]` | Scroll horizontally on the left. | `+/fset -left+` | kbd:[F12] | `pass:[>]` | Scroll horizontally on the right. | `+/fset -right+` | kbd:[Alt+Space] | `t` | Toggle boolean value. | `+/fset -toggle+` -| kbd:[Alt+-] | `-` | Subtract 1 from value for integer/color, set value for other types. | `+/fset -add -1+` -| kbd:[Alt++] | `+` | Add 1 to value for integer/color, append to value for other types. | `+/fset -add 1+` +| kbd:[Alt+-] | `-` | Subtract 1 from value for integer/color/enum, set value for other types. | `+/fset -add -1+` +| kbd:[Alt++] | `+` | Add 1 to value for integer/color/enum, append to value for other types. | `+/fset -add 1+` | kbd:[Alt+f], kbd:[Alt+r] | `r` | Reset value. | `+/fset -reset+` | kbd:[Alt+f], kbd:[Alt+u] | `u` | Unset value. | `+/fset -unset+` | kbd:[Alt+Enter] | `s` | Set value. | `+/fset -set+` @@ -2035,7 +2035,7 @@ Example of fset buffer displaying options starting with `weechat.look` : │2.fset │weechat.look.bare_display_exit_on_input: exit the bare display mode on any c│ │ │hanges in input [default: on] │ │ │----------------------------------------------------------------------------│ -│ │ weechat.look.align_end_of_lines integer message │ +│ │ weechat.look.align_end_of_lines enum message │ │ │ weechat.look.align_multiline_words boolean on │ │ │ weechat.look.bar_more_down string "++" │ │ │ weechat.look.bar_more_left string "<<" │ @@ -2044,12 +2044,12 @@ Example of fset buffer displaying options starting with `weechat.look` : │ │## weechat.look.bare_display_exit_on_input boolean on ##│ │ │ weechat.look.bare_display_time_format string "%H:%M" │ │ │ weechat.look.buffer_auto_renumber boolean on │ -│ │ weechat.look.buffer_notify_default integer all │ -│ │ weechat.look.buffer_position integer end │ +│ │ weechat.look.buffer_notify_default enum all │ +│ │ weechat.look.buffer_position enum end │ │ │ weechat.look.buffer_search_case_sensitive boolean off │ │ │ weechat.look.buffer_search_force_default boolean off │ │ │ weechat.look.buffer_search_regex boolean off │ -│ │ weechat.look.buffer_search_where integer prefix_message │ +│ │ weechat.look.buffer_search_where enum prefix_message │ │ │ weechat.look.buffer_time_format string "%H:%M:%S" │ │ │ weechat.look.buffer_time_same string "" │ │ │[12:55] [2] [fset] 2:fset │ @@ -3542,7 +3542,7 @@ irc.server.libera.autorejoin_delay integer null -> 30 irc.server.libera.away_check integer null -> 0 irc.server.libera.away_check_max_nicks integer null -> 25 irc.server.libera.capabilities string null -> "*" -irc.server.libera.charset_message integer null -> message +irc.server.libera.charset_message enum null -> message irc.server.libera.command string null -> "" irc.server.libera.command_delay integer null -> 0 irc.server.libera.connection_timeout integer null -> 60 @@ -3558,9 +3558,9 @@ irc.server.libera.notify string null -> "" irc.server.libera.password string null -> "" irc.server.libera.proxy string null -> "" irc.server.libera.realname string null -> "" -irc.server.libera.sasl_fail integer null -> reconnect +irc.server.libera.sasl_fail enum null -> reconnect irc.server.libera.sasl_key string null -> "" -irc.server.libera.sasl_mechanism integer null -> plain +irc.server.libera.sasl_mechanism enum null -> plain irc.server.libera.sasl_password string "${sec.data.libera}" irc.server.libera.sasl_timeout integer null -> 15 irc.server.libera.sasl_username string "alice" diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc index 0a79e0e09..9d773a7d7 100644 --- a/doc/ja/weechat_plugin_api.ja.adoc +++ b/doc/ja/weechat_plugin_api.ja.adoc @@ -6960,7 +6960,8 @@ section = weechat.config_search_section(config_file, "section") ==== config_new_option -_WeeChat バージョン 1.5 で更新。_ +// TRANSLATION MISSING +_Updated in 1.5, 4.1.0._ 設定ファイルのあるセクションに新しいオプションを作成。 @@ -7008,12 +7009,15 @@ struct t_config_option *weechat_config_new_option ( "name << file.section.option" * _type_: オプションの型: ** _boolean_: ブール値 (on/off) -** _integer_: 整数値 (任意で文字列を受けるようにすることも可) +** _integer_: 整数値 ** _string_: 文字列 ** _color_: 色 +// TRANSLATION MISSING +** _enum_: list of string values (stored as integer internally) * _description_: オプションの説明 +// TRANSLATION MISSING * _string_values_: 文字列で値を受ける - (`+|+` で区切る)、_integer_ 型の場合に使う (任意) + (`+|+` で区切る) (optional, required for type _enum_) * _min_: 最小値 (_integer_ 型で有効) * _max_: 最大値 (_integer_ 型で有効) * _default_value_: オプションのデフォルト値 (オプションをリセットした際に使われる) @@ -7064,8 +7068,8 @@ C 言語での使用例: [source,c] ---- /* boolean */ -struct t_config_option *option1 = - weechat_config_new_option (config_file, section, "option1", "boolean", +struct t_config_option *option_bool = + weechat_config_new_option (config_file, section, "option_bool", "boolean", "My option, type boolean", NULL, 0, 0, @@ -7077,8 +7081,8 @@ struct t_config_option *option1 = NULL, NULL, NULL); /* integer */ -struct t_config_option *option2 = - weechat_config_new_option (config_file, section, "option2", "integer", +struct t_config_option *option_int = + weechat_config_new_option (config_file, section, "option_int", "integer", "My option, type integer", NULL, 0, 100, @@ -7089,22 +7093,9 @@ struct t_config_option *option2 = NULL, NULL, NULL, NULL, NULL, NULL); -/* integer (with string values) */ -struct t_config_option *option3 = - weechat_config_new_option (config_file, section, "option3", "integer", - "My option, type integer (with string values)", - "top|bottom|left|right", - 0, 0, - "bottom", - "bottom", - 0, - NULL, NULL, NULL, - NULL, NULL, NULL, - NULL, NULL, NULL); - /* string */ -struct t_config_option *option4 = - weechat_config_new_option (config_file, section, "option4", "string", +struct t_config_option *option_str = + weechat_config_new_option (config_file, section, "option_str", "string", "My option, type string", NULL, 0, 0, @@ -7116,8 +7107,8 @@ struct t_config_option *option4 = NULL, NULL, NULL); /* color */ -struct t_config_option *option5 = - weechat_config_new_option (config_file, section, "option5", "color", +struct t_config_option *option_col = + weechat_config_new_option (config_file, section, "option_col", "color", "My option, type color", NULL, 0, 0, @@ -7127,6 +7118,19 @@ struct t_config_option *option5 = NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + +/* enum */ +struct t_config_option *option_enum = + weechat_config_new_option (config_file, section, "option_enum", "enum", + "My option, type enum", + "top|bottom|left|right", + 0, 0, + "bottom", + "bottom", + 0, + NULL, NULL, NULL, + NULL, NULL, NULL, + NULL, NULL, NULL); ---- スクリプト (Python) での使用例: @@ -7142,49 +7146,49 @@ def config_new_option(config_file: str, section: str, name: str, type: str, desc callback_delete: str, callback_delete_data: str) -> str: ... # 例 -def option4_check_value_cb(data: str, option: str, value: str) -> int: +def option_str_check_value_cb(data: str, option: str, value: str) -> int: # ... return 1 # return 0 -def option4_change_cb(data: str, option: str) -> None: +def option_str_change_cb(data: str, option: str) -> None: # ... -def option4_delete_cb(data: str, option: str) -> None: +def option_str_delete_cb(data: str, option: str) -> None: # ... -option1 = weechat.config_new_option(config_file, section, "option1", "boolean", +option_bool = weechat.config_new_option(config_file, section, "option_bool", "boolean", "My option, type boolean", "", 0, 0, "on", "on", 0, "", "", "", "", "", "") -option2 = weechat.config_new_option(config_file, section, "option2", "integer", +option_int = weechat.config_new_option(config_file, section, "option_int", "integer", "My option, type integer", "", 0, 100, "15", "15", 0, "", "", "", "", "", "") -option3 = weechat.config_new_option(config_file, section, "option3", "integer", - "My option, type integer (with string values)", - "top|bottom|left|right", - 0, 0, "bottom", "bottom", 0, +option_str = weechat.config_new_option(config_file, section, "option_str", "string", + "My option, type string", + "", 0, 0, "test", "test", 1, + "option_str_check_value_cb", "", + "option_str_change_cb", "", + "option_str_delete_cb", "") + +option_col = weechat.config_new_option(config_file, section, "option_col", "color", + "My option, type color", + "", 0, 0, "lightblue", "lightblue", 0, "", "", "", "", "", "") -option4 = weechat.config_new_option(config_file, section, "option4", "string", - "My option, type string", - "", 0, 0, "test", "test", 1, - "option4_check_value_cb", "", - "option4_change_cb", "", - "option4_delete_cb", "") - -option5 = weechat.config_new_option(config_file, section, "option5", "color", - "My option, type color", - "", 0, 0, "lightblue", "lightblue", 0, +option_enum = weechat.config_new_option(config_file, section, "option_enum", "enum", + "My option, type enum", + "top|bottom|left|right", + 0, 0, "bottom", "bottom", 0, "", "", "", "", "", "") @@ -7468,7 +7472,8 @@ int weechat_config_option_set (struct t_config_option *option, オプションの新しい値、オプションのタイプによって以下の特殊値を取ることも可能です: ** _ブール型_: *** `toggle`: 現在の値を切り替える -** _整数型_ または _色_: +// TRANSLATION MISSING +** _integer_, _color_ or _enum_: *** `++N`: 現在の値に `N` (任意の整数) を加える *** `--N`: 現在の値から `N` (任意の整数) を引く * _run_callback_: オプションが変更された際に、_callback_change_ コールバックを呼び出す場合は @@ -7702,6 +7707,7 @@ const char *weechat_config_option_get_string (struct t_config_option *option, *** _integer_ *** _string_ *** _color_ +*** _enum_ ** _description_: オプションの説明 戻り値: @@ -7875,6 +7881,7 @@ int weechat_config_boolean (struct t_config_option *option); * _integer_: 0 * _string_: 0 * _color_: 0 +* _enum_: 0 C 言語での使用例: @@ -7925,6 +7932,7 @@ int weechat_config_boolean_default (struct t_config_option *option); * _integer_: 0 * _string_: 0 * _color_: 0 +* _enum_: 0 C 言語での使用例: @@ -7975,6 +7983,8 @@ int weechat_config_integer (struct t_config_option *option); * _integer_: オプションの整数値 * _string_: 0 * _color_: 色インデックス +// TRANSLATION MISSING +* _enum_: integer value of option (index of enum value) C 言語での使用例: @@ -8017,6 +8027,8 @@ int weechat_config_integer_default (struct t_config_option *option); * _integer_: オプションのデフォルト整数値 * _string_: 0 * _color_: デフォルト色インデックス +// TRANSLATION MISSING +* _enum_: default integer value of option (index of enum value) C 言語での使用例: @@ -8056,10 +8068,11 @@ const char *weechat_config_string (struct t_config_option *option); 戻り値、オプションの型に依存: * _boolean_: 値が真の場合は "on"、それ以外の場合は "off" -* _integer_: 値が文字列に対応付けられている場合はその文字列値、それ以外の場合は - NULL +* _integer_: NULL * _string_: オプションの文字列値 * _color_: 色名 +// TRANSLATION MISSING +* _enum_: string value of option C 言語での使用例: @@ -8099,10 +8112,11 @@ const char *weechat_config_string_default (struct t_config_option *option); 戻り値、オプションの型に依存: * _boolean_: デフォルト値が真の場合は "on"、それ以外の場合は "off" -* _integer_: デフォルト値が文字列に対応付けられている場合はその文字列値、それ以外の場合は - NULL +* _integer_: NULL * _string_: オプションのデフォルト文字列値 * _color_: デフォルト色名 +// TRANSLATION MISSING +* _enum_: default string value of option C 言語での使用例: @@ -8145,6 +8159,7 @@ const char *weechat_config_color (struct t_config_option *option); * _integer_: NULL * _string_: NULL * _color_: 色名 +* _enum_: NULL C 言語での使用例: @@ -8187,6 +8202,7 @@ const char *weechat_config_color_default (struct t_config_option *option); * _integer_: NULL * _string_: NULL * _color_: デフォルト色名 +* _enum_: NULL C 言語での使用例: @@ -8208,6 +8224,98 @@ option = weechat.config_get("plugin.section.option") value = weechat.config_color_default(option) ---- +// TRANSLATION MISSING +==== config_enum + +_WeeChat ≥ 4.1.0._ + +Return enum value of option, as integer. + +Prototype: + +[source,c] +---- +int weechat_config_enum (struct t_config_option *option); +---- + +Arguments: + +* _option_: option pointer + +Return value, depending on the option type: + +* _boolean_: boolean value of option (0 or 1) +* _integer_: integer value of option +* _string_: 0 +* _color_: color index +* _enum_: integer value of option (index of enum value) + +C example: + +[source,c] +---- +struct t_config_option *option = weechat_config_get ("plugin.section.option"); +int value = weechat_config_enum (option); +---- + +Script (Python): + +[source,python] +---- +# prototype +def config_enum(option: str) -> int: ... + +# example +option = weechat.config_get("plugin.section.option") +value = weechat.config_enum(option) +---- + +// TRANSLATION MISSING +==== config_enum_default + +_WeeChat ≥ 4.1.0._ + +Return default enum value of option, as integer. + +Prototype: + +[source,c] +---- +int weechat_config_enum_default (struct t_config_option *option); +---- + +Arguments: + +* _option_: option pointer + +Return value, depending on the option type: + +* _boolean_: default boolean value of option (0 or 1) +* _integer_: default integer value of option +* _string_: 0 +* _color_: default color index +* _enum_: integer value of option (index of enum value) + +C example: + +[source,c] +---- +struct t_config_option *option = weechat_config_get ("plugin.section.option"); +int value = weechat_config_enum_default (option); +---- + +Script (Python): + +[source,python] +---- +# prototype +def config_enum_default(option: str) -> int: ... + +# example +option = weechat.config_get("plugin.section.option") +value = weechat.config_enum_default(option) +---- + ==== config_write_option 設定ファイルにオプションとその値を収めた行を書き込む (この関数をセクションの diff --git a/doc/ja/weechat_user.ja.adoc b/doc/ja/weechat_user.ja.adoc index 4f4282ca9..f19c09a42 100644 --- a/doc/ja/weechat_user.ja.adoc +++ b/doc/ja/weechat_user.ja.adoc @@ -1834,9 +1834,9 @@ These mouse actions are possible only if mouse is enabled with key kbd:[Alt+m] // TRANSLATION MISSING | ◽◽◾ | - | chat: fset buffer | Toggle boolean (on/off) or edit the option value. | `+hsignal:fset_mouse+` // TRANSLATION MISSING -| ◽◽◾ | left | chat: fset buffer | Decrease value for integer/color, set/append to value for other types. | `+hsignal:fset_mouse+` +| ◽◽◾ | left | chat: fset buffer | Decrease value for integer/color/enum, set/append to value for other types. | `+hsignal:fset_mouse+` // TRANSLATION MISSING -| ◽◽◾ | right | chat: fset buffer | Increase value for integer/color, set/append to value for other types. | `+hsignal:fset_mouse+` +| ◽◽◾ | right | chat: fset buffer | Increase value for integer/color/enum, set/append to value for other types. | `+hsignal:fset_mouse+` // TRANSLATION MISSING | ◽◽◾ | up / down | chat: fset buffer | Mark/unmark multiple options. | `+hsignal:fset_mouse+` | kbd:[▲] | - | チャット: スクリプトバッファ | スクリプトバッファを 5 行上方向にスクロール | `+/script up 5+` @@ -1887,8 +1887,8 @@ These keys and actions are used on the fset buffer (see <>). | kbd:[F11] | `pass:[<]` | Scroll horizontally on the left. | `+/fset -left+` | kbd:[F12] | `pass:[>]` | Scroll horizontally on the right. | `+/fset -right+` | kbd:[Alt+Space] | `t` | Toggle boolean value. | `+/fset -toggle+` -| kbd:[Alt+-] | `-` | Subtract 1 from value for integer/color, set value for other types. | `+/fset -add -1+` -| kbd:[Alt++] | `+` | Add 1 to value for integer/color, append to value for other types. | `+/fset -add 1+` +| kbd:[Alt+-] | `-` | Subtract 1 from value for integer/color/enum, set value for other types. | `+/fset -add -1+` +| kbd:[Alt++] | `+` | Add 1 to value for integer/color/enum, append to value for other types. | `+/fset -add 1+` | kbd:[Alt+f], kbd:[Alt+r] | `r` | Reset value. | `+/fset -reset+` | kbd:[Alt+f], kbd:[Alt+u] | `u` | Unset value. | `+/fset -unset+` | kbd:[Alt+Enter] | `s` | Set value. | `+/fset -set+` @@ -1965,7 +1965,7 @@ Example of fset buffer displaying options starting with `weechat.look` : │2.fset │weechat.look.bare_display_exit_on_input: exit the bare display mode on any c│ │ │hanges in input [default: on] │ │ │----------------------------------------------------------------------------│ -│ │ weechat.look.align_end_of_lines integer message │ +│ │ weechat.look.align_end_of_lines enum message │ │ │ weechat.look.align_multiline_words boolean on │ │ │ weechat.look.bar_more_down string "++" │ │ │ weechat.look.bar_more_left string "<<" │ @@ -1974,12 +1974,12 @@ Example of fset buffer displaying options starting with `weechat.look` : │ │## weechat.look.bare_display_exit_on_input boolean on ##│ │ │ weechat.look.bare_display_time_format string "%H:%M" │ │ │ weechat.look.buffer_auto_renumber boolean on │ -│ │ weechat.look.buffer_notify_default integer all │ -│ │ weechat.look.buffer_position integer end │ +│ │ weechat.look.buffer_notify_default enum all │ +│ │ weechat.look.buffer_position enum end │ │ │ weechat.look.buffer_search_case_sensitive boolean off │ │ │ weechat.look.buffer_search_force_default boolean off │ │ │ weechat.look.buffer_search_regex boolean off │ -│ │ weechat.look.buffer_search_where integer prefix_message │ +│ │ weechat.look.buffer_search_where enum prefix_message │ │ │ weechat.look.buffer_time_format string "%H:%M:%S" │ │ │ weechat.look.buffer_time_same string "" │ │ │[12:55] [2] [fset] 2:fset │ @@ -3414,7 +3414,7 @@ irc.server.libera.autorejoin_delay integer null -> 30 irc.server.libera.away_check integer null -> 0 irc.server.libera.away_check_max_nicks integer null -> 25 irc.server.libera.capabilities string null -> "*" -irc.server.libera.charset_message integer null -> message +irc.server.libera.charset_message enum null -> message irc.server.libera.command string null -> "" irc.server.libera.command_delay integer null -> 0 irc.server.libera.connection_timeout integer null -> 60 @@ -3430,9 +3430,9 @@ irc.server.libera.notify string null -> "" irc.server.libera.password string null -> "" irc.server.libera.proxy string null -> "" irc.server.libera.realname string null -> "" -irc.server.libera.sasl_fail integer null -> reconnect +irc.server.libera.sasl_fail enum null -> reconnect irc.server.libera.sasl_key string null -> "" -irc.server.libera.sasl_mechanism integer null -> plain +irc.server.libera.sasl_mechanism enum null -> plain irc.server.libera.sasl_password string "${sec.data.libera}" irc.server.libera.sasl_timeout integer null -> 15 irc.server.libera.sasl_username string "alice" diff --git a/doc/pl/weechat_user.pl.adoc b/doc/pl/weechat_user.pl.adoc index dd4796a45..6b5f78c03 100644 --- a/doc/pl/weechat_user.pl.adoc +++ b/doc/pl/weechat_user.pl.adoc @@ -1719,8 +1719,10 @@ za pomocą skrótu kbd:[Alt+m] (komenda: `+/mouse toggle+`). | kbd:[▼] | - | chat: bufor fset | Przewiń pięć linii w dół w buforze fset. | `+/fset -down 5+` | ◾◽◽ | - | chat: bufor fset | Zaznacz linię b buforze fset. | `+/window ${_window_number};/fset -go ${_chat_line_y}+` | ◽◽◾ | - | chat: bufor fset | Przełącz (włącz/wyłącz) lub edytuj wartośc opcji. | `+hsignal:fset_mouse+` -| ◽◽◾ | left | chat: bufor fset | Zmniejsz wartość zmiennej liczbowej / koloru, ustaw/rozszerz wartośc innego typu. | `+hsignal:fset_mouse+` -| ◽◽◾ | right | chat: bufor fset | Zwiększ wartość zmiennej liczbowej / koloru, ustaw/rozszerz wartośc innego typu. | `+hsignal:fset_mouse+` +// TRANSLATION MISSING +| ◽◽◾ | left | chat: bufor fset | Zmniejsz wartość zmiennej liczbowej / koloru / enum, ustaw/rozszerz wartośc innego typu. | `+hsignal:fset_mouse+` +// TRANSLATION MISSING +| ◽◽◾ | right | chat: bufor fset | Zwiększ wartość zmiennej liczbowej / koloru / enum, ustaw/rozszerz wartośc innego typu. | `+hsignal:fset_mouse+` | ◽◽◾ | up / down | chat: bufor fset | Zaznacz/odznacz wiele opcji. | `+hsignal:fset_mouse+` | kbd:[▲] | - | chat: bufor skryptów | Przejdź 5 linii w górę w buforze skryptów. | `+/script up 5+` | kbd:[▼] | - | chat: bufor skryptów | Przejdź 5 linii w dół w buforze skryptów. | `+/script down 5+` @@ -1767,8 +1769,10 @@ Poniższe skróty i akcje mogą zostać użyte w buforze fset (zobacz <]` | Przewiń poziomo w prawo. | `+/fset -right+` | kbd:[Alt+Space] | `t` | Przełącz zmienną boolowską. | `+/fset -toggle+` -| kbd:[Alt+-] | `-` | Odejmij 1 od wartości liczbowej/koloru, ustaw wartość pozostałych typów. | `+/fset -del -1+` -| kbd:[Alt++] | `+` | Dodaj 1 do wartości liczbowej/koloru, dodaj to wartości pozostałych typów. | `+/fset -add 1+` +// TRANSLATION MISSING +| kbd:[Alt+-] | `-` | Odejmij 1 od wartości liczbowej/koloru/enum, ustaw wartość pozostałych typów. | `+/fset -del -1+` +// TRANSLATION MISSING +| kbd:[Alt++] | `+` | Dodaj 1 do wartości liczbowej/koloru/enum, dodaj to wartości pozostałych typów. | `+/fset -add 1+` | kbd:[Alt+f], kbd:[Alt+r] | `r` | Zresetuj wartość. | `+/fset -reset+` | kbd:[Alt+f], kbd:[Alt+u] | `u` | Skasuj wartość. | `+/fset -unset+` | kbd:[Alt+Enter] | `s` | Ustaw wartość. | `+/fset -set+` @@ -1838,7 +1842,7 @@ Przykład bufora fset wyświetlający opcje zaczynające się od `weechat.look` │2.fset │weechat.look.bare_display_exit_on_input: exit the bare display mode on any c│ │ │hanges in input [default: on] │ │ │----------------------------------------------------------------------------│ -│ │ weechat.look.align_end_of_lines integer message │ +│ │ weechat.look.align_end_of_lines enum message │ │ │ weechat.look.align_multiline_words boolean on │ │ │ weechat.look.bar_more_down string "++" │ │ │ weechat.look.bar_more_left string "<<" │ @@ -1847,12 +1851,12 @@ Przykład bufora fset wyświetlający opcje zaczynające się od `weechat.look` │ │## weechat.look.bare_display_exit_on_input boolean on ##│ │ │ weechat.look.bare_display_time_format string "%H:%M" │ │ │ weechat.look.buffer_auto_renumber boolean on │ -│ │ weechat.look.buffer_notify_default integer all │ -│ │ weechat.look.buffer_position integer end │ +│ │ weechat.look.buffer_notify_default enum all │ +│ │ weechat.look.buffer_position enum end │ │ │ weechat.look.buffer_search_case_sensitive boolean off │ │ │ weechat.look.buffer_search_force_default boolean off │ │ │ weechat.look.buffer_search_regex boolean off │ -│ │ weechat.look.buffer_search_where integer prefix_message │ +│ │ weechat.look.buffer_search_where enum prefix_message │ │ │ weechat.look.buffer_time_format string "%H:%M:%S" │ │ │ weechat.look.buffer_time_same string "" │ │ │[12:55] [2] [fset] 2:fset │ @@ -3287,7 +3291,7 @@ irc.server.libera.autorejoin_delay integer null -> 30 irc.server.libera.away_check integer null -> 0 irc.server.libera.away_check_max_nicks integer null -> 25 irc.server.libera.capabilities string null -> "*" -irc.server.libera.charset_message integer null -> message +irc.server.libera.charset_message enum null -> message irc.server.libera.command string null -> "" irc.server.libera.command_delay integer null -> 0 irc.server.libera.connection_timeout integer null -> 60 @@ -3303,9 +3307,9 @@ irc.server.libera.notify string null -> "" irc.server.libera.password string null -> "" irc.server.libera.proxy string null -> "" irc.server.libera.realname string null -> "" -irc.server.libera.sasl_fail integer null -> reconnect +irc.server.libera.sasl_fail enum null -> reconnect irc.server.libera.sasl_key string null -> "" -irc.server.libera.sasl_mechanism integer null -> plain +irc.server.libera.sasl_mechanism enum null -> plain irc.server.libera.sasl_password string "${sec.data.libera}" irc.server.libera.sasl_timeout integer null -> 15 irc.server.libera.sasl_username string "alice" diff --git a/doc/sr/weechat_plugin_api.sr.adoc b/doc/sr/weechat_plugin_api.sr.adoc index 6074d2cf7..d9300c1c6 100644 --- a/doc/sr/weechat_plugin_api.sr.adoc +++ b/doc/sr/weechat_plugin_api.sr.adoc @@ -6685,7 +6685,7 @@ section = weechat.config_search_section(config_file, "section") ==== config_new_option -_Ажурирано у верзији 1.5._ +_Ажурирано у верзији 1.5, 4.1.0._ Креира нову опцију у одељку конфигурационог фајла. @@ -6730,11 +6730,15 @@ struct t_config_option *weechat_config_new_option ( * _name_: име опције; у програм у WeeChat верзије ≥ 1.4, име може да укључи и име родитељске опције (у случају да је ова опција „null”, вредност родитељске опције ће се приказати у излазу команде `/set`), тада је синтакса: „име << фајл.одељак.опција” * _type_: тип опције: ** _boolean_: логичка вредност (on/off) -** _integer_: целобројна вредност (са стринговима за вредности који нису обавезни) +** _integer_: целобројна вредност ** _string_: стринг вредност ** _color_: боја +// TRANSLATION MISSING +** _enum_: list of string values (stored as integer internally) * _description_: опис опције -* _string_values_: вредности као стринг (раздвојене са `+|+`), користе се за _integer_ тип (није обавезно) +// TRANSLATION MISSING +* _string_values_: вредности као стринг (раздвојене са `+|+`) (optional, required + for type _enum_) * _min_: минимална вредност (за _integer_ тип) * _max_: максимална вредност (за _integer_ тип) * _default_value_: подразумевана вредност опције (користи се када се опција ресетује) @@ -6772,8 +6776,8 @@ C пример: [source,c] ---- /* логичка */ -struct t_config_option *option1 = - weechat_config_new_option (config_file, section, "option1", "boolean", +struct t_config_option *option_bool = + weechat_config_new_option (config_file, section, "option_bool", "boolean", "My option, type boolean", NULL, 0, 0, @@ -6785,8 +6789,8 @@ struct t_config_option *option1 = NULL, NULL, NULL); /* целобројна */ -struct t_config_option *option2 = - weechat_config_new_option (config_file, section, "option2", "integer", +struct t_config_option *option_int = + weechat_config_new_option (config_file, section, "option_int", "integer", "My option, type integer", NULL, 0, 100, @@ -6797,22 +6801,9 @@ struct t_config_option *option2 = NULL, NULL, NULL, NULL, NULL, NULL); -/* целобројна (са стринг вредностима) */ -struct t_config_option *option3 = - weechat_config_new_option (config_file, section, "option3", "integer", - "My option, type integer (with string values)", - "top|bottom|left|right", - 0, 0, - "bottom", - "bottom", - 0, - NULL, NULL, NULL, - NULL, NULL, NULL, - NULL, NULL, NULL); - /* стринг */ -struct t_config_option *option4 = - weechat_config_new_option (config_file, section, "option4", "string", +struct t_config_option *option_str = + weechat_config_new_option (config_file, section, "option_str", "string", "My option, type string", NULL, 0, 0, @@ -6824,8 +6815,8 @@ struct t_config_option *option4 = NULL, NULL, NULL); /* боја */ -struct t_config_option *option5 = - weechat_config_new_option (config_file, section, "option5", "color", +struct t_config_option *option_col = + weechat_config_new_option (config_file, section, "option_col", "color", "My option, type color", NULL, 0, 0, @@ -6835,6 +6826,19 @@ struct t_config_option *option5 = NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + +/* целобројна (са стринг вредностима) */ +struct t_config_option *option_enum = + weechat_config_new_option (config_file, section, "option_enum", "enum", + "My option, type enum", + "top|bottom|left|right", + 0, 0, + "bottom", + "bottom", + 0, + NULL, NULL, NULL, + NULL, NULL, NULL, + NULL, NULL, NULL); ---- Скрипта (Python): @@ -6850,49 +6854,49 @@ def config_new_option(config_file: str, section: str, name: str, type: str, desc callback_delete: str, callback_delete_data: str) -> str: ... # пример -def option4_check_value_cb(data: str, option: str, value: str) -> int: +def option_str_check_value_cb(data: str, option: str, value: str) -> int: # ... return 1 # return 0 -def option4_change_cb(data: str, option: str) -> None: +def option_str_change_cb(data: str, option: str) -> None: # ... -def option4_delete_cb(data: str, option: str) -> None: +def option_str_delete_cb(data: str, option: str) -> None: # ... -option1 = weechat.config_new_option(config_file, section, "option1", "boolean", +option_bool = weechat.config_new_option(config_file, section, "option_bool", "boolean", "My option, type boolean", "", 0, 0, "on", "on", 0, "", "", "", "", "", "") -option2 = weechat.config_new_option(config_file, section, "option2", "integer", +option_int = weechat.config_new_option(config_file, section, "option_int", "integer", "My option, type integer", "", 0, 100, "15", "15", 0, "", "", "", "", "", "") -option3 = weechat.config_new_option(config_file, section, "option3", "integer", - "My option, type integer (with string values)", - "top|bottom|left|right", - 0, 0, "bottom", "bottom", 0, +option_str = weechat.config_new_option(config_file, section, "option_str", "string", + "My option, type string", + "", 0, 0, "test", "test", 1, + "option_str_check_value_cb", "", + "option_str_change_cb", "", + "option_str_delete_cb", "") + +option_col = weechat.config_new_option(config_file, section, "option_col", "color", + "My option, type color", + "", 0, 0, "lightblue", "lightblue", 0, "", "", "", "", "", "") -option4 = weechat.config_new_option(config_file, section, "option4", "string", - "My option, type string", - "", 0, 0, "test", "test", 1, - "option4_check_value_cb", "", - "option4_change_cb", "", - "option4_delete_cb", "") - -option5 = weechat.config_new_option(config_file, section, "option5", "color", - "My option, type color", - "", 0, 0, "lightblue", "lightblue", 0, +option_enum = weechat.config_new_option(config_file, section, "option_enum", "enum", + "My option, type enum", + "top|bottom|left|right", + 0, 0, "bottom", "bottom", 0, "", "", "", "", "", "") @@ -7164,7 +7168,8 @@ int weechat_config_option_set (struct t_config_option *option, * _value_: нова вредност опције, могуће су и специјалне вредности које зависе од типа опције: ** _boolean_: *** `toggle`: пребацује текућу вредност -** _integer_ или _color_: +// TRANSLATION MISSING +** _integer_, _color_ or _enum_: *** `++N`: додаје `N` (било који цео број) на текућу вредност *** `--N`: одузима `N` (било који цео број) од текуће вредности * _run_callback_: 1 за позив change функције повратног позива ако је вредност измењена, у супротном 0 @@ -7395,6 +7400,7 @@ const char *weechat_config_option_get_string (struct t_config_option *option, *** _integer_ *** _string_ *** _color_ +*** _enum_ ** _description_: опис опције Повратна вредност: @@ -7569,6 +7575,7 @@ int weechat_config_boolean (struct t_config_option *option); * _integer_: 0 * _string_: 0 * _color_: 0 +* _enum_: 0 C пример: @@ -7619,6 +7626,7 @@ int weechat_config_boolean_default (struct t_config_option *option); * _integer_: 0 * _string_: 0 * _color_: 0 +* _enum_: 0 C пример: @@ -7669,6 +7677,8 @@ int weechat_config_integer (struct t_config_option *option); * _integer_: целобројна вредност опције * _string_: 0 * _color_: индекс боје +// TRANSLATION MISSING +* _enum_: integer value of option (index of enum value) C пример: @@ -7711,6 +7721,8 @@ int weechat_config_integer_default (struct t_config_option *option); * _integer_: подразумевана целобројна вредност опције * _string_: 0 * _color_: подразумевани индекс боје +// TRANSLATION MISSING +* _enum_: default integer value of option (index of enum value) C пример: @@ -7750,9 +7762,11 @@ const char *weechat_config_string (struct t_config_option *option); Повратна вредност, зависи од типа опције: * _boolean_: „on” ако је вредност истинита, у супротном „off” -* _integer_: стринг вредност опције је цео број са стринг вредностима, у супротном је NULL +* _integer_: NULL * _string_: стринг вредност опције * _color_: име боје +// TRANSLATION MISSING +* _enum_: string value of option C пример: @@ -7792,9 +7806,11 @@ const char *weechat_config_string_default (struct t_config_option *option); Повратна вредност, зависи од типа опције: * _boolean_: „on” ако је подразумевана вредност истинита, у супротном „off” -* _integer_: подразумевана стринг вредност опције је цео број са стринг вредностима, у супротном је NULL +* _integer_: NULL * _string_: подразумевана стринг вредност опције * _color_: име подразумеване боје +// TRANSLATION MISSING +* _enum_: default string value of option C пример: @@ -7837,6 +7853,7 @@ const char *weechat_config_color (struct t_config_option *option); * _integer_: NULL * _string_: NULL * _color_: име боје +* _enum_: NULL C пример: @@ -7879,6 +7896,7 @@ const char *weechat_config_color_default (struct t_config_option *option); * _integer_: NULL * _string_: NULL * _color_: име подразумеване боје +* _enum_: NULL C пример: @@ -7900,6 +7918,98 @@ option = weechat.config_get("plugin.section.option") value = weechat.config_color_default(option) ---- +// TRANSLATION MISSING +==== config_enum + +_WeeChat ≥ 4.1.0._ + +Return enum value of option, as integer. + +Prototype: + +[source,c] +---- +int weechat_config_enum (struct t_config_option *option); +---- + +Arguments: + +* _option_: option pointer + +Return value, depending on the option type: + +* _boolean_: boolean value of option (0 or 1) +* _integer_: integer value of option +* _string_: 0 +* _color_: color index +* _enum_: integer value of option (index of enum value) + +C example: + +[source,c] +---- +struct t_config_option *option = weechat_config_get ("plugin.section.option"); +int value = weechat_config_enum (option); +---- + +Script (Python): + +[source,python] +---- +# prototype +def config_enum(option: str) -> int: ... + +# example +option = weechat.config_get("plugin.section.option") +value = weechat.config_enum(option) +---- + +// TRANSLATION MISSING +==== config_enum_default + +_WeeChat ≥ 4.1.0._ + +Return default enum value of option, as integer. + +Prototype: + +[source,c] +---- +int weechat_config_enum_default (struct t_config_option *option); +---- + +Arguments: + +* _option_: option pointer + +Return value, depending on the option type: + +* _boolean_: default boolean value of option (0 or 1) +* _integer_: default integer value of option +* _string_: 0 +* _color_: default color index +* _enum_: integer value of option (index of enum value) + +C example: + +[source,c] +---- +struct t_config_option *option = weechat_config_get ("plugin.section.option"); +int value = weechat_config_enum_default (option); +---- + +Script (Python): + +[source,python] +---- +# prototype +def config_enum_default(option: str) -> int: ... + +# example +option = weechat.config_get("plugin.section.option") +value = weechat.config_enum_default(option) +---- + ==== config_write_option Уписује линију у конфигурациони фајл са опцијом и њеном вредности (ова функција би требало да се позове само у „write” или „write_default” функцијама повратног позива за одељак). diff --git a/doc/sr/weechat_user.sr.adoc b/doc/sr/weechat_user.sr.adoc index e1ee0b1aa..5ed33f135 100644 --- a/doc/sr/weechat_user.sr.adoc +++ b/doc/sr/weechat_user.sr.adoc @@ -1623,8 +1623,10 @@ WeeChat нуди доста подразумеваних тастерских п | kbd:[▼] | - | чет: fset бафер | Помера за пет линија наниже у fset баферу. | `+/fset -down 5+` | ◾◽◽ | - | чет: fset бафер | Бира линију у fset баферу. | `+/window ${_window_number};/fset -go ${_chat_line_y}+` | ◽◽◾ | - | чет: fset бафер | Пребацује логичку вредност (on/off) или уређује вредност опције. | `+hsignal:fset_mouse+` -| ◽◽◾ | лево | чет: fset бафер | Умањује вредност за цео број/боју, поставља/надовезује вредност за остале типове. | `+hsignal:fset_mouse+` -| ◽◽◾ | десно | чет: fset бафер | Увећава вредност за цео број/боју, поставља/надовезује вредност за остале типове. | `+hsignal:fset_mouse+` +// TRANSLATION MISSING +| ◽◽◾ | лево | чет: fset бафер | Умањује вредност за цео број/боју/enum, поставља/надовезује вредност за остале типове. | `+hsignal:fset_mouse+` +// TRANSLATION MISSING +| ◽◽◾ | десно | чет: fset бафер | Увећава вредност за цео број/боју/enum, поставља/надовезује вредност за остале типове. | `+hsignal:fset_mouse+` | ◽◽◾ | горе / доле | чет: fset бафер | Маркира/уклања маркер са више опција. | `+hsignal:fset_mouse+` | kbd:[▲] | - | чет: script бафер | Помера за пет линија навише у script баферу. | `+/script up 5+` | kbd:[▼] | - | чет: script бафер | Помера за пет линија наниже у script баферу. | `+/script down 5+` @@ -1671,8 +1673,10 @@ WeeChat нуди доста подразумеваних тастерских п | kbd:[F11] | `pass:[<]` | Скролује хоризонтално у лево. | `+/fset -left+` | kbd:[F12] | `pass:[>]` | Скролује хоризонтално у десно. | `+/fset -right+` | kbd:[Alt+Space] | `t` | Пребацује стање логичке вредности. | `+/fset -toggle+` -| kbd:[Alt+-] | `-` | Одузима 1 од вредности за цео број/боју, поставља вредност за остале типове. | `+/fset -add -1+` -| kbd:[Alt++] | `+` | Додаје 1 на вредност за цео број/боју, надовезује вредност за остале типове. | `+/fset -add 1+` +// TRANSLATION MISSING +| kbd:[Alt+-] | `-` | Одузима 1 од вредности за цео број/боју/enum, поставља вредност за остале типове. | `+/fset -add -1+` +// TRANSLATION MISSING +| kbd:[Alt++] | `+` | Додаје 1 на вредност за цео број/боју/enum, надовезује вредност за остале типове. | `+/fset -add 1+` | kbd:[Alt+f], kbd:[Alt+r] | `r` | Ресетује вредност. | `+/fset -reset+` | kbd:[Alt+f], kbd:[Alt+u] | `u` | Поставља да је вредност празна. | `+/fset -unset+` | kbd:[Alt+Enter] | `s` | Поставља вредност. | `+/fset -set+` @@ -1741,7 +1745,7 @@ Fast Set додатак приказује листу опција у бафер │2.fset │weechat.look.bare_display_exit_on_input: exit the bare display mode on any c│ │ │hanges in input [default: on] │ │ │----------------------------------------------------------------------------│ -│ │ weechat.look.align_end_of_lines integer message │ +│ │ weechat.look.align_end_of_lines enum message │ │ │ weechat.look.align_multiline_words boolean on │ │ │ weechat.look.bar_more_down string "++" │ │ │ weechat.look.bar_more_left string "<<" │ @@ -1750,12 +1754,12 @@ Fast Set додатак приказује листу опција у бафер │ │## weechat.look.bare_display_exit_on_input boolean on ##│ │ │ weechat.look.bare_display_time_format string "%H:%M" │ │ │ weechat.look.buffer_auto_renumber boolean on │ -│ │ weechat.look.buffer_notify_default integer all │ -│ │ weechat.look.buffer_position integer end │ +│ │ weechat.look.buffer_notify_default enum all │ +│ │ weechat.look.buffer_position enum end │ │ │ weechat.look.buffer_search_case_sensitive boolean off │ │ │ weechat.look.buffer_search_force_default boolean off │ │ │ weechat.look.buffer_search_regex boolean off │ -│ │ weechat.look.buffer_search_where integer prefix_message │ +│ │ weechat.look.buffer_search_where enum prefix_message │ │ │ weechat.look.buffer_time_format string "%H:%M:%S" │ │ │ weechat.look.buffer_time_same string "" │ │ │[12:55] [2] [fset] 2:fset │ @@ -3065,7 +3069,7 @@ irc.server.libera.autorejoin_delay integer null -> 30 irc.server.libera.away_check integer null -> 0 irc.server.libera.away_check_max_nicks integer null -> 25 irc.server.libera.capabilities string null -> "*" -irc.server.libera.charset_message integer null -> message +irc.server.libera.charset_message enum null -> message irc.server.libera.command string null -> "" irc.server.libera.command_delay integer null -> 0 irc.server.libera.connection_timeout integer null -> 60 @@ -3081,9 +3085,9 @@ irc.server.libera.notify string null -> "" irc.server.libera.password string null -> "" irc.server.libera.proxy string null -> "" irc.server.libera.realname string null -> "" -irc.server.libera.sasl_fail integer null -> reconnect +irc.server.libera.sasl_fail enum null -> reconnect irc.server.libera.sasl_key string null -> "" -irc.server.libera.sasl_mechanism integer null -> plain +irc.server.libera.sasl_mechanism enum null -> plain irc.server.libera.sasl_password string "${sec.data.libera}" irc.server.libera.sasl_timeout integer null -> 15 irc.server.libera.sasl_username string "alice" diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 9d3f809dc..47518fb2f 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -3128,99 +3128,35 @@ COMMAND_CALLBACK(help) } break; case CONFIG_OPTION_TYPE_INTEGER: - if (ptr_option->string_values) + gui_chat_printf (NULL, " %s: %s", + _("type"), _("integer")); + gui_chat_printf (NULL, " %s: %d .. %d", + _("values"), + ptr_option->min, ptr_option->max); + if (ptr_option->default_value) { - length = 0; - i = 0; - while (ptr_option->string_values[i]) - { - length += strlen (ptr_option->string_values[i]) + 5; - i++; - } - if (length > 0) - { - string = malloc (length); - if (string) - { - string[0] = '\0'; - i = 0; - while (ptr_option->string_values[i]) - { - strcat (string, "\""); - strcat (string, ptr_option->string_values[i]); - strcat (string, "\""); - if (ptr_option->string_values[i + 1]) - strcat (string, ", "); - i++; - } - gui_chat_printf (NULL, " %s: %s", - _("type"), _("string")); - gui_chat_printf (NULL, " %s: %s", - _("values"), string); - if (ptr_option->default_value) - { - gui_chat_printf (NULL, " %s: \"%s\"", - _("default value"), - ptr_option->string_values[CONFIG_INTEGER_DEFAULT(ptr_option)]); - } - else - { - gui_chat_printf (NULL, " %s: %s", - _("default value"), - _("(undefined)")); - } - if (ptr_option->value) - { - gui_chat_printf (NULL, - " %s: \"%s%s%s\"", - _("current value"), - GUI_COLOR(GUI_COLOR_CHAT_VALUE), - ptr_option->string_values[CONFIG_INTEGER(ptr_option)], - GUI_COLOR(GUI_COLOR_CHAT)); - } - else - { - gui_chat_printf (NULL, - " %s: %s", - _("current value"), - _("(undefined)")); - } - free (string); - } - } + gui_chat_printf (NULL, " %s: %d", + _("default value"), + CONFIG_INTEGER_DEFAULT(ptr_option)); } else { gui_chat_printf (NULL, " %s: %s", - _("type"), _("integer")); - gui_chat_printf (NULL, " %s: %d .. %d", - _("values"), - ptr_option->min, ptr_option->max); - if (ptr_option->default_value) - { - gui_chat_printf (NULL, " %s: %d", - _("default value"), - CONFIG_INTEGER_DEFAULT(ptr_option)); - } - else - { - gui_chat_printf (NULL, " %s: %s", - _("default value"), - _("(undefined)")); - } - if (ptr_option->value) - { - gui_chat_printf (NULL, " %s: %s%d", - _("current value"), - GUI_COLOR(GUI_COLOR_CHAT_VALUE), - CONFIG_INTEGER(ptr_option)); - } - else - { - gui_chat_printf (NULL, " %s: %s", - _("current value"), - _("(undefined)")); - } + _("default value"), + _("(undefined)")); + } + if (ptr_option->value) + { + gui_chat_printf (NULL, " %s: %s%d", + _("current value"), + GUI_COLOR(GUI_COLOR_CHAT_VALUE), + CONFIG_INTEGER(ptr_option)); + } + else + { + gui_chat_printf (NULL, " %s: %s", + _("current value"), + _("(undefined)")); } break; case CONFIG_OPTION_TYPE_STRING: @@ -3306,6 +3242,66 @@ COMMAND_CALLBACK(help) _("(undefined)")); } break; + case CONFIG_OPTION_TYPE_ENUM: + length = 0; + i = 0; + while (ptr_option->string_values[i]) + { + length += strlen (ptr_option->string_values[i]) + 5; + i++; + } + if (length > 0) + { + string = malloc (length); + if (string) + { + string[0] = '\0'; + i = 0; + while (ptr_option->string_values[i]) + { + strcat (string, "\""); + strcat (string, ptr_option->string_values[i]); + strcat (string, "\""); + if (ptr_option->string_values[i + 1]) + strcat (string, ", "); + i++; + } + gui_chat_printf (NULL, " %s: %s", + _("type"), _("enum")); + gui_chat_printf (NULL, " %s: %s", + _("values"), string); + if (ptr_option->default_value) + { + gui_chat_printf (NULL, " %s: \"%s\"", + _("default value"), + ptr_option->string_values[CONFIG_ENUM_DEFAULT(ptr_option)]); + } + else + { + gui_chat_printf (NULL, " %s: %s", + _("default value"), + _("(undefined)")); + } + if (ptr_option->value) + { + gui_chat_printf (NULL, + " %s: \"%s%s%s\"", + _("current value"), + GUI_COLOR(GUI_COLOR_CHAT_VALUE), + ptr_option->string_values[CONFIG_ENUM(ptr_option)], + GUI_COLOR(GUI_COLOR_CHAT)); + } + else + { + gui_chat_printf (NULL, + " %s: %s", + _("current value"), + _("(undefined)")); + } + free (string); + } + } + break; case CONFIG_NUM_OPTION_TYPES: break; } diff --git a/src/core/wee-completion.c b/src/core/wee-completion.c index d6e775be2..cbd068b4d 100644 --- a/src/core/wee-completion.c +++ b/src/core/wee-completion.c @@ -1461,59 +1461,31 @@ completion_list_add_config_option_values_cb (const void *pointer, void *data, } break; case CONFIG_OPTION_TYPE_INTEGER: - if (option_found->string_values) - { - for (i = 0; option_found->string_values[i]; i++) - { - gui_completion_list_add (completion, - option_found->string_values[i], - 0, WEECHAT_LIST_POS_SORT); - } - gui_completion_list_add (completion, "++1", - 0, WEECHAT_LIST_POS_END); + if (option_found->value && CONFIG_INTEGER(option_found) > option_found->min) gui_completion_list_add (completion, "--1", - 0, WEECHAT_LIST_POS_END); - if (option_found->value) + 0, WEECHAT_LIST_POS_BEGINNING); + if (option_found->value && CONFIG_INTEGER(option_found) < option_found->max) + gui_completion_list_add (completion, "++1", + 0, WEECHAT_LIST_POS_BEGINNING); + if (option_found->value) + { + length = 64; + value_string = malloc (length); + if (value_string) { + snprintf (value_string, length, + "%d", CONFIG_INTEGER(option_found)); gui_completion_list_add (completion, - option_found->string_values[CONFIG_INTEGER(option_found)], - 0, WEECHAT_LIST_POS_BEGINNING); - } - else - { - gui_completion_list_add (completion, - WEECHAT_CONFIG_OPTION_NULL, + value_string, 0, WEECHAT_LIST_POS_BEGINNING); + free (value_string); } } else { - if (option_found->value && CONFIG_INTEGER(option_found) > option_found->min) - gui_completion_list_add (completion, "--1", - 0, WEECHAT_LIST_POS_BEGINNING); - if (option_found->value && CONFIG_INTEGER(option_found) < option_found->max) - gui_completion_list_add (completion, "++1", - 0, WEECHAT_LIST_POS_BEGINNING); - if (option_found->value) - { - length = 64; - value_string = malloc (length); - if (value_string) - { - snprintf (value_string, length, - "%d", CONFIG_INTEGER(option_found)); - gui_completion_list_add (completion, - value_string, - 0, WEECHAT_LIST_POS_BEGINNING); - free (value_string); - } - } - else - { - gui_completion_list_add (completion, - WEECHAT_CONFIG_OPTION_NULL, - 0, WEECHAT_LIST_POS_BEGINNING); - } + gui_completion_list_add (completion, + WEECHAT_CONFIG_OPTION_NULL, + 0, WEECHAT_LIST_POS_BEGINNING); } break; case CONFIG_OPTION_TYPE_STRING: @@ -1567,6 +1539,30 @@ completion_list_add_config_option_values_cb (const void *pointer, void *data, 0, WEECHAT_LIST_POS_BEGINNING); } break; + case CONFIG_OPTION_TYPE_ENUM: + for (i = 0; option_found->string_values[i]; i++) + { + gui_completion_list_add (completion, + option_found->string_values[i], + 0, WEECHAT_LIST_POS_SORT); + } + gui_completion_list_add (completion, "++1", + 0, WEECHAT_LIST_POS_END); + gui_completion_list_add (completion, "--1", + 0, WEECHAT_LIST_POS_END); + if (option_found->value) + { + gui_completion_list_add (completion, + option_found->string_values[CONFIG_ENUM(option_found)], + 0, WEECHAT_LIST_POS_BEGINNING); + } + else + { + gui_completion_list_add (completion, + WEECHAT_CONFIG_OPTION_NULL, + 0, WEECHAT_LIST_POS_BEGINNING); + } + break; case CONFIG_NUM_OPTION_TYPES: break; } diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index fc2123ffa..87ca9b47b 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -53,7 +53,7 @@ struct t_config_file *config_files = NULL; struct t_config_file *last_config_file = NULL; char *config_option_type_string[CONFIG_NUM_OPTION_TYPES] = -{ N_("boolean"), N_("integer"), N_("string"), N_("color") }; +{ N_("boolean"), N_("integer"), N_("string"), N_("color"), N_("enum") }; char *config_boolean_true[] = { "on", "yes", "y", "true", "t", "1", NULL }; char *config_boolean_false[] = { "off", "no", "n", "false", "f", "0", NULL }; @@ -547,17 +547,9 @@ config_file_hook_config_exec (struct t_config_option *option) "on" : "off"); break; case CONFIG_OPTION_TYPE_INTEGER: - if (option->string_values) - { - hook_config_exec (option_full_name, - option->string_values[CONFIG_INTEGER(option)]); - } - else - { - snprintf (str_value, sizeof (str_value), - "%d", CONFIG_INTEGER(option)); - hook_config_exec (option_full_name, str_value); - } + snprintf (str_value, sizeof (str_value), + "%d", CONFIG_INTEGER(option)); + hook_config_exec (option_full_name, str_value); break; case CONFIG_OPTION_TYPE_STRING: hook_config_exec (option_full_name, (char *)option->value); @@ -566,6 +558,10 @@ config_file_hook_config_exec (struct t_config_option *option) hook_config_exec (option_full_name, gui_color_get_name (CONFIG_COLOR(option))); break; + case CONFIG_OPTION_TYPE_ENUM: + hook_config_exec (option_full_name, + option->string_values[CONFIG_ENUM(option)]); + break; case CONFIG_NUM_OPTION_TYPES: break; } @@ -766,6 +762,22 @@ config_file_new_option (struct t_config_file *config_file, goto error; } + /* + * compatibility with versions < 4.1.0: force enum type for an integer + * with string values + */ + if ((var_type == CONFIG_OPTION_TYPE_INTEGER) + && string_values && string_values[0]) + { + var_type = CONFIG_OPTION_TYPE_ENUM; + } + + if ((var_type == CONFIG_OPTION_TYPE_ENUM) + && (!string_values || !string_values[0])) + { + goto error; + } + if (!null_value_allowed) { if (default_value && !value) @@ -804,7 +816,7 @@ config_file_new_option (struct t_config_file *config_file, new_option->default_value = malloc (sizeof (int)); if (!new_option->default_value) goto error; - CONFIG_INTEGER_DEFAULT(new_option) = int_value; + CONFIG_BOOLEAN_DEFAULT(new_option) = int_value; } if (value) { @@ -812,97 +824,41 @@ config_file_new_option (struct t_config_file *config_file, new_option->value = malloc (sizeof (int)); if (!new_option->value) goto error; - CONFIG_INTEGER(new_option) = int_value; + CONFIG_BOOLEAN(new_option) = int_value; } break; case CONFIG_OPTION_TYPE_INTEGER: - if (string_values && string_values[0]) + new_option->min = min; + new_option->max = max; + if (default_value) { - new_option->string_values = string_split ( - string_values, - "|", - NULL, - WEECHAT_STRING_SPLIT_STRIP_LEFT - | WEECHAT_STRING_SPLIT_STRIP_RIGHT - | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS, - 0, - &argc); - if (!new_option->string_values) + error = NULL; + number = strtol (default_value, &error, 10); + if (!error || error[0]) + number = 0; + if (number < min) + number = min; + else if (number > max) + number = max; + new_option->default_value = malloc (sizeof (int)); + if (!new_option->default_value) goto error; + CONFIG_INTEGER_DEFAULT(new_option) = number; } - if (new_option->string_values) + if (value) { - new_option->min = 0; - new_option->max = (argc == 0) ? 0 : argc - 1; - if (default_value) - { - index_value = 0; - for (i = 0; i < argc; i++) - { - if (strcmp (new_option->string_values[i], - default_value) == 0) - { - index_value = i; - break; - } - } - new_option->default_value = malloc (sizeof (int)); - if (!new_option->default_value) - goto error; - CONFIG_INTEGER_DEFAULT(new_option) = index_value; - } - if (value) - { - index_value = 0; - for (i = 0; i < argc; i++) - { - if (strcmp (new_option->string_values[i], - value) == 0) - { - index_value = i; - break; - } - } - new_option->value = malloc (sizeof (int)); - if (!new_option->value) - goto error; - CONFIG_INTEGER(new_option) = index_value; - } - } - else - { - new_option->min = min; - new_option->max = max; - if (default_value) - { - error = NULL; - number = strtol (default_value, &error, 10); - if (!error || error[0]) - number = 0; - if (number < min) - number = min; - else if (number > max) - number = max; - new_option->default_value = malloc (sizeof (int)); - if (!new_option->default_value) - goto error; - CONFIG_INTEGER_DEFAULT(new_option) = number; - } - if (value) - { - error = NULL; - number = strtol (value, &error, 10); - if (!error || error[0]) - number = 0; - if (number < min) - number = min; - else if (number > max) - number = max; - new_option->value = malloc (sizeof (int)); - if (!new_option->value) - goto error; - CONFIG_INTEGER(new_option) = number; - } + error = NULL; + number = strtol (value, &error, 10); + if (!error || error[0]) + number = 0; + if (number < min) + number = min; + else if (number > max) + number = max; + new_option->value = malloc (sizeof (int)); + if (!new_option->value) + goto error; + CONFIG_INTEGER(new_option) = number; } break; case CONFIG_OPTION_TYPE_STRING: @@ -930,7 +886,7 @@ config_file_new_option (struct t_config_file *config_file, if (!new_option->default_value) goto error; if (!gui_color_assign (new_option->default_value, default_value)) - CONFIG_INTEGER_DEFAULT(new_option) = 0; + CONFIG_COLOR_DEFAULT(new_option) = 0; } if (value) { @@ -938,7 +894,56 @@ config_file_new_option (struct t_config_file *config_file, if (!new_option->value) goto error; if (!gui_color_assign (new_option->value, value)) - CONFIG_INTEGER(new_option) = 0; + CONFIG_COLOR(new_option) = 0; + } + break; + case CONFIG_OPTION_TYPE_ENUM: + new_option->string_values = string_split ( + string_values, + "|", + NULL, + WEECHAT_STRING_SPLIT_STRIP_LEFT + | WEECHAT_STRING_SPLIT_STRIP_RIGHT + | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS, + 0, + &argc); + if (!new_option->string_values) + goto error; + new_option->min = 0; + new_option->max = (argc == 0) ? 0 : argc - 1; + if (default_value) + { + index_value = 0; + for (i = 0; i < argc; i++) + { + if (strcmp (new_option->string_values[i], + default_value) == 0) + { + index_value = i; + break; + } + } + new_option->default_value = malloc (sizeof (int)); + if (!new_option->default_value) + goto error; + CONFIG_ENUM_DEFAULT(new_option) = index_value; + } + if (value) + { + index_value = 0; + for (i = 0; i < argc; i++) + { + if (strcmp (new_option->string_values[i], + value) == 0) + { + index_value = i; + break; + } + } + new_option->value = malloc (sizeof (int)); + if (!new_option->value) + goto error; + CONFIG_ENUM(new_option) = index_value; } break; case CONFIG_NUM_OPTION_TYPES: @@ -1316,7 +1321,7 @@ config_file_option_reset (struct t_config_option *option, int run_callback) { option->value = malloc (sizeof (int)); if (option->value) - CONFIG_INTEGER(option) = 0; + CONFIG_COLOR(option) = 0; else break; } @@ -1328,6 +1333,23 @@ config_file_option_reset (struct t_config_option *option, int run_callback) rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; } break; + case CONFIG_OPTION_TYPE_ENUM: + if (!option->value) + { + option->value = malloc (sizeof (int)); + if (option->value) + CONFIG_ENUM(option) = 0; + else + break; + } + if (CONFIG_ENUM(option) == CONFIG_ENUM_DEFAULT(option)) + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + else + { + CONFIG_ENUM(option) = CONFIG_ENUM_DEFAULT(option); + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; + } + break; case CONFIG_NUM_OPTION_TYPES: break; } @@ -1464,117 +1486,58 @@ config_file_option_set (struct t_config_option *option, const char *value, old_value = CONFIG_INTEGER(option); if (option->value) { - if (option->string_values) + new_value_ok = 0; + if (strncmp (value, "++", 2) == 0) { - value_int = -1; - if (strncmp (value, "++", 2) == 0) + error = NULL; + number = strtol (value + 2, &error, 10); + if (error && !error[0]) { - error = NULL; - number = strtol (value + 2, &error, 10); - if (error && !error[0]) - { - number = number % (option->max + 1); - value_int = (old_value + number) % - (option->max + 1); - } + value_int = old_value + number; + if (value_int <= option->max) + new_value_ok = 1; } - else if (strncmp (value, "--", 2) == 0) + } + else if (strncmp (value, "--", 2) == 0) + { + error = NULL; + number = strtol (value + 2, &error, 10); + if (error && !error[0]) { - error = NULL; - number = strtol (value + 2, &error, 10); - if (error && !error[0]) - { - number = number % (option->max + 1); - value_int = (old_value + (option->max + 1) - number) % - (option->max + 1); - } - } - else - { - for (i = 0; option->string_values[i]; i++) - { - if (strcmp (option->string_values[i], value) == 0) - { - value_int = i; - break; - } - } - } - if (value_int >= 0) - { - if (old_value_was_null - || (value_int != old_value)) - { - CONFIG_INTEGER(option) = value_int; - rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; - } - else - rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; - } - else - { - if (old_value_was_null) - { - free (option->value); - option->value = NULL; - } + value_int = old_value - number; + if (value_int >= option->min) + new_value_ok = 1; } } else { - new_value_ok = 0; - if (strncmp (value, "++", 2) == 0) + error = NULL; + number = strtol (value, &error, 10); + if (error && !error[0]) { - error = NULL; - number = strtol (value + 2, &error, 10); - if (error && !error[0]) - { - value_int = old_value + number; - if (value_int <= option->max) - new_value_ok = 1; - } + value_int = number; + if ((value_int >= option->min) + && (value_int <= option->max)) + new_value_ok = 1; } - else if (strncmp (value, "--", 2) == 0) + } + if (new_value_ok) + { + if (old_value_was_null + || (value_int != old_value)) { - error = NULL; - number = strtol (value + 2, &error, 10); - if (error && !error[0]) - { - value_int = old_value - number; - if (value_int >= option->min) - new_value_ok = 1; - } + CONFIG_INTEGER(option) = value_int; + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; } else + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + } + else + { + if (old_value_was_null) { - error = NULL; - number = strtol (value, &error, 10); - if (error && !error[0]) - { - value_int = number; - if ((value_int >= option->min) - && (value_int <= option->max)) - new_value_ok = 1; - } - } - if (new_value_ok) - { - if (old_value_was_null - || (value_int != old_value)) - { - CONFIG_INTEGER(option) = value_int; - rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; - } - else - rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; - } - else - { - if (old_value_was_null) - { - free (option->value); - option->value = NULL; - } + free (option->value); + option->value = NULL; } } } @@ -1653,6 +1616,69 @@ config_file_option_set (struct t_config_option *option, const char *value, } } break; + case CONFIG_OPTION_TYPE_ENUM: + old_value = 0; + if (!option->value) + option->value = malloc (sizeof (int)); + else + old_value = CONFIG_ENUM(option); + if (option->value) + { + value_int = -1; + if (strncmp (value, "++", 2) == 0) + { + error = NULL; + number = strtol (value + 2, &error, 10); + if (error && !error[0]) + { + number = number % (option->max + 1); + value_int = (old_value + number) % + (option->max + 1); + } + } + else if (strncmp (value, "--", 2) == 0) + { + error = NULL; + number = strtol (value + 2, &error, 10); + if (error && !error[0]) + { + number = number % (option->max + 1); + value_int = (old_value + (option->max + 1) - number) % + (option->max + 1); + } + } + else + { + for (i = 0; option->string_values[i]; i++) + { + if (strcmp (option->string_values[i], value) == 0) + { + value_int = i; + break; + } + } + } + if (value_int >= 0) + { + if (old_value_was_null + || (value_int != old_value)) + { + CONFIG_ENUM(option) = value_int; + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; + } + else + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + } + else + { + if (old_value_was_null) + { + free (option->value); + option->value = NULL; + } + } + } + break; case CONFIG_NUM_OPTION_TYPES: break; } @@ -1741,6 +1767,10 @@ config_file_option_toggle (struct t_config_option *option, if (!values) goto end; break; + case CONFIG_OPTION_TYPE_ENUM: + if (!values) + goto end; + break; case CONFIG_NUM_OPTION_TYPES: /* make C compiler happy */ break; @@ -1929,117 +1959,58 @@ config_file_option_set_default (struct t_config_option *option, old_value = CONFIG_INTEGER_DEFAULT(option); if (option->default_value) { - if (option->string_values) + new_value_ok = 0; + if (strncmp (value, "++", 2) == 0) { - value_int = -1; - if (strncmp (value, "++", 2) == 0) + error = NULL; + number = strtol (value + 2, &error, 10); + if (error && !error[0]) { - error = NULL; - number = strtol (value + 2, &error, 10); - if (error && !error[0]) - { - number = number % (option->max + 1); - value_int = (old_value + number) % - (option->max + 1); - } + value_int = old_value + number; + if (value_int <= option->max) + new_value_ok = 1; } - else if (strncmp (value, "--", 2) == 0) + } + else if (strncmp (value, "--", 2) == 0) + { + error = NULL; + number = strtol (value + 2, &error, 10); + if (error && !error[0]) { - error = NULL; - number = strtol (value + 2, &error, 10); - if (error && !error[0]) - { - number = number % (option->max + 1); - value_int = (old_value + (option->max + 1) - number) % - (option->max + 1); - } - } - else - { - for (i = 0; option->string_values[i]; i++) - { - if (strcmp (option->string_values[i], value) == 0) - { - value_int = i; - break; - } - } - } - if (value_int >= 0) - { - if (old_value_was_null - || (value_int != old_value)) - { - CONFIG_INTEGER_DEFAULT(option) = value_int; - rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; - } - else - rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; - } - else - { - if (old_value_was_null) - { - free (option->default_value); - option->default_value = NULL; - } + value_int = old_value - number; + if (value_int >= option->min) + new_value_ok = 1; } } else { - new_value_ok = 0; - if (strncmp (value, "++", 2) == 0) + error = NULL; + number = strtol (value, &error, 10); + if (error && !error[0]) { - error = NULL; - number = strtol (value + 2, &error, 10); - if (error && !error[0]) - { - value_int = old_value + number; - if (value_int <= option->max) - new_value_ok = 1; - } + value_int = number; + if ((value_int >= option->min) + && (value_int <= option->max)) + new_value_ok = 1; } - else if (strncmp (value, "--", 2) == 0) + } + if (new_value_ok) + { + if (old_value_was_null + || (value_int != old_value)) { - error = NULL; - number = strtol (value + 2, &error, 10); - if (error && !error[0]) - { - value_int = old_value - number; - if (value_int >= option->min) - new_value_ok = 1; - } + CONFIG_INTEGER_DEFAULT(option) = value_int; + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; } else + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + } + else + { + if (old_value_was_null) { - error = NULL; - number = strtol (value, &error, 10); - if (error && !error[0]) - { - value_int = number; - if ((value_int >= option->min) - && (value_int <= option->max)) - new_value_ok = 1; - } - } - if (new_value_ok) - { - if (old_value_was_null - || (value_int != old_value)) - { - CONFIG_INTEGER_DEFAULT(option) = value_int; - rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; - } - else - rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; - } - else - { - if (old_value_was_null) - { - free (option->default_value); - option->default_value = NULL; - } + free (option->default_value); + option->default_value = NULL; } } } @@ -2118,6 +2089,69 @@ config_file_option_set_default (struct t_config_option *option, } } break; + case CONFIG_OPTION_TYPE_ENUM: + old_value = 0; + if (!option->default_value) + option->default_value = malloc (sizeof (int)); + else + old_value = CONFIG_ENUM_DEFAULT(option); + if (option->default_value) + { + value_int = -1; + if (strncmp (value, "++", 2) == 0) + { + error = NULL; + number = strtol (value + 2, &error, 10); + if (error && !error[0]) + { + number = number % (option->max + 1); + value_int = (old_value + number) % + (option->max + 1); + } + } + else if (strncmp (value, "--", 2) == 0) + { + error = NULL; + number = strtol (value + 2, &error, 10); + if (error && !error[0]) + { + number = number % (option->max + 1); + value_int = (old_value + (option->max + 1) - number) % + (option->max + 1); + } + } + else + { + for (i = 0; option->string_values[i]; i++) + { + if (strcmp (option->string_values[i], value) == 0) + { + value_int = i; + break; + } + } + } + if (value_int >= 0) + { + if (old_value_was_null + || (value_int != old_value)) + { + CONFIG_ENUM_DEFAULT(option) = value_int; + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; + } + else + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + } + else + { + if (old_value_was_null) + { + free (option->default_value); + option->default_value = NULL; + } + } + } + break; case CONFIG_NUM_OPTION_TYPES: break; } @@ -2359,33 +2393,15 @@ config_file_option_value_to_string (struct t_config_option *option, return value; break; case CONFIG_OPTION_TYPE_INTEGER: - if (option->string_values) - { - ptr_value = (default_value) ? - option->string_values[CONFIG_INTEGER_DEFAULT(option)] : - option->string_values[CONFIG_INTEGER(option)]; - length = strlen (ptr_value) + ((use_colors) ? 64 : 0) + 1; - value = malloc (length); - if (!value) - return NULL; - snprintf (value, length, - "%s%s", - (use_colors) ? GUI_COLOR(GUI_COLOR_CHAT_VALUE) : "", - ptr_value); - return value; - } - else - { - length = 31 + ((use_colors) ? 64 : 0) + 1; - value = malloc (length); - if (!value) - return NULL; - snprintf (value, length, - "%s%d", - (use_colors) ? GUI_COLOR(GUI_COLOR_CHAT_VALUE) : "", - (default_value) ? CONFIG_INTEGER_DEFAULT(option) : CONFIG_INTEGER(option)); - return value; - } + length = 31 + ((use_colors) ? 64 : 0) + 1; + value = malloc (length); + if (!value) + return NULL; + snprintf (value, length, + "%s%d", + (use_colors) ? GUI_COLOR(GUI_COLOR_CHAT_VALUE) : "", + (default_value) ? CONFIG_INTEGER_DEFAULT(option) : CONFIG_INTEGER(option)); + return value; break; case CONFIG_OPTION_TYPE_STRING: ptr_value = (default_value) ? CONFIG_STRING_DEFAULT(option) : CONFIG_STRING(option); @@ -2418,6 +2434,20 @@ config_file_option_value_to_string (struct t_config_option *option, ptr_value); return value; break; + case CONFIG_OPTION_TYPE_ENUM: + ptr_value = (default_value) ? + option->string_values[CONFIG_ENUM_DEFAULT(option)] : + option->string_values[CONFIG_ENUM(option)]; + length = strlen (ptr_value) + ((use_colors) ? 64 : 0) + 1; + value = malloc (length); + if (!value) + return NULL; + snprintf (value, length, + "%s%s", + (use_colors) ? GUI_COLOR(GUI_COLOR_CHAT_VALUE) : "", + ptr_value); + return value; + break; case CONFIG_NUM_OPTION_TYPES: /* make C compiler happy */ break; @@ -2562,6 +2592,8 @@ int config_file_option_has_changed (struct t_config_option *option) return strcmp (CONFIG_STRING(option), CONFIG_STRING_DEFAULT(option)) != 0; case CONFIG_OPTION_TYPE_COLOR: return CONFIG_COLOR(option) != CONFIG_COLOR_DEFAULT(option); + case CONFIG_OPTION_TYPE_ENUM: + return CONFIG_ENUM(option) != CONFIG_ENUM_DEFAULT(option); case CONFIG_NUM_OPTION_TYPES: /* make C compiler happy */ break; @@ -2673,10 +2705,13 @@ config_file_option_integer (struct t_config_option *option) else return 0; case CONFIG_OPTION_TYPE_INTEGER: - case CONFIG_OPTION_TYPE_COLOR: return CONFIG_INTEGER(option); case CONFIG_OPTION_TYPE_STRING: return 0; + case CONFIG_OPTION_TYPE_COLOR: + return CONFIG_COLOR(option); + case CONFIG_OPTION_TYPE_ENUM: + return CONFIG_ENUM(option); case CONFIG_NUM_OPTION_TYPES: break; } @@ -2701,10 +2736,13 @@ config_file_option_integer_default (struct t_config_option *option) else return 0; case CONFIG_OPTION_TYPE_INTEGER: - case CONFIG_OPTION_TYPE_COLOR: return CONFIG_INTEGER_DEFAULT(option); case CONFIG_OPTION_TYPE_STRING: return 0; + case CONFIG_OPTION_TYPE_COLOR: + return CONFIG_COLOR_DEFAULT(option); + case CONFIG_OPTION_TYPE_ENUM: + return CONFIG_ENUM_DEFAULT(option); case CONFIG_NUM_OPTION_TYPES: break; } @@ -2729,13 +2767,13 @@ config_file_option_string (struct t_config_option *option) else return config_boolean_false[0]; case CONFIG_OPTION_TYPE_INTEGER: - if (option->string_values) - return option->string_values[CONFIG_INTEGER(option)]; return NULL; case CONFIG_OPTION_TYPE_STRING: return CONFIG_STRING(option); case CONFIG_OPTION_TYPE_COLOR: return gui_color_get_name (CONFIG_COLOR(option)); + case CONFIG_OPTION_TYPE_ENUM: + return option->string_values[CONFIG_ENUM(option)]; case CONFIG_NUM_OPTION_TYPES: return NULL; } @@ -2760,13 +2798,13 @@ config_file_option_string_default (struct t_config_option *option) else return config_boolean_false[0]; case CONFIG_OPTION_TYPE_INTEGER: - if (option->string_values) - return option->string_values[CONFIG_INTEGER_DEFAULT(option)]; return NULL; case CONFIG_OPTION_TYPE_STRING: return CONFIG_STRING_DEFAULT(option); case CONFIG_OPTION_TYPE_COLOR: return gui_color_get_name (CONFIG_COLOR_DEFAULT(option)); + case CONFIG_OPTION_TYPE_ENUM: + return option->string_values[CONFIG_ENUM_DEFAULT(option)]; case CONFIG_NUM_OPTION_TYPES: return NULL; } @@ -2804,6 +2842,68 @@ config_file_option_color_default (struct t_config_option *option) return NULL; } +/* + * Returns enum value of an option. + */ + +int +config_file_option_enum (struct t_config_option *option) +{ + if (option && option->value) + { + switch (option->type) + { + case CONFIG_OPTION_TYPE_BOOLEAN: + if (CONFIG_BOOLEAN(option) == CONFIG_BOOLEAN_TRUE) + return 1; + else + return 0; + case CONFIG_OPTION_TYPE_INTEGER: + return CONFIG_INTEGER(option); + case CONFIG_OPTION_TYPE_STRING: + return 0; + case CONFIG_OPTION_TYPE_COLOR: + return CONFIG_COLOR(option); + case CONFIG_OPTION_TYPE_ENUM: + return CONFIG_ENUM(option); + case CONFIG_NUM_OPTION_TYPES: + break; + } + } + return 0; +} + +/* + * Returns default enum value of an option. + */ + +int +config_file_option_enum_default (struct t_config_option *option) +{ + if (option && option->default_value) + { + switch (option->type) + { + case CONFIG_OPTION_TYPE_BOOLEAN: + if (CONFIG_BOOLEAN_DEFAULT(option) == CONFIG_BOOLEAN_TRUE) + return 1; + else + return 0; + case CONFIG_OPTION_TYPE_INTEGER: + return CONFIG_INTEGER_DEFAULT(option); + case CONFIG_OPTION_TYPE_STRING: + return 0; + case CONFIG_OPTION_TYPE_COLOR: + return CONFIG_COLOR_DEFAULT(option); + case CONFIG_OPTION_TYPE_ENUM: + return CONFIG_ENUM_DEFAULT(option); + case CONFIG_NUM_OPTION_TYPES: + break; + } + } + return 0; +} + /* * Returns a char to add before the name of option to escape it. * @@ -2857,16 +2957,10 @@ config_file_write_option (struct t_config_file *config_file, "on" : "off"); break; case CONFIG_OPTION_TYPE_INTEGER: - if (option->string_values) - rc = string_fprintf (config_file->file, "%s%s = %s\n", - config_file_option_escape (option->name), - option->name, - option->string_values[CONFIG_INTEGER(option)]); - else - rc = string_fprintf (config_file->file, "%s%s = %d\n", - config_file_option_escape (option->name), - option->name, - CONFIG_INTEGER(option)); + rc = string_fprintf (config_file->file, "%s%s = %d\n", + config_file_option_escape (option->name), + option->name, + CONFIG_INTEGER(option)); break; case CONFIG_OPTION_TYPE_STRING: rc = string_fprintf (config_file->file, "%s%s = \"%s\"\n", @@ -2880,6 +2974,12 @@ config_file_write_option (struct t_config_file *config_file, option->name, gui_color_get_name (CONFIG_COLOR(option))); break; + case CONFIG_OPTION_TYPE_ENUM: + rc = string_fprintf (config_file->file, "%s%s = %s\n", + config_file_option_escape (option->name), + option->name, + option->string_values[CONFIG_ENUM(option)]); + break; case CONFIG_NUM_OPTION_TYPES: break; } @@ -4286,28 +4386,16 @@ config_file_print_log () "on" : "off") : "null"); break; case CONFIG_OPTION_TYPE_INTEGER: - if (ptr_option->string_values) - { - log_printf (" default value. . . . . . . . : '%s'", - (ptr_option->default_value) ? - ptr_option->string_values[CONFIG_INTEGER_DEFAULT(ptr_option)] : "null"); - log_printf (" value (integer/str). . . . . : '%s'", - (ptr_option->value) ? - ptr_option->string_values[CONFIG_INTEGER(ptr_option)] : "null"); - } + if (ptr_option->default_value) + log_printf (" default value. . . . . . . . : %d", + CONFIG_INTEGER_DEFAULT(ptr_option)); else - { - if (ptr_option->default_value) - log_printf (" default value. . . . . . . . : %d", - CONFIG_INTEGER_DEFAULT(ptr_option)); - else - log_printf (" default value. . . . . . . . : null"); - if (ptr_option->value) - log_printf (" value (integer). . . . . . . : %d", - CONFIG_INTEGER(ptr_option)); - else - log_printf (" value (integer). . . . . . . : null"); - } + log_printf (" default value. . . . . . . . : null"); + if (ptr_option->value) + log_printf (" value (integer). . . . . . . : %d", + CONFIG_INTEGER(ptr_option)); + else + log_printf (" value (integer). . . . . . . : null"); break; case CONFIG_OPTION_TYPE_STRING: if (ptr_option->default_value) @@ -4335,6 +4423,14 @@ config_file_print_log () else log_printf (" value (color). . . . . . . . : null"); break; + case CONFIG_OPTION_TYPE_ENUM: + log_printf (" default value. . . . . . . . : '%s'", + (ptr_option->default_value) ? + ptr_option->string_values[CONFIG_ENUM_DEFAULT(ptr_option)] : "null"); + log_printf (" value (integer/str). . . . . : '%s'", + (ptr_option->value) ? + ptr_option->string_values[CONFIG_ENUM(ptr_option)] : "null"); + break; case CONFIG_NUM_OPTION_TYPES: break; } diff --git a/src/core/wee-config-file.h b/src/core/wee-config-file.h index 9d56930b3..2e00c0529 100644 --- a/src/core/wee-config-file.h +++ b/src/core/wee-config-file.h @@ -39,6 +39,9 @@ #define CONFIG_COLOR(option) (*((int *)((option)->value))) #define CONFIG_COLOR_DEFAULT(option) (*((int *)((option)->default_value))) +#define CONFIG_ENUM(option) (*((int *)((option)->value))) +#define CONFIG_ENUM_DEFAULT(option) (*((int *)((option)->default_value))) + #define CONFIG_BOOLEAN_FALSE 0 #define CONFIG_BOOLEAN_TRUE 1 @@ -136,6 +139,7 @@ enum t_config_option_type CONFIG_OPTION_TYPE_INTEGER, CONFIG_OPTION_TYPE_STRING, CONFIG_OPTION_TYPE_COLOR, + CONFIG_OPTION_TYPE_ENUM, /* number of option types */ CONFIG_NUM_OPTION_TYPES, }; @@ -317,6 +321,8 @@ extern const char *config_file_option_string (struct t_config_option *option); extern const char *config_file_option_string_default (struct t_config_option *option); extern const char *config_file_option_color (struct t_config_option *option); extern const char *config_file_option_color_default (struct t_config_option *option); +extern int config_file_option_enum (struct t_config_option *option); +extern int config_file_option_enum_default (struct t_config_option *option); extern int config_file_write_option (struct t_config_file *config_file, struct t_config_option *option); extern int config_file_write_line (struct t_config_file *config_file, diff --git a/src/core/wee-doc.c b/src/core/wee-doc.c index 406388a9d..21e5ce401 100644 --- a/src/core/wee-doc.c +++ b/src/core/wee-doc.c @@ -541,19 +541,11 @@ doc_gen_user_options (const char *path, const char *lang) values = strdup ("on, off"); break; case CONFIG_OPTION_TYPE_INTEGER: - if (ptr_option->string_values) - { - values = string_rebuild_split_string ( - (const char **)ptr_option->string_values, ", ", 0, -1); - } - else - { - snprintf (str_values, sizeof (str_values), - "%d .. %d", - ptr_option->min, - ptr_option->max); - values = strdup (str_values); - } + snprintf (str_values, sizeof (str_values), + "%d .. %d", + ptr_option->min, + ptr_option->max); + values = strdup (str_values); break; case CONFIG_OPTION_TYPE_STRING: if (ptr_option->max <= 0) @@ -573,6 +565,10 @@ doc_gen_user_options (const char *path, const char *lang) case CONFIG_OPTION_TYPE_COLOR: values = strdup (command_help_option_color_values ()); break; + case CONFIG_OPTION_TYPE_ENUM: + values = string_rebuild_split_string ( + (const char **)ptr_option->string_values, ", ", 0, -1); + break; default: values = NULL; break; diff --git a/src/core/wee-eval.c b/src/core/wee-eval.c index b828a972d..81b4bd875 100644 --- a/src/core/wee-eval.c +++ b/src/core/wee-eval.c @@ -1832,11 +1832,6 @@ eval_replace_vars_cb (void *data, const char *text) EVAL_STR_TRUE : EVAL_STR_FALSE); goto end; case CONFIG_OPTION_TYPE_INTEGER: - if (ptr_option->string_values) - { - value = strdup (ptr_option->string_values[CONFIG_INTEGER(ptr_option)]); - goto end; - } snprintf (str_value, sizeof (str_value), "%d", CONFIG_INTEGER(ptr_option)); value = strdup (str_value); @@ -1847,6 +1842,9 @@ eval_replace_vars_cb (void *data, const char *text) case CONFIG_OPTION_TYPE_COLOR: value = strdup (gui_color_get_name (CONFIG_COLOR(ptr_option))); goto end; + case CONFIG_OPTION_TYPE_ENUM: + value = strdup (ptr_option->string_values[CONFIG_ENUM(ptr_option)]); + goto end; case CONFIG_NUM_OPTION_TYPES: value = strdup (""); goto end; diff --git a/src/plugins/fset/fset-bar-item.c b/src/plugins/fset/fset-bar-item.c index 430ada4e1..51df05e67 100644 --- a/src/plugins/fset/fset-bar-item.c +++ b/src/plugins/fset/fset-bar-item.c @@ -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); } } diff --git a/src/plugins/fset/fset-command.c b/src/plugins/fset/fset-command.c index 7ab4f3a5d..bd90af332 100644 --- a/src/plugins/fset/fset-command.c +++ b/src/plugins/fset/fset-command.c @@ -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 " diff --git a/src/plugins/fset/fset-mouse.c b/src/plugins/fset/fset-mouse.c index 642d33d44..89bfe8acd 100644 --- a/src/plugins/fset/fset-mouse.c +++ b/src/plugins/fset/fset-mouse.c @@ -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", diff --git a/src/plugins/fset/fset-option.c b/src/plugins/fset/fset-option.c index a8fdf2057..2a227c932 100644 --- a/src/plugins/fset/fset-option.c +++ b/src/plugins/fset/fset-option.c @@ -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), diff --git a/src/plugins/fset/fset-option.h b/src/plugins/fset/fset-option.h index 508db23f1..1d6041946 100644 --- a/src/plugins/fset/fset-option.h +++ b/src/plugins/fset/fset-option.h @@ -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, }; diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h index 4b88cfb33..8f9323d15 100644 --- a/src/plugins/irc/irc-server.h +++ b/src/plugins/irc/irc-server.h @@ -120,6 +120,13 @@ enum t_irc_server_option weechat_config_string(irc_config_server_default[__index]) \ : weechat_config_string_default(irc_config_server_default[__index]))) +#define IRC_SERVER_OPTION_ENUM(__server, __index) \ + ((!weechat_config_option_is_null(__server->options[__index])) ? \ + weechat_config_enum(__server->options[__index]) : \ + ((!weechat_config_option_is_null(irc_config_server_default[__index])) ? \ + weechat_config_enum(irc_config_server_default[__index]) \ + : weechat_config_enum_default(irc_config_server_default[__index]))) + #define IRC_SERVER_DEFAULT_PORT_CLEARTEXT 6667 #define IRC_SERVER_DEFAULT_PORT_TLS 6697 diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index ea4b9fb5a..f2e290bc3 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -761,6 +761,8 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv) new_plugin->config_boolean_default = &config_file_option_boolean_default; new_plugin->config_integer = &config_file_option_integer; new_plugin->config_integer_default = &config_file_option_integer_default; + new_plugin->config_enum = &config_file_option_enum; + new_plugin->config_enum_default = &config_file_option_enum_default; new_plugin->config_string = &config_file_option_string; new_plugin->config_string_default = &config_file_option_string_default; new_plugin->config_color = &config_file_option_color; diff --git a/src/plugins/python/weechat.pyi b/src/plugins/python/weechat.pyi index d3c2cb214..6d743e4c2 100644 --- a/src/plugins/python/weechat.pyi +++ b/src/plugins/python/weechat.pyi @@ -602,49 +602,49 @@ def config_new_option(config_file: str, section: str, name: str, type: str, desc :: # example - def option4_check_value_cb(data: str, option: str, value: str) -> int: + def option_str_check_value_cb(data: str, option: str, value: str) -> int: # ... return 1 # return 0 - def option4_change_cb(data: str, option: str) -> None: + def option_str_change_cb(data: str, option: str) -> None: # ... - def option4_delete_cb(data: str, option: str) -> None: + def option_str_delete_cb(data: str, option: str) -> None: # ... - option1 = weechat.config_new_option(config_file, section, "option1", "boolean", + option_bool = weechat.config_new_option(config_file, section, "option_bool", "boolean", "My option, type boolean", "", 0, 0, "on", "on", 0, "", "", "", "", "", "") - option2 = weechat.config_new_option(config_file, section, "option2", "integer", + option_int = weechat.config_new_option(config_file, section, "option_int", "integer", "My option, type integer", "", 0, 100, "15", "15", 0, "", "", "", "", "", "") - option3 = weechat.config_new_option(config_file, section, "option3", "integer", - "My option, type integer (with string values)", - "top|bottom|left|right", - 0, 0, "bottom", "bottom", 0, + option_str = weechat.config_new_option(config_file, section, "option_str", "string", + "My option, type string", + "", 0, 0, "test", "test", 1, + "option_str_check_value_cb", "", + "option_str_change_cb", "", + "option_str_delete_cb", "") + + option_col = weechat.config_new_option(config_file, section, "option_col", "color", + "My option, type color", + "", 0, 0, "lightblue", "lightblue", 0, "", "", "", "", "", "") - option4 = weechat.config_new_option(config_file, section, "option4", "string", - "My option, type string", - "", 0, 0, "test", "test", 1, - "option4_check_value_cb", "", - "option4_change_cb", "", - "option4_delete_cb", "") - - option5 = weechat.config_new_option(config_file, section, "option5", "color", - "My option, type color", - "", 0, 0, "lightblue", "lightblue", 0, + option_enum = weechat.config_new_option(config_file, section, "option_enum", "enum", + "My option, type enum", + "top|bottom|left|right", + 0, 0, "bottom", "bottom", 0, "", "", "", "", "", "") @@ -861,6 +861,28 @@ def config_color_default(option: str) -> str: ... +def config_enum(option: str) -> int: + """`config_enum in WeeChat plugin API reference `_ + :: + + # example + option = weechat.config_get("plugin.section.option") + value = weechat.config_enum(option) + """ + ... + + +def config_enum_default(option: str) -> int: + """`config_enum_default in WeeChat plugin API reference `_ + :: + + # example + option = weechat.config_get("plugin.section.option") + value = weechat.config_enum_default(option) + """ + ... + + def config_write_option(config_file: str, option: str) -> int: """`config_write_option in WeeChat plugin API reference `_ :: diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index f0f8cae49..3e425ff6e 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -68,7 +68,7 @@ struct timeval; * please change the date with current one; for a second change at same * date, increment the 01, otherwise please keep 01. */ -#define WEECHAT_PLUGIN_API_VERSION "20230220-01" +#define WEECHAT_PLUGIN_API_VERSION "20230706-01" /* macros for defining plugin infos */ #define WEECHAT_PLUGIN_NAME(__name) \ @@ -639,6 +639,8 @@ struct t_weechat_plugin int (*config_boolean_default) (struct t_config_option *option); int (*config_integer) (struct t_config_option *option); int (*config_integer_default) (struct t_config_option *option); + int (*config_enum) (struct t_config_option *option); + int (*config_enum_default) (struct t_config_option *option); const char *(*config_string) (struct t_config_option *option); const char *(*config_string_default) (struct t_config_option *option); const char *(*config_color) (struct t_config_option *option); @@ -1699,6 +1701,10 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); (weechat_plugin->config_integer)(__option) #define weechat_config_integer_default(__option) \ (weechat_plugin->config_integer_default)(__option) +#define weechat_config_enum(__option) \ + (weechat_plugin->config_enum)(__option) +#define weechat_config_enum_default(__option) \ + (weechat_plugin->config_enum_default)(__option) #define weechat_config_string(__option) \ (weechat_plugin->config_string)(__option) #define weechat_config_string_default(__option) \ diff --git a/tests/scripts/python/testapi.py b/tests/scripts/python/testapi.py index d301d1c64..6e9bb22e1 100644 --- a/tests/scripts/python/testapi.py +++ b/tests/scripts/python/testapi.py @@ -254,7 +254,7 @@ def test_config(): check(weechat.config_option_reset(ptr_opt_int, 1) == 2) # SET_OK_CHANGED check(weechat.config_option_reset(ptr_opt_int, 1) == 1) # SET_OK_SAME_VALUE check(weechat.config_integer(ptr_opt_int) == 2) - # integer option (with string values) + # integer option (with string values: enum with WeeChat >= 4.1.0) ptr_opt_int_str = weechat.config_new_option( ptr_config, ptr_section, 'option_int_str', 'integer', 'int option str', 'val1|val2|val3', 0, 0, 'val2', 'val2', 0, @@ -318,6 +318,27 @@ def test_config(): check(weechat.config_option_reset(ptr_opt_col, 1) == 2) # SET_OK_CHANGED check(weechat.config_option_reset(ptr_opt_col, 1) == 1) # SET_OK_SAME_VALUE check(weechat.config_color(ptr_opt_col) == 'lightgreen') + # enum option + ptr_opt_enum = weechat.config_new_option( + ptr_config, ptr_section, 'option_enum', 'enum', 'enum option', + 'val1|val2|val3', 0, 0, 'val2', 'val2', 0, + 'option_check_value_cb', '', + 'option_change_cb', '', + 'option_delete_cb', '', + ) + check(ptr_opt_enum != '') + check(weechat.config_integer(ptr_opt_enum) == 1) + check(weechat.config_string(ptr_opt_enum) == 'val2') + check(weechat.config_option_set(ptr_opt_enum, 'val1', 1) == 2) # SET_OK_CHANGED + check(weechat.config_option_set(ptr_opt_enum, 'val1', 1) == 1) # SET_OK_SAME_VALUE + check(weechat.config_integer(ptr_opt_enum) == 0) + check(weechat.config_string(ptr_opt_enum) == 'val1') + check(weechat.config_integer_default(ptr_opt_enum) == 1) + check(weechat.config_string_default(ptr_opt_enum) == 'val2') + check(weechat.config_option_reset(ptr_opt_enum, 1) == 2) # SET_OK_CHANGED + check(weechat.config_option_reset(ptr_opt_enum, 1) == 1) # SET_OK_SAME_VALUE + check(weechat.config_integer(ptr_opt_enum) == 1) + check(weechat.config_string(ptr_opt_enum) == 'val2') # search option ptr_opt_bool2 = weechat.config_search_option(ptr_config, ptr_section, 'option_bool') diff --git a/tests/unit/core/test-core-config-file.cpp b/tests/unit/core/test-core-config-file.cpp index 8b2bfe0f9..baf75f21e 100644 --- a/tests/unit/core/test-core-config-file.cpp +++ b/tests/unit/core/test-core-config-file.cpp @@ -45,6 +45,7 @@ struct t_config_option *ptr_option_int = NULL; struct t_config_option *ptr_option_int_str = NULL; struct t_config_option *ptr_option_str = NULL; struct t_config_option *ptr_option_col = NULL; +struct t_config_option *ptr_option_enum = NULL; TEST_GROUP(CoreConfigFile) { @@ -79,6 +80,7 @@ TEST_GROUP(CoreConfigFileWithNewOptions) NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + /* auto-created as enum with WeeChat >= 4.1.0 */ ptr_option_int_str = config_file_new_option ( weechat_config_file, weechat_config_section_look, "test_integer_values", "integer", "", "v1|v2|v3", 0, 0, "v1", NULL, 0, @@ -97,6 +99,12 @@ TEST_GROUP(CoreConfigFileWithNewOptions) NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + ptr_option_enum = config_file_new_option ( + weechat_config_file, weechat_config_section_look, + "test_enum", "enum", "", "v1|v2|v3", 0, 0, "v1", NULL, 0, + NULL, NULL, NULL, + NULL, NULL, NULL, + NULL, NULL, NULL); } void teardown () @@ -111,6 +119,9 @@ TEST_GROUP(CoreConfigFileWithNewOptions) ptr_option_str = NULL; config_file_option_free (ptr_option_col, 0); ptr_option_col = NULL; + config_file_option_free (ptr_option_enum, 0); + ptr_option_enum = NULL; + } }; @@ -615,7 +626,7 @@ TEST(CoreConfigFileWithNewOptions, OptionSetReset) config_file_option_reset (ptr_option_int, 1)); LONGS_EQUAL(100, CONFIG_INTEGER(ptr_option_int)); - /* integer with string values */ + /* integer with string values (enum with WeeChat >= 4.1.0) */ LONGS_EQUAL(0, CONFIG_INTEGER(ptr_option_int_str)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_ERROR, config_file_option_set (ptr_option_int_str, "zzz", 1)); @@ -685,6 +696,17 @@ TEST(CoreConfigFileWithNewOptions, OptionSetReset) LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, config_file_option_reset (ptr_option_col, 1)); LONGS_EQUAL(9, CONFIG_COLOR(ptr_option_col)); + + /* enum */ + LONGS_EQUAL(0, CONFIG_ENUM(ptr_option_enum)); + LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_ERROR, + config_file_option_set (ptr_option_enum, "zzz", 1)); + LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, + config_file_option_set (ptr_option_enum, "v2", 1)); + LONGS_EQUAL(1, CONFIG_ENUM(ptr_option_enum)); + LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, + config_file_option_reset (ptr_option_enum, 1)); + LONGS_EQUAL(0, CONFIG_INTEGER(ptr_option_enum)); } /* @@ -770,7 +792,7 @@ TEST(CoreConfigFileWithNewOptions, OptionToggle) config_file_option_reset (ptr_option_int, 1)); LONGS_EQUAL(100, CONFIG_INTEGER(ptr_option_int)); - /* integer with string values */ + /* integer with string values (enum with WeeChat >= 4.1.0) */ LONGS_EQUAL(0, CONFIG_INTEGER(ptr_option_int_str)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_ERROR, config_file_option_toggle (ptr_option_int_str, @@ -845,6 +867,30 @@ TEST(CoreConfigFileWithNewOptions, OptionToggle) LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, config_file_option_reset (ptr_option_col, 1)); LONGS_EQUAL(9, CONFIG_COLOR(ptr_option_col)); + + /* enum */ + LONGS_EQUAL(0, CONFIG_ENUM(ptr_option_enum)); + LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_ERROR, + config_file_option_toggle (ptr_option_enum, + values_integer_str_error, 2, 1)); + LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_ERROR, + config_file_option_toggle (ptr_option_enum, + NULL, 0, 1)); + LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, + config_file_option_toggle (ptr_option_enum, + value_integer_str_ok, 1, 1)); + LONGS_EQUAL(1, CONFIG_ENUM(ptr_option_enum)); + LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, + config_file_option_toggle (ptr_option_enum, + values_integer_str_ok, 2, 1)); + LONGS_EQUAL(2, CONFIG_ENUM(ptr_option_enum)); + LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, + config_file_option_toggle (ptr_option_enum, + values_integer_str_ok, 2, 1)); + LONGS_EQUAL(1, CONFIG_ENUM(ptr_option_enum)); + LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, + config_file_option_reset (ptr_option_enum, 1)); + LONGS_EQUAL(0, CONFIG_ENUM(ptr_option_enum)); } /* @@ -903,7 +949,7 @@ TEST(CoreConfigFileWithNewOptions, OptionSetDefault) config_file_option_set_default (ptr_option_int, "--3", 1)); LONGS_EQUAL(62, CONFIG_INTEGER_DEFAULT(ptr_option_int)); - /* integer with string values */ + /* integer with string values (enum with WeeChat >= 4.1.0) */ LONGS_EQUAL(0, CONFIG_INTEGER_DEFAULT(ptr_option_int_str)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE, config_file_option_set_default (ptr_option_int_str, NULL, 1)); @@ -966,6 +1012,16 @@ TEST(CoreConfigFileWithNewOptions, OptionSetDefault) | GUI_COLOR_EXTENDED_UNDERLINE_FLAG | GUI_COLOR_EXTENDED_KEEPATTR_FLAG, CONFIG_COLOR_DEFAULT(ptr_option_col)); + + /* enum */ + LONGS_EQUAL(0, CONFIG_ENUM_DEFAULT(ptr_option_enum)); + LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE, + config_file_option_set_default (ptr_option_enum, NULL, 1)); + LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_ERROR, + config_file_option_set_default (ptr_option_enum, "zzz", 1)); + LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, + config_file_option_set_default (ptr_option_enum, "v2", 1)); + LONGS_EQUAL(1, CONFIG_INTEGER_DEFAULT(ptr_option_enum)); } /*