summaryrefslogtreecommitdiff
path: root/src/gui/curses
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/curses')
-rw-r--r--src/gui/curses/gui-curses-bar.c283
-rw-r--r--src/gui/curses/gui-curses-chat.c268
-rw-r--r--src/gui/curses/gui-curses-infobar.c4
-rw-r--r--src/gui/curses/gui-curses-input.c4
-rw-r--r--src/gui/curses/gui-curses-status.c4
-rw-r--r--src/gui/curses/gui-curses-window.c178
-rw-r--r--src/gui/curses/gui-curses.h15
7 files changed, 415 insertions, 341 deletions
diff --git a/src/gui/curses/gui-curses-bar.c b/src/gui/curses/gui-curses-bar.c
index bc8eeb052..5da3963cb 100644
--- a/src/gui/curses/gui-curses-bar.c
+++ b/src/gui/curses/gui-curses-bar.c
@@ -363,6 +363,13 @@ gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window)
if (window)
window->refresh_needed = 1;
}
+ else
+ {
+ new_bar_window->x = 0;
+ new_bar_window->y = 0;
+ new_bar_window->width = 1;
+ new_bar_window->height = 1;
+ }
return 1;
}
@@ -526,40 +533,84 @@ gui_bar_window_add_missing_bars (struct t_gui_window *window)
/*
* gui_bar_window_print_string: print a string text on a bar window
- * return number of chars displayed on screen
*/
-int
+void
gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
- char *string, int max_chars_on_screen)
+ int *x, int *y, char *string)
{
- int weechat_color, chars_displayed, size_on_screen;
- char str_color[3], utf_char[16], *next_char, *output;
+ int weechat_color, size_on_screen, fg, bg;
+ char str_fg[3], str_bg[3], utf_char[16], *next_char, *output;
if (!string || !string[0])
- return 0;
-
- if ((CONFIG_INTEGER(bar_window->bar->position) == GUI_BAR_POSITION_LEFT)
- || (CONFIG_INTEGER(bar_window->bar->position) == GUI_BAR_POSITION_RIGHT))
- gui_window_set_weechat_color (bar_window->win_bar, GUI_COLOR_CHAT);
- else
- gui_window_set_weechat_color (bar_window->win_bar, GUI_COLOR_STATUS);
+ return;
- chars_displayed = 0;
+ wmove (bar_window->win_bar, *y, *x);
+
+ gui_window_set_custom_color_fg_bg (bar_window->win_bar,
+ CONFIG_COLOR(bar_window->bar->color_fg),
+ CONFIG_COLOR(bar_window->bar->color_bg));
while (string && string[0])
{
if (string[0] == GUI_COLOR_COLOR_CHAR)
{
string++;
- if (isdigit (string[0]) && isdigit (string[1]))
+ switch (string[0])
{
- str_color[0] = string[0];
- str_color[1] = string[1];
- str_color[2] = '\0';
- string += 2;
- sscanf (str_color, "%d", &weechat_color);
- gui_window_set_weechat_color (bar_window->win_bar, weechat_color);
+ case 'F':
+ if (string[1] && string[2])
+ {
+ str_fg[0] = string[1];
+ str_fg[1] = string[2];
+ str_fg[2] = '\0';
+ sscanf (str_fg, "%d", &fg);
+ gui_window_set_custom_color_fg (bar_window->win_bar,
+ fg);
+ string += 3;
+ }
+ break;
+ case 'B':
+ if (string[1] && string[2])
+ {
+ str_bg[0] = string[1];
+ str_bg[1] = string[2];
+ str_bg[2] = '\0';
+ sscanf (str_bg, "%d", &bg);
+ gui_window_set_custom_color_bg (bar_window->win_bar,
+ bg);
+ string += 3;
+ }
+ break;
+ case '*':
+ if (string[1] && string[2] && (string[3] == ',')
+ && string[4] && string[5])
+ {
+ str_fg[0] = string[1];
+ str_fg[1] = string[2];
+ str_fg[2] = '\0';
+ str_bg[0] = string[4];
+ str_bg[1] = string[5];
+ str_bg[2] = '\0';
+ sscanf (str_fg, "%d", &fg);
+ sscanf (str_bg, "%d", &bg);
+ gui_window_set_custom_color_fg_bg (bar_window->win_bar,
+ fg, bg);
+ string += 6;
+ }
+ break;
+ default:
+ if (isdigit (string[0]) && isdigit (string[1]))
+ {
+ str_fg[0] = string[0];
+ str_fg[1] = string[1];
+ str_fg[2] = '\0';
+ sscanf (str_fg, "%d", &weechat_color);
+ gui_window_set_weechat_color (bar_window->win_bar,
+ weechat_color);
+ string += 2;
+ }
+ break;
}
}
else
@@ -571,45 +622,31 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
memcpy (utf_char, string, next_char - string);
utf_char[next_char - string] = '\0';
- if (gui_window_utf_char_valid (utf_char))
- {
- size_on_screen = utf8_char_size_screen (utf_char);
- if (chars_displayed + size_on_screen > max_chars_on_screen)
- return chars_displayed;
- chars_displayed += size_on_screen;
- output = string_iconv_from_internal (NULL, utf_char);
- wprintw (bar_window->win_bar, "%s",
- (output) ? output : utf_char);
- if (output)
- free (output);
- }
- else
+ if (!gui_window_utf_char_valid (utf_char))
+ snprintf (utf_char, sizeof (utf_char), ".");
+
+ size_on_screen = utf8_char_size_screen (utf_char);
+ if (*x + size_on_screen > bar_window->width)
{
- if (chars_displayed + 1 > max_chars_on_screen)
- return chars_displayed;
- chars_displayed++;
- wprintw (bar_window->win_bar, ".");
+ if (CONFIG_INTEGER(bar_window->bar->filling) == GUI_BAR_FILLING_VERTICAL)
+ return;
+ if (*y >= bar_window->height - 1)
+ return;
+ *x = 0;
+ (*y)++;
+ wmove (bar_window->win_bar, *y, *x);
}
+ output = string_iconv_from_internal (NULL, utf_char);
+ wprintw (bar_window->win_bar, "%s",
+ (output) ? output : utf_char);
+ if (output)
+ free (output);
+
+ *x += size_on_screen;
string = next_char;
}
}
-
- return chars_displayed;
-}
-
-/*
- * gui_bar_window_clear_bg: clear background for a bar window
- */
-
-void
-gui_bar_window_clear_bg (struct t_gui_bar_window *bar_window)
-{
- if ((CONFIG_INTEGER(bar_window->bar->position) == GUI_BAR_POSITION_LEFT)
- || (CONFIG_INTEGER(bar_window->bar->position) == GUI_BAR_POSITION_RIGHT))
- gui_window_curses_clear (bar_window->win_bar, GUI_COLOR_CHAT);
- else
- gui_window_curses_clear (bar_window->win_bar, GUI_COLOR_STATUS);
}
/*
@@ -622,9 +659,13 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
{
int x, y, i, items_count, num_lines, line;
char *content, *item_value, *item_value2, **items;
- int content_length, length, max_length;
+ char space_with_reinit_color[32];
+ int content_length, length, max_length, optimal_number_of_lines;
struct t_gui_bar_item *ptr_item;
+ if (!gui_init_ok)
+ return;
+
if (CONFIG_INTEGER(bar_window->bar->size) == 0)
{
content = NULL;
@@ -641,22 +682,40 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
{
if (item_value[0])
{
+ if (CONFIG_INTEGER(bar_window->bar->filling) == GUI_BAR_FILLING_HORIZONTAL)
+ {
+ snprintf (space_with_reinit_color,
+ sizeof (space_with_reinit_color),
+ "%c*%02d,%02d ",
+ GUI_COLOR_COLOR_CHAR,
+ CONFIG_COLOR(bar_window->bar->color_fg),
+ CONFIG_COLOR(bar_window->bar->color_bg));
+ item_value2 = string_replace (item_value, "\n",
+ space_with_reinit_color);
+ }
+ else
+ item_value2 = NULL;
if (!content)
{
- content_length += strlen (item_value);
- content = strdup (item_value);
+ content_length += strlen ((item_value2) ?
+ item_value2 : item_value);
+ content = strdup ((item_value2) ?
+ item_value2 : item_value);
}
else
{
- content_length += 1 + strlen (item_value);
+ content_length += 1 +
+ strlen ((item_value2) ? item_value2 : item_value);
content = realloc (content, content_length);
- if ((CONFIG_INTEGER(bar_window->bar->position) == GUI_BAR_POSITION_LEFT)
- || (CONFIG_INTEGER(bar_window->bar->position) == GUI_BAR_POSITION_RIGHT))
- {
+ if (CONFIG_INTEGER(bar_window->bar->filling) == GUI_BAR_FILLING_HORIZONTAL)
+ strcat (content, " ");
+ else
strcat (content, "\n");
- }
- strcat (content, item_value);
+ strcat (content,
+ (item_value2) ? item_value2 : item_value);
}
+ if (item_value2)
+ free (item_value2);
}
free (item_value);
}
@@ -669,32 +728,47 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
{
gui_bar_set_current_size (bar_window->bar, 1);
gui_bar_window_recreate_bar_windows (bar_window->bar);
- gui_bar_window_clear_bg (bar_window);
+ gui_window_clear (bar_window->win_bar,
+ CONFIG_COLOR(bar_window->bar->color_bg));
}
else
{
+ /* search longer line and optimal number of lines */
+ max_length = 0;
+ optimal_number_of_lines = 0;
+ for (line = 0; line < items_count; line++)
+ {
+ length = gui_chat_strlen_screen (items[line]);
+ if (length > max_length)
+ max_length = length;
+
+ if (length % bar_window->width == 0)
+ num_lines = length / bar_window->width;
+ else
+ num_lines = (length / bar_window->width) + 1;
+ if (num_lines == 0)
+ num_lines = 1;
+ optimal_number_of_lines += num_lines;
+ }
+ if (max_length == 0)
+ max_length = 1;
+
switch (CONFIG_INTEGER(bar_window->bar->position))
{
case GUI_BAR_POSITION_BOTTOM:
case GUI_BAR_POSITION_TOP:
- if (bar_window->bar->current_size != items_count)
+ if (CONFIG_INTEGER(bar_window->bar->filling) == GUI_BAR_FILLING_HORIZONTAL)
+ num_lines = optimal_number_of_lines;
+ else
+ num_lines = items_count;
+ if (bar_window->bar->current_size != num_lines)
{
- gui_bar_set_current_size (bar_window->bar, items_count);
+ gui_bar_set_current_size (bar_window->bar, num_lines);
gui_bar_window_recreate_bar_windows (bar_window->bar);
}
break;
case GUI_BAR_POSITION_LEFT:
case GUI_BAR_POSITION_RIGHT:
- /* search longer line */
- max_length = 0;
- for (line = 0; line < items_count; line++)
- {
- length = gui_chat_strlen_screen (items[line]);
- if (length > max_length)
- max_length = length;
- }
- if (max_length == 0)
- max_length = 1;
if (bar_window->bar->current_size != max_length)
{
gui_bar_set_current_size (bar_window->bar,
@@ -705,17 +779,21 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
case GUI_BAR_NUM_POSITIONS:
break;
}
- gui_bar_window_clear_bg (bar_window);
+ gui_window_clear (bar_window->win_bar,
+ CONFIG_COLOR(bar_window->bar->color_bg));
x = 0;
y = 0;
- for (line = 0; line < items_count; line++)
+ for (line = 0;
+ (line < items_count) && (y < bar_window->height);
+ line++)
{
- wmove (bar_window->win_bar, y, x);
- x += gui_bar_window_print_string (bar_window,
- items[line],
- bar_window->width);
- x = 0;
- y++;
+ gui_bar_window_print_string (bar_window, &x, &y,
+ items[line]);
+ if (CONFIG_INTEGER(bar_window->bar->filling) == GUI_BAR_FILLING_VERTICAL)
+ {
+ x = 0;
+ y++;
+ }
}
}
if (items)
@@ -726,12 +804,14 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
{
gui_bar_set_current_size (bar_window->bar, 1);
gui_bar_window_recreate_bar_windows (bar_window->bar);
- gui_bar_window_clear_bg (bar_window);
+ gui_window_clear (bar_window->win_bar,
+ CONFIG_COLOR(bar_window->bar->color_bg));
}
}
else
{
- gui_bar_window_clear_bg (bar_window);
+ gui_window_clear (bar_window->win_bar,
+ CONFIG_COLOR(bar_window->bar->color_bg));
x = 0;
y = 0;
@@ -749,21 +829,30 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
{
if (item_value[0])
{
- /* replace \n by spaces when height is 1 */
- item_value2 = (bar_window->height == 1) ?
- string_replace (item_value, "\n", " ") : NULL;
- items = string_explode ((item_value2) ? item_value2 : item_value,
+ if (CONFIG_INTEGER(bar_window->bar->filling) == GUI_BAR_FILLING_HORIZONTAL)
+ {
+ snprintf (space_with_reinit_color,
+ sizeof (space_with_reinit_color),
+ "%c*%02d,%02d ",
+ GUI_COLOR_COLOR_CHAR,
+ CONFIG_COLOR(bar_window->bar->color_fg),
+ CONFIG_COLOR(bar_window->bar->color_bg));
+ item_value2 = string_replace (item_value, "\n",
+ space_with_reinit_color);
+ }
+ else
+ item_value2 = NULL;
+ items = string_explode ((item_value2) ?
+ item_value2 : item_value,
"\n", 0, 0,
&items_count);
- num_lines = (items_count <= bar_window->height) ?
- items_count : bar_window->height;
- for (line = 0; line < num_lines; line++)
+ for (line = 0;
+ (line < items_count) && (y < bar_window->height);
+ line++)
{
- wmove (bar_window->win_bar, y, x);
- x += gui_bar_window_print_string (bar_window,
- items[line],
- bar_window->width);
- if (num_lines > 1)
+ gui_bar_window_print_string (bar_window, &x, &y,
+ items[line]);
+ if (CONFIG_INTEGER(bar_window->bar->filling) == GUI_BAR_FILLING_VERTICAL)
{
x = 0;
y++;
diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c
index 98ea32fd1..6855065ab 100644
--- a/src/gui/curses/gui-curses-chat.c
+++ b/src/gui/curses/gui-curses-chat.c
@@ -42,202 +42,6 @@
/*
- * gui_chat_set_style: set style (bold, underline, ..)
- * for a chat window
- */
-
-void
-gui_chat_set_style (struct t_gui_window *window, int style)
-{
- wattron (GUI_CURSES(window)->win_chat, style);
-}
-
-/*
- * gui_chat_remove_style: remove style (bold, underline, ..)
- * for a chat window
- */
-
-void
-gui_chat_remove_style (struct t_gui_window *window, int style)
-{
- wattroff (GUI_CURSES(window)->win_chat, style);
-}
-
-/*
- * gui_chat_toggle_style: toggle a style (bold, underline, ..)
- * for a chat window
- */
-
-void
-gui_chat_toggle_style (struct t_gui_window *window, int style)
-{
- GUI_CURSES(window)->current_style_attr ^= style;
- if (GUI_CURSES(window)->current_style_attr & style)
- gui_chat_set_style (window, style);
- else
- gui_chat_remove_style (window, style);
-}
-
-/*
- * gui_chat_reset_style: reset style (color and attr)
- * for a chat window
- */
-
-void
-gui_chat_reset_style (struct t_gui_window *window)
-{
- GUI_CURSES(window)->current_style_fg = -1;
- GUI_CURSES(window)->current_style_bg = -1;
- GUI_CURSES(window)->current_style_attr = 0;
- GUI_CURSES(window)->current_color_attr = 0;
-
- gui_window_set_weechat_color (GUI_CURSES(window)->win_chat, GUI_COLOR_CHAT);
- gui_chat_remove_style (window,
- A_BOLD | A_UNDERLINE | A_REVERSE);
-}
-
-/*
- * gui_chat_set_color_style: set style for color
- */
-
-void
-gui_chat_set_color_style (struct t_gui_window *window, int style)
-{
- GUI_CURSES(window)->current_color_attr |= style;
- wattron (GUI_CURSES(window)->win_chat, style);
-}
-
-/*
- * gui_chat_remove_color_style: remove style for color
- */
-
-void
-gui_chat_remove_color_style (struct t_gui_window *window, int style)
-{
- GUI_CURSES(window)->current_color_attr &= !style;
- wattroff (GUI_CURSES(window)->win_chat, style);
-}
-
-/*
- * gui_chat_reset_color_style: reset style for color
- */
-
-void
-gui_chat_reset_color_style (struct t_gui_window *window)
-{
- wattroff (GUI_CURSES(window)->win_chat,
- GUI_CURSES(window)->current_color_attr);
- GUI_CURSES(window)->current_color_attr = 0;
-}
-
-/*
- * gui_chat_set_color: set color for a chat window
- */
-
-void
-gui_chat_set_color (struct t_gui_window *window, int fg, int bg)
-{
- GUI_CURSES(window)->current_style_fg = fg;
- GUI_CURSES(window)->current_style_bg = bg;
-
- if (((fg == -1) || (fg == 99))
- && ((bg == -1) || (bg == 99)))
- wattron (GUI_CURSES(window)->win_chat, COLOR_PAIR(63));
- else
- {
- if ((fg == -1) || (fg == 99))
- fg = COLOR_WHITE;
- if ((bg == -1) || (bg == 99))
- bg = 0;
- wattron (GUI_CURSES(window)->win_chat, COLOR_PAIR((bg * 8) + fg));
- }
-}
-
-/*
- * gui_chat_set_weechat_color: set a WeeChat color for a chat window
- */
-
-void
-gui_chat_set_weechat_color (struct t_gui_window *window, int weechat_color)
-{
- if ((weechat_color >= 0) && (weechat_color < GUI_COLOR_NUM_COLORS))
- {
- gui_chat_reset_style (window);
- gui_chat_set_style (window,
- gui_color[weechat_color]->attributes);
- gui_chat_set_color (window,
- gui_color[weechat_color]->foreground,
- gui_color[weechat_color]->background);
- }
-}
-
-/*
- * gui_chat_set_custom_color_fg_bg: set a custom color for a chat window
- * (foreground and background)
- */
-
-void
-gui_chat_set_custom_color_fg_bg (struct t_gui_window *window, int fg, int bg)
-{
- if ((fg >= 0) && (fg < GUI_CURSES_NUM_WEECHAT_COLORS)
- && (bg >= 0) && (bg < GUI_CURSES_NUM_WEECHAT_COLORS))
- {
- gui_chat_reset_style (window);
- gui_chat_set_style (window,
- gui_weechat_colors[fg].attributes);
- gui_chat_set_color (window,
- gui_weechat_colors[fg].foreground,
- gui_weechat_colors[bg].foreground);
- }
-}
-
-/*
- * gui_chat_set_custom_color_fg: set a custom color for a chat window
- * (foreground only)
- */
-
-void
-gui_chat_set_custom_color_fg (struct t_gui_window *window, int fg)
-{
- int current_attr, current_bg;
-
- if ((fg >= 0) && (fg < GUI_CURSES_NUM_WEECHAT_COLORS))
- {
- current_attr = GUI_CURSES(window)->current_style_attr;
- current_bg = GUI_CURSES(window)->current_style_bg;
- gui_chat_reset_style (window);
- gui_chat_set_color_style (window, current_attr);
- gui_chat_remove_color_style (window, A_BOLD);
- gui_chat_set_color_style (window, gui_weechat_colors[fg].attributes);
- gui_chat_set_color (window,
- gui_weechat_colors[fg].foreground,
- current_bg);
- }
-}
-
-/*
- * gui_chat_set_custom_color_bg: set a custom color for a chat window
- * (background only)
- */
-
-void
-gui_chat_set_custom_color_bg (struct t_gui_window *window, int bg)
-{
- int current_attr, current_fg;
-
- if ((bg >= 0) && (bg < GUI_CURSES_NUM_WEECHAT_COLORS))
- {
- current_attr = GUI_CURSES(window)->current_style_attr;
- current_fg = GUI_CURSES(window)->current_style_fg;
- gui_chat_reset_style (window);
- gui_chat_set_color_style (window, current_attr);
- gui_chat_set_color (window,
- current_fg,
- gui_weechat_colors[bg].foreground);
- }
-}
-
-/*
* gui_chat_draw_title: draw title window for a buffer
*/
@@ -258,7 +62,8 @@ gui_chat_draw_title (struct t_gui_buffer *buffer, int erase)
if (ptr_win->buffer == buffer)
{
if (erase)
- gui_window_curses_clear (GUI_CURSES(ptr_win)->win_title, GUI_COLOR_TITLE);
+ gui_window_clear_weechat (GUI_CURSES(ptr_win)->win_title,
+ GUI_COLOR_TITLE);
snprintf (format, sizeof (format), "%%-%ds", ptr_win->win_title_width);
wmove (GUI_CURSES(ptr_win)->win_title, 0, 0);
@@ -380,7 +185,7 @@ gui_chat_string_next_char (struct t_gui_window *window, unsigned char *string,
case GUI_COLOR_RESET_CHAR:
string++;
if (apply_style)
- gui_chat_reset_style (window);
+ gui_window_reset_style (GUI_CURSES(window)->win_chat, GUI_COLOR_CHAT);
break;
case GUI_COLOR_COLOR_CHAR:
string++;
@@ -395,7 +200,8 @@ gui_chat_string_next_char (struct t_gui_window *window, unsigned char *string,
str_fg[1] = string[2];
str_fg[2] = '\0';
sscanf (str_fg, "%d", &fg);
- gui_chat_set_custom_color_fg (window, fg);
+ gui_window_set_custom_color_fg (GUI_CURSES(window)->win_chat,
+ fg);
}
string += 3;
}
@@ -409,7 +215,8 @@ gui_chat_string_next_char (struct t_gui_window *window, unsigned char *string,
str_bg[1] = string[2];
str_bg[2] = '\0';
sscanf (str_bg, "%d", &bg);
- gui_chat_set_custom_color_bg (window, bg);
+ gui_window_set_custom_color_bg (GUI_CURSES(window)->win_chat,
+ bg);
}
string += 3;
}
@@ -428,7 +235,8 @@ gui_chat_string_next_char (struct t_gui_window *window, unsigned char *string,
str_bg[2] = '\0';
sscanf (str_fg, "%d", &fg);
sscanf (str_bg, "%d", &bg);
- gui_chat_set_custom_color_fg_bg (window, fg, bg);
+ gui_window_set_custom_color_fg_bg (GUI_CURSES(window)->win_chat,
+ fg, bg);
}
string += 6;
}
@@ -442,7 +250,8 @@ gui_chat_string_next_char (struct t_gui_window *window, unsigned char *string,
str_fg[1] = string[1];
str_fg[2] = '\0';
sscanf (str_fg, "%d", &weechat_color);
- gui_chat_set_weechat_color (window, weechat_color);
+ gui_window_set_weechat_color (GUI_CURSES(window)->win_chat,
+ weechat_color);
}
string += 2;
}
@@ -456,12 +265,14 @@ gui_chat_string_next_char (struct t_gui_window *window, unsigned char *string,
case GUI_COLOR_ATTR_BOLD_CHAR:
string++;
if (apply_style)
- gui_chat_set_color_style (window, A_BOLD);
+ gui_window_set_color_style (GUI_CURSES(window)->win_chat,
+ A_BOLD);
break;
case GUI_COLOR_ATTR_REVERSE_CHAR:
string++;
if (apply_style)
- gui_chat_set_color_style (window, A_REVERSE);
+ gui_window_set_color_style (GUI_CURSES(window)->win_chat,
+ A_REVERSE);
break;
case GUI_COLOR_ATTR_ITALIC_CHAR:
/* not available in Curses GUI */
@@ -470,7 +281,8 @@ gui_chat_string_next_char (struct t_gui_window *window, unsigned char *string,
case GUI_COLOR_ATTR_UNDERLINE_CHAR:
string++;
if (apply_style)
- gui_chat_set_color_style (window, A_UNDERLINE);
+ gui_window_set_color_style (GUI_CURSES(window)->win_chat,
+ A_UNDERLINE);
break;
}
break;
@@ -481,12 +293,14 @@ gui_chat_string_next_char (struct t_gui_window *window, unsigned char *string,
case GUI_COLOR_ATTR_BOLD_CHAR:
string++;
if (apply_style)
- gui_chat_remove_color_style (window, A_BOLD);
+ gui_window_remove_color_style (GUI_CURSES(window)->win_chat,
+ A_BOLD);
break;
case GUI_COLOR_ATTR_REVERSE_CHAR:
string++;
if (apply_style)
- gui_chat_remove_color_style (window, A_REVERSE);
+ gui_window_remove_color_style (GUI_CURSES(window)->win_chat,
+ A_REVERSE);
break;
case GUI_COLOR_ATTR_ITALIC_CHAR:
/* not available in Curses GUI */
@@ -495,7 +309,8 @@ gui_chat_string_next_char (struct t_gui_window *window, unsigned char *string,
case GUI_COLOR_ATTR_UNDERLINE_CHAR:
string++;
if (apply_style)
- gui_chat_remove_color_style (window, A_UNDERLINE);
+ gui_window_remove_color_style (GUI_CURSES(window)->win_chat,
+ A_UNDERLINE);
break;
}
break;
@@ -630,7 +445,8 @@ gui_chat_display_word (struct t_gui_window *window,
{
if (!simulate)
{
- gui_chat_set_weechat_color (window, GUI_COLOR_CHAT_PREFIX_SUFFIX);
+ gui_window_set_weechat_color (GUI_CURSES(window)->win_chat,
+ GUI_COLOR_CHAT_PREFIX_SUFFIX);
gui_chat_display_word_raw (window,
CONFIG_STRING(config_look_prefix_suffix),
0, 1);
@@ -640,7 +456,8 @@ gui_chat_display_word (struct t_gui_window *window,
gui_chat_display_word_raw (window, str_space, 0, 1);
window->win_chat_cursor_x += gui_chat_strlen_screen (str_space);
if (!simulate)
- gui_chat_set_weechat_color (window, GUI_COLOR_CHAT);
+ gui_window_set_weechat_color (GUI_CURSES(window)->win_chat,
+ GUI_COLOR_CHAT);
}
}
@@ -713,7 +530,7 @@ gui_chat_display_time_and_prefix (struct t_gui_window *window,
if (line->str_time && line->str_time[0])
{
if (!simulate)
- gui_chat_reset_style (window);
+ gui_window_reset_style (GUI_CURSES(window)->win_chat, GUI_COLOR_CHAT);
gui_chat_display_word (window, line, line->str_time,
NULL, 1, num_lines, count, lines_displayed,
@@ -729,7 +546,7 @@ gui_chat_display_time_and_prefix (struct t_gui_window *window,
|| (CONFIG_INTEGER(config_look_prefix_align) != CONFIG_LOOK_PREFIX_ALIGN_NONE)))
{
if (!simulate)
- gui_chat_reset_style (window);
+ gui_window_reset_style (GUI_CURSES(window)->win_chat, GUI_COLOR_CHAT);
if (CONFIG_INTEGER(config_look_prefix_align_max) > 0)
{
@@ -770,7 +587,7 @@ gui_chat_display_time_and_prefix (struct t_gui_window *window,
}
if (!simulate)
- gui_chat_reset_style (window);
+ gui_window_reset_style (GUI_CURSES(window)->win_chat, GUI_COLOR_CHAT);
if (CONFIG_INTEGER(config_look_prefix_align) == CONFIG_LOOK_PREFIX_ALIGN_LEFT)
{
@@ -785,7 +602,8 @@ gui_chat_display_time_and_prefix (struct t_gui_window *window,
&& (num_spaces < 0))
{
if (!simulate)
- gui_chat_set_weechat_color (window, GUI_COLOR_CHAT_PREFIX_MORE);
+ gui_window_set_weechat_color (GUI_CURSES(window)->win_chat,
+ GUI_COLOR_CHAT_PREFIX_MORE);
gui_chat_display_word (window, line, str_plus,
NULL, 1, num_lines, count, lines_displayed,
simulate);
@@ -801,7 +619,8 @@ gui_chat_display_time_and_prefix (struct t_gui_window *window,
&& CONFIG_STRING(config_look_prefix_suffix)[0]))
{
if (!simulate)
- gui_chat_set_weechat_color (window, GUI_COLOR_CHAT_PREFIX_SUFFIX);
+ gui_window_set_weechat_color (GUI_CURSES(window)->win_chat,
+ GUI_COLOR_CHAT_PREFIX_SUFFIX);
gui_chat_display_word (window, line,
CONFIG_STRING(config_look_prefix_suffix),
NULL, 1, num_lines, count,
@@ -869,7 +688,7 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line,
/* reset color & style for a new line */
if (!simulate)
- gui_chat_reset_style (window);
+ gui_window_reset_style (GUI_CURSES(window)->win_chat, GUI_COLOR_CHAT);
if (!line->message || !line->message[0])
gui_chat_display_new_line (window, num_lines, count,
@@ -969,8 +788,8 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line,
if (gui_chat_line_search (line, window->buffer->input_buffer,
window->buffer->text_search_exact))
{
- gui_chat_set_weechat_color (window,
- GUI_COLOR_CHAT_READ_MARKER);
+ gui_window_set_weechat_color (GUI_CURSES(window)->win_chat,
+ GUI_COLOR_CHAT_READ_MARKER);
mvwprintw (GUI_CURSES(window)->win_chat,
read_marker_y, read_marker_x,
"%c", CONFIG_STRING(config_look_read_marker)[0]);
@@ -982,8 +801,8 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line,
if (window->buffer->last_read_line &&
(window->buffer->last_read_line == gui_chat_get_prev_line_displayed (line)))
{
- gui_chat_set_weechat_color (window,
- GUI_COLOR_CHAT_READ_MARKER);
+ gui_window_set_weechat_color (GUI_CURSES(window)->win_chat,
+ GUI_COLOR_CHAT_READ_MARKER);
mvwprintw (GUI_CURSES(window)->win_chat,
read_marker_y, read_marker_x,
"%c", CONFIG_STRING(config_look_read_marker)[0]);
@@ -1004,10 +823,8 @@ void
gui_chat_display_line_y (struct t_gui_window *window, struct t_gui_line *line,
int y)
{
- int pair;
-
/* reset color & style for a new line */
- gui_chat_reset_style (window);
+ gui_window_reset_style (GUI_CURSES(window)->win_chat, GUI_COLOR_CHAT);
window->win_chat_cursor_x = 0;
window->win_chat_cursor_y = y;
@@ -1020,10 +837,7 @@ gui_chat_display_line_y (struct t_gui_window *window, struct t_gui_line *line,
gui_chat_display_word_raw (window, line->message,
window->win_chat_width, 1);
- pair = (GUI_CURSES(window)->current_style_bg < 0) ?
- 63 : GUI_CURSES(window)->current_style_bg * 8;
- wbkgdset (GUI_CURSES(window)->win_chat, ' ' | COLOR_PAIR (pair));
- wclrtoeol (GUI_CURSES(window)->win_chat);
+ gui_window_clrtoeol_with_current_bg (GUI_CURSES(window)->win_chat);
}
/*
diff --git a/src/gui/curses/gui-curses-infobar.c b/src/gui/curses/gui-curses-infobar.c
index 94a222136..f4a7d04f8 100644
--- a/src/gui/curses/gui-curses-infobar.c
+++ b/src/gui/curses/gui-curses-infobar.c
@@ -98,8 +98,8 @@ gui_infobar_draw (struct t_gui_buffer *buffer, int erase)
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
{
if (erase)
- gui_window_curses_clear (GUI_CURSES(ptr_win)->win_infobar,
- GUI_COLOR_INFOBAR);
+ gui_window_clear_weechat (GUI_CURSES(ptr_win)->win_infobar,
+ GUI_COLOR_INFOBAR);
gui_window_set_weechat_color (GUI_CURSES(ptr_win)->win_infobar,
GUI_COLOR_INFOBAR);
diff --git a/src/gui/curses/gui-curses-input.c b/src/gui/curses/gui-curses-input.c
index 8a871e19a..dd027e2a3 100644
--- a/src/gui/curses/gui-curses-input.c
+++ b/src/gui/curses/gui-curses-input.c
@@ -289,8 +289,8 @@ gui_input_draw (struct t_gui_buffer *buffer, int erase)
if (ptr_win->buffer == buffer)
{
if (erase)
- gui_window_curses_clear (GUI_CURSES(ptr_win)->win_input,
- GUI_COLOR_INPUT);
+ gui_window_clear_weechat (GUI_CURSES(ptr_win)->win_input,
+ GUI_COLOR_INPUT);
if (gui_keyboard_paste_pending)
{
diff --git a/src/gui/curses/gui-curses-status.c b/src/gui/curses/gui-curses-status.c
index 93125d639..5117752b2 100644
--- a/src/gui/curses/gui-curses-status.c
+++ b/src/gui/curses/gui-curses-status.c
@@ -58,8 +58,8 @@ gui_status_draw (int erase)
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
{
if (erase)
- gui_window_curses_clear (GUI_CURSES(ptr_win)->win_status,
- GUI_COLOR_STATUS);
+ gui_window_clear_weechat (GUI_CURSES(ptr_win)->win_status,
+ GUI_COLOR_STATUS);
gui_window_set_weechat_color (GUI_CURSES(ptr_win)->win_status,
GUI_COLOR_STATUS);
diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c
index 68207c6d5..adff0e7fb 100644
--- a/src/gui/curses/gui-curses-window.c
+++ b/src/gui/curses/gui-curses-window.c
@@ -46,6 +46,12 @@
#include "gui-curses.h"
+int current_style_fg; /* current foreground color */
+int current_style_bg; /* current background color */
+int current_style_attr; /* current attributes (bold, ..) */
+int current_color_attr; /* attr sum of last color(s) used */
+
+
/*
* gui_window_get_width: get screen width (terminal width in chars for Curses)
*/
@@ -185,11 +191,11 @@ gui_window_wprintw (WINDOW *window, char *data, ...)
}
/*
- * gui_window_curses_clear: clear a Curses window
+ * gui_window_curses_clear_weechat: clear a Curses window with a weechat color
*/
void
-gui_window_curses_clear (WINDOW *window, int num_color)
+gui_window_clear_weechat (WINDOW *window, int num_color)
{
if (!gui_ok)
return;
@@ -200,6 +206,91 @@ gui_window_curses_clear (WINDOW *window, int num_color)
}
/*
+ * gui_window_clear: clear a Curses window
+ */
+
+void
+gui_window_clear (WINDOW *window, int bg)
+{
+ int color;
+
+ if (!gui_ok)
+ return;
+
+ if ((bg >= 0) && (bg < GUI_CURSES_NUM_WEECHAT_COLORS))
+ {
+ color = gui_weechat_colors[bg].foreground;
+ wbkgdset (window,
+ ' ' | COLOR_PAIR (((color == -1) || (color == 99)) ?
+ 63 : color * 8));
+ werase (window);
+ wmove (window, 0, 0);
+ }
+}
+
+/*
+ * gui_window_reset_style: reset style (color and attr) for a window
+ */
+
+void
+gui_window_reset_style (WINDOW *window, int num_color)
+{
+ current_style_fg = -1;
+ current_style_bg = -1;
+ current_style_attr = 0;
+ current_color_attr = 0;
+
+ wattron (window, COLOR_PAIR(gui_color_get_pair (num_color)) |
+ gui_color[num_color]->attributes);
+ wattroff (window, A_BOLD | A_UNDERLINE | A_REVERSE);
+}
+
+/*
+ * gui_window_set_color_style: set style for color
+ */
+
+void
+gui_window_set_color_style (WINDOW *window, int style)
+{
+ current_color_attr |= style;
+ wattron (window, style);
+}
+
+/*
+ * gui_window_remove_color_style: remove style for color
+ */
+
+void
+gui_window_remove_color_style (WINDOW *window, int style)
+{
+ current_color_attr &= !style;
+ wattroff (window, style);
+}
+
+/*
+ * gui_window_set_color: set color for a window
+ */
+
+void
+gui_window_set_color (WINDOW *window, int fg, int bg)
+{
+ current_style_fg = fg;
+ current_style_bg = bg;
+
+ if (((fg == -1) || (fg == 99))
+ && ((bg == -1) || (bg == 99)))
+ wattron (window, COLOR_PAIR(63));
+ else
+ {
+ if ((fg == -1) || (fg == 99))
+ fg = COLOR_WHITE;
+ if ((bg == -1) || (bg == 99))
+ bg = 0;
+ wattron (window, COLOR_PAIR((bg * 8) + fg));
+ }
+}
+
+/*
* gui_window_set_weechat_color: set WeeChat color for window
*/
@@ -208,13 +299,92 @@ gui_window_set_weechat_color (WINDOW *window, int num_color)
{
if ((num_color >= 0) && (num_color < GUI_COLOR_NUM_COLORS))
{
+ /*
wattroff (window, A_BOLD | A_UNDERLINE | A_REVERSE);
wattron (window, COLOR_PAIR(gui_color_get_pair (num_color)) |
gui_color[num_color]->attributes);
+ */
+ gui_window_reset_style (window, num_color);
+ wattron (window, gui_color[num_color]->attributes);
+ gui_window_set_color (window,
+ gui_color[num_color]->foreground,
+ gui_color[num_color]->background);
}
}
/*
+ * gui_window_set_custom_color_fg_bg: set a custom color for a window
+ * (foreground and background)
+ */
+
+void
+gui_window_set_custom_color_fg_bg (WINDOW *window, int fg, int bg)
+{
+ if ((fg >= 0) && (fg < GUI_CURSES_NUM_WEECHAT_COLORS)
+ && (bg >= 0) && (bg < GUI_CURSES_NUM_WEECHAT_COLORS))
+ {
+ wattron (window, gui_weechat_colors[fg].attributes);
+ gui_window_set_color (window,
+ gui_weechat_colors[fg].foreground,
+ gui_weechat_colors[bg].foreground);
+ }
+}
+
+/*
+ * gui_window_set_custom_color_fg: set a custom color for a window
+ * (foreground only)
+ */
+
+void
+gui_window_set_custom_color_fg (WINDOW *window, int fg)
+{
+ int current_attr, current_bg;
+
+ if ((fg >= 0) && (fg < GUI_CURSES_NUM_WEECHAT_COLORS))
+ {
+ current_attr = current_style_attr;
+ current_bg = current_style_bg;
+ gui_window_remove_color_style (window, A_BOLD);
+ gui_window_set_color_style (window, gui_weechat_colors[fg].attributes);
+ gui_window_set_color (window,
+ gui_weechat_colors[fg].foreground,
+ current_bg);
+ }
+}
+
+/*
+ * gui_window_set_custom_color_bg: set a custom color for a window
+ * (background only)
+ */
+
+void
+gui_window_set_custom_color_bg (WINDOW *window, int bg)
+{
+ int current_attr, current_fg;
+
+ if ((bg >= 0) && (bg < GUI_CURSES_NUM_WEECHAT_COLORS))
+ {
+ current_attr = current_style_attr;
+ current_fg = current_style_fg;
+ gui_window_set_color_style (window, current_attr);
+ gui_window_set_color (window, current_fg,
+ gui_weechat_colors[bg].foreground);
+ }
+}
+
+/*
+ * gui_window_clrtoeol_with_current_bg: clear until end of line with current bg
+ */
+
+void
+gui_window_clrtoeol_with_current_bg (WINDOW *window)
+{
+ wbkgdset (window,
+ ' ' | COLOR_PAIR ((current_style_bg < 0) ? 63 : current_style_bg * 8));
+ wclrtoeol (window);
+}
+
+/*
* gui_window_calculate_pos_size: calculate position and size for a buffer & subwindows
* return 1 if pos/size changed, 0 if no change
*/
@@ -1694,10 +1864,6 @@ gui_window_objects_print_log (struct t_gui_window *window)
log_printf (" win_separator . . . : 0x%x", GUI_CURSES(window)->win_separator);
log_printf (" bar_windows . . . . : 0x%x", GUI_CURSES(window)->bar_windows);
log_printf (" last_bar_windows. . : 0x%x", GUI_CURSES(window)->last_bar_window);
- log_printf (" current_style_fg. . : %d", GUI_CURSES(window)->current_style_fg);
- log_printf (" current_style_bg. . : %d", GUI_CURSES(window)->current_style_bg);
- log_printf (" current_style_attr. : %d", GUI_CURSES(window)->current_style_attr);
- log_printf (" current_color_attr. : %d", GUI_CURSES(window)->current_color_attr);
for (ptr_bar_win = GUI_CURSES(window)->bar_windows; ptr_bar_win;
ptr_bar_win = ptr_bar_win->next_bar_window)
diff --git a/src/gui/curses/gui-curses.h b/src/gui/curses/gui-curses.h
index 3a2d9d3e4..02c9d7987 100644
--- a/src/gui/curses/gui-curses.h
+++ b/src/gui/curses/gui-curses.h
@@ -62,10 +62,6 @@ struct t_gui_curses_objects
WINDOW *win_separator; /* separation between 2 splited (V) win */
struct t_gui_bar_window *bar_windows; /* bar windows */
struct t_gui_bar_window *last_bar_window; /* last bar window */
- int current_style_fg; /* current foreground color */
- int current_style_bg; /* current background color */
- int current_style_attr; /* current attributes (bold, ..) */
- int current_color_attr; /* attr sum of last color(s) used */
};
extern struct t_gui_color gui_weechat_colors[];
@@ -95,8 +91,17 @@ extern int gui_keyboard_read_cb (void *data);
/* window functions */
extern int gui_window_utf_char_valid (char *utf_char);
extern void gui_window_wprintw (WINDOW *window, char *data, ...);
-extern void gui_window_curses_clear (WINDOW *window, int num_color);
+extern void gui_window_clear_weechat (WINDOW *window, int num_color);
+extern void gui_window_clear (WINDOW *window, int bg);
+extern void gui_window_reset_style (WINDOW *window, int num_color);
+extern void gui_window_set_color_style (WINDOW *window, int style);
+extern void gui_window_remove_color_style (WINDOW *window, int style);
+extern void gui_window_set_color (WINDOW *window, int fg, int bg);
extern void gui_window_set_weechat_color (WINDOW *window, int num_color);
+extern void gui_window_set_custom_color_fg_bg (WINDOW *window, int fg, int bg);
+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_clrtoeol_with_current_bg (WINDOW *window);
extern void gui_window_refresh_screen_sigwinch ();
extern void gui_window_title_set ();
extern void gui_window_title_reset ();