mirror of
https://github.com/weechat/weechat.git
synced 2026-06-30 23:06:38 +02:00
Factorize code used to apply color codes in strings (for chat and bars)
This commit is contained in:
@@ -27,7 +27,6 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "../../core/weechat.h"
|
||||
@@ -155,10 +154,8 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
|
||||
int reset_color_before_display,
|
||||
int hide_chars_if_scrolling)
|
||||
{
|
||||
int weechat_color, x_with_hidden, size_on_screen, fg, bg, low_char, hidden;
|
||||
int pair;
|
||||
char str_fg[6], str_bg[6], str_pair[6], utf_char[16], *next_char, *output;
|
||||
char *error;
|
||||
int x_with_hidden, size_on_screen, low_char, hidden;
|
||||
char utf_char[16], *next_char, *output;
|
||||
|
||||
if (!string || !string[0])
|
||||
return 1;
|
||||
@@ -185,189 +182,45 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
|
||||
switch (string[0])
|
||||
{
|
||||
case GUI_COLOR_FG_CHAR: /* fg color */
|
||||
if (string[1] == GUI_COLOR_EXTENDED_CHAR)
|
||||
{
|
||||
if (string[2] && string[3] && string[4]
|
||||
&& string[5] && string[6])
|
||||
{
|
||||
memcpy (str_fg, string + 2, 5);
|
||||
str_fg[5] = '\0';
|
||||
error = NULL;
|
||||
fg = (int)strtol (str_fg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
fg | GUI_COLOR_EXTENDED_FLAG);
|
||||
}
|
||||
string += 7;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string[1] && string[2])
|
||||
{
|
||||
str_fg[0] = string[1];
|
||||
str_fg[1] = string[2];
|
||||
str_fg[2] = '\0';
|
||||
error = NULL;
|
||||
fg = (int)strtol (str_fg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
fg);
|
||||
}
|
||||
string += 3;
|
||||
}
|
||||
}
|
||||
string++;
|
||||
gui_window_string_apply_color_fg ((unsigned char **)&string,
|
||||
GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar);
|
||||
break;
|
||||
case GUI_COLOR_BG_CHAR: /* bg color */
|
||||
if (string[1] == GUI_COLOR_EXTENDED_CHAR)
|
||||
{
|
||||
if (string[2] && string[3] && string[4]
|
||||
&& string[5] && string[6])
|
||||
{
|
||||
memcpy (str_bg, string + 2, 5);
|
||||
str_bg[5] = '\0';
|
||||
error = NULL;
|
||||
bg = (int)strtol (str_bg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
bg | GUI_COLOR_EXTENDED_FLAG);
|
||||
}
|
||||
string += 7;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string[1] && string[2])
|
||||
{
|
||||
str_bg[0] = string[1];
|
||||
str_bg[1] = string[2];
|
||||
str_bg[2] = '\0';
|
||||
error = NULL;
|
||||
bg = (int)strtol (str_bg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
bg);
|
||||
}
|
||||
string += 3;
|
||||
}
|
||||
}
|
||||
string++;
|
||||
gui_window_string_apply_color_bg ((unsigned char **)&string,
|
||||
GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar);
|
||||
break;
|
||||
case GUI_COLOR_FG_BG_CHAR: /* fg + bg color */
|
||||
str_fg[0] = '\0';
|
||||
str_bg[0] = '\0';
|
||||
fg = -1;
|
||||
bg = -1;
|
||||
if (string[1] == GUI_COLOR_EXTENDED_CHAR)
|
||||
{
|
||||
if (string[2] && string[3] && string[4]
|
||||
&& string[5] && string[6])
|
||||
{
|
||||
memcpy (str_fg, string + 2, 5);
|
||||
str_fg[5] = '\0';
|
||||
error = NULL;
|
||||
fg = (int)strtol (str_fg, &error, 10);
|
||||
if (!error || error[0])
|
||||
fg = -1;
|
||||
else
|
||||
fg |= GUI_COLOR_EXTENDED_FLAG;
|
||||
string += 7;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string[1] && string[2])
|
||||
{
|
||||
str_fg[0] = string[1];
|
||||
str_fg[1] = string[2];
|
||||
str_fg[2] = '\0';
|
||||
error = NULL;
|
||||
fg = (int)strtol (str_fg, &error, 10);
|
||||
if (!error || error[0])
|
||||
fg = -1;
|
||||
string += 3;
|
||||
}
|
||||
}
|
||||
if (string[0] == ',')
|
||||
{
|
||||
string++;
|
||||
if (string[0] == GUI_COLOR_EXTENDED_CHAR)
|
||||
{
|
||||
if (string[1] && string[2] && string[3]
|
||||
&& string[4] && string[5])
|
||||
{
|
||||
memcpy (str_bg, string + 1, 5);
|
||||
str_bg[5] = '\0';
|
||||
error = NULL;
|
||||
bg = (int)strtol (str_bg, &error, 10);
|
||||
if (!error || error[0])
|
||||
bg = -1;
|
||||
else
|
||||
bg |= GUI_COLOR_EXTENDED_FLAG;
|
||||
string += 6;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string[0] && string[1])
|
||||
{
|
||||
str_bg[0] = string[0];
|
||||
str_bg[1] = string[1];
|
||||
str_bg[2] = '\0';
|
||||
error = NULL;
|
||||
bg = (int)strtol (str_bg, &error, 10);
|
||||
if (!error || error[0])
|
||||
bg = -1;
|
||||
string += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((fg >= 0) && (bg >= 0))
|
||||
{
|
||||
gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
fg, bg);
|
||||
}
|
||||
string++;
|
||||
gui_window_string_apply_color_fg_bg ((unsigned char **)&string,
|
||||
GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar);
|
||||
break;
|
||||
case GUI_COLOR_EXTENDED_CHAR: /* pair number */
|
||||
if ((isdigit (string[1])) && (isdigit (string[2]))
|
||||
&& (isdigit (string[3])) && (isdigit (string[4]))
|
||||
&& (isdigit (string[5])))
|
||||
{
|
||||
memcpy (str_pair, string + 1, 5);
|
||||
str_pair[5] = '\0';
|
||||
error = NULL;
|
||||
pair = (int)strtol (str_pair, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_pair (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
pair);
|
||||
}
|
||||
string += 6;
|
||||
}
|
||||
string++;
|
||||
gui_window_string_apply_color_pair ((unsigned char **)&string,
|
||||
GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar);
|
||||
break;
|
||||
case GUI_COLOR_BAR_CHAR: /* bar color */
|
||||
switch (string[1])
|
||||
{
|
||||
case GUI_COLOR_BAR_FG_CHAR:
|
||||
/* bar foreground */
|
||||
string += 2;
|
||||
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG]));
|
||||
string += 2;
|
||||
break;
|
||||
case GUI_COLOR_BAR_DELIM_CHAR:
|
||||
/* bar delimiter */
|
||||
string += 2;
|
||||
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_DELIM]));
|
||||
string += 2;
|
||||
break;
|
||||
case GUI_COLOR_BAR_BG_CHAR:
|
||||
/* bar background */
|
||||
string += 2;
|
||||
gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
|
||||
string += 2;
|
||||
break;
|
||||
case GUI_COLOR_BAR_START_INPUT_CHAR:
|
||||
string += 2;
|
||||
@@ -379,12 +232,12 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
|
||||
break;
|
||||
case GUI_COLOR_BAR_MOVE_CURSOR_CHAR:
|
||||
/* move cursor to current position on screen */
|
||||
string += 2;
|
||||
getyx (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
bar_window->cursor_y,
|
||||
bar_window->cursor_x);
|
||||
bar_window->cursor_x += bar_window->x;
|
||||
bar_window->cursor_y += bar_window->y;
|
||||
string += 2;
|
||||
break;
|
||||
default:
|
||||
string++;
|
||||
@@ -392,81 +245,29 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (isdigit (string[0]) && isdigit (string[1]))
|
||||
{
|
||||
str_fg[0] = string[0];
|
||||
str_fg[1] = string[1];
|
||||
str_fg[2] = '\0';
|
||||
error = NULL;
|
||||
weechat_color = (int)strtol (str_fg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_weechat_color (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
weechat_color);
|
||||
}
|
||||
string += 2;
|
||||
}
|
||||
gui_window_string_apply_color_weechat ((unsigned char **)&string,
|
||||
GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case GUI_COLOR_SET_WEECHAT_CHAR:
|
||||
string++;
|
||||
gui_window_string_apply_color_set ((unsigned char **)&string,
|
||||
GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar);
|
||||
break;
|
||||
case GUI_COLOR_REMOVE_WEECHAT_CHAR:
|
||||
string++;
|
||||
gui_window_string_apply_color_remove ((unsigned char **)&string,
|
||||
GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar);
|
||||
break;
|
||||
case GUI_COLOR_RESET_CHAR:
|
||||
string++;
|
||||
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG]));
|
||||
gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
|
||||
gui_window_remove_color_style (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
A_BOLD | A_UNDERLINE | A_REVERSE);
|
||||
string++;
|
||||
break;
|
||||
case GUI_COLOR_SET_WEECHAT_CHAR:
|
||||
string++;
|
||||
switch (string[0])
|
||||
{
|
||||
case GUI_COLOR_ATTR_BOLD_CHAR:
|
||||
string++;
|
||||
gui_window_set_color_style (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
A_BOLD);
|
||||
break;
|
||||
case GUI_COLOR_ATTR_REVERSE_CHAR:
|
||||
string++;
|
||||
gui_window_set_color_style (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
A_REVERSE);
|
||||
break;
|
||||
case GUI_COLOR_ATTR_ITALIC_CHAR:
|
||||
/* not available in Curses GUI */
|
||||
string++;
|
||||
break;
|
||||
case GUI_COLOR_ATTR_UNDERLINE_CHAR:
|
||||
string++;
|
||||
gui_window_set_color_style (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
A_UNDERLINE);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case GUI_COLOR_REMOVE_WEECHAT_CHAR:
|
||||
string++;
|
||||
switch (string[0])
|
||||
{
|
||||
case GUI_COLOR_ATTR_BOLD_CHAR:
|
||||
string++;
|
||||
gui_window_remove_color_style (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
A_BOLD);
|
||||
break;
|
||||
case GUI_COLOR_ATTR_REVERSE_CHAR:
|
||||
string++;
|
||||
gui_window_remove_color_style (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
A_REVERSE);
|
||||
break;
|
||||
case GUI_COLOR_ATTR_ITALIC_CHAR:
|
||||
/* not available in Curses GUI */
|
||||
string++;
|
||||
break;
|
||||
case GUI_COLOR_ATTR_UNDERLINE_CHAR:
|
||||
string++;
|
||||
gui_window_remove_color_style (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
A_UNDERLINE);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
next_char = utf8_next_char (string);
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "../../core/weechat.h"
|
||||
#include "../../core/wee-config.h"
|
||||
@@ -172,215 +171,37 @@ char *
|
||||
gui_chat_string_next_char (struct t_gui_window *window,
|
||||
const unsigned char *string, int apply_style)
|
||||
{
|
||||
char str_fg[6], str_bg[6], str_pair[6], *error;
|
||||
int weechat_color, fg, bg, pair;
|
||||
|
||||
while (string[0])
|
||||
{
|
||||
switch (string[0])
|
||||
{
|
||||
case GUI_COLOR_RESET_CHAR:
|
||||
string++;
|
||||
if (apply_style)
|
||||
gui_window_reset_style (GUI_WINDOW_OBJECTS(window)->win_chat, GUI_COLOR_CHAT);
|
||||
break;
|
||||
case GUI_COLOR_COLOR_CHAR:
|
||||
string++;
|
||||
switch (string[0])
|
||||
{
|
||||
case GUI_COLOR_FG_CHAR: /* fg color */
|
||||
if (string[1] == GUI_COLOR_EXTENDED_CHAR)
|
||||
{
|
||||
if (string[2] && string[3] && string[4]
|
||||
&& string[5] && string[6])
|
||||
{
|
||||
if (apply_style)
|
||||
{
|
||||
memcpy (str_fg, string + 2, 5);
|
||||
str_fg[5] = '\0';
|
||||
error = NULL;
|
||||
fg = (int)strtol (str_fg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_fg (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
fg | GUI_COLOR_EXTENDED_FLAG);
|
||||
}
|
||||
}
|
||||
string += 7;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string[1] && string[2])
|
||||
{
|
||||
if (apply_style)
|
||||
{
|
||||
str_fg[0] = string[1];
|
||||
str_fg[1] = string[2];
|
||||
str_fg[2] = '\0';
|
||||
error = NULL;
|
||||
fg = (int)strtol (str_fg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_fg (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
fg);
|
||||
}
|
||||
}
|
||||
string += 3;
|
||||
}
|
||||
}
|
||||
string++;
|
||||
gui_window_string_apply_color_fg ((unsigned char **)&string,
|
||||
(apply_style) ? GUI_WINDOW_OBJECTS(window)->win_chat : NULL);
|
||||
break;
|
||||
case GUI_COLOR_BG_CHAR: /* bg color */
|
||||
if (string[1] == GUI_COLOR_EXTENDED_CHAR)
|
||||
{
|
||||
if (string[2] && string[3] && string[4]
|
||||
&& string[5] && string[6])
|
||||
{
|
||||
if (apply_style)
|
||||
{
|
||||
memcpy (str_bg, string + 2, 5);
|
||||
str_bg[5] = '\0';
|
||||
error = NULL;
|
||||
bg = (int)strtol (str_bg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_bg (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
bg | GUI_COLOR_EXTENDED_FLAG);
|
||||
}
|
||||
}
|
||||
string += 7;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string[1] && string[2])
|
||||
{
|
||||
if (apply_style)
|
||||
{
|
||||
str_bg[0] = string[1];
|
||||
str_bg[1] = string[2];
|
||||
str_bg[2] = '\0';
|
||||
error = NULL;
|
||||
bg = (int)strtol (str_bg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_bg (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
bg);
|
||||
}
|
||||
}
|
||||
string += 3;
|
||||
}
|
||||
}
|
||||
string++;
|
||||
gui_window_string_apply_color_bg ((unsigned char **)&string,
|
||||
(apply_style) ? GUI_WINDOW_OBJECTS(window)->win_chat : NULL);
|
||||
break;
|
||||
case GUI_COLOR_FG_BG_CHAR: /* fg + bg color */
|
||||
str_fg[0] = '\0';
|
||||
str_bg[0] = '\0';
|
||||
fg = -1;
|
||||
bg = -1;
|
||||
if (string[1] == GUI_COLOR_EXTENDED_CHAR)
|
||||
{
|
||||
if (string[2] && string[3] && string[4]
|
||||
&& string[5] && string[6])
|
||||
{
|
||||
if (apply_style)
|
||||
{
|
||||
memcpy (str_fg, string + 2, 5);
|
||||
str_fg[5] = '\0';
|
||||
error = NULL;
|
||||
fg = (int)strtol (str_fg, &error, 10);
|
||||
if (!error || error[0])
|
||||
fg = -1;
|
||||
else
|
||||
fg |= GUI_COLOR_EXTENDED_FLAG;
|
||||
}
|
||||
string += 7;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string[1] && string[2])
|
||||
{
|
||||
if (apply_style)
|
||||
{
|
||||
str_fg[0] = string[1];
|
||||
str_fg[1] = string[2];
|
||||
str_fg[2] = '\0';
|
||||
error = NULL;
|
||||
fg = (int)strtol (str_fg, &error, 10);
|
||||
if (!error || error[0])
|
||||
fg = -1;
|
||||
}
|
||||
string += 3;
|
||||
}
|
||||
}
|
||||
if (string[0] == ',')
|
||||
{
|
||||
string++;
|
||||
if (string[0] == GUI_COLOR_EXTENDED_CHAR)
|
||||
{
|
||||
if (string[1] && string[2] && string[3]
|
||||
&& string[4] && string[5])
|
||||
{
|
||||
if (apply_style)
|
||||
{
|
||||
memcpy (str_bg, string + 1, 5);
|
||||
str_bg[5] = '\0';
|
||||
error = NULL;
|
||||
bg = (int)strtol (str_bg, &error, 10);
|
||||
if (!error || error[0])
|
||||
bg = -1;
|
||||
else
|
||||
bg |= GUI_COLOR_EXTENDED_FLAG;
|
||||
}
|
||||
string += 6;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string[0] && string[1])
|
||||
{
|
||||
if (apply_style)
|
||||
{
|
||||
str_bg[0] = string[0];
|
||||
str_bg[1] = string[1];
|
||||
str_bg[2] = '\0';
|
||||
error = NULL;
|
||||
bg = (int)strtol (str_bg, &error, 10);
|
||||
if (!error || error[0])
|
||||
bg = -1;
|
||||
}
|
||||
string += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (apply_style && (fg >= 0) && (bg >= 0))
|
||||
{
|
||||
gui_window_set_custom_color_fg_bg (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
fg, bg);
|
||||
}
|
||||
string++;
|
||||
gui_window_string_apply_color_fg_bg ((unsigned char **)&string,
|
||||
(apply_style) ? GUI_WINDOW_OBJECTS(window)->win_chat : NULL);
|
||||
break;
|
||||
case GUI_COLOR_EXTENDED_CHAR: /* pair number */
|
||||
if ((isdigit (string[1])) && (isdigit (string[2]))
|
||||
&& (isdigit (string[3])) && (isdigit (string[4]))
|
||||
&& (isdigit (string[5])))
|
||||
{
|
||||
if (apply_style)
|
||||
{
|
||||
memcpy (str_pair, string + 1, 5);
|
||||
str_pair[5] = '\0';
|
||||
error = NULL;
|
||||
pair = (int)strtol (str_pair, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_pair (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
pair);
|
||||
}
|
||||
}
|
||||
string += 6;
|
||||
}
|
||||
string++;
|
||||
gui_window_string_apply_color_pair ((unsigned char **)&string,
|
||||
(apply_style) ? GUI_WINDOW_OBJECTS(window)->win_chat : NULL);
|
||||
break;
|
||||
case GUI_COLOR_BAR_CHAR: /* bar color */
|
||||
switch (string[1])
|
||||
string++;
|
||||
switch (string[0])
|
||||
{
|
||||
case GUI_COLOR_BAR_FG_CHAR:
|
||||
case GUI_COLOR_BAR_DELIM_CHAR:
|
||||
@@ -388,95 +209,35 @@ gui_chat_string_next_char (struct t_gui_window *window,
|
||||
case GUI_COLOR_BAR_START_INPUT_CHAR:
|
||||
case GUI_COLOR_BAR_START_INPUT_HIDDEN_CHAR:
|
||||
case GUI_COLOR_BAR_MOVE_CURSOR_CHAR:
|
||||
string += 2;
|
||||
break;
|
||||
default:
|
||||
string++;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (isdigit (string[0]) && isdigit (string[1]))
|
||||
{
|
||||
if (apply_style)
|
||||
{
|
||||
str_fg[0] = string[0];
|
||||
str_fg[1] = string[1];
|
||||
str_fg[2] = '\0';
|
||||
error = NULL;
|
||||
weechat_color = (int)strtol (str_fg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
weechat_color);
|
||||
}
|
||||
}
|
||||
string += 2;
|
||||
}
|
||||
gui_window_string_apply_color_weechat ((unsigned char **)&string,
|
||||
(apply_style) ? GUI_WINDOW_OBJECTS(window)->win_chat : NULL);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case GUI_COLOR_SET_WEECHAT_CHAR:
|
||||
string++;
|
||||
switch (string[0])
|
||||
{
|
||||
case GUI_COLOR_ATTR_BOLD_CHAR:
|
||||
string++;
|
||||
if (apply_style)
|
||||
gui_window_set_color_style (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
A_BOLD);
|
||||
break;
|
||||
case GUI_COLOR_ATTR_REVERSE_CHAR:
|
||||
string++;
|
||||
if (apply_style)
|
||||
gui_window_set_color_style (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
A_REVERSE);
|
||||
break;
|
||||
case GUI_COLOR_ATTR_ITALIC_CHAR:
|
||||
/* not available in Curses GUI */
|
||||
string++;
|
||||
break;
|
||||
case GUI_COLOR_ATTR_UNDERLINE_CHAR:
|
||||
string++;
|
||||
if (apply_style)
|
||||
gui_window_set_color_style (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
A_UNDERLINE);
|
||||
break;
|
||||
}
|
||||
gui_window_string_apply_color_set ((unsigned char **)&string,
|
||||
(apply_style) ? GUI_WINDOW_OBJECTS(window)->win_chat : NULL);
|
||||
break;
|
||||
case GUI_COLOR_REMOVE_WEECHAT_CHAR:
|
||||
string++;
|
||||
switch (string[0])
|
||||
{
|
||||
case GUI_COLOR_ATTR_BOLD_CHAR:
|
||||
string++;
|
||||
if (apply_style)
|
||||
gui_window_remove_color_style (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
A_BOLD);
|
||||
break;
|
||||
case GUI_COLOR_ATTR_REVERSE_CHAR:
|
||||
string++;
|
||||
if (apply_style)
|
||||
gui_window_remove_color_style (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
A_REVERSE);
|
||||
break;
|
||||
case GUI_COLOR_ATTR_ITALIC_CHAR:
|
||||
/* not available in Curses GUI */
|
||||
string++;
|
||||
break;
|
||||
case GUI_COLOR_ATTR_UNDERLINE_CHAR:
|
||||
string++;
|
||||
if (apply_style)
|
||||
gui_window_remove_color_style (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
A_UNDERLINE);
|
||||
break;
|
||||
}
|
||||
gui_window_string_apply_color_remove ((unsigned char **)&string,
|
||||
(apply_style) ? GUI_WINDOW_OBJECTS(window)->win_chat : NULL);
|
||||
break;
|
||||
case GUI_COLOR_RESET_CHAR:
|
||||
string++;
|
||||
if (apply_style)
|
||||
gui_window_reset_style (GUI_WINDOW_OBJECTS(window)->win_chat, GUI_COLOR_CHAT);
|
||||
break;
|
||||
default:
|
||||
return (char *)string;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* nothing found except color/attrib codes, so return NULL */
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
#include <libgen.h>
|
||||
#include <sys/ioctl.h>
|
||||
@@ -205,6 +206,19 @@ gui_window_clear (WINDOW *window, int fg, int bg)
|
||||
wmove (window, 0, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_clrtoeol: clear until end of line with current background
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_clrtoeol (WINDOW *window)
|
||||
{
|
||||
wbkgdset (window,
|
||||
' ' | COLOR_PAIR (gui_color_get_pair (window_current_style_fg,
|
||||
window_current_style_bg)));
|
||||
wclrtoeol (window);
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_reset_style: reset style (color and attr) with a weechat color
|
||||
* for a window
|
||||
@@ -427,16 +441,385 @@ gui_window_set_custom_color_pair (WINDOW *window, int pair)
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_clrtoeol: clear until end of line with current background
|
||||
* gui_window_string_apply_color_fg: apply foreground color code in string and
|
||||
* move string pointer after color in string
|
||||
* If window is NULL, no color is applied but
|
||||
* string pointer is moved anyway
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_clrtoeol (WINDOW *window)
|
||||
gui_window_string_apply_color_fg (unsigned char **str, WINDOW *window)
|
||||
{
|
||||
wbkgdset (window,
|
||||
' ' | COLOR_PAIR (gui_color_get_pair (window_current_style_fg,
|
||||
window_current_style_bg)));
|
||||
wclrtoeol (window);
|
||||
unsigned char *ptr_string;
|
||||
char str_fg[6], *error;
|
||||
int fg;
|
||||
|
||||
ptr_string = *str;
|
||||
|
||||
if (ptr_string[0] == GUI_COLOR_EXTENDED_CHAR)
|
||||
{
|
||||
if (ptr_string[1] && ptr_string[2] && ptr_string[3]
|
||||
&& ptr_string[4] && ptr_string[5])
|
||||
{
|
||||
if (window)
|
||||
{
|
||||
memcpy (str_fg, ptr_string + 1, 5);
|
||||
str_fg[5] = '\0';
|
||||
error = NULL;
|
||||
fg = (int)strtol (str_fg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_fg (window,
|
||||
fg | GUI_COLOR_EXTENDED_FLAG);
|
||||
}
|
||||
}
|
||||
ptr_string += 6;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ptr_string[0] && ptr_string[1])
|
||||
{
|
||||
if (window)
|
||||
{
|
||||
str_fg[0] = ptr_string[0];
|
||||
str_fg[1] = ptr_string[1];
|
||||
str_fg[2] = '\0';
|
||||
error = NULL;
|
||||
fg = (int)strtol (str_fg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_fg (window, fg);
|
||||
}
|
||||
}
|
||||
ptr_string += 2;
|
||||
}
|
||||
}
|
||||
|
||||
*str = ptr_string;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_string_apply_color_bg: apply background color code in string and
|
||||
* move string pointer after color in string
|
||||
* If window is NULL, no color is applied but
|
||||
* string pointer is moved anyway
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_string_apply_color_bg (unsigned char **str, WINDOW *window)
|
||||
{
|
||||
unsigned char *ptr_string;
|
||||
char str_bg[6], *error;
|
||||
int bg;
|
||||
|
||||
ptr_string = *str;
|
||||
|
||||
if (ptr_string[0] == GUI_COLOR_EXTENDED_CHAR)
|
||||
{
|
||||
if (ptr_string[1] && ptr_string[2] && ptr_string[3]
|
||||
&& ptr_string[4] && ptr_string[5])
|
||||
{
|
||||
if (window)
|
||||
{
|
||||
memcpy (str_bg, ptr_string + 1, 5);
|
||||
str_bg[5] = '\0';
|
||||
error = NULL;
|
||||
bg = (int)strtol (str_bg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_bg (window,
|
||||
bg | GUI_COLOR_EXTENDED_FLAG);
|
||||
}
|
||||
}
|
||||
ptr_string += 6;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ptr_string[0] && ptr_string[1])
|
||||
{
|
||||
if (window)
|
||||
{
|
||||
str_bg[0] = ptr_string[0];
|
||||
str_bg[1] = ptr_string[1];
|
||||
str_bg[2] = '\0';
|
||||
error = NULL;
|
||||
bg = (int)strtol (str_bg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_bg (window, bg);
|
||||
}
|
||||
}
|
||||
ptr_string += 2;
|
||||
}
|
||||
}
|
||||
|
||||
*str = ptr_string;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_string_apply_color_fg_bg: apply foreground + background color
|
||||
* code in string and move string pointer
|
||||
* after color in string
|
||||
* If window is NULL, no color is applied
|
||||
* but string pointer is moved anyway
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_string_apply_color_fg_bg (unsigned char **str, WINDOW *window)
|
||||
{
|
||||
unsigned char *ptr_string;
|
||||
char str_fg[6], str_bg[6], *error;
|
||||
int fg, bg;
|
||||
|
||||
ptr_string = *str;
|
||||
|
||||
str_fg[0] = '\0';
|
||||
str_bg[0] = '\0';
|
||||
fg = -1;
|
||||
bg = -1;
|
||||
if (ptr_string[0] == GUI_COLOR_EXTENDED_CHAR)
|
||||
{
|
||||
if (ptr_string[1] && ptr_string[2] && ptr_string[3]
|
||||
&& ptr_string[4] && ptr_string[5])
|
||||
{
|
||||
if (window)
|
||||
{
|
||||
memcpy (str_fg, ptr_string + 1, 5);
|
||||
str_fg[5] = '\0';
|
||||
error = NULL;
|
||||
fg = (int)strtol (str_fg, &error, 10);
|
||||
if (!error || error[0])
|
||||
fg = -1;
|
||||
else
|
||||
fg |= GUI_COLOR_EXTENDED_FLAG;
|
||||
}
|
||||
ptr_string += 6;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ptr_string[0] && ptr_string[1])
|
||||
{
|
||||
if (window)
|
||||
{
|
||||
str_fg[0] = ptr_string[0];
|
||||
str_fg[1] = ptr_string[1];
|
||||
str_fg[2] = '\0';
|
||||
error = NULL;
|
||||
fg = (int)strtol (str_fg, &error, 10);
|
||||
if (!error || error[0])
|
||||
fg = -1;
|
||||
}
|
||||
ptr_string += 2;
|
||||
}
|
||||
}
|
||||
if (ptr_string[0] == ',')
|
||||
{
|
||||
ptr_string++;
|
||||
if (ptr_string[0] == GUI_COLOR_EXTENDED_CHAR)
|
||||
{
|
||||
if (ptr_string[1] && ptr_string[2] && ptr_string[3]
|
||||
&& ptr_string[4] && ptr_string[5])
|
||||
{
|
||||
if (window)
|
||||
{
|
||||
memcpy (str_bg, ptr_string + 1, 5);
|
||||
str_bg[5] = '\0';
|
||||
error = NULL;
|
||||
bg = (int)strtol (str_bg, &error, 10);
|
||||
if (!error || error[0])
|
||||
bg = -1;
|
||||
else
|
||||
bg |= GUI_COLOR_EXTENDED_FLAG;
|
||||
}
|
||||
ptr_string += 6;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ptr_string[0] && ptr_string[1])
|
||||
{
|
||||
if (window)
|
||||
{
|
||||
str_bg[0] = ptr_string[0];
|
||||
str_bg[1] = ptr_string[1];
|
||||
str_bg[2] = '\0';
|
||||
error = NULL;
|
||||
bg = (int)strtol (str_bg, &error, 10);
|
||||
if (!error || error[0])
|
||||
bg = -1;
|
||||
}
|
||||
ptr_string += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (window && (fg >= 0) && (bg >= 0))
|
||||
{
|
||||
gui_window_set_custom_color_fg_bg (window, fg, bg);
|
||||
}
|
||||
|
||||
*str = ptr_string;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_string_apply_color_pair: apply pair color code in string and
|
||||
* move string pointer after color in
|
||||
* string
|
||||
* If window is NULL, no color is applied
|
||||
* but string pointer is moved anyway
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_string_apply_color_pair (unsigned char **str, WINDOW *window)
|
||||
{
|
||||
unsigned char *ptr_string;
|
||||
char str_pair[6], *error;
|
||||
int pair;
|
||||
|
||||
ptr_string = *str;
|
||||
|
||||
if ((isdigit (ptr_string[0])) && (isdigit (ptr_string[1]))
|
||||
&& (isdigit (ptr_string[2])) && (isdigit (ptr_string[3]))
|
||||
&& (isdigit (ptr_string[4])))
|
||||
{
|
||||
if (window)
|
||||
{
|
||||
memcpy (str_pair, ptr_string, 5);
|
||||
str_pair[5] = '\0';
|
||||
error = NULL;
|
||||
pair = (int)strtol (str_pair, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_pair (window, pair);
|
||||
}
|
||||
}
|
||||
ptr_string += 5;
|
||||
}
|
||||
|
||||
*str = ptr_string;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_string_apply_color_weechat: apply weechat color code in string
|
||||
* and move string pointer after color
|
||||
* in string
|
||||
* If window is NULL, no color is
|
||||
* applied but string pointer is moved
|
||||
* anyway
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_string_apply_color_weechat (unsigned char **str, WINDOW *window)
|
||||
{
|
||||
unsigned char *ptr_string;
|
||||
char str_number[3], *error;
|
||||
int weechat_color;
|
||||
|
||||
ptr_string = *str;
|
||||
|
||||
if (isdigit (ptr_string[0]) && isdigit (ptr_string[1]))
|
||||
{
|
||||
if (window)
|
||||
{
|
||||
str_number[0] = ptr_string[0];
|
||||
str_number[1] = ptr_string[1];
|
||||
str_number[2] = '\0';
|
||||
error = NULL;
|
||||
weechat_color = (int)strtol (str_number, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_weechat_color (window,
|
||||
weechat_color);
|
||||
}
|
||||
}
|
||||
ptr_string += 2;
|
||||
}
|
||||
|
||||
*str = ptr_string;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_string_apply_color_set: apply "set attribute" color code in
|
||||
* string and move string pointer after
|
||||
* color in string
|
||||
* If window is NULL, no color is applied
|
||||
* but string pointer is moved anyway
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_string_apply_color_set (unsigned char **str, WINDOW *window)
|
||||
{
|
||||
unsigned char *ptr_string;
|
||||
|
||||
ptr_string = *str;
|
||||
|
||||
switch (ptr_string[0])
|
||||
{
|
||||
case GUI_COLOR_ATTR_BOLD_CHAR:
|
||||
ptr_string++;
|
||||
if (window)
|
||||
gui_window_set_color_style (window, A_BOLD);
|
||||
break;
|
||||
case GUI_COLOR_ATTR_REVERSE_CHAR:
|
||||
ptr_string++;
|
||||
if (window)
|
||||
gui_window_set_color_style (window, A_REVERSE);
|
||||
break;
|
||||
case GUI_COLOR_ATTR_ITALIC_CHAR:
|
||||
/* not available in Curses GUI */
|
||||
ptr_string++;
|
||||
break;
|
||||
case GUI_COLOR_ATTR_UNDERLINE_CHAR:
|
||||
ptr_string++;
|
||||
if (window)
|
||||
gui_window_set_color_style (window, A_UNDERLINE);
|
||||
break;
|
||||
}
|
||||
|
||||
*str = ptr_string;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_string_apply_color_remove: apply "remove attribute" color code in
|
||||
* string and move string pointer after
|
||||
* color in string
|
||||
* If window is NULL, no color is applied
|
||||
* but string pointer is moved anyway
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_string_apply_color_remove (unsigned char **str, WINDOW *window)
|
||||
{
|
||||
unsigned char *ptr_string;
|
||||
|
||||
ptr_string = *str;
|
||||
|
||||
switch (ptr_string[0])
|
||||
{
|
||||
case GUI_COLOR_ATTR_BOLD_CHAR:
|
||||
ptr_string++;
|
||||
if (window)
|
||||
gui_window_remove_color_style (window, A_BOLD);
|
||||
break;
|
||||
case GUI_COLOR_ATTR_REVERSE_CHAR:
|
||||
ptr_string++;
|
||||
if (window)
|
||||
gui_window_remove_color_style (window, A_REVERSE);
|
||||
break;
|
||||
case GUI_COLOR_ATTR_ITALIC_CHAR:
|
||||
/* not available in Curses GUI */
|
||||
ptr_string++;
|
||||
break;
|
||||
case GUI_COLOR_ATTR_UNDERLINE_CHAR:
|
||||
ptr_string++;
|
||||
if (window)
|
||||
gui_window_remove_color_style (window, A_UNDERLINE);
|
||||
break;
|
||||
}
|
||||
|
||||
*str = ptr_string;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -81,6 +81,7 @@ extern int gui_keyboard_read_cb (void *data, int fd);
|
||||
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_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);
|
||||
@@ -90,7 +91,22 @@ 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_clrtoeol (WINDOW *window);
|
||||
extern void gui_window_string_apply_color_fg (unsigned char **str,
|
||||
WINDOW *window);
|
||||
extern void gui_window_string_apply_color_bg (unsigned char **str,
|
||||
WINDOW *window);
|
||||
extern void gui_window_string_apply_color_fg_bg (unsigned char **str,
|
||||
WINDOW *window);
|
||||
extern void gui_window_string_apply_color_pair (unsigned char **str,
|
||||
WINDOW *window);
|
||||
extern void gui_window_string_apply_color_weechat (unsigned char **str,
|
||||
WINDOW *window);
|
||||
extern void gui_window_string_apply_color_set (unsigned char **str,
|
||||
WINDOW *window);
|
||||
extern void gui_window_string_apply_color_remove (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 */
|
||||
|
||||
Reference in New Issue
Block a user