summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2024-04-11 22:52:54 +0200
committerSébastien Helleu <flashcode@flashtux.org>2024-04-11 22:52:54 +0200
commitb0b733a8f0af0adcd268ddb161f0c5b9269dcfad (patch)
tree31fe14e2691655d683478c1da3a3279447060c5c /src/gui
parentae892d2893aa78e5c9674aed0134c9ef64a518ef (diff)
downloadweechat-b0b733a8f0af0adcd268ddb161f0c5b9269dcfad.zip
core: use nick offline color for nick in action message
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/curses/gui-curses-chat.c31
-rw-r--r--src/gui/gui-line.c57
-rw-r--r--src/gui/gui-line.h2
3 files changed, 79 insertions, 11 deletions
diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c
index 62272f463..78aae4063 100644
--- a/src/gui/curses/gui-curses-chat.c
+++ b/src/gui/curses/gui-curses-chat.c
@@ -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)
diff --git a/src/gui/gui-line.c b/src/gui/gui-line.c
index 5ec6b0da8..ee238881a 100644
--- a/src/gui/gui-line.c
+++ b/src/gui/gui-line.c
@@ -406,6 +406,37 @@ gui_line_build_string_prefix_message (const char *prefix, const char *message)
}
/*
+ * 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.
*
* If colors == 1, keep colors in message and use color for delimiters around
@@ -1088,6 +1119,32 @@ gui_line_has_offline_nick (struct t_gui_line *line)
}
/*
+ * 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.
*/
diff --git a/src/gui/gui-line.h b/src/gui/gui-line.h
index f991f5bb7..50932eb1c 100644
--- a/src/gui/gui-line.h
+++ b/src/gui/gui-line.h
@@ -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);