diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2013-08-16 16:16:37 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2013-08-16 16:16:37 +0200 |
commit | c6249603368de12acfac60868d4bddd18d29abba (patch) | |
tree | 30a8197fd786eb605abf7461f38d560042166da1 /src/gui | |
parent | 170acfe6f2eda62eed610804fbf821274e002d28 (diff) | |
download | weechat-c6249603368de12acfac60868d4bddd18d29abba.zip |
core: add text emphasis in messages when searching text in buffer
New options:
- weechat.look.emphasized_attributes
- weechat.color.emphasized
- weechat.color.emphasized_bg
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/curses/gui-curses-bar-window.c | 12 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-chat.c | 51 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-color.c | 1 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-window.c | 118 | ||||
-rw-r--r-- | src/gui/curses/gui-curses.h | 17 | ||||
-rw-r--r-- | src/gui/gui-chat.c | 32 | ||||
-rw-r--r-- | src/gui/gui-chat.h | 1 | ||||
-rw-r--r-- | src/gui/gui-color.c | 160 | ||||
-rw-r--r-- | src/gui/gui-color.h | 6 | ||||
-rw-r--r-- | src/gui/gui-window.h | 2 |
10 files changed, 358 insertions, 42 deletions
diff --git a/src/gui/curses/gui-curses-bar-window.c b/src/gui/curses/gui-curses-bar-window.c index 02a52478b..9176e8c8b 100644 --- a/src/gui/curses/gui-curses-bar-window.c +++ b/src/gui/curses/gui-curses-bar-window.c @@ -204,6 +204,10 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window, gui_window_string_apply_color_pair ((unsigned char **)&string, GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar); break; + case GUI_COLOR_EMPHASIS_CHAR: /* emphasis */ + string++; + gui_window_toggle_emphasis (); + break; case GUI_COLOR_BAR_CHAR: /* bar color */ switch (string[1]) { @@ -364,6 +368,12 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window, if (output) free (output); + if (gui_window_current_emphasis) + { + gui_window_emphasize (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, + *x, *y, size_on_screen); + } + *x += size_on_screen; } } @@ -437,6 +447,8 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window, index_subitem = -1; index_line = 0; + gui_window_current_emphasis = 0; + filling = gui_bar_get_filling (bar_window->bar); content = gui_bar_window_content_get_with_filling (bar_window, window); diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c index 0d753719f..e28dc92a6 100644 --- a/src/gui/curses/gui-curses-chat.c +++ b/src/gui/curses/gui-curses-chat.c @@ -262,6 +262,11 @@ gui_chat_string_next_char (struct t_gui_window *window, struct t_gui_line *line, gui_window_string_apply_color_pair ((unsigned char **)&string, (apply_style) ? GUI_WINDOW_OBJECTS(window)->win_chat : NULL); break; + case GUI_COLOR_EMPHASIS_CHAR: /* emphasis */ + string++; + if (apply_style) + gui_window_toggle_emphasis (); + break; case GUI_COLOR_BAR_CHAR: /* bar color */ string++; switch (string[0]) @@ -402,6 +407,13 @@ gui_chat_display_word_raw (struct t_gui_window *window, struct t_gui_line *line, "%s", (output) ? output : utf_char); if (output) free (output); + + if (gui_window_current_emphasis) + { + gui_window_emphasize (GUI_WINDOW_OBJECTS(window)->win_chat, + x, window->win_chat_cursor_y, + size_on_screen); + } } chars_displayed += size_on_screen; } @@ -432,10 +444,6 @@ gui_chat_display_word (struct t_gui_window *window, char *data, *ptr_data, *end_line, saved_char, str_space[] = " "; int chars_displayed, pos_saved_char, chars_to_display, num_displayed; int length_align; - attr_t attrs; - attr_t *ptr_attrs; - short pair; - short *ptr_pair; chars_displayed = 0; @@ -481,17 +489,12 @@ gui_chat_display_word (struct t_gui_window *window, && CONFIG_STRING(config_look_prefix_suffix)[0] && line->data->date > 0) { - attrs = 0; - pair = 0; if (!simulate) { - ptr_attrs = &attrs; - ptr_pair = &pair; - wattr_get (GUI_WINDOW_OBJECTS(window)->win_chat, - ptr_attrs, ptr_pair, NULL); - gui_window_save_style (); + gui_window_save_style (GUI_WINDOW_OBJECTS(window)->win_chat); gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat, GUI_COLOR_CHAT_PREFIX_SUFFIX); + gui_window_current_emphasis = 0; } chars_displayed += gui_chat_display_word_raw (window, line, CONFIG_STRING(config_look_prefix_suffix), @@ -506,16 +509,7 @@ gui_chat_display_word (struct t_gui_window *window, nick_offline); window->win_chat_cursor_x += gui_chat_strlen_screen (str_space); if (!simulate) - { - wattr_set (GUI_WINDOW_OBJECTS(window)->win_chat, attrs, pair, NULL); - /* - * for unknown reason, the wattr_set function sometimes - * fails to set the color pair under FreeBSD, so we force - * it again with wcolor_set - */ - wcolor_set (GUI_WINDOW_OBJECTS(window)->win_chat, pair, NULL); - gui_window_restore_style (); - } + gui_window_restore_style (GUI_WINDOW_OBJECTS(window)->win_chat); } if (window->win_chat_cursor_y < window->coords_size) window->coords[window->win_chat_cursor_y].data = (char *)word + (ptr_data - data); @@ -1130,7 +1124,7 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line, int word_start_offset, word_end_offset; int word_length_with_spaces, word_length; char *ptr_data, *ptr_end_offset, *next_char; - char *ptr_style, *message_with_tags; + char *ptr_style, *message_with_tags, *message_with_search; if (!line) return 0; @@ -1152,6 +1146,7 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line, num_lines = gui_chat_display_line (window, line, 0, 1); window->win_chat_cursor_x = x; window->win_chat_cursor_y = y; + gui_window_current_emphasis = 0; } /* calculate marker position (maybe not used for this line!) */ @@ -1205,6 +1200,16 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line, gui_chat_build_string_message_tags (line) : NULL; ptr_data = (message_with_tags) ? message_with_tags : line->data->message; + message_with_search = NULL; + if (window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED) + { + message_with_search = gui_color_emphasize (ptr_data, + window->buffer->input_buffer, + window->buffer->text_search_exact, + NULL); + if (message_with_search) + ptr_data = message_with_search; + } while (ptr_data && ptr_data[0]) { gui_chat_get_word_info (window, @@ -1295,6 +1300,8 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line, } if (message_with_tags) free (message_with_tags); + if (message_with_search) + free (message_with_search); } if (marker_line) diff --git a/src/gui/curses/gui-curses-color.c b/src/gui/curses/gui-curses-color.c index 77402a835..91bf38089 100644 --- a/src/gui/curses/gui-curses-color.c +++ b/src/gui/curses/gui-curses-color.c @@ -1434,6 +1434,7 @@ gui_color_init_weechat () 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)); + gui_color_build (GUI_COLOR_EMPHASIS, CONFIG_COLOR(config_color_emphasized), CONFIG_COLOR(config_color_emphasized_bg)); /* * define old nick colors for compatibility on /upgrade with previous diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c index 6c92d34a7..13ca8434e 100644 --- a/src/gui/curses/gui-curses-window.c +++ b/src/gui/curses/gui-curses-window.c @@ -57,11 +57,16 @@ #include "gui-curses.h" +#define GUI_WINDOW_MAX_SAVED_STYLES 32 + + int gui_window_current_style_fg; /* current foreground color */ int gui_window_current_style_bg; /* current background color */ -int gui_window_current_style_attr; /* current attributes (bold, ..) */ int gui_window_current_color_attr; /* attr sum of last color(s) used */ -int gui_window_saved_style[4]; /* current style saved */ +int gui_window_current_emphasis; /* 1 if text emphasis is enabled */ +struct t_gui_window_saved_style gui_window_saved_style[GUI_WINDOW_MAX_SAVED_STYLES]; + /* circular list of saved styles */ +int gui_window_saved_style_index = 0; /* index in list of savec styles */ /* @@ -218,12 +223,28 @@ gui_window_clrtoeol (WINDOW *window) */ void -gui_window_save_style () +gui_window_save_style (WINDOW *window) { - gui_window_saved_style[0] = gui_window_current_style_fg; - gui_window_saved_style[1] = gui_window_current_style_bg; - gui_window_saved_style[2] = gui_window_current_style_attr; - gui_window_saved_style[3] = gui_window_current_color_attr; + struct t_gui_window_saved_style *ptr_saved_style; + attr_t *ptr_attrs; + short *ptr_pair; + + /* get pointer on saved style */ + ptr_saved_style = &gui_window_saved_style[gui_window_saved_style_index]; + + /* save current style */ + ptr_saved_style->style_fg = gui_window_current_style_fg; + ptr_saved_style->style_bg = gui_window_current_style_bg; + ptr_saved_style->color_attr = gui_window_current_color_attr; + ptr_saved_style->emphasis = gui_window_current_emphasis; + ptr_attrs = &ptr_saved_style->attrs; + ptr_pair = &ptr_saved_style->pair; + wattr_get (window, ptr_attrs, ptr_pair, NULL); + + /* increment style index (circular list) */ + gui_window_saved_style_index++; + if (gui_window_saved_style_index >= GUI_WINDOW_MAX_SAVED_STYLES) + gui_window_saved_style_index = 0; } /* @@ -231,12 +252,30 @@ gui_window_save_style () */ void -gui_window_restore_style () +gui_window_restore_style (WINDOW *window) { - gui_window_current_style_fg = gui_window_saved_style[0]; - gui_window_current_style_bg = gui_window_saved_style[1]; - gui_window_current_style_attr = gui_window_saved_style[2]; - gui_window_current_color_attr = gui_window_saved_style[3]; + struct t_gui_window_saved_style *ptr_saved_style; + + /* decrement style index (circular list) */ + gui_window_saved_style_index--; + if (gui_window_saved_style_index < 0) + gui_window_saved_style_index = GUI_WINDOW_MAX_SAVED_STYLES - 1; + + /* get pointer on saved style */ + ptr_saved_style = &gui_window_saved_style[gui_window_saved_style_index]; + + /* restore style */ + gui_window_current_style_fg = ptr_saved_style->style_fg; + gui_window_current_style_bg = ptr_saved_style->style_bg; + gui_window_current_color_attr = ptr_saved_style->color_attr; + gui_window_current_emphasis = ptr_saved_style->emphasis; + wattr_set (window, ptr_saved_style->attrs, ptr_saved_style->pair, NULL); + /* + * for unknown reason, the wattr_set function sometimes + * fails to set the color pair under FreeBSD, so we force + * it again with wcolor_set + */ + wcolor_set (window, ptr_saved_style->pair, NULL); } /* @@ -248,7 +287,6 @@ gui_window_reset_style (WINDOW *window, int weechat_color) { gui_window_current_style_fg = -1; gui_window_current_style_bg = -1; - gui_window_current_style_attr = 0; gui_window_current_color_attr = 0; wattroff (window, A_BOLD | A_UNDERLINE | A_REVERSE); @@ -406,11 +444,10 @@ gui_window_set_custom_color_fg (WINDOW *window, int fg) void gui_window_set_custom_color_bg (WINDOW *window, int bg) { - int current_attr, current_fg; + int current_fg; if (bg >= 0) { - current_attr = gui_window_current_style_attr; current_fg = gui_window_current_style_fg; if ((bg > 0) && (bg & GUI_COLOR_EXTENDED_FLAG)) @@ -422,7 +459,6 @@ gui_window_set_custom_color_bg (WINDOW *window, int bg) else if ((bg & GUI_COLOR_EXTENDED_MASK) < GUI_CURSES_NUM_WEECHAT_COLORS) { bg &= GUI_COLOR_EXTENDED_MASK; - gui_window_set_color_style (window, current_attr); gui_window_set_color (window, current_fg, (gui_color_term_colors >= 16) ? gui_weechat_colors[bg].background : gui_weechat_colors[bg].foreground); @@ -515,6 +551,56 @@ gui_window_set_custom_color_pair (WINDOW *window, int pair) } /* + * Toggles text emphasis. + */ + +void +gui_window_toggle_emphasis () +{ + gui_window_current_emphasis ^= 1; +} + +/* + * Emphasizes some chars already displayed in a window, either using a color + * (from config options), or by doing an exclusive or (XOR) with attributes + * (like reverse video). + * + * It is used for example when searching a string in buffer. + */ + +void +gui_window_emphasize (WINDOW *window, int x, int y, int count) +{ + attr_t attrs, *ptr_attrs; + short pair, *ptr_pair; + + if (config_emphasized_attributes == 0) + { + /* use color for emphasis (from config) */ + mvwchgat (window, y, x, count, + gui_color[GUI_COLOR_EMPHASIS]->attributes, + gui_color_weechat_get_pair (GUI_COLOR_EMPHASIS), NULL); + } + else + { + /* exclusive or (XOR) with attributes */ + ptr_attrs = &attrs; + ptr_pair = &pair; + wattr_get (window, ptr_attrs, ptr_pair, NULL); + if (config_emphasized_attributes & GUI_COLOR_EXTENDED_BOLD_FLAG) + attrs ^= A_BOLD; + if (config_emphasized_attributes & GUI_COLOR_EXTENDED_REVERSE_FLAG) + attrs ^= A_REVERSE; + if (config_emphasized_attributes & GUI_COLOR_EXTENDED_UNDERLINE_FLAG) + attrs ^= A_UNDERLINE; + mvwchgat (window, y, x, count, attrs, pair, NULL); + } + + /* move the cursor after the text (mvwchgat does not move cursor) */ + wmove (window, y, x + count); +} + +/* * Applies foreground color code in string and moves string pointer after color * in string. * diff --git a/src/gui/curses/gui-curses.h b/src/gui/curses/gui-curses.h index 2b2860f2d..83a68b36d 100644 --- a/src/gui/curses/gui-curses.h +++ b/src/gui/curses/gui-curses.h @@ -45,6 +45,16 @@ struct t_gui_bar_window; #define GUI_BAR_WINDOW_OBJECTS(bar_window) \ ((struct t_gui_bar_window_curses_objects *)(bar_window->gui_objects)) +struct t_gui_window_saved_style +{ + int style_fg; + int style_bg; + int color_attr; + int emphasis; + attr_t attrs; + short pair; +}; + struct t_gui_window_curses_objects { WINDOW *win_chat; /* chat window (example: channel) */ @@ -66,6 +76,7 @@ extern int gui_color_pairs_auto_reset; extern int gui_color_pairs_auto_reset_pending; extern time_t gui_color_pairs_auto_reset_last; extern int gui_color_buffer_refresh_needed; +extern int gui_window_current_emphasis; /* color functions */ extern int gui_color_get_pair (int fg, int bg); @@ -88,6 +99,8 @@ extern void gui_window_read_terminal_size (); extern void gui_window_redraw_buffer (struct t_gui_buffer *buffer); extern void gui_window_clear (WINDOW *window, int fg, int bg); extern void gui_window_clrtoeol (WINDOW *window); +extern void gui_window_save_style (WINDOW *window); +extern void gui_window_restore_style (WINDOW *window); extern void gui_window_reset_style (WINDOW *window, int num_color); extern void gui_window_reset_color (WINDOW *window, int num_color); extern void gui_window_set_color_style (WINDOW *window, int style); @@ -98,6 +111,8 @@ extern void gui_window_set_custom_color_fg_bg (WINDOW *window, int fg, int bg); extern void gui_window_set_custom_color_pair (WINDOW *window, int pair); extern void gui_window_set_custom_color_fg (WINDOW *window, int fg); extern void gui_window_set_custom_color_bg (WINDOW *window, int bg); +extern void gui_window_toggle_emphasis (); +extern void gui_window_emphasize (WINDOW *window, int x, int y, int count); extern void gui_window_string_apply_color_fg (unsigned char **str, WINDOW *window); extern void gui_window_string_apply_color_bg (unsigned char **str, @@ -112,8 +127,6 @@ extern void gui_window_string_apply_color_set_attr (unsigned char **str, WINDOW *window); extern void gui_window_string_apply_color_remove_attr (unsigned char **str, WINDOW *window); -extern void gui_window_apply_color (unsigned char **str, WINDOW *window, - int apply_bar_colors); extern void gui_window_set_title (const char *title); #endif /* __WEECHAT_GUI_CURSES_H */ diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c index b1045f6b2..d596e1714 100644 --- a/src/gui/gui-chat.c +++ b/src/gui/gui-chat.c @@ -241,6 +241,8 @@ gui_chat_string_add_offset_screen (const char *string, int offset_screen) /* * Gets real position in string (ignoring formatting chars like * colors/attributes). + * + * Returns real position, in bytes. */ int @@ -276,6 +278,36 @@ gui_chat_string_real_pos (const char *string, int pos) } /* + * Gets real position in string (ignoring formatting chars like + * colors/attributes). + * + * Returns position, in number of UTF-8 chars. + */ + +int +gui_chat_string_pos (const char *string, int real_pos) +{ + const char *ptr_string, *limit; + int count; + + count = 0; + ptr_string = string; + limit = ptr_string + real_pos; + while (ptr_string && ptr_string[0] && (ptr_string < limit)) + { + ptr_string = gui_chat_string_next_char (NULL, NULL, + (unsigned char *)ptr_string, + 0, 0, 0); + if (ptr_string) + { + ptr_string = utf8_next_char (ptr_string); + count++; + } + } + return count; +} + +/* * Returns info about next word: beginning, end, length. * * Note: the word_{start|end}_offset are in bytes, but word_length(_with_spaces) diff --git a/src/gui/gui-chat.h b/src/gui/gui-chat.h index cd77d77d0..80ec2c622 100644 --- a/src/gui/gui-chat.h +++ b/src/gui/gui-chat.h @@ -71,6 +71,7 @@ extern char *gui_chat_string_add_offset (const char *string, int offset); extern char *gui_chat_string_add_offset_screen (const char *string, int offset_screen); extern int gui_chat_string_real_pos (const char *string, int pos); +extern int gui_chat_string_pos (const char *string, int real_pos); extern void gui_chat_get_word_info (struct t_gui_window *window, const char *data, int *word_start_offset, int *word_end_offset, diff --git a/src/gui/gui-color.c b/src/gui/gui-color.c index 184d13cdf..d9e4d3e8e 100644 --- a/src/gui/gui-color.c +++ b/src/gui/gui-color.c @@ -40,6 +40,7 @@ #include "../core/wee-utf8.h" #include "../plugins/plugin.h" #include "gui-color.h" +#include "gui-chat.h" #include "gui-window.h" @@ -171,6 +172,13 @@ gui_color_get_custom (const char *color_name) GUI_COLOR_COLOR_CHAR, GUI_COLOR_RESET_CHAR); } + else if (string_strcasecmp (color_name, "emphasis") == 0) + { + snprintf (color[index_color], sizeof (color[index_color]), + "%c%c", + GUI_COLOR_COLOR_CHAR, + GUI_COLOR_EMPHASIS_CHAR); + } else if (string_strcasecmp (color_name, "bold") == 0) { snprintf (color[index_color], sizeof (color[index_color]), @@ -518,6 +526,9 @@ gui_color_decode (const char *string, const char *replacement) && (isdigit (ptr_string[5]))) ptr_string += 6; break; + case GUI_COLOR_EMPHASIS_CHAR: + ptr_string++; + break; case GUI_COLOR_BAR_CHAR: ptr_string++; switch (ptr_string[0]) @@ -583,6 +594,155 @@ gui_color_decode (const char *string, const char *replacement) } /* + * Emphasizes a string or regular expression in a string (which can contain + * colors). + * + * Argument "case_sensitive" is used only for "search", if the "regex" is NULL. + * + * Returns string with the search string/regex emphasized, NULL if error. + * + * Note: result must be freed after use. + */ + +char * +gui_color_emphasize (const char *string, + const char *search, int case_sensitive, + regex_t *regex) +{ + regmatch_t regex_match; + char *result, *result2, *string_no_color, *pos; + const char *ptr_string, *ptr_no_color, *color_emphasis; + int rc, length_search, length_emphasis, length_result; + int pos1, pos2, real_pos1, real_pos2, count_emphasis; + + if (!string && !regex) + return NULL; + + color_emphasis = gui_color_get_custom ("emphasis"); + if (!color_emphasis) + return NULL; + length_emphasis = strlen (color_emphasis); + + /* + * allocate space for 8 emphasized strings (8 before + 8 after = 16); + * more space will be allocated later (if there are more than 8 emphasized + * strings) + */ + length_result = strlen (string) + (length_emphasis * 2 * 8) + 1; + result = malloc (length_result); + if (!result) + return NULL; + result[0] = '\0'; + + /* + * build a string without color codes to search in this one (then with the + * position of text found, we will retrieve position in original string, + * which can contain color codes) + */ + string_no_color = gui_color_decode (string, NULL); + if (!string_no_color) + { + free (result); + return NULL; + } + + length_search = (search) ? strlen (search) : 0; + + ptr_string = string; + ptr_no_color = string_no_color; + + count_emphasis = 0; + + while (ptr_no_color && ptr_no_color[0]) + { + if (regex) + { + /* search next match using the regex */ + rc = regexec (regex, ptr_no_color, 1, ®ex_match, 0); + + /* + * no match found: exit the loop (if rm_no == 0, it is an empty + * match at beginning of string: we consider there is no match, to + * prevent an infinite loop) + */ + if ((rc != 0) || (regex_match.rm_so < 0) || (regex_match.rm_eo <= 0)) + { + strcat (result, ptr_string); + break; + } + pos1 = regex_match.rm_so; + pos2 = regex_match.rm_eo; + } + else + { + /* search next match in the string */ + if (case_sensitive) + pos = strstr (ptr_no_color, search); + else + pos = string_strcasestr (ptr_no_color, search); + if (!pos) + { + strcat (result, ptr_string); + break; + } + pos1 = pos - ptr_no_color; + pos2 = pos1 + length_search; + if (pos2 <= 0) + { + strcat (result, ptr_string); + break; + } + } + + /* + * find the position of match in the original string (which can contain + * color codes) + */ + real_pos1 = gui_chat_string_real_pos (ptr_string, + gui_chat_string_pos (ptr_no_color, pos1)); + real_pos2 = gui_chat_string_real_pos (ptr_string, + gui_chat_string_pos (ptr_no_color, pos2)); + + /* + * concatenate following strings to the result: + * - beginning of string (before match) + * - emphasis color code + * - the matching string + * - emphasis color code + */ + if (real_pos1 > 0) + strncat (result, ptr_string, real_pos1); + strcat (result, color_emphasis); + strncat (result, ptr_string + real_pos1, real_pos2 - real_pos1); + strcat (result, color_emphasis); + + /* restart next loop after the matching string */ + ptr_string += real_pos2; + ptr_no_color += pos2; + + /* check if we should allocate more space for emphasis color codes */ + count_emphasis++; + if (count_emphasis == 8) + { + /* allocate more space for emphasis color codes */ + length_result += (length_emphasis * 2 * 8); + result2 = realloc (result, length_result); + if (!result2) + { + free (result); + return NULL; + } + result = result2; + count_emphasis = 0; + } + } + + free (string_no_color); + + return result; +} + +/* * Frees a color. */ diff --git a/src/gui/gui-color.h b/src/gui/gui-color.h index 91e56fe60..e480c72e2 100644 --- a/src/gui/gui-color.h +++ b/src/gui/gui-color.h @@ -20,6 +20,8 @@ #ifndef __WEECHAT_GUI_COLOR_H #define __WEECHAT_GUI_COLOR_H 1 +#include <regex.h> + /* * Color from configuration options. * When changing some colors below: @@ -78,6 +80,7 @@ enum t_gui_color_enum GUI_COLOR_CHAT_NICK_OFFLINE_HIGHLIGHT, GUI_COLOR_CHAT_NICK_PREFIX, GUI_COLOR_CHAT_NICK_SUFFIX, + GUI_COLOR_EMPHASIS, /* number of colors */ GUI_COLOR_NUM_COLORS, @@ -112,6 +115,7 @@ enum t_gui_color_enum #define GUI_COLOR_EXTENDED_ITALIC_CHAR '/' #define GUI_COLOR_EXTENDED_UNDERLINE_CHAR '_' #define GUI_COLOR_EXTENDED_KEEPATTR_CHAR '|' +#define GUI_COLOR_EMPHASIS_CHAR 'E' /* color codes specific to bars */ #define GUI_COLOR_BAR_CHAR 'b' @@ -165,6 +169,8 @@ extern int gui_color_attr_get_flag (char c); extern void gui_color_attr_build_string (int color, char *str_attr); extern const char *gui_color_get_custom (const char *color_name); extern char *gui_color_decode (const char *string, const char *replacement); +extern char *gui_color_emphasize (const char *string, const char *search, + int case_sensitive, regex_t *regex); extern void gui_color_free (struct t_gui_color *color); extern void gui_color_palette_alloc_structs (); extern int gui_color_palette_get_alias (const char *alias); diff --git a/src/gui/gui-window.h b/src/gui/gui-window.h index 4296b7b6d..bfcbcc154 100644 --- a/src/gui/gui-window.h +++ b/src/gui/gui-window.h @@ -201,8 +201,6 @@ extern int gui_window_get_height (); extern int gui_window_objects_init (struct t_gui_window *window); extern void gui_window_objects_free (struct t_gui_window *window, int free_separators); -extern void gui_window_save_style (); -extern void gui_window_restore_style (); extern void gui_window_calculate_pos_size (struct t_gui_window *window); extern void gui_window_switch_to_buffer (struct t_gui_window *window, struct t_gui_buffer *buffer, |