mirror of
https://github.com/weechat/weechat.git
synced 2026-07-05 09:13:14 +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:
+49
-10
@@ -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_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;
|
||||
@@ -241,6 +242,7 @@ struct t_config_option *config_plugin_save_config_on_unload;
|
||||
|
||||
/* other */
|
||||
|
||||
int config_length_prefix_same_nick = 0;
|
||||
struct t_hook *config_day_change_timer = NULL;
|
||||
int config_day_change_old_day = -1;
|
||||
regex_t *config_highlight_regex = NULL;
|
||||
@@ -365,6 +367,44 @@ config_change_buffer_time_format (void *data, struct t_config_option *option)
|
||||
gui_window_ask_refresh (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* config_compute_prefix_max_length_all_buffers: compute the "prefix_max_length"
|
||||
* on all buffers
|
||||
*/
|
||||
|
||||
void
|
||||
config_compute_prefix_max_length_all_buffers ()
|
||||
{
|
||||
struct t_gui_buffer *ptr_buffer;
|
||||
|
||||
for (ptr_buffer = gui_buffers; ptr_buffer;
|
||||
ptr_buffer = ptr_buffer->next_buffer)
|
||||
{
|
||||
if (ptr_buffer->own_lines)
|
||||
gui_line_compute_prefix_max_length (ptr_buffer->own_lines);
|
||||
if (ptr_buffer->mixed_lines)
|
||||
gui_line_compute_prefix_max_length (ptr_buffer->mixed_lines);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* config_change_prefix_same_nick: called when "prefix for same nick" changes
|
||||
*/
|
||||
|
||||
void
|
||||
config_change_prefix_same_nick (void *data, struct t_config_option *option)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
config_length_prefix_same_nick =
|
||||
gui_chat_strlen_screen (CONFIG_STRING(config_look_prefix_same_nick));
|
||||
|
||||
config_compute_prefix_max_length_all_buffers ();
|
||||
gui_window_ask_refresh (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* config_change_eat_newline_glitch: called when eat_newline_glitch changes
|
||||
*/
|
||||
@@ -516,20 +556,11 @@ config_change_prefix (void *data, struct t_config_option *option)
|
||||
void
|
||||
config_change_prefix_align_min (void *data, struct t_config_option *option)
|
||||
{
|
||||
struct t_gui_buffer *ptr_buffer;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
for (ptr_buffer = gui_buffers; ptr_buffer;
|
||||
ptr_buffer = ptr_buffer->next_buffer)
|
||||
{
|
||||
if (ptr_buffer->own_lines)
|
||||
gui_line_compute_prefix_max_length (ptr_buffer->own_lines);
|
||||
if (ptr_buffer->mixed_lines)
|
||||
gui_line_compute_prefix_max_length (ptr_buffer->mixed_lines);
|
||||
}
|
||||
config_compute_prefix_max_length_all_buffers ();
|
||||
gui_window_ask_refresh (1);
|
||||
}
|
||||
|
||||
@@ -2059,6 +2090,14 @@ 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_same_nick = config_file_new_option (
|
||||
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)"),
|
||||
NULL, 0, 0, "", NULL, 0, NULL, NULL, &config_change_prefix_same_nick, NULL, NULL, NULL);
|
||||
config_look_prefix_suffix = config_file_new_option (
|
||||
weechat_config_file, ptr_section,
|
||||
"prefix_suffix", "string",
|
||||
|
||||
@@ -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_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;
|
||||
@@ -253,6 +254,7 @@ extern struct t_config_option *config_plugin_extension;
|
||||
extern struct t_config_option *config_plugin_path;
|
||||
extern struct t_config_option *config_plugin_save_config_on_unload;
|
||||
|
||||
extern int config_length_prefix_same_nick;
|
||||
extern regex_t *config_highlight_regex;
|
||||
extern char **config_highlight_tags;
|
||||
extern int config_num_highlight_tags;
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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
@@ -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))
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user