From 2fac9d34f3f5db1b7d59420acb93ee4be5c84d10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Tue, 30 May 2017 21:16:38 +0200 Subject: [PATCH] fset: add ${string_values}, add options fset.color.string_values and fset.color.string_values_selected --- src/plugins/fset/fset-buffer.c | 28 ++++++++++++++++++++++------ src/plugins/fset/fset-config.c | 17 +++++++++++++++++ src/plugins/fset/fset-config.h | 1 + src/plugins/fset/fset-mouse.c | 2 ++ src/plugins/fset/fset-option.c | 29 +++++++++++++++++++++++++++++ src/plugins/fset/fset-option.h | 1 + 6 files changed, 72 insertions(+), 6 deletions(-) diff --git a/src/plugins/fset/fset-buffer.c b/src/plugins/fset/fset-buffer.c index 3f708eb90..618c08213 100644 --- a/src/plugins/fset/fset-buffer.c +++ b/src/plugins/fset/fset-buffer.c @@ -98,7 +98,7 @@ fset_buffer_display_line (int y, struct t_fset_option *fset_option) snprintf (str_field, sizeof (str_field), "%s%s", weechat_color (weechat_config_string (fset_config_color_name[selected_line])), - ptr_field); + (ptr_field) ? ptr_field : ""); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_name", str_field); fset_buffer_fills_field (str_field, sizeof (str_field), "name", 64); @@ -114,7 +114,7 @@ fset_buffer_display_line (int y, struct t_fset_option *fset_option) snprintf (str_field, sizeof (str_field), "%s%s", weechat_color (weechat_config_string (fset_config_color_parent_name[selected_line])), - ptr_field); + (ptr_field) ? ptr_field : ""); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_parent_name", str_field); fset_buffer_fills_field (str_field, sizeof (str_field), "parent_name", 64); @@ -130,7 +130,7 @@ fset_buffer_display_line (int y, struct t_fset_option *fset_option) snprintf (str_field, sizeof (str_field), "%s%s", weechat_color (weechat_config_string (fset_config_color_type[selected_line])), - ptr_field); + (ptr_field) ? ptr_field : ""); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_type", str_field); fset_buffer_fills_field (str_field, sizeof (str_field), "type", 8); @@ -255,7 +255,7 @@ fset_buffer_display_line (int y, struct t_fset_option *fset_option) snprintf (str_field, sizeof (str_field), "%s%s", weechat_color (weechat_config_string (fset_config_color_min[selected_line])), - ptr_field); + (ptr_field) ? ptr_field : ""); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_min", str_field); fset_buffer_fills_field (str_field, sizeof (str_field), "min", 8); @@ -271,7 +271,7 @@ fset_buffer_display_line (int y, struct t_fset_option *fset_option) snprintf (str_field, sizeof (str_field), "%s%s", weechat_color (weechat_config_string (fset_config_color_max[selected_line])), - ptr_field); + (ptr_field) ? ptr_field : ""); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_max", str_field); fset_buffer_fills_field (str_field, sizeof (str_field), "max", 8); @@ -287,13 +287,29 @@ fset_buffer_display_line (int y, struct t_fset_option *fset_option) snprintf (str_field, sizeof (str_field), "%s%s", weechat_color (weechat_config_string (fset_config_color_description[selected_line])), - ptr_field); + (ptr_field) ? ptr_field : ""); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_description", str_field); fset_buffer_fills_field (str_field, sizeof (str_field), "description", 64); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "description", str_field); + /* string_values */ + ptr_field = weechat_hdata_string (fset_hdata_fset_option, + fset_option, "string_values"); + snprintf (str_field, sizeof (str_field), "%s", ptr_field); + weechat_hashtable_set (fset_buffer_hashtable_extra_vars, + "__string_values", str_field); + snprintf (str_field, sizeof (str_field), + "%s%s", + weechat_color (weechat_config_string (fset_config_color_string_values[selected_line])), + (ptr_field) ? ptr_field : ""); + weechat_hashtable_set (fset_buffer_hashtable_extra_vars, + "_string_values", str_field); + fset_buffer_fills_field (str_field, sizeof (str_field), "string_values", 32); + weechat_hashtable_set (fset_buffer_hashtable_extra_vars, + "string_values", str_field); + /* set other variables depending on the value */ weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "value_undef", diff --git a/src/plugins/fset/fset-config.c b/src/plugins/fset/fset-config.c index 210c60846..c5fb1bc82 100644 --- a/src/plugins/fset/fset-config.c +++ b/src/plugins/fset/fset-config.c @@ -50,6 +50,7 @@ struct t_config_option *fset_config_color_min[2]; struct t_config_option *fset_config_color_name[2]; struct t_config_option *fset_config_color_parent_name[2]; struct t_config_option *fset_config_color_quotes[2]; +struct t_config_option *fset_config_color_string_values[2]; struct t_config_option *fset_config_color_type[2]; struct t_config_option *fset_config_color_value[2]; struct t_config_option *fset_config_color_value_diff[2]; @@ -334,6 +335,22 @@ fset_config_init () NULL, NULL, NULL, &fset_config_change_color, NULL, NULL, NULL, NULL, NULL); + fset_config_color_string_values[0] = weechat_config_new_option ( + fset_config_file, ptr_section, + "string_values", "color", + N_("color for string values"), + NULL, 0, 0, "default", NULL, 0, + NULL, NULL, NULL, + &fset_config_change_color, NULL, NULL, + NULL, NULL, NULL); + fset_config_color_string_values[1] = weechat_config_new_option ( + fset_config_file, ptr_section, + "string_values_selected", "color", + N_("color for string values on the selected line"), + NULL, 0, 0, "white", NULL, 0, + NULL, NULL, NULL, + &fset_config_change_color, NULL, NULL, + NULL, NULL, NULL); fset_config_color_type[0] = weechat_config_new_option ( fset_config_file, ptr_section, "type", "color", diff --git a/src/plugins/fset/fset-config.h b/src/plugins/fset/fset-config.h index 6452347f9..83f82a789 100644 --- a/src/plugins/fset/fset-config.h +++ b/src/plugins/fset/fset-config.h @@ -38,6 +38,7 @@ extern struct t_config_option *fset_config_color_min[2]; extern struct t_config_option *fset_config_color_name[2]; extern struct t_config_option *fset_config_color_parent_name[2]; extern struct t_config_option *fset_config_color_quotes[2]; +extern struct t_config_option *fset_config_color_string_values[2]; extern struct t_config_option *fset_config_color_type[2]; extern struct t_config_option *fset_config_color_value[2]; extern struct t_config_option *fset_config_color_value_diff[2]; diff --git a/src/plugins/fset/fset-mouse.c b/src/plugins/fset/fset-mouse.c index 6a2200a50..902d20354 100644 --- a/src/plugins/fset/fset-mouse.c +++ b/src/plugins/fset/fset-mouse.c @@ -90,6 +90,8 @@ fset_focus_cb (const void *pointer, void *data, struct t_hashtable *info) weechat_hashtable_set (info, "fset_option_parent_value", ptr_fset_option->parent_value); weechat_hashtable_set (info, "fset_option_min", ptr_fset_option->min); weechat_hashtable_set (info, "fset_option_max", ptr_fset_option->max); + weechat_hashtable_set (info, "fset_option_description", ptr_fset_option->description); + weechat_hashtable_set (info, "fset_option_string_values", ptr_fset_option->string_values); return info; } diff --git a/src/plugins/fset/fset-option.c b/src/plugins/fset/fset-option.c index 4f68c3742..da09b43c1 100644 --- a/src/plugins/fset/fset-option.c +++ b/src/plugins/fset/fset-option.c @@ -259,6 +259,7 @@ fset_option_set_values (struct t_fset_option *fset_option, struct t_config_option *option) { const char *ptr_parent_name, *ptr_type, *ptr_description; + const char **ptr_string_values; void *ptr_default_value, *ptr_value; struct t_config_option *ptr_parent_option; int *ptr_min, *ptr_max; @@ -358,6 +359,23 @@ fset_option_set_values (struct t_fset_option *fset_option, } ptr_description = weechat_config_option_get_string (option, "description"); fset_option->description = strdup ((ptr_description) ? ptr_description : ""); + + /* string_values */ + if (fset_option->string_values) + { + free (fset_option->string_values); + fset_option->string_values = NULL; + } + ptr_string_values = weechat_config_option_get_pointer (option, "string_values"); + if (ptr_string_values) + { + fset_option->string_values = weechat_string_build_with_split_string ( + ptr_string_values, ","); + } + else + { + fset_option->string_values = strdup (""); + } } /* @@ -452,6 +470,10 @@ fset_option_set_max_length_fields_option (struct t_fset_option *fset_option) /* description */ fset_option_set_max_length_field ( "description", weechat_strlen_screen (fset_option->description)); + + /* string_values */ + fset_option_set_max_length_field ( + "string_values", weechat_strlen_screen (fset_option->string_values)); } /* @@ -526,6 +548,7 @@ fset_option_alloc (struct t_config_file *config_file, new_fset_option->min = NULL; new_fset_option->max = NULL; new_fset_option->description = NULL; + new_fset_option->string_values = NULL; fset_option_set_values (new_fset_option, option); if (!fset_option_match_filters (ptr_config_name, ptr_section_name, new_fset_option)) @@ -652,6 +675,8 @@ fset_option_free (struct t_fset_option *fset_option) free (fset_option->max); if (fset_option->description) free (fset_option->description); + if (fset_option->string_values) + free (fset_option->string_values); free (fset_option); } @@ -854,6 +879,7 @@ fset_option_hdata_option_cb (const void *pointer, void *data, WEECHAT_HDATA_VAR(struct t_fset_option, min, STRING, 0, NULL, NULL); WEECHAT_HDATA_VAR(struct t_fset_option, max, STRING, 0, NULL, NULL); WEECHAT_HDATA_VAR(struct t_fset_option, description, STRING, 0, NULL, NULL); + WEECHAT_HDATA_VAR(struct t_fset_option, string_values, STRING, 0, NULL, NULL); } return hdata; } @@ -897,6 +923,8 @@ fset_option_add_to_infolist (struct t_infolist *infolist, return 0; if (!weechat_infolist_new_var_string (ptr_item, "description", fset_option->description)) return 0; + if (!weechat_infolist_new_var_string (ptr_item, "string_values", fset_option->description)) + return 0; return 1; } @@ -926,6 +954,7 @@ fset_option_print_log () weechat_log_printf (" min . . . . . . . . . : '%s'", ptr_fset_option->min); weechat_log_printf (" max . . . . . . . . . : '%s'", ptr_fset_option->max); weechat_log_printf (" description . . . . . : '%s'", ptr_fset_option->description); + weechat_log_printf (" string_values . . . . : '%s'", ptr_fset_option->string_values); } } diff --git a/src/plugins/fset/fset-option.h b/src/plugins/fset/fset-option.h index 62e195c52..185a74edd 100644 --- a/src/plugins/fset/fset-option.h +++ b/src/plugins/fset/fset-option.h @@ -33,6 +33,7 @@ struct t_fset_option char *min; /* min value */ char *max; /* max value */ char *description; /* option description */ + char *string_values; /* string values for option */ struct t_fset_option *prev_option; /* link to previous option */ struct t_fset_option *next_option; /* link to next option */ };