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

core: search in message tags when tags are displayed with /debug tags

This commit is contained in:
Sébastien Helleu
2022-01-30 13:33:21 +01:00
parent 9259442dbf
commit 608f56020d
5 changed files with 92 additions and 33 deletions
+18 -16
View File
@@ -1423,7 +1423,8 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line,
message_with_tags = (gui_chat_display_tags) ?
gui_line_build_string_message_tags (line->data->message,
line->data->tags_count,
line->data->tags_array) : NULL;
line->data->tags_array,
1) : NULL;
ptr_data = (message_with_tags) ?
message_with_tags : line->data->message;
message_with_search = NULL;
@@ -1641,10 +1642,10 @@ void
gui_chat_display_line_y (struct t_gui_window *window, struct t_gui_line *line,
int y)
{
char *ptr_data, *message_with_search, *message_with_tags;
char *ptr_data, *message_with_tags, *message_with_search;
message_with_search = NULL;
message_with_tags = NULL;
message_with_search = NULL;
/* reset color & style for a new line */
gui_chat_reset_style (window, line, 0, 1,
@@ -1660,6 +1661,18 @@ gui_chat_display_line_y (struct t_gui_window *window, struct t_gui_line *line,
ptr_data = line->data->message;
/* add tags if debug of tags is enabled */
if (gui_chat_display_tags)
{
message_with_tags = gui_line_build_string_message_tags (
ptr_data,
line->data->tags_count,
line->data->tags_array,
1);
if (message_with_tags)
ptr_data = message_with_tags;
}
/* emphasize text (if searching text) */
if ((window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED)
&& (window->buffer->text_search_where & GUI_TEXT_SEARCH_IN_MESSAGE)
@@ -1674,17 +1687,6 @@ gui_chat_display_line_y (struct t_gui_window *window, struct t_gui_line *line,
ptr_data = message_with_search;
}
/* add tags if debug of tags is enabled */
if (gui_chat_display_tags)
{
message_with_tags = gui_line_build_string_message_tags (
ptr_data,
line->data->tags_count,
line->data->tags_array);
if (message_with_tags)
ptr_data = message_with_tags;
}
/* display the line */
if (gui_chat_display_word_raw (window, line, ptr_data,
window->win_chat_width, 0,
@@ -1694,10 +1696,10 @@ gui_chat_display_line_y (struct t_gui_window *window, struct t_gui_line *line,
gui_window_clrtoeol (GUI_WINDOW_OBJECTS(window)->win_chat);
}
if (message_with_search)
free (message_with_search);
if (message_with_tags)
free (message_with_tags);
if (message_with_search)
free (message_with_search);
}
/*
+41 -7
View File
@@ -403,15 +403,21 @@ gui_line_build_string_prefix_message (const char *prefix, const char *message)
/*
* Builds a string with message and tags.
*
* If colors == 1, keep colors in message and use color for delimiters around
* tags.
* If colors == 0, strip colors from message and do not use color for
* delimiters around tags.
*
* Note: result must be freed after use.
*/
char *
gui_line_build_string_message_tags (const char *message,
int tags_count, char **tags_array)
int tags_count, char **tags_array,
int colors)
{
int i;
char **string, *result;
char **string, *message_no_colors, *result;
if ((tags_count < 0) || ((tags_count > 0) && !tags_array))
return NULL;
@@ -421,17 +427,34 @@ gui_line_build_string_message_tags (const char *message,
return NULL;
if (message)
string_dyn_concat (string, message, -1);
string_dyn_concat (string, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), -1);
{
if (colors)
{
string_dyn_concat (string, message, -1);
}
else
{
message_no_colors = gui_color_decode (message, NULL);
if (message_no_colors)
{
string_dyn_concat (string, message_no_colors, -1);
free (message_no_colors);
}
}
}
if (colors)
string_dyn_concat (string, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), -1);
string_dyn_concat (string, " [", -1);
string_dyn_concat (string, GUI_COLOR(GUI_COLOR_CHAT_TAGS), -1);
if (colors)
string_dyn_concat (string, GUI_COLOR(GUI_COLOR_CHAT_TAGS), -1);
for (i = 0; i < tags_count; i++)
{
string_dyn_concat (string, tags_array[i], -1);
if (i < tags_count - 1)
string_dyn_concat (string, ",", -1);
}
string_dyn_concat (string, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), -1);
if (colors)
string_dyn_concat (string, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), -1);
string_dyn_concat (string, "]", -1);
result = strdup (*string);
@@ -595,7 +618,18 @@ gui_line_search_text (struct t_gui_buffer *buffer, struct t_gui_line *line)
if (!rc && (buffer->text_search_where & GUI_TEXT_SEARCH_IN_MESSAGE))
{
message = gui_color_decode (line->data->message, NULL);
if (gui_chat_display_tags)
{
message = gui_line_build_string_message_tags (
line->data->message,
line->data->tags_count,
line->data->tags_array,
0);
}
else
{
message = gui_color_decode (line->data->message, NULL);
}
if (message)
{
if (buffer->text_search_regex)
+2 -1
View File
@@ -84,7 +84,8 @@ extern char *gui_line_build_string_prefix_message (const char *prefix,
const char *message);
extern char *gui_line_build_string_message_tags (const char *message,
int tags_count,
char **tags_array);
char **tags_array,
int colors);
extern int gui_line_is_displayed (struct t_gui_line *line);
extern struct t_gui_line *gui_line_get_first_displayed (struct t_gui_buffer *buffer);
extern struct t_gui_line *gui_line_get_last_displayed (struct t_gui_buffer *buffer);