diff options
Diffstat (limited to 'src/plugins/fset')
-rw-r--r-- | src/plugins/fset/fset-buffer.c | 27 | ||||
-rw-r--r-- | src/plugins/fset/fset-config.c | 34 | ||||
-rw-r--r-- | src/plugins/fset/fset-config.h | 2 | ||||
-rw-r--r-- | src/plugins/fset/fset-option.c | 29 | ||||
-rw-r--r-- | src/plugins/fset/fset-option.h | 1 |
5 files changed, 87 insertions, 6 deletions
diff --git a/src/plugins/fset/fset-buffer.c b/src/plugins/fset/fset-buffer.c index 4dfe40716..08d8bf521 100644 --- a/src/plugins/fset/fset-buffer.c +++ b/src/plugins/fset/fset-buffer.c @@ -47,10 +47,15 @@ void fset_buffer_display_line (int y, struct t_fset_option *option) { char *line, str_format[32], str_value[1024]; - int i, selected_line, *ptr_length; + const char *ptr_value; + int i, selected_line, *ptr_length, value_undef, value_diff; + struct t_config_option *ptr_option_color_value; selected_line = (y == fset_buffer_selected_line) ? 1 : 0; + value_undef = (option->value == NULL) ? 1 : 0; + value_diff = (fset_option_value_different_from_default (option)) ? 1 : 0; + /* set pointers */ weechat_hashtable_set (fset_buffer_hashtable_pointers, "fset_option", option); @@ -62,11 +67,12 @@ fset_buffer_display_line (int y, struct t_fset_option *option) snprintf (str_format, sizeof (str_format), "%%-%ds", (ptr_length) ? *ptr_length : fset_buffer_columns_default_size[i]); + ptr_value = weechat_hdata_string (fset_hdata_fset_option, + option, + fset_buffer_columns[i]); snprintf (str_value, sizeof (str_value), str_format, - weechat_hdata_string (fset_hdata_fset_option, - option, - fset_buffer_columns[i])); + (ptr_value) ? ptr_value : "null"); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, fset_buffer_columns[i], str_value); @@ -88,12 +94,23 @@ fset_buffer_display_line (int y, struct t_fset_option *option) weechat_color (weechat_config_string (fset_config_color_default_value[selected_line]))); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "color_default_value", str_value); + if (value_undef) + ptr_option_color_value = fset_config_color_value_undef[selected_line]; + else if (value_diff) + ptr_option_color_value = fset_config_color_value_diff[selected_line]; + else + ptr_option_color_value = fset_config_color_value[selected_line]; snprintf (str_value, sizeof (str_value), "%s", - weechat_color (weechat_config_string (fset_config_color_value[selected_line]))); + weechat_color (weechat_config_string (ptr_option_color_value))); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "color_value", str_value); + /* set other variables depending on the value */ + weechat_hashtable_set (fset_buffer_hashtable_extra_vars, + "value_undef", + (option->value == NULL) ? "1" : "0"); + /* build string for line */ line = weechat_string_eval_expression ( (selected_line) ? fset_config_eval_format_option_current : weechat_config_string (fset_config_format_option), diff --git a/src/plugins/fset/fset-config.c b/src/plugins/fset/fset-config.c index 3e71e369d..adc00954d 100644 --- a/src/plugins/fset/fset-config.c +++ b/src/plugins/fset/fset-config.c @@ -46,6 +46,8 @@ struct t_config_option *fset_config_color_default_value[2]; struct t_config_option *fset_config_color_name[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]; +struct t_config_option *fset_config_color_value_undef[2]; char *fset_config_eval_format_option_current = NULL; @@ -270,6 +272,38 @@ fset_config_init () NULL, NULL, NULL, &fset_config_change_color, NULL, NULL, NULL, NULL, NULL); + fset_config_color_value_diff[0] = weechat_config_new_option ( + fset_config_file, ptr_section, + "value_diff", "color", + N_("color for value different from default"), + NULL, 0, 0, "green", NULL, 0, + NULL, NULL, NULL, + &fset_config_change_color, NULL, NULL, + NULL, NULL, NULL); + fset_config_color_value_diff[1] = weechat_config_new_option ( + fset_config_file, ptr_section, + "value_diff_selected", "color", + N_("color for value different from default on the selected line"), + NULL, 0, 0, "lightgreen", NULL, 0, + NULL, NULL, NULL, + &fset_config_change_color, NULL, NULL, + NULL, NULL, NULL); + fset_config_color_value_undef[0] = weechat_config_new_option ( + fset_config_file, ptr_section, + "value_undef", "color", + N_("color for undefined value"), + NULL, 0, 0, "magenta", NULL, 0, + NULL, NULL, NULL, + &fset_config_change_color, NULL, NULL, + NULL, NULL, NULL); + fset_config_color_value_undef[1] = weechat_config_new_option ( + fset_config_file, ptr_section, + "value_undef_selected", "color", + N_("color for undefined value on the selected line"), + NULL, 0, 0, "lightmagenta", NULL, 0, + NULL, NULL, NULL, + &fset_config_change_color, NULL, NULL, + NULL, NULL, NULL); return 1; } diff --git a/src/plugins/fset/fset-config.h b/src/plugins/fset/fset-config.h index fb1ef7156..e5bec0eb5 100644 --- a/src/plugins/fset/fset-config.h +++ b/src/plugins/fset/fset-config.h @@ -34,6 +34,8 @@ extern struct t_config_option *fset_config_color_default_value[2]; extern struct t_config_option *fset_config_color_name[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]; +extern struct t_config_option *fset_config_color_value_undef[2]; extern char *fset_config_eval_format_option_current; diff --git a/src/plugins/fset/fset-option.c b/src/plugins/fset/fset-option.c index ed2afc9c9..db44b37fb 100644 --- a/src/plugins/fset/fset-option.c +++ b/src/plugins/fset/fset-option.c @@ -89,6 +89,29 @@ fset_option_search_by_name (const char *name) } /* + * Checks if the option value is different from the default value. + * + * Returns: + * 1: value is different from default value + * 0: value is the same as default value + */ + +int +fset_option_value_different_from_default (struct t_fset_option *option) +{ + if (!option->value && !option->default_value) + return 0; + + if ((option->value && !option->default_value) + || (!option->value && option->default_value)) + { + return 1; + } + + return (strcmp (option->value, option->default_value) != 0) ? 1 : 0; +} + +/* * Sets max length for a field in hashtable "fset_option_max_length_field". */ @@ -112,6 +135,7 @@ fset_option_set_value_string (struct t_config_option *option, char **value_string) { char str_value[64]; + int length; if (!value) { @@ -128,7 +152,10 @@ fset_option_set_value_string (struct t_config_option *option, } else if (strcmp (type, "string") == 0) { - *value_string = strdup ((const char *)value); + length = 1 + strlen ((const char *)value) + 1 + 1; + *value_string = malloc (length); + if (*value_string) + snprintf (*value_string, length, "\"%s\"", (const char *)value); } else if (strcmp (type, "color") == 0) { diff --git a/src/plugins/fset/fset-option.h b/src/plugins/fset/fset-option.h index 44457015e..c1382b880 100644 --- a/src/plugins/fset/fset-option.h +++ b/src/plugins/fset/fset-option.h @@ -45,6 +45,7 @@ extern char *fset_option_filter; extern int fset_option_valid (struct t_fset_option *option); extern struct t_fset_option *fset_option_search_by_name (const char *name); +extern int fset_option_value_different_from_default (struct t_fset_option *option); extern void fset_option_set_filter (const char *filter); extern void fset_option_get_options (); extern void fset_option_filter_options (const char *search); |