diff options
author | Adrian Bjugård <adrian@qng.se> | 2019-04-13 20:36:41 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2019-04-13 20:36:41 +0200 |
commit | 0b5bff9ef5cdb6319bb9e5aff1a70ba563a5b94e (patch) | |
tree | c809894efd0fb0f57649e5c3bd8bfa15e3a99f0e /src | |
parent | 36fc3fdc3b17c71d5d12ba6e8aebd5199aaed6cc (diff) | |
download | weechat-0b5bff9ef5cdb6319bb9e5aff1a70ba563a5b94e.zip |
core: add option weechat.look.prefix_same_nick_middle (closes #930, closes #931)
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-config.c | 39 | ||||
-rw-r--r-- | src/core/wee-config.h | 2 | ||||
-rw-r--r-- | src/gui/gui-line.c | 127 |
3 files changed, 145 insertions, 23 deletions
diff --git a/src/core/wee-config.c b/src/core/wee-config.c index f635b7cf2..7d515acb6 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -171,6 +171,7 @@ struct t_config_option *config_look_prefix_buffer_align_max; struct t_config_option *config_look_prefix_buffer_align_more; struct t_config_option *config_look_prefix_buffer_align_more_after; struct t_config_option *config_look_prefix_same_nick; +struct t_config_option *config_look_prefix_same_nick_middle; struct t_config_option *config_look_prefix_suffix; struct t_config_option *config_look_quote_nick_prefix; struct t_config_option *config_look_quote_nick_suffix; @@ -303,6 +304,7 @@ struct t_config_option *config_plugin_save_config_on_unload; int config_length_nick_prefix_suffix = 0; int config_length_prefix_same_nick = 0; +int config_length_prefix_same_nick_middle = 0; struct t_hook *config_day_change_timer = NULL; int config_day_change_old_day = -1; int config_emphasized_attributes = 0; @@ -816,6 +818,26 @@ config_change_prefix_same_nick (const void *pointer, void *data, } /* + * Callback for changes on option "weechat.look.prefix_same_nick_middle". + */ + +void +config_change_prefix_same_nick_middle (const void *pointer, void *data, + struct t_config_option *option) +{ + /* make C compiler happy */ + (void) pointer; + (void) data; + (void) option; + + config_length_prefix_same_nick_middle = + gui_chat_strlen_screen (CONFIG_STRING(config_look_prefix_same_nick_middle)); + + config_compute_prefix_max_length_all_buffers (); + gui_window_ask_refresh (1); +} + +/* * Callback for changes on option "weechat.look.eat_newline_glitch". */ @@ -3394,13 +3416,24 @@ config_weechat_init_options () weechat_config_file, ptr_section, "prefix_same_nick", "string", N_("prefix displayed for a message with same nick as previous " - "message: use a space \" \" to hide prefix, another string to " - "display this string instead of prefix, or an empty string to " - "disable feature (display prefix)"), + "but not next message: use a space \" \" to hide prefix, another " + "string to display this string instead of prefix, or an empty " + "string to disable feature (display prefix)"), NULL, 0, 0, "", NULL, 0, NULL, NULL, NULL, &config_change_prefix_same_nick, NULL, NULL, NULL, NULL, NULL); + config_look_prefix_same_nick_middle = config_file_new_option ( + weechat_config_file, ptr_section, + "prefix_same_nick_middle", "string", + N_("prefix displayed for a message with same nick as previous " + "and next message: use a space \" \" to hide prefix, another " + "string to display this string instead of prefix, or an empty " + "string to disable feature (display prefix)"), + NULL, 0, 0, "", NULL, 0, + NULL, NULL, NULL, + &config_change_prefix_same_nick_middle, NULL, NULL, + NULL, NULL, NULL); config_look_prefix_suffix = config_file_new_option ( weechat_config_file, ptr_section, "prefix_suffix", "string", diff --git a/src/core/wee-config.h b/src/core/wee-config.h index 69b32ad1f..d3fc51694 100644 --- a/src/core/wee-config.h +++ b/src/core/wee-config.h @@ -222,6 +222,7 @@ extern struct t_config_option *config_look_prefix_buffer_align_max; extern struct t_config_option *config_look_prefix_buffer_align_more; extern struct t_config_option *config_look_prefix_buffer_align_more_after; extern struct t_config_option *config_look_prefix_same_nick; +extern struct t_config_option *config_look_prefix_same_nick_middle; extern struct t_config_option *config_look_prefix_suffix; extern struct t_config_option *config_look_quote_nick_prefix; extern struct t_config_option *config_look_quote_nick_suffix; @@ -342,6 +343,7 @@ extern struct t_config_option *config_plugin_save_config_on_unload; extern int config_length_nick_prefix_suffix; extern int config_length_prefix_same_nick; +extern int config_length_prefix_same_nick_middle; extern int config_emphasized_attributes; extern regex_t *config_highlight_regex; extern char ***config_highlight_tags; diff --git a/src/gui/gui-line.c b/src/gui/gui-line.c index 16e92e02f..c54cb643b 100644 --- a/src/gui/gui-line.c +++ b/src/gui/gui-line.c @@ -181,6 +181,58 @@ gui_line_prefix_is_same_nick_as_previous (struct t_gui_line *line) } /* + * Checks if prefix on line is a nick and is the same as nick on next line. + * + * Returns: + * 1: prefix is a nick and same as nick on next line + * 0: prefix is not a nick, or different from nick on next line + */ + +int +gui_line_prefix_is_same_nick_as_next (struct t_gui_line *line) +{ + const char *nick, *nick_next; + struct t_gui_line *next_line; + + /* + * if line is not displayed, has a highlight, or does not have a tag + * beginning with "prefix_nick" => display standard prefix + */ + if (!line->data->displayed || line->data->highlight + || !gui_line_search_tag_starting_with (line, "prefix_nick")) + return 0; + + /* no nick on line => display standard prefix */ + nick = gui_line_get_nick_tag (line); + if (!nick) + return 0; + + /* next line is not found => display standard prefix */ + next_line = gui_line_get_next_displayed (line); + if (!next_line) + return 0; + + /* buffer is not the same as next line => display standard prefix */ + if (line->data->buffer != next_line->data->buffer) + return 0; + + /* + * next line does not have a tag beginning with "prefix_nick" + * => display standard prefix + */ + if (!gui_line_search_tag_starting_with (next_line, "prefix_nick")) + return 0; + + /* no nick on next line => display standard prefix */ + nick_next = gui_line_get_nick_tag (next_line); + if (!nick_next) + return 0; + + /* prefix can be hidden/replaced if nicks are equal */ + return (strcmp (nick, nick_next) == 0) ? 1 : 0; +} + +/* * Gets prefix and its length (for display only). * * If the prefix can be hidden (same nick as previous message), and if the @@ -199,33 +251,68 @@ gui_line_get_prefix_for_display (struct t_gui_line *line, && CONFIG_STRING(config_look_prefix_same_nick)[0] && gui_line_prefix_is_same_nick_as_previous (line)) { - /* same nick: return empty prefix or value from option */ - if (strcmp (CONFIG_STRING(config_look_prefix_same_nick), " ") == 0) + if (CONFIG_STRING(config_look_prefix_same_nick_middle) + && CONFIG_STRING(config_look_prefix_same_nick_middle)[0] + && gui_line_prefix_is_same_nick_as_next (line)) { - /* return empty prefix */ - if (prefix) - *prefix = gui_chat_prefix_empty; - if (length) - *length = 0; - if (color) - *color = NULL; + /* same nick: return empty prefix or value from option */ + if (strcmp (CONFIG_STRING(config_look_prefix_same_nick_middle), " ") == 0) + { + /* return empty prefix */ + if (prefix) + *prefix = gui_chat_prefix_empty; + if (length) + *length = 0; + if (color) + *color = NULL; + } + else + { + /* return prefix from option "weechat.look.prefix_same_nick_middle" */ + if (prefix) + *prefix = CONFIG_STRING(config_look_prefix_same_nick_middle); + if (length) + *length = config_length_prefix_same_nick_middle; + if (color) + { + tag_prefix_nick = gui_line_search_tag_starting_with (line, + "prefix_nick_"); + *color = (tag_prefix_nick) ? (char *)(tag_prefix_nick + 12) : NULL; + } + } + if (prefix_is_nick) + *prefix_is_nick = 0; } else { - /* return prefix from option "weechat.look.prefix_same_nick" */ - if (prefix) - *prefix = CONFIG_STRING(config_look_prefix_same_nick); - if (length) - *length = config_length_prefix_same_nick; - if (color) + /* same nick: return empty prefix or value from option */ + if (strcmp (CONFIG_STRING(config_look_prefix_same_nick), " ") == 0) + { + /* return empty prefix */ + if (prefix) + *prefix = gui_chat_prefix_empty; + if (length) + *length = 0; + if (color) + *color = NULL; + } + else { - tag_prefix_nick = gui_line_search_tag_starting_with (line, - "prefix_nick_"); - *color = (tag_prefix_nick) ? (char *)(tag_prefix_nick + 12) : NULL; + /* return prefix from option "weechat.look.prefix_same_nick" */ + if (prefix) + *prefix = CONFIG_STRING(config_look_prefix_same_nick); + if (length) + *length = config_length_prefix_same_nick; + if (color) + { + tag_prefix_nick = gui_line_search_tag_starting_with (line, + "prefix_nick_"); + *color = (tag_prefix_nick) ? (char *)(tag_prefix_nick + 12) : NULL; + } } + if (prefix_is_nick) + *prefix_is_nick = 0; } - if (prefix_is_nick) - *prefix_is_nick = 0; } else { |