diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2019-04-13 20:46:05 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2019-04-13 20:46:05 +0200 |
commit | ebf38f142e5fb513b7f3781cd567f7fe2090289f (patch) | |
tree | 7d4036bc03045e7c07f3fe7a96912d4bdf5a8d5c /src/gui | |
parent | 573377e2d96ab9a4f310363d432ff8fe66b93bd3 (diff) | |
download | weechat-ebf38f142e5fb513b7f3781cd567f7fe2090289f.zip |
core: merge functions gui_line_prefix_is_same_nick_as_{previous|next} (issue #931)
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/gui-line.c | 90 |
1 files changed, 21 insertions, 69 deletions
diff --git a/src/gui/gui-line.c b/src/gui/gui-line.c index c54cb643b..90fd2d2c1 100644 --- a/src/gui/gui-line.c +++ b/src/gui/gui-line.c @@ -127,18 +127,20 @@ gui_line_tags_free (struct t_gui_line_data *line_data) } /* - * Checks if prefix on line is a nick and is the same as nick on previous line. + * Checks if prefix on line is a nick and is the same as nick on previous/next + * line (according to direction: if < 0, check if it's the same nick as + * previous line, otherwise next line). * * Returns: - * 1: prefix is a nick and same as nick on previous line - * 0: prefix is not a nick, or different from nick on previous line + * 1: prefix is a nick and same as nick on previous/next line + * 0: prefix is not a nick, or different from nick on previous/next line */ int -gui_line_prefix_is_same_nick_as_previous (struct t_gui_line *line) +gui_line_prefix_is_same_nick (struct t_gui_line *line, int direction) { - const char *nick, *nick_previous; - struct t_gui_line *prev_line; + const char *nick, *nick_other; + struct t_gui_line *other_line; /* * if line is not displayed, has a highlight, or does not have a tag @@ -156,80 +158,30 @@ gui_line_prefix_is_same_nick_as_previous (struct t_gui_line *line) /* * previous line is not found => display standard prefix */ - prev_line = gui_line_get_prev_displayed (line); - if (!prev_line) + other_line = (direction < 0) ? + gui_line_get_prev_displayed (line) : + gui_line_get_next_displayed (line); + if (!other_line) return 0; - /* buffer is not the same as previous line => display standard prefix */ - if (line->data->buffer != prev_line->data->buffer) + /* buffer is not the same as the other line => display standard prefix */ + if (line->data->buffer != other_line->data->buffer) return 0; /* - * previous line does not have a tag beginning with "prefix_nick" + * the other line does not have a tag beginning with "prefix_nick" * => display standard prefix */ - if (!gui_line_search_tag_starting_with (prev_line, "prefix_nick")) + if (!gui_line_search_tag_starting_with (other_line, "prefix_nick")) return 0; /* no nick on previous line => display standard prefix */ - nick_previous = gui_line_get_nick_tag (prev_line); - if (!nick_previous) + nick_other = gui_line_get_nick_tag (other_line); + if (!nick_other) return 0; /* prefix can be hidden/replaced if nicks are equal */ - return (strcmp (nick, nick_previous) == 0) ? 1 : 0; -} - -/* - * 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; + return (strcmp (nick, nick_other) == 0) ? 1 : 0; } /* @@ -249,11 +201,11 @@ gui_line_get_prefix_for_display (struct t_gui_line *line, if (CONFIG_STRING(config_look_prefix_same_nick) && CONFIG_STRING(config_look_prefix_same_nick)[0] - && gui_line_prefix_is_same_nick_as_previous (line)) + && gui_line_prefix_is_same_nick (line, -1)) { 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)) + && gui_line_prefix_is_same_nick (line, 1)) { /* same nick: return empty prefix or value from option */ if (strcmp (CONFIG_STRING(config_look_prefix_same_nick_middle), " ") == 0) |