summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2017-06-18 14:07:47 +0200
committerSébastien Helleu <flashcode@flashtux.org>2017-06-25 16:35:28 +0200
commit68b337eb606214c64e6ae735765ab6753f3f511a (patch)
treedf17092ced7870cde41f0b85e6956426b8d29640 /src/plugins
parent1552a2327ff65122b852ce68fea7edc30946462e (diff)
downloadweechat-68b337eb606214c64e6ae735765ab6753f3f511a.zip
fset: add format options for marked options
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/fset/fset-buffer.c27
-rw-r--r--src/plugins/fset/fset-command.c8
-rw-r--r--src/plugins/fset/fset-config.c81
-rw-r--r--src/plugins/fset/fset-config.h2
4 files changed, 98 insertions, 20 deletions
diff --git a/src/plugins/fset/fset-buffer.c b/src/plugins/fset/fset-buffer.c
index 3921be7c1..c6a7bb87f 100644
--- a/src/plugins/fset/fset-buffer.c
+++ b/src/plugins/fset/fset-buffer.c
@@ -155,7 +155,7 @@ fset_buffer_display_line (int y, struct t_fset_option *fset_option)
{
char *line, str_field[4096], str_color_value[128], str_color_quotes[128];
char str_number[64];
- const char *ptr_field, *ptr_parent_value;
+ const char *ptr_field, *ptr_parent_value, *ptr_format;
int selected_line;
int default_value_undef, value_undef, value_changed;
int type, marked, add_quotes, add_quotes_parent, format_number;
@@ -691,14 +691,23 @@ fset_buffer_display_line (int y, struct t_fset_option *fset_option)
/* 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_selected[format_number - 1] :
- weechat_config_string (fset_config_format_option[format_number - 1]),
- fset_buffer_hashtable_pointers,
- fset_buffer_hashtable_extra_vars,
- NULL);
-
+ if (selected_line)
+ {
+ ptr_format = fset_config_eval_format_option_selected[format_number - 1];
+ }
+ else if (fset_option->marked)
+ {
+ ptr_format = fset_config_eval_format_option_marked[format_number - 1];
+ }
+ else
+ {
+ ptr_format = weechat_config_string (
+ fset_config_format_option[format_number - 1]);
+ }
+ line = weechat_string_eval_expression (ptr_format,
+ fset_buffer_hashtable_pointers,
+ fset_buffer_hashtable_extra_vars,
+ NULL);
if (line)
{
weechat_printf_y (fset_buffer, y, "%s", line);
diff --git a/src/plugins/fset/fset-command.c b/src/plugins/fset/fset-command.c
index 622cc5d21..da55b0b84 100644
--- a/src/plugins/fset/fset-command.c
+++ b/src/plugins/fset/fset-command.c
@@ -646,9 +646,11 @@ fset_command_init ()
"\n"
"The lines with options are displayed using string evaluation "
"(see /help eval for the format), with these options:\n"
- " - fset.format.option: format for an option which is not on "
- "current line\n"
- " - fset.format.option_selected: format for the selected option\n"
+ " - fset.format.option{1,2}: formats for an option which is not "
+ "marked nor the selected line\n"
+ " - fset.format.option_marked{1,2}: formats for a marked option\n"
+ " - fset.format.option_selected{1,2}: formats for the selected "
+ "option\n"
"\n"
"The following variables can be used in these options:\n"
" - option data, with color and padded by spaces on the right:\n"
diff --git a/src/plugins/fset/fset-config.c b/src/plugins/fset/fset-config.c
index d02d226e9..ddfac2c8d 100644
--- a/src/plugins/fset/fset-config.c
+++ b/src/plugins/fset/fset-config.c
@@ -51,6 +51,7 @@ struct t_config_option *fset_config_look_use_mute;
/* fset config, format section */
struct t_config_option *fset_config_format_option[2];
+struct t_config_option *fset_config_format_option_marked[2];
struct t_config_option *fset_config_format_option_selected[2];
struct t_config_option *fset_config_format_export_help;
struct t_config_option *fset_config_format_export_option;
@@ -95,6 +96,7 @@ 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_marked[2] = { NULL, NULL };
char *fset_config_eval_format_option_selected[2] = { NULL, NULL };
@@ -220,6 +222,7 @@ fset_config_change_format_cb (const void *pointer, void *data,
struct t_config_option *option)
{
int i;
+ const char *ptr_format;
/* make C compiler happy */
(void) pointer;
@@ -228,12 +231,39 @@ fset_config_change_format_cb (const void *pointer, void *data,
for (i = 0; i < 2; i++)
{
+ /* format_option_marked */
+ if (fset_config_eval_format_option_marked[i])
+ free (fset_config_eval_format_option_marked[i]);
+ ptr_format = weechat_config_string (fset_config_format_option_marked[i]);
+ if (ptr_format && ptr_format[0])
+ {
+ fset_config_eval_format_option_marked[i] = weechat_string_replace (
+ ptr_format,
+ "${format_option}",
+ weechat_config_string (fset_config_format_option[i]));
+ }
+ else
+ {
+ fset_config_eval_format_option_marked[i] = strdup (
+ weechat_config_string (fset_config_format_option[i]));
+ }
+
+ /* format_option_selected */
if (fset_config_eval_format_option_selected[i])
free (fset_config_eval_format_option_selected[i]);
- fset_config_eval_format_option_selected[i] = weechat_string_replace (
- weechat_config_string (fset_config_format_option_selected[i]),
- "${format_option}",
- weechat_config_string (fset_config_format_option[i]));
+ ptr_format = weechat_config_string (fset_config_format_option_selected[i]);
+ if (ptr_format && ptr_format[0])
+ {
+ fset_config_eval_format_option_selected[i] = weechat_string_replace (
+ ptr_format,
+ "${format_option}",
+ weechat_config_string (fset_config_format_option[i]));
+ }
+ else
+ {
+ fset_config_eval_format_option_selected[i] = strdup (
+ weechat_config_string (fset_config_format_option[i]));
+ }
}
fset_buffer_refresh (0);
@@ -457,7 +487,8 @@ fset_config_init ()
fset_config_format_option[0] = weechat_config_new_option (
fset_config_file, ptr_section,
"option1", "string",
- N_("first format of each line with an option "
+ N_("first format of each line with an option which is not marked "
+ "nor the selected one "
"(note: content is evaluated, see /help fset); formats can be "
"switched with key ctrl+X"),
NULL, 0, 0,
@@ -469,7 +500,8 @@ fset_config_init ()
fset_config_format_option[1] = weechat_config_new_option (
fset_config_file, ptr_section,
"option2", "string",
- N_("second format of each line with an option "
+ N_("second format of each line with an option which is not marked "
+ "not the selected one "
"(note: content is evaluated, see /help fset); "
"formats can be switched with key ctrl+X"),
NULL, 0, 0,
@@ -479,13 +511,40 @@ fset_config_init ()
NULL, NULL, NULL,
&fset_config_change_format_cb, NULL, NULL,
NULL, NULL, NULL);
+ fset_config_format_option_marked[0] = weechat_config_new_option (
+ fset_config_file, ptr_section,
+ "option_marked1", "string",
+ N_("first format for a line with a marked option "
+ "(note: content is evaluated, see /help fset, "
+ "${format_option} is replaced by the content of option "
+ "fset.format.option1 before evaluation; if this option is "
+ "empty, the value of fset.format.option1 is used); "
+ "formats can be switched with key ctrl+X"),
+ NULL, 0, 0, "", NULL, 0,
+ NULL, NULL, NULL,
+ &fset_config_change_format_cb, NULL, NULL,
+ NULL, NULL, NULL);
+ fset_config_format_option_marked[1] = weechat_config_new_option (
+ fset_config_file, ptr_section,
+ "option_marked2", "string",
+ N_("second format for a line with a marked option "
+ "(note: content is evaluated, see /help fset, "
+ "${format_option} is replaced by the content of option "
+ "fset.format.option2 before evaluation; if this option is "
+ "empty, the value of fset.format.option2 is used); "
+ "formats can be switched with key ctrl+X"),
+ NULL, 0, 0, "", NULL, 0,
+ NULL, NULL, NULL,
+ &fset_config_change_format_cb, NULL, NULL,
+ NULL, NULL, NULL);
fset_config_format_option_selected[0] = weechat_config_new_option (
fset_config_file, ptr_section,
"option_selected1", "string",
N_("first format for the line with selected option "
"(note: content is evaluated, see /help fset, "
"${format_option} is replaced by the content of option "
- "fset.format.option1 before evaluation); "
+ "fset.format.option1 before evaluation; if this option is "
+ "empty, the value of fset.format.option1 is used); "
"formats can be switched with key ctrl+X"),
NULL, 0, 0, "${color:,blue}${format_option}", NULL, 0,
NULL, NULL, NULL,
@@ -497,7 +556,8 @@ fset_config_init ()
N_("second format for the line with selected option "
"(note: content is evaluated, see /help fset, "
"${format_option} is replaced by the content of option "
- "fset.format.option2 before evaluation); "
+ "fset.format.option2 before evaluation; if this option is "
+ "empty, the value of fset.format.option2 is used); "
"formats can be switched with key ctrl+X"),
NULL, 0, 0, "${color:,red}${format_option}", NULL, 0,
NULL, NULL, NULL,
@@ -1072,6 +1132,11 @@ fset_config_free ()
for (i = 0; i < 2; i++)
{
+ if (fset_config_eval_format_option_marked[i])
+ {
+ free (fset_config_eval_format_option_marked[i]);
+ fset_config_eval_format_option_marked[i] = NULL;
+ }
if (fset_config_eval_format_option_selected[i])
{
free (fset_config_eval_format_option_selected[i]);
diff --git a/src/plugins/fset/fset-config.h b/src/plugins/fset/fset-config.h
index b6b57eeb2..cb7d4c3b6 100644
--- a/src/plugins/fset/fset-config.h
+++ b/src/plugins/fset/fset-config.h
@@ -39,6 +39,7 @@ 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[2];
+extern struct t_config_option *fset_config_format_option_marked[2];
extern struct t_config_option *fset_config_format_option_selected[2];
extern struct t_config_option *fset_config_format_export_help;
extern struct t_config_option *fset_config_format_export_option;
@@ -81,6 +82,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_marked[2];
extern char *fset_config_eval_format_option_selected[2];
extern int fset_config_init ();