mirror of
https://github.com/weechat/weechat.git
synced 2026-07-01 23:36:37 +02:00
Dynamically allocate color pairs
This commit introduces major changes in 256 colors support: - extended colors can be used without being added with command "/color add" - background color is now allowed for nick colors (using slash separator)
This commit is contained in:
+48
-49
@@ -889,7 +889,7 @@ COMMAND_CALLBACK(buffer)
|
||||
|
||||
COMMAND_CALLBACK(color)
|
||||
{
|
||||
char *str_alias, *str_pair, *str_rgb, *pos, *error;
|
||||
char *str_alias, *str_rgb, *pos, *error;
|
||||
char str_color[1024], str_command[1024];
|
||||
long number;
|
||||
int i;
|
||||
@@ -905,17 +905,17 @@ COMMAND_CALLBACK(color)
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* add a color pair */
|
||||
/* add a color */
|
||||
if (string_strcasecmp (argv[1], "add") == 0)
|
||||
{
|
||||
COMMAND_MIN_ARGS(3, "color add");
|
||||
COMMAND_MIN_ARGS(4, "color add");
|
||||
|
||||
/* check pair number */
|
||||
/* check color number */
|
||||
error = NULL;
|
||||
number = strtol (argv[2], &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
if ((number < 1) || (number > gui_color_get_last_pair ()))
|
||||
if ((number < 0) || (number > gui_color_get_term_colors ()))
|
||||
number = -1;
|
||||
}
|
||||
else
|
||||
@@ -925,30 +925,23 @@ COMMAND_CALLBACK(color)
|
||||
if (number < 0)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sInvalid pair number \"%s\" (must be between "
|
||||
"%d and %d)"),
|
||||
_("%sInvalid color number \"%s\" (must be "
|
||||
"between %d and %d)"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
argv[2], 1, gui_color_get_last_pair ());
|
||||
argv[2], 0, gui_color_get_term_colors ());
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
/* check other arguments */
|
||||
str_alias = NULL;
|
||||
str_pair = NULL;
|
||||
str_rgb = NULL;
|
||||
for (i = 3; i < argc; i++)
|
||||
{
|
||||
pos = strchr (argv[i], ',');
|
||||
pos = strchr (argv[i], '/');
|
||||
if (pos)
|
||||
str_pair = argv[i];
|
||||
str_rgb = argv[i];
|
||||
else
|
||||
{
|
||||
pos = strchr (argv[i], '/');
|
||||
if (pos)
|
||||
str_rgb = argv[i];
|
||||
else
|
||||
str_alias = argv[i];
|
||||
}
|
||||
str_alias = argv[i];
|
||||
}
|
||||
str_color[0] = '\0';
|
||||
if (str_alias)
|
||||
@@ -956,18 +949,13 @@ COMMAND_CALLBACK(color)
|
||||
strcat (str_color, ";");
|
||||
strcat (str_color, str_alias);
|
||||
}
|
||||
if (str_pair)
|
||||
{
|
||||
strcat (str_color, ";");
|
||||
strcat (str_color, str_pair);
|
||||
}
|
||||
if (str_rgb)
|
||||
{
|
||||
strcat (str_color, ";");
|
||||
strcat (str_color, str_rgb);
|
||||
}
|
||||
|
||||
/* add color pair */
|
||||
/* add color */
|
||||
snprintf (str_command, sizeof (str_command),
|
||||
"/set weechat.palette.%d \"%s\"",
|
||||
(int)number,
|
||||
@@ -976,17 +964,17 @@ COMMAND_CALLBACK(color)
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* delete a color pair */
|
||||
/* delete a color */
|
||||
if (string_strcasecmp (argv[1], "del") == 0)
|
||||
{
|
||||
COMMAND_MIN_ARGS(3, "color del");
|
||||
|
||||
/* check pair number */
|
||||
/* check color number */
|
||||
error = NULL;
|
||||
number = strtol (argv[2], &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
if ((number < 1) || (number > gui_color_get_last_pair ()))
|
||||
if ((number < 0) || (number > gui_color_get_term_colors ()))
|
||||
number = -1;
|
||||
}
|
||||
else
|
||||
@@ -996,14 +984,14 @@ COMMAND_CALLBACK(color)
|
||||
if (number < 0)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sInvalid pair number \"%s\" (must be between "
|
||||
"%d and %d)"),
|
||||
_("%sInvalid color number \"%s\" (must be "
|
||||
"between %d and %d)"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
argv[2], 1, gui_color_get_last_pair ());
|
||||
argv[2], 0, gui_color_get_term_colors ());
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
/* search color pair */
|
||||
/* search color */
|
||||
color_palette = gui_color_palette_get ((int)number);
|
||||
if (!color_palette)
|
||||
{
|
||||
@@ -1014,7 +1002,7 @@ COMMAND_CALLBACK(color)
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
/* delete color pair */
|
||||
/* delete color */
|
||||
snprintf (str_command, sizeof (str_command),
|
||||
"/unset weechat.palette.%d",
|
||||
(int)number);
|
||||
@@ -1022,6 +1010,13 @@ COMMAND_CALLBACK(color)
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* reset color pairs */
|
||||
if (string_strcasecmp (argv[1], "reset") == 0)
|
||||
{
|
||||
gui_color_reset_pairs ();
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* switch WeeChat/terminal colors */
|
||||
if (string_strcasecmp (argv[1], "switch") == 0)
|
||||
{
|
||||
@@ -1138,6 +1133,10 @@ COMMAND_CALLBACK(debug)
|
||||
{
|
||||
gui_window_term_display_infos ();
|
||||
}
|
||||
else if (string_strcasecmp (argv[1], "color") == 0)
|
||||
{
|
||||
gui_color_dump (buffer);
|
||||
}
|
||||
else if (string_strcasecmp (argv[1], "set") == 0)
|
||||
{
|
||||
COMMAND_MIN_ARGS(4, "debug set");
|
||||
@@ -4524,27 +4523,25 @@ command_init ()
|
||||
" || %(buffers_numbers)",
|
||||
&command_buffer, NULL);
|
||||
hook_command (NULL, "color",
|
||||
N_("define custom colors and display palette of colors"),
|
||||
N_("[add pair [alias] [fg,bg]] | [del pair] | switch"),
|
||||
N_(" add: add a color pair\n"
|
||||
" del: delete a color pair\n"
|
||||
"switch: switch WeeChat/terminal colors\n"
|
||||
" pair: pair number (>= 1)\n"
|
||||
N_("define color aliases and display palette of colors"),
|
||||
N_("[add color alias] | [del color] | reset"),
|
||||
N_(" add: add an alias for a color\n"
|
||||
" del: delete an alias\n"
|
||||
" color: color number (>= 1, max depends on terminal, "
|
||||
"commonly 63 or 255)\n"
|
||||
" alias: alias name for color (for example: \"orange\")\n"
|
||||
" fg,bg: foreground and background pair number (-1 for "
|
||||
"default terminal foreground or background)\n\n"
|
||||
" reset: reset all color pairs (useful when no more "
|
||||
"pairs are available)\n\n"
|
||||
"Without argument, this command displays colors in a new "
|
||||
"buffer.\n\n"
|
||||
"Examples:\n"
|
||||
" add color 214 with alias \"orange\":\n"
|
||||
" add alias \"orange\" for color 214:\n"
|
||||
" /color add 214 orange\n"
|
||||
" add color 250 with orange on blue:\n"
|
||||
" /color add 250 214,4 orange_blue\n"
|
||||
" delete color 214:\n"
|
||||
" /color del 214"),
|
||||
"add %(color_pairs)"
|
||||
" || del %(color_pairs)"
|
||||
" || switch",
|
||||
"add %(palette_colors)"
|
||||
" || del %(palette_colors)"
|
||||
" || reset",
|
||||
&command_color, NULL);
|
||||
hook_command (NULL, "command",
|
||||
N_("launch explicit WeeChat or plugin command"),
|
||||
@@ -4558,7 +4555,7 @@ command_init ()
|
||||
hook_command (NULL, "debug",
|
||||
N_("control debug for core/plugins"),
|
||||
N_("[list | set plugin level | dump [plugin] | buffer | "
|
||||
"windows | term]"),
|
||||
"windows | term | color]"),
|
||||
N_(" set: set log level for plugin\n"
|
||||
" plugin: name of plugin (\"core\" for WeeChat core)\n"
|
||||
" level: debug level for plugin (0 = disable debug)\n"
|
||||
@@ -4568,13 +4565,15 @@ command_init ()
|
||||
"in log file\n"
|
||||
"windows: display windows tree\n"
|
||||
" term: display infos about terminal and available "
|
||||
"colors"),
|
||||
"colors\n"
|
||||
" color: display infos about current color pairs"),
|
||||
"list"
|
||||
" || set %(plugins_names)|core"
|
||||
" || dump %(plugins_names)|core"
|
||||
" || buffer"
|
||||
" || windows"
|
||||
" || term",
|
||||
" || term"
|
||||
" || color",
|
||||
&command_debug, NULL);
|
||||
hook_command (NULL, "filter",
|
||||
N_("filter messages in buffers, to hide/show them according "
|
||||
|
||||
+36
-18
@@ -261,13 +261,13 @@ completion_list_add_buffer_properties_get_cb (void *data,
|
||||
}
|
||||
|
||||
/*
|
||||
* completion_list_map_add_color_cb: add color pairs in completion
|
||||
* completion_list_map_add_palette_color_cb: add palette color in completion
|
||||
*/
|
||||
|
||||
void
|
||||
completion_list_map_add_color_cb (void *data,
|
||||
struct t_hashtable *hashtable,
|
||||
const void *key, const void *value)
|
||||
completion_list_map_add_palette_color_cb (void *data,
|
||||
struct t_hashtable *hashtable,
|
||||
const void *key, const void *value)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) hashtable;
|
||||
@@ -279,14 +279,14 @@ completion_list_map_add_color_cb (void *data,
|
||||
}
|
||||
|
||||
/*
|
||||
* completion_list_add_color_pairs_cb: add color pairs (in section "palette")
|
||||
* completion_list_add_palette_colors_cb: add colors (in section "palette")
|
||||
*/
|
||||
|
||||
int
|
||||
completion_list_add_color_pairs_cb (void *data,
|
||||
const char *completion_item,
|
||||
struct t_gui_buffer *buffer,
|
||||
struct t_gui_completion *completion)
|
||||
completion_list_add_palette_colors_cb (void *data,
|
||||
const char *completion_item,
|
||||
struct t_gui_buffer *buffer,
|
||||
struct t_gui_completion *completion)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
@@ -294,7 +294,7 @@ completion_list_add_color_pairs_cb (void *data,
|
||||
(void) buffer;
|
||||
|
||||
hashtable_map (gui_color_hash_palette_color,
|
||||
&completion_list_map_add_color_cb,
|
||||
&completion_list_map_add_palette_color_cb,
|
||||
completion);
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
@@ -776,12 +776,13 @@ completion_list_add_config_option_values_cb (void *data,
|
||||
struct t_gui_completion *completion)
|
||||
{
|
||||
char *pos_space, *option_full_name, *pos_section, *pos_option;
|
||||
char *file, *section, *value_string;
|
||||
char *file, *section, *value_string, str_number[64];
|
||||
const char *color_name;
|
||||
int length, i, num_colors;
|
||||
struct t_config_file *ptr_config;
|
||||
struct t_config_section *ptr_section, *section_found;
|
||||
struct t_config_option *option_found;
|
||||
struct t_gui_color_palette *color_palette;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
@@ -943,15 +944,32 @@ completion_list_add_config_option_values_cb (void *data,
|
||||
{
|
||||
color_name = gui_color_get_name (i);
|
||||
if (color_name)
|
||||
{
|
||||
gui_completion_list_add (completion,
|
||||
color_name,
|
||||
0, WEECHAT_LIST_POS_SORT);
|
||||
}
|
||||
}
|
||||
if (gui_color_hash_palette_alias)
|
||||
num_colors = gui_color_get_term_colors ();
|
||||
for (i = 0; i <= num_colors; i++)
|
||||
{
|
||||
hashtable_map (gui_color_hash_palette_alias,
|
||||
&completion_list_map_add_color_alias_cb,
|
||||
completion);
|
||||
color_palette = gui_color_palette_get (i);
|
||||
if (color_palette)
|
||||
{
|
||||
gui_completion_list_add (completion,
|
||||
color_palette->alias,
|
||||
0, WEECHAT_LIST_POS_END);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf (str_number,
|
||||
sizeof (str_number),
|
||||
"%d",
|
||||
i);
|
||||
gui_completion_list_add (completion,
|
||||
str_number,
|
||||
0, WEECHAT_LIST_POS_END);
|
||||
}
|
||||
}
|
||||
gui_completion_list_add (completion, "++1",
|
||||
0, WEECHAT_LIST_POS_END);
|
||||
@@ -1195,9 +1213,9 @@ completion_init ()
|
||||
hook_completion (NULL, "buffer_properties_get",
|
||||
N_("properties that can be read on a buffer"),
|
||||
&completion_list_add_buffer_properties_get_cb, NULL);
|
||||
hook_completion (NULL, "color_pairs",
|
||||
N_("color pairs"),
|
||||
&completion_list_add_color_pairs_cb, NULL);
|
||||
hook_completion (NULL, "palette_colors",
|
||||
N_("palette colors"),
|
||||
&completion_list_add_palette_colors_cb, NULL);
|
||||
hook_completion (NULL, "config_files", /* formerly "%c" */
|
||||
N_("configuration files"),
|
||||
&completion_list_add_config_files_cb, NULL);
|
||||
|
||||
@@ -251,7 +251,7 @@ config_change_buffers (void *data, struct t_config_option *option)
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
gui_window_refresh_windows ();
|
||||
gui_window_ask_refresh (1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -384,7 +384,7 @@ config_change_prefix_align_min (void *data, struct t_config_option *option)
|
||||
if (ptr_buffer->mixed_lines)
|
||||
gui_line_compute_prefix_max_length (ptr_buffer->mixed_lines);
|
||||
}
|
||||
gui_window_refresh_windows ();
|
||||
gui_window_ask_refresh (1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -400,9 +400,8 @@ config_change_color (void *data, struct t_config_option *option)
|
||||
|
||||
if (gui_ok)
|
||||
{
|
||||
gui_color_init_pairs ();
|
||||
gui_color_init_weechat ();
|
||||
gui_window_refresh_windows ();
|
||||
gui_window_ask_refresh (1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -742,10 +741,7 @@ config_weechat_palette_create_option_cb (void *data,
|
||||
ptr_option = config_file_new_option (
|
||||
config_file, section,
|
||||
option_name, "string",
|
||||
_("custom color in palette, format is: \"alias;fg,bg\" "
|
||||
"where alias is color name, fg,bg is \"foreground,background\" "
|
||||
"(example: \"200,-1\") (everything is optional "
|
||||
"in this format and order is not important)"),
|
||||
_("alias for color"),
|
||||
NULL, 0, 0, "", value, 0, NULL, NULL,
|
||||
&config_weechat_palette_change_cb, NULL,
|
||||
NULL, NULL);
|
||||
@@ -1879,7 +1875,8 @@ config_weechat_init_options ()
|
||||
config_color_chat_nick_colors = config_file_new_option (
|
||||
weechat_config_file, ptr_section,
|
||||
"chat_nick_colors", "string",
|
||||
N_("text color for nicks (comma separated list of colors)"),
|
||||
N_("text color for nicks (comma separated list of colors, background "
|
||||
"is allowed with format: \"fg/bg\", for example: \"blue/red\")"),
|
||||
NULL, 0, 0, "cyan,magenta,green,brown,lightblue,default,lightcyan,"
|
||||
"lightmagenta,lightgreen,blue", NULL, 0,
|
||||
NULL, NULL, &config_change_nick_colors, NULL, NULL, NULL);
|
||||
|
||||
Reference in New Issue
Block a user