mirror of
https://github.com/weechat/weechat.git
synced 2026-07-05 17:23:15 +02:00
core: make nick prefix/suffix dynamic (move options from irc plugin to core, add logger options) (bug #37531)
This commit is contained in:
@@ -602,9 +602,9 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
|
||||
char str_space[] = " ";
|
||||
char *prefix_no_color, *prefix_highlighted, *ptr_prefix, *ptr_prefix2;
|
||||
char *ptr_prefix_color;
|
||||
const char *short_name, *str_color;
|
||||
const char *short_name, *str_color, *ptr_nick_prefix, *ptr_nick_suffix;
|
||||
int i, length, length_allowed, num_spaces, prefix_length, extra_spaces;
|
||||
int chars_displayed, nick_offline;
|
||||
int chars_displayed, nick_offline, prefix_is_nick, length_nick_prefix_suffix;
|
||||
struct t_gui_lines *mixed_lines;
|
||||
|
||||
if (!simulate)
|
||||
@@ -773,7 +773,7 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
|
||||
|
||||
/* get prefix for display */
|
||||
gui_line_get_prefix_for_display (line, &ptr_prefix, &prefix_length,
|
||||
&ptr_prefix_color);
|
||||
&ptr_prefix_color, &prefix_is_nick);
|
||||
if (ptr_prefix)
|
||||
{
|
||||
ptr_prefix2 = NULL;
|
||||
@@ -794,6 +794,20 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
|
||||
ptr_prefix = (ptr_prefix2) ? ptr_prefix2 : strdup (ptr_prefix);
|
||||
}
|
||||
|
||||
/* get nick prefix/suffix (if prefix is a nick) */
|
||||
if (prefix_is_nick && (config_length_nick_prefix_suffix > 0))
|
||||
{
|
||||
ptr_nick_prefix = CONFIG_STRING(config_look_nick_prefix);
|
||||
ptr_nick_suffix = CONFIG_STRING(config_look_nick_suffix);
|
||||
length_nick_prefix_suffix = config_length_nick_prefix_suffix;
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr_nick_prefix = NULL;
|
||||
ptr_nick_suffix = NULL;
|
||||
length_nick_prefix_suffix = 0;
|
||||
}
|
||||
|
||||
/* display prefix */
|
||||
if (ptr_prefix
|
||||
&& (ptr_prefix[0]
|
||||
@@ -816,7 +830,19 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
|
||||
else
|
||||
length_allowed = window->buffer->lines->prefix_max_length;
|
||||
|
||||
num_spaces = length_allowed - prefix_length;
|
||||
/*
|
||||
* if we are not able to display at least 1 char of prefix (inside
|
||||
* prefix/suffix), then do not display nick prefix/suffix at all
|
||||
*/
|
||||
if (ptr_nick_prefix && ptr_nick_suffix
|
||||
&& (length_nick_prefix_suffix + 1 > length_allowed))
|
||||
{
|
||||
ptr_nick_prefix = NULL;
|
||||
ptr_nick_suffix = NULL;
|
||||
length_nick_prefix_suffix = 0;
|
||||
}
|
||||
|
||||
num_spaces = length_allowed - prefix_length - length_nick_prefix_suffix;
|
||||
|
||||
if (CONFIG_INTEGER(config_look_prefix_align) == CONFIG_LOOK_PREFIX_ALIGN_RIGHT)
|
||||
{
|
||||
@@ -830,6 +856,20 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
|
||||
}
|
||||
}
|
||||
|
||||
/* display prefix before nick (for example "<") */
|
||||
if (ptr_nick_prefix)
|
||||
{
|
||||
if (!simulate)
|
||||
{
|
||||
gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
GUI_COLOR_CHAT_NICK_PREFIX);
|
||||
}
|
||||
gui_chat_display_word (window, line,
|
||||
ptr_nick_prefix,
|
||||
NULL, 1, num_lines, count,
|
||||
lines_displayed, simulate, 0, 0);
|
||||
}
|
||||
|
||||
nick_offline = CONFIG_BOOLEAN(config_look_color_nick_offline)
|
||||
&& gui_line_has_offline_nick (line);
|
||||
|
||||
@@ -888,15 +928,14 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
|
||||
(prefix_highlighted) ? prefix_highlighted : ptr_prefix,
|
||||
(prefix_highlighted) ?
|
||||
prefix_highlighted + gui_chat_string_real_pos (prefix_highlighted,
|
||||
length_allowed) :
|
||||
length_allowed - length_nick_prefix_suffix - 1) :
|
||||
ptr_prefix + gui_chat_string_real_pos (ptr_prefix,
|
||||
length_allowed),
|
||||
length_allowed - length_nick_prefix_suffix - 1),
|
||||
1, num_lines, count, lines_displayed,
|
||||
simulate,
|
||||
CONFIG_BOOLEAN(config_look_color_inactive_prefix),
|
||||
nick_offline);
|
||||
if (chars_displayed < length_allowed)
|
||||
extra_spaces = length_allowed - chars_displayed;
|
||||
extra_spaces = length_allowed - length_nick_prefix_suffix - 1 - chars_displayed;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -922,17 +961,15 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
|
||||
GUI_COLOR_CHAT);
|
||||
}
|
||||
|
||||
if (CONFIG_INTEGER(config_look_prefix_align) == CONFIG_LOOK_PREFIX_ALIGN_LEFT)
|
||||
for (i = 0; i < extra_spaces; i++)
|
||||
{
|
||||
for (i = 0; i < num_spaces; i++)
|
||||
{
|
||||
gui_chat_display_word (window, line, str_space,
|
||||
NULL, 1, num_lines, count, lines_displayed,
|
||||
simulate,
|
||||
CONFIG_BOOLEAN(config_look_color_inactive_prefix),
|
||||
0);
|
||||
}
|
||||
gui_chat_display_word (window, line, str_space,
|
||||
NULL, 1, num_lines, count, lines_displayed,
|
||||
simulate,
|
||||
CONFIG_BOOLEAN(config_look_color_inactive_prefix),
|
||||
0);
|
||||
}
|
||||
|
||||
if ((CONFIG_INTEGER(config_look_prefix_align) != CONFIG_LOOK_PREFIX_ALIGN_NONE)
|
||||
&& (num_spaces < 0))
|
||||
{
|
||||
@@ -948,9 +985,24 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
|
||||
CONFIG_BOOLEAN(config_look_color_inactive_prefix),
|
||||
0);
|
||||
}
|
||||
else
|
||||
|
||||
/* display suffix after nick (for example ">") */
|
||||
if (ptr_nick_suffix)
|
||||
{
|
||||
if (window->buffer->lines->prefix_max_length > 0)
|
||||
if (!simulate)
|
||||
{
|
||||
gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
GUI_COLOR_CHAT_NICK_SUFFIX);
|
||||
}
|
||||
gui_chat_display_word (window, line,
|
||||
ptr_nick_suffix,
|
||||
NULL, 1, num_lines, count,
|
||||
lines_displayed, simulate, 0, 0);
|
||||
}
|
||||
|
||||
if (CONFIG_INTEGER(config_look_prefix_align) == CONFIG_LOOK_PREFIX_ALIGN_LEFT)
|
||||
{
|
||||
for (i = 0; i < num_spaces; i++)
|
||||
{
|
||||
gui_chat_display_word (window, line, str_space,
|
||||
NULL, 1, num_lines, count, lines_displayed,
|
||||
@@ -959,7 +1011,8 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
|
||||
0);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < extra_spaces; i++)
|
||||
|
||||
if (window->buffer->lines->prefix_max_length > 0)
|
||||
{
|
||||
gui_chat_display_word (window, line, str_space,
|
||||
NULL, 1, num_lines, count, lines_displayed,
|
||||
@@ -967,6 +1020,7 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
|
||||
CONFIG_BOOLEAN(config_look_color_inactive_prefix),
|
||||
0);
|
||||
}
|
||||
|
||||
if ((CONFIG_INTEGER(config_look_prefix_align) != CONFIG_LOOK_PREFIX_ALIGN_NONE)
|
||||
&& (CONFIG_STRING(config_look_prefix_suffix)
|
||||
&& CONFIG_STRING(config_look_prefix_suffix)[0]))
|
||||
|
||||
@@ -1421,6 +1421,8 @@ gui_color_init_weechat ()
|
||||
gui_color_build (GUI_COLOR_CHAT_PREFIX_BUFFER_INACTIVE_BUFFER, CONFIG_COLOR(config_color_chat_prefix_buffer_inactive_buffer), CONFIG_COLOR(config_color_chat_bg));
|
||||
gui_color_build (GUI_COLOR_CHAT_NICK_OFFLINE, CONFIG_COLOR(config_color_chat_nick_offline), CONFIG_COLOR(config_color_chat_bg));
|
||||
gui_color_build (GUI_COLOR_CHAT_NICK_OFFLINE_HIGHLIGHT, CONFIG_COLOR(config_color_chat_nick_offline_highlight), CONFIG_COLOR(config_color_chat_nick_offline_highlight_bg));
|
||||
gui_color_build (GUI_COLOR_CHAT_NICK_PREFIX, CONFIG_COLOR(config_color_chat_nick_prefix), CONFIG_COLOR(config_color_chat_bg));
|
||||
gui_color_build (GUI_COLOR_CHAT_NICK_SUFFIX, CONFIG_COLOR(config_color_chat_nick_suffix), CONFIG_COLOR(config_color_chat_bg));
|
||||
|
||||
/*
|
||||
* define old nick colors for compatibility on /upgrade with previous
|
||||
|
||||
@@ -76,6 +76,8 @@ enum t_gui_color_enum
|
||||
GUI_COLOR_CHAT_PREFIX_BUFFER_INACTIVE_BUFFER,
|
||||
GUI_COLOR_CHAT_NICK_OFFLINE,
|
||||
GUI_COLOR_CHAT_NICK_OFFLINE_HIGHLIGHT,
|
||||
GUI_COLOR_CHAT_NICK_PREFIX,
|
||||
GUI_COLOR_CHAT_NICK_SUFFIX,
|
||||
|
||||
/* number of colors */
|
||||
GUI_COLOR_NUM_COLORS,
|
||||
|
||||
+29
-12
@@ -149,7 +149,7 @@ gui_line_prefix_is_same_nick_as_previous (struct t_gui_line *line)
|
||||
void
|
||||
gui_line_get_prefix_for_display (struct t_gui_line *line,
|
||||
char **prefix, int *length,
|
||||
char **color)
|
||||
char **color, int *prefix_is_nick)
|
||||
{
|
||||
const char *tag_prefix_nick;
|
||||
|
||||
@@ -160,6 +160,7 @@ gui_line_get_prefix_for_display (struct t_gui_line *line,
|
||||
/* 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)
|
||||
@@ -169,19 +170,20 @@ gui_line_get_prefix_for_display (struct t_gui_line *line,
|
||||
}
|
||||
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)
|
||||
{
|
||||
*color = NULL;
|
||||
tag_prefix_nick = gui_line_search_tag_starting_with (line,
|
||||
"prefix_nick_");
|
||||
if (tag_prefix_nick)
|
||||
*color = (char *)(tag_prefix_nick + 12);
|
||||
*color = (tag_prefix_nick) ? (char *)(tag_prefix_nick + 12) : NULL;
|
||||
}
|
||||
}
|
||||
if (prefix_is_nick)
|
||||
*prefix_is_nick = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -192,6 +194,8 @@ gui_line_get_prefix_for_display (struct t_gui_line *line,
|
||||
*length = line->data->prefix_length;
|
||||
if (color)
|
||||
*color = NULL;
|
||||
if (prefix_is_nick)
|
||||
*prefix_is_nick = gui_line_search_tag_starting_with (line, "prefix_nick_") ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,7 +207,7 @@ 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, prefix_length;
|
||||
int length_time, length_buffer, length_suffix, prefix_length, prefix_is_nick;
|
||||
|
||||
/* return immediately if alignment for end of lines is "time" */
|
||||
if (!first_line
|
||||
@@ -253,7 +257,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, NULL, &prefix_length, NULL);
|
||||
/* length of prefix */
|
||||
gui_line_get_prefix_for_display (line, NULL, &prefix_length, NULL,
|
||||
&prefix_is_nick);
|
||||
if (prefix_is_nick)
|
||||
prefix_length += config_length_nick_prefix_suffix;
|
||||
|
||||
if (CONFIG_INTEGER(config_look_prefix_align) == CONFIG_LOOK_PREFIX_ALIGN_NONE)
|
||||
{
|
||||
@@ -720,7 +728,7 @@ void
|
||||
gui_line_compute_prefix_max_length (struct t_gui_lines *lines)
|
||||
{
|
||||
struct t_gui_line *ptr_line;
|
||||
int prefix_length;
|
||||
int prefix_length, prefix_is_nick;
|
||||
|
||||
lines->prefix_max_length = CONFIG_INTEGER(config_look_prefix_align_min);
|
||||
|
||||
@@ -729,7 +737,10 @@ gui_line_compute_prefix_max_length (struct t_gui_lines *lines)
|
||||
{
|
||||
if (ptr_line->data->displayed)
|
||||
{
|
||||
gui_line_get_prefix_for_display (ptr_line, NULL, &prefix_length, NULL);
|
||||
gui_line_get_prefix_for_display (ptr_line, NULL, &prefix_length,
|
||||
NULL, &prefix_is_nick);
|
||||
if (prefix_is_nick)
|
||||
prefix_length += config_length_nick_prefix_suffix;
|
||||
if (prefix_length > lines->prefix_max_length)
|
||||
lines->prefix_max_length = prefix_length;
|
||||
}
|
||||
@@ -744,7 +755,7 @@ void
|
||||
gui_line_add_to_list (struct t_gui_lines *lines,
|
||||
struct t_gui_line *line)
|
||||
{
|
||||
int prefix_length;
|
||||
int prefix_length, prefix_is_nick;
|
||||
|
||||
if (!lines->first_line)
|
||||
lines->first_line = line;
|
||||
@@ -755,7 +766,10 @@ gui_line_add_to_list (struct t_gui_lines *lines,
|
||||
lines->last_line = line;
|
||||
|
||||
/* adjust "prefix_max_length" if this prefix length is > max */
|
||||
gui_line_get_prefix_for_display (line, NULL, &prefix_length, NULL);
|
||||
gui_line_get_prefix_for_display (line, NULL, &prefix_length, NULL,
|
||||
&prefix_is_nick);
|
||||
if (prefix_is_nick)
|
||||
prefix_length += config_length_nick_prefix_suffix;
|
||||
if (prefix_length > lines->prefix_max_length)
|
||||
lines->prefix_max_length = prefix_length;
|
||||
|
||||
@@ -774,7 +788,7 @@ 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, prefix_length;
|
||||
int i, update_prefix_max_length, prefix_length, prefix_is_nick;
|
||||
|
||||
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
|
||||
{
|
||||
@@ -800,7 +814,10 @@ gui_line_remove_from_list (struct t_gui_buffer *buffer,
|
||||
}
|
||||
}
|
||||
|
||||
gui_line_get_prefix_for_display (line, NULL, &prefix_length, NULL);
|
||||
gui_line_get_prefix_for_display (line, NULL, &prefix_length, NULL,
|
||||
&prefix_is_nick);
|
||||
if (prefix_is_nick)
|
||||
prefix_length += config_length_nick_prefix_suffix;
|
||||
update_prefix_max_length =
|
||||
(prefix_length == lines->prefix_max_length);
|
||||
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ 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,
|
||||
char **color);
|
||||
char **color, int *prefix_is_nick);
|
||||
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