1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-08 10:43:13 +02:00

core: add option weechat.look.prefix_same_nick (hide or change prefix on messages whose nick is the same as previous message) (task #11965)

This commit is contained in:
Sebastien Helleu
2012-03-28 18:07:15 +02:00
parent 272046d012
commit 67115edf3d
22 changed files with 248 additions and 47 deletions
+11 -10
View File
@@ -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_line_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));
+8 -3
View File
@@ -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_same_nick: %d",
(tags) ? tags : "(none)",
ptr_line->data->displayed,
ptr_line->data->highlight,
ptr_line->data->prefix_same_nick);
if (tags)
free (tags);
snprintf (buf, sizeof (buf), "%s", ctime (&ptr_line->data->date));
@@ -3551,11 +3554,13 @@ gui_buffer_print_log ()
tags = string_build_with_split_string ((const char **)ptr_line->data->tags_array,
",");
log_printf (" line N-%05d: y:%d, str_time:'%s', tags:'%s', "
"displayed:%d, highlight:%d, refresh_needed:%d, prefix:'%s'",
"displayed:%d, highlight:%d, prefix_same_nick:%d, "
"refresh_needed:%d, prefix:'%s'",
num, ptr_line->data->y, ptr_line->data->str_time,
(tags) ? tags : "",
(int)(ptr_line->data->displayed),
(int)(ptr_line->data->highlight),
(int)(ptr_line->data->prefix_same_nick),
(int)(ptr_line->data->refresh_needed),
ptr_line->data->prefix);
log_printf (" data: '%s'",
+69 -11
View File
@@ -83,6 +83,43 @@ gui_lines_free (struct t_gui_lines *lines)
free (lines);
}
/*
* gui_line_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 is
* enabled (not empty string), then this
* this function will return empty prefix or
* prefix from option
*/
void
gui_line_get_prefix_for_display (struct t_gui_line *line,
char **prefix, int *length)
{
if (line->data->prefix_same_nick
&& CONFIG_STRING(config_look_prefix_same_nick)
&& CONFIG_STRING(config_look_prefix_same_nick)[0])
{
/* same nick: return empty prefix or value from option */
if (strcmp (CONFIG_STRING(config_look_prefix_same_nick), " ") == 0)
{
*prefix = gui_chat_prefix_empty;
*length = 0;
}
else
{
*prefix = CONFIG_STRING(config_look_prefix_same_nick);
*length = config_length_prefix_same_nick;
}
}
else
{
/* not same nick: return prefix from line */
*prefix = line->data->prefix;
*length = line->data->prefix_length;
}
}
/*
* gui_line_get_align: get alignment for a line
*/
@@ -91,7 +128,8 @@ int
gui_line_get_align (struct t_gui_buffer *buffer, struct t_gui_line *line,
int with_suffix, int first_line)
{
int length_time, length_buffer, length_suffix;
int length_time, length_buffer, length_suffix, prefix_length;
char *ptr_prefix;
/* return immediately if alignment for end of lines is "time" */
if (!first_line
@@ -141,10 +179,11 @@ gui_line_get_align (struct t_gui_buffer *buffer, struct t_gui_line *line,
return length_time + length_buffer;
}
gui_line_get_prefix_for_display (line, &ptr_prefix, &prefix_length);
if (CONFIG_INTEGER(config_look_prefix_align) == CONFIG_LOOK_PREFIX_ALIGN_NONE)
{
return length_time + length_buffer + line->data->prefix_length
+ ((line->data->prefix_length > 0) ? 1 : 0);
return length_time + length_buffer + prefix_length + ((prefix_length > 0) ? 1 : 0);
}
length_suffix = 0;
@@ -533,13 +572,16 @@ void
gui_line_compute_prefix_max_length (struct t_gui_lines *lines)
{
struct t_gui_line *ptr_line;
char *ptr_prefix;
int prefix_length;
lines->prefix_max_length = CONFIG_INTEGER(config_look_prefix_align_min);
for (ptr_line = lines->first_line; ptr_line;
ptr_line = ptr_line->next_line)
{
if (ptr_line->data->prefix_length > lines->prefix_max_length)
lines->prefix_max_length = ptr_line->data->prefix_length;
gui_line_get_prefix_for_display (ptr_line, &ptr_prefix, &prefix_length);
if (prefix_length > lines->prefix_max_length)
lines->prefix_max_length = prefix_length;
}
}
@@ -551,6 +593,9 @@ void
gui_line_add_to_list (struct t_gui_lines *lines,
struct t_gui_line *line)
{
char *ptr_prefix;
int prefix_length;
if (!lines->first_line)
lines->first_line = line;
else
@@ -559,8 +604,9 @@ gui_line_add_to_list (struct t_gui_lines *lines,
line->next_line = NULL;
lines->last_line = line;
if (line->data->prefix_length > lines->prefix_max_length)
lines->prefix_max_length = line->data->prefix_length;
gui_line_get_prefix_for_display (line, &ptr_prefix, &prefix_length);
if (prefix_length > lines->prefix_max_length)
lines->prefix_max_length = prefix_length;
lines->lines_count++;
}
@@ -577,7 +623,8 @@ gui_line_remove_from_list (struct t_gui_buffer *buffer,
{
struct t_gui_window *ptr_win;
struct t_gui_window_scroll *ptr_scroll;
int i, update_prefix_max_length;
int i, update_prefix_max_length, prefix_length;
char *ptr_prefix;
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
{
@@ -603,8 +650,9 @@ gui_line_remove_from_list (struct t_gui_buffer *buffer,
}
}
gui_line_get_prefix_for_display (line, &ptr_prefix, &prefix_length);
update_prefix_max_length =
(line->data->prefix_length == lines->prefix_max_length);
(prefix_length == lines->prefix_max_length);
/* move read marker if it was on line we are removing */
if (lines->last_read_line == line)
@@ -794,7 +842,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 +907,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_same_nick = (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 +1369,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_same_nick", line->data->prefix_same_nick))
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))
+4
View File
@@ -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_same_nick; /* 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) */
@@ -67,6 +69,8 @@ struct t_gui_lines
extern struct t_gui_lines *gui_lines_alloc ();
extern void gui_lines_free (struct t_gui_lines *lines);
extern void gui_line_get_prefix_for_display (struct t_gui_line *line,
char **prefix, int *length);
extern int gui_line_get_align (struct t_gui_buffer *buffer,
struct t_gui_line *line,
int with_suffix, int first_line);