1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-01 07:16:37 +02:00

core: use nick offline color for nick in action message

This commit is contained in:
Sébastien Helleu
2024-04-11 22:52:54 +02:00
parent ae892d2893
commit b0b733a8f0
5 changed files with 105 additions and 11 deletions
+1
View File
@@ -15,6 +15,7 @@ For a list of important changes that require manual actions, please look at rele
New features::
* core: use nick offline color for nick in action message
* core: display a specific message when the value of option is unchanged after `/set` command
* core: add option weechat.completion.case_sensitive
* core: add option weechat.look.highlight_prefix (issue #2079)
+20 -11
View File
@@ -805,14 +805,15 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
int num_lines, int count,
int pre_lines_displayed,
int *lines_displayed,
int simulate)
int simulate,
int nick_offline)
{
char str_space[] = " ";
char *prefix_no_color, *prefix_highlighted, *ptr_prefix, *ptr_prefix2;
char *ptr_prefix_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, prefix_is_nick, length_nick_prefix_suffix;
int chars_displayed, prefix_is_nick, length_nick_prefix_suffix;
int chars_to_display;
struct t_gui_lines *mixed_lines;
@@ -1151,9 +1152,6 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
simulate, 0, 0);
}
nick_offline = CONFIG_BOOLEAN(config_look_color_nick_offline)
&& gui_line_has_offline_nick (line);
prefix_highlighted = NULL;
if (line->data->highlight
&& CONFIG_BOOLEAN(config_look_highlight_prefix))
@@ -1396,7 +1394,8 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line,
int read_marker_x, read_marker_y;
int word_start_offset, word_end_offset;
int word_length_with_spaces, word_length;
char *message_with_tags, *message_with_search;
int nick_offline, nick_offline_action;
char *message_nick_offline, *message_with_tags, *message_with_search;
const char *ptr_data, *ptr_end_offset, *ptr_style, *next_char;
struct t_gui_line *ptr_prev_line, *ptr_next_line;
struct tm local_time, local_time2;
@@ -1426,6 +1425,10 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line,
gui_window_current_emphasis = 0;
}
nick_offline = CONFIG_BOOLEAN(config_look_color_nick_offline)
&& gui_line_has_offline_nick (line);
nick_offline_action = nick_offline && gui_line_is_action (line);
pre_lines_displayed = 0;
lines_displayed = 0;
@@ -1472,7 +1475,7 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line,
/* display time and prefix */
gui_chat_display_time_to_prefix (window, line, num_lines, count,
pre_lines_displayed, &lines_displayed,
simulate);
simulate, nick_offline);
if (!simulate && !gui_chat_display_tags)
{
if (window->win_chat_cursor_y < window->coords_size)
@@ -1500,19 +1503,23 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line,
/* display message */
ptr_data = NULL;
message_nick_offline = NULL;
message_with_tags = NULL;
message_with_search = NULL;
if (line->data->message && line->data->message[0])
{
message_nick_offline = (nick_offline_action) ?
gui_line_build_string_message_nick_offline (line->data->message) : NULL;
ptr_data = (message_nick_offline) ?
message_nick_offline : line->data->message;
message_with_tags = (gui_chat_display_tags) ?
gui_line_build_string_message_tags (line->data->message,
gui_line_build_string_message_tags (ptr_data,
line->data->tags_count,
line->data->tags_array,
1) : NULL;
ptr_data = (message_with_tags) ?
message_with_tags : line->data->message;
message_with_search = NULL;
if (message_with_tags)
ptr_data = message_with_tags;
if ((window->buffer->text_search == GUI_BUFFER_SEARCH_LINES)
&& (window->buffer->text_search_where & GUI_BUFFER_SEARCH_IN_MESSAGE)
&& (!window->buffer->text_search_regex
@@ -1643,6 +1650,8 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line,
&lines_displayed, simulate);
}
if (message_nick_offline)
free (message_nick_offline);
if (message_with_tags)
free (message_with_tags);
if (message_with_search)
+57
View File
@@ -405,6 +405,37 @@ gui_line_build_string_prefix_message (const char *prefix, const char *message)
return string_without_colors;
}
/*
* Builds a string with action message and nick with nick offline color.
*
* Note: result must be freed after use.
*/
char *
gui_line_build_string_message_nick_offline (const char *message)
{
const char *ptr_message;
char *message2;
if (!message)
return NULL;
ptr_message = gui_chat_string_next_char (NULL, NULL,
(unsigned char *)message,
0, 0, 0);
if (!ptr_message)
return strdup ("");
if (string_asprintf (&message2, "%s%s",
GUI_COLOR(GUI_COLOR_CHAT_NICK_OFFLINE),
ptr_message) >= 0)
{
return message2;
}
return NULL;
}
/*
* Builds a string with message and tags.
*
@@ -1087,6 +1118,32 @@ gui_line_has_offline_nick (struct t_gui_line *line)
return 0;
}
/*
* Checks if line is an action (eg: `/me` in irc plugin).
*
* Returns:
* 1: line is an action
* 0: line is not an action
*/
int
gui_line_is_action (struct t_gui_line *line)
{
int i, length;
for (i = 0; i < line->data->tags_count; i++)
{
length = strlen (line->data->tags_array[i]);
if ((length >= 7)
&& (strcmp (line->data->tags_array[i] + length - 7, "_action") == 0))
{
return 1;
}
}
return 0;
}
/*
* Computes "buffer_max_length" for a "t_gui_lines" structure.
*/
+2
View File
@@ -87,6 +87,7 @@ extern int gui_line_get_align (struct t_gui_buffer *buffer,
int with_suffix, int first_line);
extern char *gui_line_build_string_prefix_message (const char *prefix,
const char *message);
extern char *gui_line_build_string_message_nick_offline (const char *message);
extern char *gui_line_build_string_message_tags (const char *message,
int tags_count,
char **tags_array,
@@ -109,6 +110,7 @@ extern const char *gui_line_search_tag_starting_with (struct t_gui_line *line,
extern const char *gui_line_get_nick_tag (struct t_gui_line *line);
extern int gui_line_has_highlight (struct t_gui_line *line);
extern int gui_line_has_offline_nick (struct t_gui_line *line);
extern int gui_line_is_action (struct t_gui_line *line);
extern void gui_line_compute_buffer_max_length (struct t_gui_buffer *buffer,
struct t_gui_lines *lines);
extern void gui_line_compute_prefix_max_length (struct t_gui_lines *lines);
+25
View File
@@ -21,6 +21,8 @@
#include "CppUTest/TestHarness.h"
#include "tests/tests.h"
extern "C"
{
#include <string.h>
@@ -210,6 +212,29 @@ TEST(GuiLine, BuildStringPrefixMessage)
WEE_BUILD_STR_PREFIX_MSG("blue prefix\tred message", str_prefix, str_message);
}
/*
* Tests functions:
* gui_line_build_string_message_nick_offline
*/
TEST(GuiLine, BuildStringMessageNickOffline)
{
char *str, str_msg_expected[256], str_msg[256];
POINTERS_EQUAL(NULL, gui_line_build_string_message_nick_offline (NULL));
WEE_TEST_STR("", gui_line_build_string_message_nick_offline (""));
snprintf (str_msg_expected, sizeof (str_msg_expected),
"%stest",
GUI_COLOR(GUI_COLOR_CHAT_NICK_OFFLINE));
WEE_TEST_STR(str_msg_expected, gui_line_build_string_message_nick_offline ("test"));
snprintf (str_msg, sizeof (str_msg),
"%stest",
gui_color_get_custom ("blue"));
WEE_TEST_STR(str_msg_expected, gui_line_build_string_message_nick_offline (str_msg));
}
/*
* Tests functions:
* gui_line_build_string_message_tags