mirror of
https://github.com/weechat/weechat.git
synced 2026-06-29 22:36:38 +02:00
Replace the 10 nick color options and number of nick colors by a single option "weechat.color.chat_nick_colors" (comma separated list of colors)
This commit is contained in:
@@ -68,13 +68,12 @@ demo_printf_command_cb (void *data, struct t_gui_buffer *buffer, int argc,
|
||||
_("%sdemo message with error prefix"),
|
||||
weechat_prefix ("error"));
|
||||
weechat_printf (buffer,
|
||||
_("colors: %s buffer %s nick1 %s nick2 %s nick3 "
|
||||
"%s nick4"),
|
||||
"%s: %s chat_buffer %s chat_server "
|
||||
"%s chat_host",
|
||||
_("colors"),
|
||||
weechat_color ("chat_buffer"),
|
||||
weechat_color ("chat_nick_color1"),
|
||||
weechat_color ("chat_nick_color2"),
|
||||
weechat_color ("chat_nick_color3"),
|
||||
weechat_color ("chat_nick_color4"));
|
||||
weechat_color ("chat_server"),
|
||||
weechat_color ("chat_host"));
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
@@ -126,7 +126,9 @@ struct t_config_option *irc_config_network_send_unknown_commands;
|
||||
|
||||
struct t_config_option *irc_config_server_default[IRC_SERVER_NUM_OPTIONS];
|
||||
|
||||
struct t_hook *hook_config_color_nicks_number = NULL;
|
||||
struct t_hook *irc_config_hook_config_nick_colors = NULL;
|
||||
char **irc_config_nick_colors = NULL;
|
||||
int irc_config_num_nick_colors = 0;
|
||||
struct t_hashtable *irc_config_hashtable_nick_color_force = NULL;
|
||||
|
||||
int irc_config_write_temp_servers = 0;
|
||||
@@ -187,20 +189,41 @@ irc_config_compute_nick_colors ()
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_config_change_look_color_nicks_number: called when the
|
||||
* "weechat.look.color_nicks_number"
|
||||
* option is changed
|
||||
* irc_config_set_nick_colors: set nick colors using option
|
||||
* "weechat.color.chat_nick_colors"
|
||||
*/
|
||||
|
||||
void
|
||||
irc_config_set_nick_colors ()
|
||||
{
|
||||
if (irc_config_nick_colors)
|
||||
{
|
||||
weechat_string_free_split (irc_config_nick_colors);
|
||||
irc_config_nick_colors = NULL;
|
||||
irc_config_num_nick_colors = 0;
|
||||
}
|
||||
|
||||
irc_config_nick_colors =
|
||||
weechat_string_split (weechat_config_string (weechat_config_get ("weechat.color.chat_nick_colors")),
|
||||
",", 0, 0,
|
||||
&irc_config_num_nick_colors);
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_config_change_nick_colors_cb: callback called when option
|
||||
* "weechat.color.chat_nick_colors" is changed
|
||||
*/
|
||||
|
||||
int
|
||||
irc_config_change_look_color_nicks_number (void *data, const char *option,
|
||||
const char *value)
|
||||
irc_config_change_nick_colors_cb (void *data, const char *option,
|
||||
const char *value)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
(void) value;
|
||||
|
||||
irc_config_set_nick_colors ();
|
||||
irc_config_compute_nick_colors ();
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
@@ -2254,8 +2277,8 @@ irc_config_init ()
|
||||
}
|
||||
irc_config_section_server = ptr_section;
|
||||
|
||||
hook_config_color_nicks_number = weechat_hook_config ("weechat.look.color_nicks_number",
|
||||
&irc_config_change_look_color_nicks_number, NULL);
|
||||
irc_config_hook_config_nick_colors = weechat_hook_config ("weechat.color.chat_nick_colors",
|
||||
&irc_config_change_nick_colors_cb, NULL);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -2299,13 +2322,19 @@ void
|
||||
irc_config_free ()
|
||||
{
|
||||
weechat_config_free (irc_config_file);
|
||||
|
||||
if (hook_config_color_nicks_number)
|
||||
|
||||
if (irc_config_hook_config_nick_colors)
|
||||
{
|
||||
weechat_unhook (hook_config_color_nicks_number);
|
||||
hook_config_color_nicks_number = NULL;
|
||||
weechat_unhook (irc_config_hook_config_nick_colors);
|
||||
irc_config_hook_config_nick_colors = NULL;
|
||||
}
|
||||
|
||||
if (irc_config_nick_colors)
|
||||
{
|
||||
weechat_string_free_split (irc_config_nick_colors);
|
||||
irc_config_nick_colors = NULL;
|
||||
irc_config_num_nick_colors = 0;
|
||||
}
|
||||
|
||||
if (irc_config_hashtable_nick_color_force)
|
||||
{
|
||||
weechat_hashtable_free (irc_config_hashtable_nick_color_force);
|
||||
|
||||
@@ -145,8 +145,12 @@ extern struct t_config_option *irc_config_network_send_unknown_commands;
|
||||
|
||||
extern struct t_config_option *irc_config_server_default[];
|
||||
|
||||
extern char **irc_config_nick_colors;
|
||||
extern int irc_config_num_nick_colors;
|
||||
|
||||
extern struct t_hashtable *irc_config_hashtable_nick_color_force;
|
||||
|
||||
extern void irc_config_set_nick_colors ();
|
||||
extern void irc_config_server_change_cb (void *data,
|
||||
struct t_config_option *option);
|
||||
struct t_config_option *irc_config_server_new_option (struct t_config_file *config_file,
|
||||
|
||||
+25
-10
@@ -141,6 +141,12 @@ irc_nick_hash_color (const char *nickname)
|
||||
int color;
|
||||
const char *ptr_nick;
|
||||
|
||||
if (!irc_config_nick_colors)
|
||||
irc_config_set_nick_colors ();
|
||||
|
||||
if (irc_config_num_nick_colors == 0)
|
||||
return 0;
|
||||
|
||||
color = 0;
|
||||
ptr_nick = nickname;
|
||||
while (ptr_nick && ptr_nick[0])
|
||||
@@ -148,8 +154,8 @@ irc_nick_hash_color (const char *nickname)
|
||||
color += weechat_utf8_char_int (ptr_nick);
|
||||
ptr_nick = weechat_utf8_next_char (ptr_nick);
|
||||
}
|
||||
return (color %
|
||||
weechat_config_integer (weechat_config_get ("weechat.look.color_nicks_number")));
|
||||
|
||||
return (color % irc_config_num_nick_colors);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -161,9 +167,15 @@ const char *
|
||||
irc_nick_find_color (const char *nickname)
|
||||
{
|
||||
int color;
|
||||
char *nickname2, color_name[64];
|
||||
char *nickname2;
|
||||
const char *forced_color;
|
||||
|
||||
if (!irc_config_nick_colors)
|
||||
irc_config_set_nick_colors ();
|
||||
|
||||
if (irc_config_num_nick_colors == 0)
|
||||
return weechat_color ("default");
|
||||
|
||||
nickname2 = irc_nick_strdup_for_color (nickname);
|
||||
|
||||
/* look if color is forced */
|
||||
@@ -186,9 +198,7 @@ irc_nick_find_color (const char *nickname)
|
||||
free (nickname2);
|
||||
|
||||
/* return color */
|
||||
snprintf (color_name, sizeof (color_name),
|
||||
"chat_nick_color%02d", color + 1);
|
||||
return weechat_color (color_name);
|
||||
return weechat_color (irc_config_nick_colors[color]);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -200,8 +210,15 @@ const char *
|
||||
irc_nick_find_color_name (const char *nickname)
|
||||
{
|
||||
int color;
|
||||
char *nickname2, color_name[128];
|
||||
char *nickname2;
|
||||
const char *forced_color;
|
||||
static char *default_color = "default";
|
||||
|
||||
if (!irc_config_nick_colors)
|
||||
irc_config_set_nick_colors ();
|
||||
|
||||
if (irc_config_num_nick_colors == 0)
|
||||
return default_color;
|
||||
|
||||
nickname2 = irc_nick_strdup_for_color (nickname);
|
||||
|
||||
@@ -221,9 +238,7 @@ irc_nick_find_color_name (const char *nickname)
|
||||
free (nickname2);
|
||||
|
||||
/* return color name */
|
||||
snprintf (color_name, sizeof (color_name),
|
||||
"weechat.color.chat_nick_color%02d", color + 1);
|
||||
return weechat_config_color (weechat_config_get (color_name));
|
||||
return irc_config_nick_colors[color];
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -46,6 +46,8 @@ struct t_irc_nick
|
||||
extern int irc_nick_valid (struct t_irc_channel *channel,
|
||||
struct t_irc_nick *nick);
|
||||
extern int irc_nick_is_nick (const char *string);
|
||||
extern int irc_nick_config_colors_cb (void *data, const char *option,
|
||||
const char *value);
|
||||
extern const char *irc_nick_find_color (const char *nickname);
|
||||
extern const char *irc_nick_find_color_name (const char *nickname);
|
||||
extern int irc_nick_is_op (struct t_irc_server *server,
|
||||
|
||||
Reference in New Issue
Block a user