1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-02 15:53:12 +02:00

Reintroduce highlight (move code from irc plugin to core)

This commit is contained in:
Sebastien Helleu
2008-06-01 22:09:12 +02:00
parent 4fa856c773
commit bd436db2bc
26 changed files with 1562 additions and 1700 deletions
+19 -4
View File
@@ -566,7 +566,7 @@ gui_chat_display_time_and_prefix (struct t_gui_window *window,
int *lines_displayed,
int simulate)
{
char str_space[] = " ", str_plus[] = "+";
char str_space[] = " ", str_plus[] = "+", *prefix_highlighted;
int i, length_allowed, num_spaces;
/* display time */
@@ -608,14 +608,25 @@ gui_chat_display_time_and_prefix (struct t_gui_window *window,
{
gui_chat_display_word (window, line, str_space,
NULL, 1, num_lines, count,
lines_displayed,simulate);
lines_displayed, simulate);
}
}
prefix_highlighted = NULL;
if (line->highlight)
{
prefix_highlighted = (char *)gui_color_decode ((unsigned char *)line->prefix);
if (!simulate)
gui_window_set_weechat_color (GUI_CURSES(window)->win_chat,
GUI_COLOR_CHAT_HIGHLIGHT);
}
/* not enough space to display full prefix ? => truncate it! */
if ((CONFIG_INTEGER(config_look_prefix_align) != CONFIG_LOOK_PREFIX_ALIGN_NONE)
&& (num_spaces < 0))
{
gui_chat_display_word (window, line, line->prefix,
gui_chat_display_word (window, line,
(prefix_highlighted) ? prefix_highlighted : line->prefix,
line->prefix +
gui_chat_string_real_pos (line->prefix,
length_allowed - 1),
@@ -624,11 +635,15 @@ gui_chat_display_time_and_prefix (struct t_gui_window *window,
}
else
{
gui_chat_display_word (window, line, line->prefix,
gui_chat_display_word (window, line,
(prefix_highlighted) ? prefix_highlighted : line->prefix,
NULL, 1, num_lines, count, lines_displayed,
simulate);
}
if (prefix_highlighted)
free (prefix_highlighted);
if (!simulate)
gui_window_reset_style (GUI_CURSES(window)->win_chat, GUI_COLOR_CHAT);
+1 -1
View File
@@ -380,7 +380,7 @@ gui_color_init_weechat ()
}
gui_color[GUI_COLOR_CHAT_HOST] = gui_color_build (GUI_COLOR_CHAT_HOST, CONFIG_COLOR(config_color_chat_host), CONFIG_COLOR(config_color_chat_bg));
gui_color[GUI_COLOR_CHAT_DELIMITERS] = gui_color_build (GUI_COLOR_CHAT_DELIMITERS, CONFIG_COLOR(config_color_chat_delimiters), CONFIG_COLOR(config_color_chat_bg));
gui_color[GUI_COLOR_CHAT_HIGHLIGHT] = gui_color_build (GUI_COLOR_CHAT_HIGHLIGHT, CONFIG_COLOR(config_color_chat_highlight), CONFIG_COLOR(config_color_chat_bg));
gui_color[GUI_COLOR_CHAT_HIGHLIGHT] = gui_color_build (GUI_COLOR_CHAT_HIGHLIGHT, CONFIG_COLOR(config_color_chat_highlight), CONFIG_COLOR(config_color_chat_highlight_bg));
gui_color[GUI_COLOR_CHAT_READ_MARKER] = gui_color_build (GUI_COLOR_CHAT_READ_MARKER, CONFIG_COLOR(config_color_chat_read_marker), CONFIG_COLOR(config_color_chat_read_marker_bg));
gui_color[GUI_COLOR_STATUS] = gui_color_build (GUI_COLOR_STATUS, CONFIG_COLOR(config_color_status), CONFIG_COLOR(config_color_status_bg));
+60 -1
View File
@@ -164,6 +164,11 @@ gui_buffer_new (struct t_weechat_plugin *plugin, char *category, char *name,
new_buffer->text_search_found = 0;
new_buffer->text_search_input = NULL;
/* highlight */
new_buffer->highlight_words = NULL;
new_buffer->highlight_tags_count = 0;
new_buffer->highlight_tags_array = NULL;
/* keys */
new_buffer->keys = NULL;
new_buffer->last_key = NULL;
@@ -426,6 +431,44 @@ gui_buffer_set_nick (struct t_gui_buffer *buffer, char *new_nick)
gui_buffer_ask_input_refresh (buffer, 1);
}
/*
* gui_buffer_set_highlight_words: set highlight words for a buffer
*/
void
gui_buffer_set_highlight_words (struct t_gui_buffer *buffer,
char *new_highlight_words)
{
if (buffer->highlight_words)
free (buffer->highlight_words);
buffer->highlight_words = (new_highlight_words && new_highlight_words[0]) ?
strdup (new_highlight_words) : NULL;
}
/*
* gui_buffer_set_highlight_tags: set highlight tags for a buffer
*/
void
gui_buffer_set_highlight_tags (struct t_gui_buffer *buffer,
char *new_highlight_tags)
{
if (buffer->highlight_tags_array)
string_free_exploded (buffer->highlight_tags_array);
if (new_highlight_tags)
{
buffer->highlight_tags_array = string_explode (new_highlight_tags,
",", 0, 0,
&buffer->highlight_tags_count);
}
else
{
buffer->highlight_tags_count = 0;
buffer->highlight_tags_array = NULL;
}
}
/*
* gui_buffer_set: set a buffer property
*/
@@ -502,6 +545,14 @@ gui_buffer_set (struct t_gui_buffer *buffer, char *property, char *value)
gui_hotlist_add (buffer, number, NULL, 1);
}
}
else if (string_strcasecmp (property, "highlight_words") == 0)
{
gui_buffer_set_highlight_words (buffer, value);
}
else if (string_strcasecmp (property, "highlight_tags") == 0)
{
gui_buffer_set_highlight_tags (buffer, value);
}
else if (string_strncasecmp (property, "key_bind_", 9) == 0)
{
gui_keyboard_bind (buffer, property + 9, value);
@@ -805,6 +856,10 @@ gui_buffer_close (struct t_gui_buffer *buffer, int switch_to_another)
if (buffer->text_search_input)
free (buffer->text_search_input);
gui_nicklist_remove_all (buffer);
if (buffer->highlight_words)
free (buffer->highlight_words);
if (buffer->highlight_tags_array)
string_free_exploded (buffer->highlight_tags_array);
gui_keyboard_free_all (&buffer->keys, &buffer->last_key);
/* remove buffer from buffers list */
@@ -1126,6 +1181,9 @@ gui_buffer_print_log ()
log_printf (" text_search_exact. . . : %d", ptr_buffer->text_search_exact);
log_printf (" text_search_found. . . : %d", ptr_buffer->text_search_found);
log_printf (" text_search_input. . . : '%s'", ptr_buffer->text_search_input);
log_printf (" highlight_words. . . . : '%s'", ptr_buffer->highlight_words);
log_printf (" highlight_tags_count . : %d", ptr_buffer->highlight_tags_count);
log_printf (" highlight_tags_array . : 0x%x", ptr_buffer->highlight_tags_array);
log_printf (" prev_buffer. . . . . . : 0x%x", ptr_buffer->prev_buffer);
log_printf (" next_buffer. . . . . . : 0x%x", ptr_buffer->next_buffer);
@@ -1160,10 +1218,11 @@ gui_buffer_print_log ()
num--;
tags = string_build_with_exploded (ptr_line->tags_array, ",");
log_printf (" line N-%05d: y:%d, str_time:'%s', tags:'%s', "
"displayed:%d, refresh_needed:%d, prefix:'%s'",
"displayed:%d, highlight:%d, refresh_needed:%d, prefix:'%s'",
num, ptr_line->y, ptr_line->str_time,
(tags) ? tags : "",
(int)(ptr_line->displayed),
(int) (ptr_line->highlight),
(int)(ptr_line->refresh_needed),
ptr_line->prefix);
log_printf (" data: '%s'",
+7
View File
@@ -49,6 +49,7 @@ struct t_gui_line
int tags_count; /* number of tags for line */
char **tags_array; /* tags for line */
char displayed; /* 1 if line is displayed */
char highlight; /* 1 if line has highlight */
char refresh_needed; /* 1 if refresh asked (free buffer) */
char *prefix; /* prefix for line (may be NULL) */
int prefix_length; /* prefix length (on screen) */
@@ -131,6 +132,12 @@ struct t_gui_buffer
int text_search_found; /* 1 if text found, otherwise 0 */
char *text_search_input; /* input saved before text search */
/* highlight settings for buffer */
char *highlight_words; /* list of words to highlight */
int highlight_tags_count; /* number of tags to highlight */
/* (if 0, any tag is highlighted) */
char **highlight_tags_array; /* tags to highlight */
/* keys associated to buffer */
struct t_gui_key *keys; /* keys specific to buffer */
struct t_gui_key *last_key; /* last key for buffer */
+47
View File
@@ -557,6 +557,50 @@ gui_chat_line_match_tags (struct t_gui_line *line, int tags_count,
return 0;
}
/*
* gui_chat_line_has_highlight: return 1 if given message contains highlight (with
* a string in global highlight or buffer highlight)
*/
int
gui_chat_line_has_highlight (struct t_gui_buffer *buffer,
struct t_gui_line *line)
{
int rc;
char *msg_no_color;
/* highlights are disabled on this buffer? (special value "-" means that
buffer does not want any highlight) */
if (buffer->highlight_words && (strcmp (buffer->highlight_words, "-") == 0))
return 0;
/* check that line matches highlight tags, if any (if no tag is specified,
then any tag is allowed) */
if (buffer->highlight_tags_count > 0)
{
if (!gui_chat_line_match_tags (line,
buffer->highlight_tags_count,
buffer->highlight_tags_array))
return 0;
}
/* remove color codes from line message */
msg_no_color = (char *)gui_color_decode ((unsigned char *)line->message);
if (!msg_no_color)
return 0;
/* there is highlight on line if one of global highlight words matches line
or one of buffer highlight words matches line */
rc = (string_has_highlight (msg_no_color,
CONFIG_STRING(config_look_highlight)) ||
string_has_highlight (msg_no_color,
buffer->highlight_words));
free (msg_no_color);
return rc;
}
/*
* gui_chat_line_free: delete a formated line from a buffer
*/
@@ -662,6 +706,9 @@ gui_chat_line_add (struct t_gui_buffer *buffer, time_t date,
if (new_line->prefix_length > buffer->prefix_max_length)
buffer->prefix_max_length = new_line->prefix_length;
new_line->message = (message) ? strdup (message) : strdup ("");
new_line->highlight = gui_chat_line_has_highlight (buffer, new_line);
if (new_line->highlight)
gui_hotlist_add (buffer, GUI_HOTLIST_HIGHLIGHT, NULL, 0);
/* add line to lines list */
if (!buffer->lines)