summaryrefslogtreecommitdiff
path: root/src/gui/curses
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2013-08-16 16:16:37 +0200
committerSebastien Helleu <flashcode@flashtux.org>2013-08-16 16:16:37 +0200
commitc6249603368de12acfac60868d4bddd18d29abba (patch)
tree30a8197fd786eb605abf7461f38d560042166da1 /src/gui/curses
parent170acfe6f2eda62eed610804fbf821274e002d28 (diff)
downloadweechat-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/curses')
-rw-r--r--src/gui/curses/gui-curses-bar-window.c12
-rw-r--r--src/gui/curses/gui-curses-chat.c51
-rw-r--r--src/gui/curses/gui-curses-color.c1
-rw-r--r--src/gui/curses/gui-curses-window.c118
-rw-r--r--src/gui/curses/gui-curses.h17
5 files changed, 159 insertions, 40 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 */