1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-03 16:23:14 +02:00

fset: add format options for marked options

This commit is contained in:
Sébastien Helleu
2017-06-18 14:07:47 +02:00
parent 1552a2327f
commit 68b337eb60
4 changed files with 98 additions and 20 deletions
+18 -9
View File
@@ -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);
+5 -3
View File
@@ -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"
+73 -8
View File
@@ -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]);
+2
View File
@@ -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 ();