From 02a94b496082fe55d06083601c777ff576405343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Wed, 31 May 2017 19:38:03 +0200 Subject: fset: add fset bar item content, add options for colors in help bar --- src/plugins/fset/fset-bar-item.c | 96 +++++++++++++++++++++++++++++++++++++++- src/plugins/fset/fset-buffer.c | 3 ++ src/plugins/fset/fset-config.c | 90 ++++++++++++++++++++++++++++++++++++- src/plugins/fset/fset-config.h | 6 +++ src/plugins/fset/fset-option.c | 3 +- src/plugins/fset/fset.c | 11 +++-- 6 files changed, 201 insertions(+), 8 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/fset/fset-bar-item.c b/src/plugins/fset/fset-bar-item.c index cfeaeb70e..e722cb247 100644 --- a/src/plugins/fset/fset-bar-item.c +++ b/src/plugins/fset/fset-bar-item.c @@ -20,11 +20,15 @@ */ #include +#include +#include #include "../weechat-plugin.h" #include "fset.h" #include "fset-bar-item.h" +#include "fset-buffer.h" #include "fset-config.h" +#include "fset-option.h" struct t_gui_bar_item *fset_bar_item_fset = NULL; @@ -37,7 +41,7 @@ struct t_gui_bar_item *fset_bar_item_fset = NULL; void fset_bar_item_update () { - if (weechat_config_boolean (fset_config_look_enabled)) + if (weechat_config_boolean (fset_config_look_help_bar)) weechat_bar_item_update (FSET_BAR_ITEM_NAME); } @@ -52,7 +56,95 @@ fset_bar_item_fset_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, struct t_hashtable *extra_info) { - return NULL; + struct t_fset_option *ptr_fset_option; + struct t_config_option *ptr_option; + char str_help[8192], **string_values; + const char **ptr_string_values; + int i; + + /* make C compiler happy */ + (void) pointer; + (void) data; + (void) item; + (void) window; + (void) buffer; + (void) extra_info; + + if (!fset_buffer) + return NULL; + + ptr_fset_option = weechat_arraylist_get (fset_options, + fset_buffer_selected_line); + if (!ptr_fset_option) + return NULL; + + string_values = weechat_string_dyn_alloc (256); + if (!string_values) + return NULL; + + if (ptr_fset_option->string_values && ptr_fset_option->string_values[0]) + { + ptr_option = weechat_config_get (ptr_fset_option->name); + if (ptr_option) + { + ptr_string_values = weechat_config_option_get_pointer ( + ptr_option, "string_values"); + if (ptr_string_values) + { + weechat_string_dyn_concat (string_values, + weechat_color ("bar_fg")); + weechat_string_dyn_concat (string_values, ", "); + weechat_string_dyn_concat (string_values, _("values:")); + weechat_string_dyn_concat (string_values, " "); + for (i = 0; ptr_string_values[i]; i++) + { + if (i > 0) + { + weechat_string_dyn_concat (string_values, + weechat_color ("bar_fg")); + weechat_string_dyn_concat (string_values, ", "); + } + weechat_string_dyn_concat ( + string_values, + weechat_color ( + weechat_config_string ( + fset_config_color_help_quotes))); + weechat_string_dyn_concat (string_values, "\""); + weechat_string_dyn_concat ( + string_values, + weechat_color ( + weechat_config_string ( + fset_config_color_help_string_values))); + weechat_string_dyn_concat (string_values, + ptr_string_values[i]); + weechat_string_dyn_concat ( + string_values, + weechat_color ( + weechat_config_string ( + fset_config_color_help_quotes))); + weechat_string_dyn_concat (string_values, "\""); + } + } + } + } + + snprintf (str_help, sizeof (str_help), + _("%s%s%s: %s %s[%sdefault: %s%s%s%s]%s"), + weechat_color (weechat_config_string (fset_config_color_help_name)), + ptr_fset_option->name, + weechat_color ("bar_fg"), + ptr_fset_option->description, + weechat_color ("bar_delim"), + weechat_color ("bar_fg"), + weechat_color (weechat_config_string (fset_config_color_help_default_value)), + ptr_fset_option->default_value, + *string_values, + weechat_color ("bar_delim"), + weechat_color ("bar_fg")); + + weechat_string_dyn_free (string_values, 1); + + return strdup (str_help); } /* diff --git a/src/plugins/fset/fset-buffer.c b/src/plugins/fset/fset-buffer.c index f0af24b40..004b7c3c7 100644 --- a/src/plugins/fset/fset-buffer.c +++ b/src/plugins/fset/fset-buffer.c @@ -26,6 +26,7 @@ #include "../weechat-plugin.h" #include "fset.h" #include "fset-buffer.h" +#include "fset-bar-item.h" #include "fset-config.h" #include "fset-option.h" @@ -381,6 +382,7 @@ fset_buffer_refresh (int clear) } fset_buffer_set_title (); + fset_bar_item_update (); } /* @@ -405,6 +407,7 @@ fset_buffer_set_current_line (int line) weechat_arraylist_get (fset_options, fset_buffer_selected_line)); fset_buffer_set_title (); + fset_bar_item_update (); } } diff --git a/src/plugins/fset/fset-config.c b/src/plugins/fset/fset-config.c index c5fb1bc82..2e5999f93 100644 --- a/src/plugins/fset/fset-config.c +++ b/src/plugins/fset/fset-config.c @@ -25,6 +25,7 @@ #include "../weechat-plugin.h" #include "fset.h" #include "fset-config.h" +#include "fset-bar-item.h" #include "fset-buffer.h" @@ -33,6 +34,7 @@ struct t_config_file *fset_config_file = NULL; /* fset config, look section */ struct t_config_option *fset_config_look_enabled; +struct t_config_option *fset_config_look_help_bar; struct t_config_option *fset_config_look_use_keys; struct t_config_option *fset_config_look_use_mute; @@ -45,6 +47,11 @@ struct t_config_option *fset_config_format_option_current; struct t_config_option *fset_config_color_default_value[2]; struct t_config_option *fset_config_color_description[2]; +struct t_config_option *fset_config_color_help_default_value; +struct t_config_option *fset_config_color_help_description; +struct t_config_option *fset_config_color_help_name; +struct t_config_option *fset_config_color_help_quotes; +struct t_config_option *fset_config_color_help_string_values; struct t_config_option *fset_config_color_max[2]; struct t_config_option *fset_config_color_min[2]; struct t_config_option *fset_config_color_name[2]; @@ -59,6 +66,22 @@ struct t_config_option *fset_config_color_value_undef[2]; char *fset_config_eval_format_option_current = NULL; +/* + * Callback for changes on option "fset.look.help_bar". + */ + +void +fset_config_change_help_bar_cb (const void *pointer, void *data, + struct t_config_option *option) +{ + /* make C compiler happy */ + (void) pointer; + (void) data; + (void) option; + + weechat_command (NULL, "/window refresh"); +} + /* * Callback for changes on option "fset.look.use_keys". */ @@ -100,6 +123,22 @@ fset_config_change_format (const void *pointer, void *data, fset_buffer_refresh (0); } +/* + * Callback for changes on help color options. + */ + +void +fset_config_change_help_color (const void *pointer, void *data, + struct t_config_option *option) +{ + /* make C compiler happy */ + (void) pointer; + (void) data; + (void) option; + + fset_bar_item_update (); +} + /* * Callback for changes on color options. */ @@ -156,6 +195,15 @@ fset_config_init () NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + fset_config_look_help_bar = weechat_config_new_option ( + fset_config_file, ptr_section, + "help_bar", "boolean", + N_("display help bar in fset buffer (description of option, " + "allowed values and default value)"), + NULL, 0, 0, "on", NULL, 0, + NULL, NULL, NULL, + &fset_config_change_help_bar_cb, NULL, NULL, + NULL, NULL, NULL); fset_config_look_use_keys = weechat_config_new_option ( fset_config_file, ptr_section, "use_keys", "boolean", @@ -255,6 +303,46 @@ fset_config_init () NULL, NULL, NULL, &fset_config_change_color, NULL, NULL, NULL, NULL, NULL); + fset_config_color_help_default_value = weechat_config_new_option ( + fset_config_file, ptr_section, + "help_default_value", "color", + N_("color for default value in help bar"), + NULL, 0, 0, "white", NULL, 0, + NULL, NULL, NULL, + &fset_config_change_help_color, NULL, NULL, + NULL, NULL, NULL); + fset_config_color_help_description = weechat_config_new_option ( + fset_config_file, ptr_section, + "help_description", "color", + N_("color for description in help bar"), + NULL, 0, 0, "default", NULL, 0, + NULL, NULL, NULL, + &fset_config_change_help_color, NULL, NULL, + NULL, NULL, NULL); + fset_config_color_help_name = weechat_config_new_option ( + fset_config_file, ptr_section, + "help_name", "color", + N_("color for name in help bar"), + NULL, 0, 0, "white", NULL, 0, + NULL, NULL, NULL, + &fset_config_change_help_color, NULL, NULL, + NULL, NULL, NULL); + fset_config_color_help_quotes = weechat_config_new_option ( + fset_config_file, ptr_section, + "help_quotes", "color", + N_("color for quotes around string values"), + NULL, 0, 0, "darkgray", NULL, 0, + NULL, NULL, NULL, + &fset_config_change_color, NULL, NULL, + NULL, NULL, NULL); + fset_config_color_help_string_values = weechat_config_new_option ( + fset_config_file, ptr_section, + "help_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_max[0] = weechat_config_new_option ( fset_config_file, ptr_section, "max", "color", @@ -321,7 +409,7 @@ fset_config_init () NULL, NULL, NULL); fset_config_color_quotes[0] = weechat_config_new_option ( fset_config_file, ptr_section, - "quote", "color", + "quotes", "color", N_("color for quotes around string values"), NULL, 0, 0, "darkgray", NULL, 0, NULL, NULL, NULL, diff --git a/src/plugins/fset/fset-config.h b/src/plugins/fset/fset-config.h index 83f82a789..fa38a2b7f 100644 --- a/src/plugins/fset/fset-config.h +++ b/src/plugins/fset/fset-config.h @@ -25,6 +25,7 @@ extern struct t_config_file *fset_config_file; extern struct t_config_option *fset_config_look_enabled; +extern struct t_config_option *fset_config_look_help_bar; extern struct t_config_option *fset_config_look_use_keys; extern struct t_config_option *fset_config_look_use_mute; @@ -33,6 +34,11 @@ extern struct t_config_option *fset_config_format_option_current; extern struct t_config_option *fset_config_color_default_value[2]; extern struct t_config_option *fset_config_color_description[2]; +extern struct t_config_option *fset_config_color_help_default_value; +extern struct t_config_option *fset_config_color_help_description; +extern struct t_config_option *fset_config_color_help_name; +extern struct t_config_option *fset_config_color_help_quotes; +extern struct t_config_option *fset_config_color_help_string_values; extern struct t_config_option *fset_config_color_max[2]; extern struct t_config_option *fset_config_color_min[2]; extern struct t_config_option *fset_config_color_name[2]; diff --git a/src/plugins/fset/fset-option.c b/src/plugins/fset/fset-option.c index 14c73df63..d09e84e06 100644 --- a/src/plugins/fset/fset-option.c +++ b/src/plugins/fset/fset-option.c @@ -379,7 +379,8 @@ fset_option_set_values (struct t_fset_option *fset_option, fset_option->description = NULL; } ptr_description = weechat_config_option_get_string (option, "description"); - fset_option->description = strdup ((ptr_description) ? ptr_description : ""); + fset_option->description = strdup ( + (ptr_description && ptr_description[0]) ? _(ptr_description) : ""); /* string_values */ if (fset_option->string_values) diff --git a/src/plugins/fset/fset.c b/src/plugins/fset/fset.c index 1d743efbc..74ae90123 100644 --- a/src/plugins/fset/fset.c +++ b/src/plugins/fset/fset.c @@ -56,10 +56,13 @@ struct t_hdata *fset_hdata_fset_option = NULL; void fset_add_bar () { - weechat_bar_new (FSET_BAR_NAME, "on", "0", "window", "", "top", - "horizontal", "vertical", "3", "3", - "default", "cyan", "default", "on", - FSET_BAR_ITEM_NAME); + weechat_bar_new ( + FSET_BAR_NAME, "off", "0", "window", + "${fset.look.help_bar} " + "&& ${buffer.full_name} == " FSET_PLUGIN_NAME "." FSET_BAR_NAME, + "top", "horizontal", "vertical", "3", "3", + "default", "cyan", "default", "on", + FSET_BAR_ITEM_NAME); } /* -- cgit v1.2.3