diff --git a/src/core/wee-config.c b/src/core/wee-config.c index 8d6970f..d69091a 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -136,6 +136,7 @@ struct t_config_option *config_look_prefix_align_more; struct t_config_option *config_look_prefix_buffer_align; 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_empty_for_same_nick; struct t_config_option *config_look_prefix_suffix; struct t_config_option *config_look_read_marker; struct t_config_option *config_look_read_marker_always_show; @@ -2059,6 +2060,12 @@ config_weechat_init_options () N_("display '+' if buffer name is truncated (when many buffers are " "merged with same number)"), NULL, 0, 0, "on", NULL, 0, NULL, NULL, &config_change_buffers, NULL, NULL, NULL); + config_look_prefix_empty_for_same_nick = config_file_new_option ( + weechat_config_file, ptr_section, + "prefix_empty_for_same_nick", "boolean", + N_("hide prefix if message is from same nick as previous message " + "displayed in buffer"), + NULL, 0, 0, "on", NULL, 0, NULL, NULL, &config_change_buffers, 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 c08dfb1..4464a5e 100644 --- a/src/core/wee-config.h +++ b/src/core/wee-config.h @@ -160,6 +160,7 @@ extern struct t_config_option *config_look_prefix_align_more; extern struct t_config_option *config_look_prefix_buffer_align; 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_empty_for_same_nick; extern struct t_config_option *config_look_prefix_suffix; extern struct t_config_option *config_look_read_marker; extern struct t_config_option *config_look_read_marker_always_show; diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c index 50a9881..18cacc9 100644 --- a/src/gui/curses/gui-curses-chat.c +++ b/src/gui/curses/gui-curses-chat.c @@ -559,9 +559,9 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window, int simulate) { char str_space[] = " ", str_plus[] = "+"; - char *prefix_no_color, *prefix_highlighted; + char *prefix_no_color, *prefix_highlighted, *ptr_prefix; const char *short_name; - int i, length, length_allowed, num_spaces; + int i, length, length_allowed, num_spaces, prefix_length; struct t_gui_lines *mixed_lines; if (!simulate) @@ -722,8 +722,9 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window, } /* display prefix */ - if (line->data->prefix - && (line->data->prefix[0] + gui_chat_get_prefix_for_display (line, &ptr_prefix, &prefix_length); + if (ptr_prefix + && (ptr_prefix[0] || (CONFIG_INTEGER(config_look_prefix_align) != CONFIG_LOOK_PREFIX_ALIGN_NONE))) { if (!simulate) @@ -743,7 +744,7 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window, else length_allowed = window->buffer->lines->prefix_max_length; - num_spaces = length_allowed - line->data->prefix_length; + num_spaces = length_allowed - prefix_length; if (CONFIG_INTEGER(config_look_prefix_align) == CONFIG_LOOK_PREFIX_ALIGN_RIGHT) { @@ -759,7 +760,7 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window, prefix_highlighted = NULL; if (line->data->highlight) { - prefix_no_color = gui_color_decode (line->data->prefix, NULL); + prefix_no_color = gui_color_decode (ptr_prefix, NULL); if (prefix_no_color) { length = strlen (prefix_no_color) + 32; @@ -807,12 +808,12 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window, && (num_spaces < 0)) { gui_chat_display_word (window, line, - (prefix_highlighted) ? prefix_highlighted : line->data->prefix, + (prefix_highlighted) ? prefix_highlighted : ptr_prefix, (prefix_highlighted) ? prefix_highlighted + gui_chat_string_real_pos (prefix_highlighted, length_allowed) : - line->data->prefix + gui_chat_string_real_pos (line->data->prefix, - length_allowed), + ptr_prefix + gui_chat_string_real_pos (ptr_prefix, + length_allowed), 1, num_lines, count, lines_displayed, simulate, CONFIG_BOOLEAN(config_look_color_inactive_prefix)); @@ -820,7 +821,7 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window, else { gui_chat_display_word (window, line, - (prefix_highlighted) ? prefix_highlighted : line->data->prefix, + (prefix_highlighted) ? prefix_highlighted : ptr_prefix, NULL, 1, num_lines, count, lines_displayed, simulate, CONFIG_BOOLEAN(config_look_color_inactive_prefix)); diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 4b7ea0d..36d61d6 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -3364,8 +3364,11 @@ gui_buffer_dump_hexa (struct t_gui_buffer *buffer) free (message_without_colors); tags = string_build_with_split_string ((const char **)ptr_line->data->tags_array, ","); - log_printf (" tags: %s, highlight: %d", - (tags) ? tags : "(none)", ptr_line->data->highlight); + log_printf (" tags: %s, displayed: %d, highlight: %d, prefix_hidden: %d", + (tags) ? tags : "(none)", + ptr_line->data->displayed, + ptr_line->data->highlight, + ptr_line->data->prefix_hidden); if (tags) free (tags); snprintf (buf, sizeof (buf), "%s", ctime (&ptr_line->data->date)); diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c index 64272a9..80708b8 100644 --- a/src/gui/gui-chat.c +++ b/src/gui/gui-chat.c @@ -485,6 +485,34 @@ gui_chat_change_time_format () } /* + * gui_chat_get_prefix_for_display: get prefix and its length for display (ONLY) + * if the prefix can be hidden (same nick as + * previous message), and if the option + * weechat.look.xxxxxxx is on, + * then this function will return empty prefix + * and 0 for length + */ + +void +gui_chat_get_prefix_for_display (struct t_gui_line *line, + char **prefix, int *length) +{ + if (line->data->prefix_hidden + && CONFIG_BOOLEAN(config_look_prefix_empty_for_same_nick)) + { + /* prefix hidden, return NULL */ + *prefix = gui_chat_prefix_empty; + *length = 0; + } + else + { + /* prefix not hidden, return it from line */ + *prefix = line->data->prefix; + *length = line->data->prefix_length; + } +} + +/* * gui_chat_build_string_prefix_message: build a string with prefix and message */ diff --git a/src/gui/gui-chat.h b/src/gui/gui-chat.h index e5a2e37..43f627d 100644 --- a/src/gui/gui-chat.h +++ b/src/gui/gui-chat.h @@ -73,6 +73,8 @@ extern void gui_chat_get_word_info (struct t_gui_window *window, extern char *gui_chat_get_time_string (time_t date); extern int gui_chat_get_time_length (); extern void gui_chat_change_time_format (); +extern void gui_chat_get_prefix_for_display (struct t_gui_line *line, + char **prefix, int *length); extern char *gui_chat_build_string_prefix_message (struct t_gui_line *line); extern char *gui_chat_build_string_message_tags (struct t_gui_line *line); extern void gui_chat_printf_date_tags (struct t_gui_buffer *buffer, diff --git a/src/gui/gui-line.c b/src/gui/gui-line.c index c4fab0c..fee34d5 100644 --- a/src/gui/gui-line.c +++ b/src/gui/gui-line.c @@ -794,7 +794,7 @@ gui_line_add (struct t_gui_buffer *buffer, time_t date, struct t_gui_line_data *new_line_data; struct t_gui_window *ptr_win; char *message_for_signal; - const char *nick; + const char *nick, *nick_previous; int notify_level, *max_notify_level, lines_removed; time_t current_time; @@ -859,9 +859,17 @@ gui_line_add (struct t_gui_buffer *buffer, time_t date, gui_chat_strlen_screen (prefix) : 0; new_line->data->message = (message) ? strdup (message) : strdup (""); + /* + * check if prefix can be hidden: if nick is the same as previous message + * on this buffer + */ + nick = gui_line_get_nick_tag (new_line); + nick_previous = (buffer->own_lines->last_line) ? + gui_line_get_nick_tag (buffer->own_lines->last_line) : NULL; + new_line->data->prefix_hidden = (nick && nick_previous && (strcmp (nick, nick_previous) == 0)) ? 1 : 0; + /* get notify level and max notify level for nick in buffer */ notify_level = gui_line_get_notify_level (new_line); - nick = gui_line_get_nick_tag (new_line); max_notify_level = NULL; if (nick) max_notify_level = hashtable_get (buffer->hotlist_max_level_nicks, nick); @@ -1313,6 +1321,8 @@ gui_line_add_to_infolist (struct t_infolist *infolist, return 0; if (!infolist_new_var_integer (ptr_item, "highlight", line->data->highlight)) return 0; + if (!infolist_new_var_integer (ptr_item, "prefix_hidden", line->data->prefix_hidden)) + return 0; if (!infolist_new_var_string (ptr_item, "prefix", line->data->prefix)) return 0; if (!infolist_new_var_string (ptr_item, "message", line->data->message)) diff --git a/src/gui/gui-line.h b/src/gui/gui-line.h index b4a7458..a2d793a 100644 --- a/src/gui/gui-line.h +++ b/src/gui/gui-line.h @@ -37,6 +37,8 @@ struct t_gui_line_data char **tags_array; /* tags for line */ char displayed; /* 1 if line is displayed */ char highlight; /* 1 if line has highlight */ + char prefix_hidden; /* 1 if prefix can be hidden */ + /* (same nick as previous message) */ char refresh_needed; /* 1 if refresh asked (free buffer) */ char *prefix; /* prefix for line (may be NULL) */ int prefix_length; /* prefix length (on screen) */