mirror of
https://github.com/weechat/weechat.git
synced 2026-07-03 16:23:14 +02:00
Add delimiter color for bars, fix some bugs with bars
This commit is contained in:
@@ -222,10 +222,7 @@ plugin_api_prefix (const char *prefix)
|
||||
char *
|
||||
plugin_api_color (const char *color_name)
|
||||
{
|
||||
int num_color, fg, bg;
|
||||
static char color[20][16];
|
||||
static int index_color = 0;
|
||||
char *pos_comma, *str_fg, *pos_bg;
|
||||
int num_color;
|
||||
|
||||
if (!color_name)
|
||||
return GUI_NO_COLOR;
|
||||
@@ -234,91 +231,8 @@ plugin_api_color (const char *color_name)
|
||||
num_color = gui_color_search_config_int (color_name);
|
||||
if (num_color >= 0)
|
||||
return GUI_COLOR(num_color);
|
||||
|
||||
/* attribute or other color name (GUI dependent) */
|
||||
index_color = (index_color + 1) % 20;
|
||||
color[index_color][0] = '\0';
|
||||
|
||||
if (string_strcasecmp (color_name, "reset") == 0)
|
||||
{
|
||||
snprintf (color[index_color], sizeof (color[index_color]),
|
||||
"%s",
|
||||
GUI_COLOR_RESET_STR);
|
||||
}
|
||||
else if (string_strcasecmp (color_name, "bold") == 0)
|
||||
{
|
||||
snprintf (color[index_color], sizeof (color[index_color]),
|
||||
"%s%s",
|
||||
GUI_COLOR_SET_STR,
|
||||
GUI_COLOR_ATTR_BOLD_STR);
|
||||
}
|
||||
else if (string_strcasecmp (color_name, "reverse") == 0)
|
||||
{
|
||||
snprintf (color[index_color], sizeof (color[index_color]),
|
||||
"%s%s",
|
||||
GUI_COLOR_SET_STR,
|
||||
GUI_COLOR_ATTR_REVERSE_STR);
|
||||
}
|
||||
else if (string_strcasecmp (color_name, "italic") == 0)
|
||||
{
|
||||
snprintf (color[index_color], sizeof (color[index_color]),
|
||||
"%s%s",
|
||||
GUI_COLOR_SET_STR,
|
||||
GUI_COLOR_ATTR_ITALIC_STR);
|
||||
}
|
||||
else if (string_strcasecmp (color_name, "underline") == 0)
|
||||
{
|
||||
snprintf (color[index_color], sizeof (color[index_color]),
|
||||
"%s%s",
|
||||
GUI_COLOR_SET_STR,
|
||||
GUI_COLOR_ATTR_UNDERLINE_STR);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* custom color name (GUI dependent) */
|
||||
pos_comma = strchr (color_name, ',');
|
||||
if (pos_comma)
|
||||
{
|
||||
if (pos_comma == color_name)
|
||||
str_fg = NULL;
|
||||
else
|
||||
str_fg = string_strndup (color_name, pos_comma - color_name);
|
||||
pos_bg = pos_comma + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
str_fg = strdup (color_name);
|
||||
pos_bg = NULL;
|
||||
}
|
||||
|
||||
if (str_fg && pos_bg)
|
||||
{
|
||||
fg = gui_color_search (str_fg);
|
||||
bg = gui_color_search (pos_bg);
|
||||
snprintf (color[index_color], sizeof (color[index_color]),
|
||||
"%s*%02d,%02d",
|
||||
GUI_COLOR_COLOR_STR, fg, bg);
|
||||
}
|
||||
else if (str_fg && !pos_bg)
|
||||
{
|
||||
fg = gui_color_search (str_fg);
|
||||
snprintf (color[index_color], sizeof (color[index_color]),
|
||||
"%sF%02d",
|
||||
GUI_COLOR_COLOR_STR, fg);
|
||||
}
|
||||
else if (!str_fg && pos_bg)
|
||||
{
|
||||
bg = gui_color_search (pos_bg);
|
||||
snprintf (color[index_color], sizeof (color[index_color]),
|
||||
"%sB%02d",
|
||||
GUI_COLOR_COLOR_STR, bg);
|
||||
}
|
||||
|
||||
if (str_fg)
|
||||
free (str_fg);
|
||||
}
|
||||
|
||||
return color[index_color];
|
||||
return gui_color_get_custom (color_name);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -4038,7 +4038,8 @@ static int
|
||||
weechat_lua_api_bar_new (lua_State *L)
|
||||
{
|
||||
const char *name, *priority, *type, *conditions, *position, *filling;
|
||||
const char *size, *size_max, *color_fg, *color_bg, *separator, *items;
|
||||
const char *size, *size_max, *color_fg, *color_delim, *color_bg;
|
||||
const char *separator, *items;
|
||||
char *result;
|
||||
int n;
|
||||
|
||||
@@ -4060,27 +4061,29 @@ weechat_lua_api_bar_new (lua_State *L)
|
||||
size = NULL;
|
||||
size_max = NULL;
|
||||
color_fg = NULL;
|
||||
color_delim = NULL;
|
||||
color_bg = NULL;
|
||||
separator = NULL;
|
||||
items = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n < 12)
|
||||
if (n < 13)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_new");
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
name = lua_tostring (lua_current_interpreter, -12);
|
||||
priority = lua_tostring (lua_current_interpreter, -11);
|
||||
type = lua_tostring (lua_current_interpreter, -10);
|
||||
conditions = lua_tostring (lua_current_interpreter, -9);
|
||||
position = lua_tostring (lua_current_interpreter, -8);
|
||||
filling = lua_tostring (lua_current_interpreter, -7);
|
||||
size = lua_tostring (lua_current_interpreter, -6);
|
||||
size_max = lua_tostring (lua_current_interpreter, -5);
|
||||
color_fg = lua_tostring (lua_current_interpreter, -4);
|
||||
name = lua_tostring (lua_current_interpreter, -13);
|
||||
priority = lua_tostring (lua_current_interpreter, -12);
|
||||
type = lua_tostring (lua_current_interpreter, -11);
|
||||
conditions = lua_tostring (lua_current_interpreter, -10);
|
||||
position = lua_tostring (lua_current_interpreter, -9);
|
||||
filling = lua_tostring (lua_current_interpreter, -8);
|
||||
size = lua_tostring (lua_current_interpreter, -7);
|
||||
size_max = lua_tostring (lua_current_interpreter, -6);
|
||||
color_fg = lua_tostring (lua_current_interpreter, -5);
|
||||
color_delim = lua_tostring (lua_current_interpreter, -4);
|
||||
color_bg = lua_tostring (lua_current_interpreter, -3);
|
||||
separator = lua_tostring (lua_current_interpreter, -2);
|
||||
items = lua_tostring (lua_current_interpreter, -1);
|
||||
@@ -4094,6 +4097,7 @@ weechat_lua_api_bar_new (lua_State *L)
|
||||
size,
|
||||
size_max,
|
||||
color_fg,
|
||||
color_delim,
|
||||
color_bg,
|
||||
separator,
|
||||
items));
|
||||
|
||||
@@ -3354,7 +3354,8 @@ static XS (XS_weechat_bar_search)
|
||||
static XS (XS_weechat_bar_new)
|
||||
{
|
||||
char *result, *name, *priority, *type, *conditions, *position, *filling;
|
||||
char *size, *size_max, *color_fg, *color_bg, *separator, *bar_items;
|
||||
char *size, *size_max, *color_fg, *color_delim, *color_bg, *separator;
|
||||
char *bar_items;
|
||||
dXSARGS;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -3366,7 +3367,7 @@ static XS (XS_weechat_bar_new)
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (items < 12)
|
||||
if (items < 13)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_new");
|
||||
PERL_RETURN_EMPTY;
|
||||
@@ -3381,9 +3382,10 @@ static XS (XS_weechat_bar_new)
|
||||
size = SvPV (ST (6), PL_na);
|
||||
size_max = SvPV (ST (7), PL_na);
|
||||
color_fg = SvPV (ST (8), PL_na);
|
||||
color_bg = SvPV (ST (9), PL_na);
|
||||
separator = SvPV (ST (10), PL_na);
|
||||
bar_items = SvPV (ST (11), PL_na);
|
||||
color_delim = SvPV (ST (9), PL_na);
|
||||
color_bg = SvPV (ST (10), PL_na);
|
||||
separator = SvPV (ST (11), PL_na);
|
||||
bar_items = SvPV (ST (12), PL_na);
|
||||
result = script_ptr2str (weechat_bar_new (name,
|
||||
priority,
|
||||
type,
|
||||
@@ -3393,6 +3395,7 @@ static XS (XS_weechat_bar_new)
|
||||
size,
|
||||
size_max,
|
||||
color_fg,
|
||||
color_delim,
|
||||
color_bg,
|
||||
separator,
|
||||
bar_items));
|
||||
|
||||
@@ -3566,7 +3566,8 @@ static PyObject *
|
||||
weechat_python_api_bar_new (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *name, *priority, *type, *conditions, *position, *filling, *size;
|
||||
char *size_max, *color_fg, *color_bg, *separator, *items, *result;
|
||||
char *size_max, *color_fg, *color_delim, *color_bg, *separator, *items;
|
||||
char *result;
|
||||
PyObject *object;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -3587,13 +3588,15 @@ weechat_python_api_bar_new (PyObject *self, PyObject *args)
|
||||
size = NULL;
|
||||
size_max = NULL;
|
||||
color_fg = NULL;
|
||||
color_delim = NULL;
|
||||
color_bg = NULL;
|
||||
separator = NULL;
|
||||
items = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ssssssssssss", &name, &priority, &conditions,
|
||||
&type, &position, &filling, &size, &size_max,
|
||||
&color_fg, &color_bg, &separator, &items))
|
||||
if (!PyArg_ParseTuple (args, "sssssssssssss", &name, &priority,
|
||||
&conditions, &type, &position, &filling, &size,
|
||||
&size_max, &color_fg, &color_delim, &color_bg,
|
||||
&separator, &items))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_new");
|
||||
PYTHON_RETURN_EMPTY;
|
||||
@@ -3608,6 +3611,7 @@ weechat_python_api_bar_new (PyObject *self, PyObject *args)
|
||||
size,
|
||||
size_max,
|
||||
color_fg,
|
||||
color_delim,
|
||||
color_bg,
|
||||
separator,
|
||||
items));
|
||||
|
||||
@@ -4096,11 +4096,12 @@ static VALUE
|
||||
weechat_ruby_api_bar_new (VALUE class, VALUE name, VALUE priority, VALUE type,
|
||||
VALUE conditions, VALUE position, VALUE filling,
|
||||
VALUE size, VALUE size_max, VALUE color_fg,
|
||||
VALUE color_bg, VALUE separator, VALUE items)
|
||||
VALUE color_delim, VALUE color_bg, VALUE separator,
|
||||
VALUE items)
|
||||
{
|
||||
char *c_name, *c_priority, *c_type, *c_conditions, *c_position, *c_filling;
|
||||
char *c_size, *c_size_max, *c_color_fg, *c_color_bg, *c_separator;
|
||||
char *c_items;
|
||||
char *c_size, *c_size_max, *c_color_fg, *c_color_delim, *c_color_bg;
|
||||
char *c_separator, *c_items;
|
||||
char *result;
|
||||
VALUE return_value;
|
||||
|
||||
@@ -4122,14 +4123,15 @@ weechat_ruby_api_bar_new (VALUE class, VALUE name, VALUE priority, VALUE type,
|
||||
c_size = NULL;
|
||||
c_size_max = NULL;
|
||||
c_color_fg = NULL;
|
||||
c_color_delim = NULL;
|
||||
c_color_bg = NULL;
|
||||
c_separator = NULL;
|
||||
c_items = NULL;
|
||||
|
||||
if (NIL_P (name) || NIL_P (priority) || NIL_P (type) || NIL_P (conditions)
|
||||
|| NIL_P (position) || NIL_P (filling) || NIL_P (size)
|
||||
|| NIL_P (size_max) || NIL_P (color_fg) || NIL_P (color_bg)
|
||||
|| NIL_P (separator) || NIL_P (items))
|
||||
|| NIL_P (size_max) || NIL_P (color_fg) || NIL_P (color_delim)
|
||||
|| NIL_P (color_bg) || NIL_P (separator) || NIL_P (items))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_new");
|
||||
RUBY_RETURN_EMPTY;
|
||||
@@ -4144,6 +4146,7 @@ weechat_ruby_api_bar_new (VALUE class, VALUE name, VALUE priority, VALUE type,
|
||||
Check_Type (size, T_STRING);
|
||||
Check_Type (size_max, T_STRING);
|
||||
Check_Type (color_fg, T_STRING);
|
||||
Check_Type (color_delim, T_STRING);
|
||||
Check_Type (color_bg, T_STRING);
|
||||
Check_Type (separator, T_STRING);
|
||||
Check_Type (items, T_STRING);
|
||||
@@ -4157,6 +4160,7 @@ weechat_ruby_api_bar_new (VALUE class, VALUE name, VALUE priority, VALUE type,
|
||||
c_size = STR2CSTR (size);
|
||||
c_size_max = STR2CSTR (size_max);
|
||||
c_color_fg = STR2CSTR (color_fg);
|
||||
c_color_delim = STR2CSTR (color_delim);
|
||||
c_color_bg = STR2CSTR (color_bg);
|
||||
c_separator = STR2CSTR (separator);
|
||||
c_items = STR2CSTR (items);
|
||||
@@ -4170,6 +4174,7 @@ weechat_ruby_api_bar_new (VALUE class, VALUE name, VALUE priority, VALUE type,
|
||||
c_size,
|
||||
c_size_max,
|
||||
c_color_fg,
|
||||
c_color_delim,
|
||||
c_color_bg,
|
||||
c_separator,
|
||||
c_items));
|
||||
@@ -4793,7 +4798,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
|
||||
rb_define_module_function (ruby_mWeechat, "bar_item_update", &weechat_ruby_api_bar_item_update, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "bar_item_remove", &weechat_ruby_api_bar_item_remove, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "bar_search", &weechat_ruby_api_bar_search, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "bar_new", &weechat_ruby_api_bar_new, 12);
|
||||
rb_define_module_function (ruby_mWeechat, "bar_new", &weechat_ruby_api_bar_new, 13);
|
||||
rb_define_module_function (ruby_mWeechat, "bar_set", &weechat_ruby_api_bar_set, 3);
|
||||
rb_define_module_function (ruby_mWeechat, "bar_update", &weechat_ruby_api_bar_update, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "bar_remove", &weechat_ruby_api_bar_remove, 1);
|
||||
|
||||
@@ -422,13 +422,18 @@ struct t_weechat_plugin
|
||||
void (*bar_item_update) (const char *name);
|
||||
void (*bar_item_remove) (struct t_gui_bar_item *item);
|
||||
struct t_gui_bar *(*bar_search) (const char *name);
|
||||
struct t_gui_bar *(*bar_new) (struct t_weechat_plugin *plugin, const char *name,
|
||||
const char *priority, const char *type, const char *condition,
|
||||
const char *position, const char *filling, const char *size,
|
||||
struct t_gui_bar *(*bar_new) (struct t_weechat_plugin *plugin,
|
||||
const char *name,
|
||||
const char *priority, const char *type,
|
||||
const char *condition,
|
||||
const char *position, const char *filling,
|
||||
const char *size,
|
||||
const char *size_max, const char *color_fg,
|
||||
const char *color_delim,
|
||||
const char *color_bg, const char *separator,
|
||||
const char *items);
|
||||
int (*bar_set) (struct t_gui_bar *bar, const char *property, const char *value);
|
||||
int (*bar_set) (struct t_gui_bar *bar, const char *property,
|
||||
const char *value);
|
||||
void (*bar_update) (const char *name);
|
||||
void (*bar_remove) (struct t_gui_bar *bar);
|
||||
|
||||
@@ -853,11 +858,12 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
|
||||
weechat_plugin->bar_search(__name)
|
||||
#define weechat_bar_new(__name, __priority, __type, __condition, \
|
||||
__position, __filling, __size, __size_max, \
|
||||
__color_fg, __color_bg, __separator, __items) \
|
||||
__color_fg, __color_delim, __color_bg, \
|
||||
__separator, __items) \
|
||||
weechat_plugin->bar_new(weechat_plugin, __name, __priority, __type, \
|
||||
__condition, __position, __filling, __size, \
|
||||
__size_max, __color_fg, __color_bg, \
|
||||
__separator, __items)
|
||||
__size_max, __color_fg, __color_delim, \
|
||||
__color_bg, __separator, __items)
|
||||
#define weechat_bar_set(__bar, __property, __value) \
|
||||
weechat_plugin->bar_set(__bar, __property, __value)
|
||||
#define weechat_bar_update(__name) \
|
||||
|
||||
Reference in New Issue
Block a user