diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2017-06-16 21:03:56 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2017-06-25 16:35:28 +0200 |
commit | 850922ff92890f231dba08db6348d35dd86ebb0e (patch) | |
tree | c80be2856f33f9190e202833df35b148e2f3cbcb /src | |
parent | fdf7a5f13db9b31c13f06e57dc72ca01975f7da9 (diff) | |
download | weechat-850922ff92890f231dba08db6348d35dd86ebb0e.zip |
fset: add a second format for options, new key ctrl-X and input "x" to switch the format used
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/fset/fset-buffer.c | 13 | ||||
-rw-r--r-- | src/plugins/fset/fset-command.c | 25 | ||||
-rw-r--r-- | src/plugins/fset/fset-config.c | 106 | ||||
-rw-r--r-- | src/plugins/fset/fset-config.h | 7 |
4 files changed, 122 insertions, 29 deletions
diff --git a/src/plugins/fset/fset-buffer.c b/src/plugins/fset/fset-buffer.c index 0fcf03c4e..d91825785 100644 --- a/src/plugins/fset/fset-buffer.c +++ b/src/plugins/fset/fset-buffer.c @@ -79,6 +79,7 @@ fset_buffer_set_title () "($)=refresh, " "($$)=unmark/refresh, " "alt+v(v)=toggle help bar, " + "ctrl+X(x)=switch format, " "(q)=close buffer"), weechat_color (weechat_config_string (fset_config_color_title_filter)), (fset_option_filter) ? fset_option_filter : "*", @@ -137,7 +138,7 @@ fset_buffer_display_line (int y, struct t_fset_option *fset_option) const char *ptr_field, *ptr_parent_value; int selected_line; int default_value_undef, value_undef, value_changed; - int type, marked, add_quotes, add_quotes_parent; + int type, marked, add_quotes, add_quotes_parent, format_number; if (!fset_option) return; @@ -647,8 +648,11 @@ fset_buffer_display_line (int y, struct t_fset_option *fset_option) (value_changed) ? "1" : "0"); /* build string for line */ + format_number = weechat_config_integer (fset_config_look_format_number); line = weechat_string_eval_expression ( - (selected_line) ? fset_config_eval_format_option_current : weechat_config_string (fset_config_format_option), + (selected_line) ? + fset_config_eval_format_option_current[format_number - 1] : + weechat_config_string (fset_config_format_option[format_number - 1]), fset_buffer_hashtable_pointers, fset_buffer_hashtable_extra_vars, NULL); @@ -854,7 +858,9 @@ fset_buffer_input_cb (const void *pointer, void *data, { ",", "/fset -mark 1" }, { "p", "/mute /set fset.look.show_plugins_desc toggle", }, { "v", "/mute /set fset.look.show_help_bar toggle" }, - { NULL, NULL } }; + { "x", "/fset -format" }, + { NULL, NULL }, + }; const char *ptr_input; int i; @@ -1014,6 +1020,7 @@ fset_buffer_set_keys () { "ctrl-L", "/fset -refresh" }, { "meta-p", "/mute /set fset.look.show_plugins_desc toggle", }, { "meta-v", "/mute /set fset.look.show_help_bar toggle" }, + { "ctrl-X", "/fset -format" }, { NULL, NULL }, }; char str_key[64]; diff --git a/src/plugins/fset/fset-command.c b/src/plugins/fset/fset-command.c index 42dd4a43c..5467a3f66 100644 --- a/src/plugins/fset/fset-command.c +++ b/src/plugins/fset/fset-command.c @@ -81,8 +81,8 @@ fset_command_fset (const void *pointer, void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { - int num_options, line, value, i, with_help; - char str_command[512]; + int num_options, line, value, i, with_help, min, max, format_number; + char str_command[512], str_number[64]; const char *ptr_filename; struct t_fset_option *ptr_fset_option; struct t_config_option *ptr_option; @@ -373,6 +373,23 @@ fset_command_fset (const void *pointer, void *data, return WEECHAT_RC_OK; } + if (weechat_strcasecmp (argv[1], "-format") == 0) + { + min = weechat_hdata_integer (fset_hdata_config_option, + fset_config_look_format_number, + "min"); + max = weechat_hdata_integer (fset_hdata_config_option, + fset_config_look_format_number, + "max"); + format_number = weechat_config_integer (fset_config_look_format_number) + 1; + if (format_number > max) + format_number = min; + snprintf (str_number, sizeof (str_number), "%d", format_number); + weechat_config_option_set (fset_config_look_format_number, + str_number, 1); + return WEECHAT_RC_OK; + } + if (weechat_strcasecmp (argv[1], "-export") == 0) { if (argc < 3) @@ -573,6 +590,7 @@ fset_command_init () " || -set" " || -append" " || -mark [<number>]" + " || -format" " || -export [-help|-nohelp] <filename>" " || filter"), N_(" -bar: add the help bar\n" @@ -597,6 +615,7 @@ fset_command_init () "of option (move the cursor at the end of value)\n" " -mark: toggle mark on the option and move \"number\" lines " "(up/down, default is 1: one line down)\n" + " -format: switch to the next available format\n" " -export: export the options and values displayed in a file " "(each line has format: \"/set name value\" or \"/unset name\")\n" " -help: force writing of help on options in exported file " @@ -711,6 +730,7 @@ fset_command_init () " w:xxx export options in file \"xxx\"\n" " w-:xxx export options in file \"xxx\" without help\n" " w+:xxx export options in file \"xxx\" with help\n" + " ctrl+X x switch the format used to display options\n" " q close fset buffer\n" "\n" "Mouse actions on fset buffer:\n" @@ -750,6 +770,7 @@ fset_command_init () " || -set" " || -append" " || -mark" + " || -format" " || -export -help|-nohelp|%(filename) %(filename)" " || *|c:|f:|s:|d|d:|d=|d==|=|==|%(fset_options)", &fset_command_fset, NULL, NULL); diff --git a/src/plugins/fset/fset-config.c b/src/plugins/fset/fset-config.c index 355de57b1..422db2d97 100644 --- a/src/plugins/fset/fset-config.c +++ b/src/plugins/fset/fset-config.c @@ -37,6 +37,7 @@ struct t_config_file *fset_config_file = NULL; struct t_config_option *fset_config_look_auto_unmark; struct t_config_option *fset_config_look_condition_catch_set; struct t_config_option *fset_config_look_export_help_default; +struct t_config_option *fset_config_look_format_number; struct t_config_option *fset_config_look_marked_string; struct t_config_option *fset_config_look_scroll_horizontal; struct t_config_option *fset_config_look_show_help_bar; @@ -49,8 +50,8 @@ struct t_config_option *fset_config_look_use_mute; /* fset config, format section */ -struct t_config_option *fset_config_format_option; -struct t_config_option *fset_config_format_option_current; +struct t_config_option *fset_config_format_option[2]; +struct t_config_option *fset_config_format_option_current[2]; struct t_config_option *fset_config_format_export_help; struct t_config_option *fset_config_format_export_option; struct t_config_option *fset_config_format_export_option_null; @@ -93,10 +94,26 @@ struct t_config_option *fset_config_color_value_undef[2]; char **fset_config_sort_fields = NULL; int fset_config_sort_fields_count = 0; -char *fset_config_eval_format_option_current = NULL; +char *fset_config_eval_format_option_current[2] = { NULL, NULL }; /* + * Callback for changes on option "fset.look.format_number". + */ + +void +fset_config_change_format_number_cb (const void *pointer, void *data, + struct t_config_option *option) +{ + /* make C compiler happy */ + (void) pointer; + (void) data; + (void) option; + + fset_buffer_refresh (0); +} + +/* * Callback for changes on option "fset.look.show_help_bar". */ @@ -201,18 +218,22 @@ void fset_config_change_format_cb (const void *pointer, void *data, struct t_config_option *option) { + int i; + /* make C compiler happy */ (void) pointer; (void) data; (void) option; - if (fset_config_eval_format_option_current) - free (fset_config_eval_format_option_current); - - fset_config_eval_format_option_current = weechat_string_replace ( - weechat_config_string (fset_config_format_option_current), - "${format_option}", - weechat_config_string (fset_config_format_option)); + for (i = 0; i < 2; i++) + { + if (fset_config_eval_format_option_current[i]) + free (fset_config_eval_format_option_current[i]); + fset_config_eval_format_option_current[i] = weechat_string_replace ( + weechat_config_string (fset_config_format_option_current[i]), + "${format_option}", + weechat_config_string (fset_config_format_option[i])); + } fset_buffer_refresh (0); } @@ -329,6 +350,15 @@ fset_config_init () NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + fset_config_look_format_number = weechat_config_new_option ( + fset_config_file, ptr_section, + "format_number", "integer", + N_("number of format used to display options; this is dynamically " + "changed by the key ctrl-X on the fset buffer"), + NULL, 1, 2, "1", NULL, 0, + NULL, NULL, NULL, + &fset_config_change_format_number_cb, NULL, NULL, + NULL, NULL, NULL); fset_config_look_marked_string = weechat_config_new_option ( fset_config_file, ptr_section, "marked_string", "string", @@ -423,26 +453,55 @@ fset_config_init () return 0; } - fset_config_format_option = weechat_config_new_option ( + fset_config_format_option[0] = weechat_config_new_option ( fset_config_file, ptr_section, - "option", "string", - N_("format of each line with an option " - "(note: content is evaluated, see /help fset)"), + "option1", "string", + N_("first format of each line with an option " + "(note: content is evaluated, see /help fset); formats can be " + "switched with key ctrl+X"), NULL, 0, 0, "${marked} ${name} ${type} ${value2}", NULL, 0, NULL, NULL, NULL, &fset_config_change_format_cb, NULL, NULL, NULL, NULL, NULL); - fset_config_format_option_current = weechat_config_new_option ( + fset_config_format_option[1] = weechat_config_new_option ( fset_config_file, ptr_section, - "option_current", "string", - N_("format for the line with current option " - "(note: content is evaluated, see /help fset)"), + "option2", "string", + N_("second format of each line with an option " + "(note: content is evaluated, see /help fset); " + "formats can be switched with key ctrl+X"), + NULL, 0, 0, + "${marked} ${name} ${type_short} ${min} ${max} ${default_value} " + "${value2} ${description}", + NULL, 0, + NULL, NULL, NULL, + &fset_config_change_format_cb, NULL, NULL, + NULL, NULL, NULL); + fset_config_format_option_current[0] = weechat_config_new_option ( + fset_config_file, ptr_section, + "option_current1", "string", + N_("first format for the line with current option " + "(note: content is evaluated, see /help fset, " + "${format_option} is replaced by the content of option " + "fset.format.option1 before evaluation); " + "formats can be switched with key ctrl+X"), NULL, 0, 0, "${color:,blue}${format_option}", NULL, 0, NULL, NULL, NULL, &fset_config_change_format_cb, NULL, NULL, NULL, NULL, NULL); + fset_config_format_option_current[1] = weechat_config_new_option ( + fset_config_file, ptr_section, + "option_current2", "string", + N_("second format for the line with current option " + "(note: content is evaluated, see /help fset, " + "${format_option} is replaced by the content of option " + "fset.format.option2 before evaluation); " + "formats can be switched with key ctrl+X"), + NULL, 0, 0, "${color:,red}${format_option}", NULL, 0, + NULL, NULL, NULL, + &fset_config_change_format_cb, NULL, NULL, + NULL, NULL, NULL); fset_config_format_export_help = weechat_config_new_option ( fset_config_file, ptr_section, "export_help", "string", @@ -983,6 +1042,8 @@ fset_config_write () void fset_config_free () { + int i; + weechat_config_free (fset_config_file); if (fset_config_sort_fields) @@ -992,9 +1053,12 @@ fset_config_free () fset_config_sort_fields_count = 0; } - if (fset_config_eval_format_option_current) + for (i = 0; i < 2; i++) { - free (fset_config_eval_format_option_current); - fset_config_eval_format_option_current = NULL; + if (fset_config_eval_format_option_current[i]) + { + free (fset_config_eval_format_option_current[i]); + fset_config_eval_format_option_current[i] = NULL; + } } } diff --git a/src/plugins/fset/fset-config.h b/src/plugins/fset/fset-config.h index 3dc04a965..57e3c3da5 100644 --- a/src/plugins/fset/fset-config.h +++ b/src/plugins/fset/fset-config.h @@ -27,6 +27,7 @@ extern struct t_config_file *fset_config_file; extern struct t_config_option *fset_config_look_auto_unmark; extern struct t_config_option *fset_config_look_condition_catch_set; extern struct t_config_option *fset_config_look_export_help_default; +extern struct t_config_option *fset_config_look_format_number; extern struct t_config_option *fset_config_look_marked_string; extern struct t_config_option *fset_config_look_scroll_horizontal; extern struct t_config_option *fset_config_look_show_help_bar; @@ -37,8 +38,8 @@ extern struct t_config_option *fset_config_look_use_color_value; extern struct t_config_option *fset_config_look_use_keys; extern struct t_config_option *fset_config_look_use_mute; -extern struct t_config_option *fset_config_format_option; -extern struct t_config_option *fset_config_format_option_current; +extern struct t_config_option *fset_config_format_option[2]; +extern struct t_config_option *fset_config_format_option_current[2]; extern struct t_config_option *fset_config_format_export_help; extern struct t_config_option *fset_config_format_export_option; extern struct t_config_option *fset_config_format_export_option_null; @@ -79,7 +80,7 @@ extern struct t_config_option *fset_config_color_value_undef[2]; extern char **fset_config_sort_fields; extern int fset_config_sort_fields_count; -extern char *fset_config_eval_format_option_current; +extern char *fset_config_eval_format_option_current[2]; extern int fset_config_init (); extern int fset_config_read (); |