mirror of
https://github.com/weechat/weechat.git
synced 2026-07-04 16:53:14 +02:00
Add new option irc.look.nick_color_stop_chars
This commit is contained in:
@@ -75,6 +75,7 @@ struct t_config_option *irc_config_look_hide_nickserv_pwd;
|
||||
struct t_config_option *irc_config_look_highlight_tags;
|
||||
struct t_config_option *irc_config_look_item_display_server;
|
||||
struct t_config_option *irc_config_look_msgbuffer_fallback;
|
||||
struct t_config_option *irc_config_look_nick_color_stop_chars;
|
||||
struct t_config_option *irc_config_look_notice_as_pv;
|
||||
struct t_config_option *irc_config_look_part_closes_buffer;
|
||||
struct t_config_option *irc_config_look_raw_messages;
|
||||
@@ -153,24 +154,17 @@ irc_config_get_server_from_option_name (const char *name)
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_config_change_look_color_nicks_number: called when the
|
||||
* "weechat.look.color_nicks_number"
|
||||
* option is changed
|
||||
* irc_config_compute_nick_colors: compute nick colors for all servers and
|
||||
* channels
|
||||
*/
|
||||
|
||||
int
|
||||
irc_config_change_look_color_nicks_number (void *data, const char *option,
|
||||
const char *value)
|
||||
void
|
||||
irc_config_compute_nick_colors ()
|
||||
{
|
||||
struct t_irc_server *ptr_server;
|
||||
struct t_irc_channel *ptr_channel;
|
||||
struct t_irc_nick *ptr_nick;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
(void) value;
|
||||
|
||||
for (ptr_server = irc_servers; ptr_server;
|
||||
ptr_server = ptr_server->next_server)
|
||||
{
|
||||
@@ -184,6 +178,24 @@ irc_config_change_look_color_nicks_number (void *data, const char *option,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_config_change_look_color_nicks_number: called when the
|
||||
* "weechat.look.color_nicks_number"
|
||||
* option is changed
|
||||
*/
|
||||
|
||||
int
|
||||
irc_config_change_look_color_nicks_number (void *data, const char *option,
|
||||
const char *value)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
(void) value;
|
||||
|
||||
irc_config_compute_nick_colors ();
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
@@ -337,6 +349,22 @@ irc_config_change_look_highlight_tags (void *data,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_config_change_look_nick_color_stop_chars: called when the "nick color
|
||||
* stop chars" option is changed
|
||||
*/
|
||||
|
||||
void
|
||||
irc_config_change_look_nick_color_stop_chars (void *data,
|
||||
struct t_config_option *option)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
irc_config_compute_nick_colors ();
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_config_change_look_item_display_server: called when the
|
||||
* "item_display_server" option is
|
||||
@@ -1641,6 +1669,26 @@ irc_config_init ()
|
||||
"private and that private buffer is not found"),
|
||||
"current|server", 0, 0, "current", NULL, 0, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL);
|
||||
irc_config_look_nick_color_stop_chars = weechat_config_new_option (
|
||||
irc_config_file, ptr_section,
|
||||
"nick_color_stop_chars", "string",
|
||||
N_("chars used to stop in nick when computing color with letters of "
|
||||
"nick (at least one char outside this list must be in string before "
|
||||
"stopping) (example: nick \"_nick_away\" with \"_\" in chars will "
|
||||
"return color of nick \"_nick\")"),
|
||||
NULL, 0, 0, "_|[", NULL, 0, NULL, NULL,
|
||||
&irc_config_change_look_nick_color_stop_chars, NULL, NULL, NULL);
|
||||
irc_config_look_notice_as_pv = weechat_config_new_option (
|
||||
irc_config_file, ptr_section,
|
||||
"notice_as_pv", "integer",
|
||||
N_("display notices as private messages (if auto, use private buffer "
|
||||
"if found)"),
|
||||
"auto|never|always", 0, 0, "auto", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
irc_config_look_part_closes_buffer = weechat_config_new_option (
|
||||
irc_config_file, ptr_section,
|
||||
"part_closes_buffer", "boolean",
|
||||
N_("close buffer when /part is issued on a channel"),
|
||||
NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
irc_config_look_raw_messages = weechat_config_new_option (
|
||||
irc_config_file, ptr_section,
|
||||
"raw_messages", "integer",
|
||||
@@ -1669,17 +1717,6 @@ irc_config_init ()
|
||||
"smart_filter_quit", "boolean",
|
||||
N_("enable smart filter for \"part\" and \"quit\" messages"),
|
||||
NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
irc_config_look_notice_as_pv = weechat_config_new_option (
|
||||
irc_config_file, ptr_section,
|
||||
"notice_as_pv", "integer",
|
||||
N_("display notices as private messages (if auto, use private buffer "
|
||||
"if found)"),
|
||||
"auto|never|always", 0, 0, "auto", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
irc_config_look_part_closes_buffer = weechat_config_new_option (
|
||||
irc_config_file, ptr_section,
|
||||
"part_closes_buffer", "boolean",
|
||||
N_("close buffer when /part is issued on a channel"),
|
||||
NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
irc_config_look_topic_strip_colors = weechat_config_new_option (
|
||||
irc_config_file, ptr_section,
|
||||
"topic_strip_colors", "boolean",
|
||||
|
||||
@@ -94,6 +94,7 @@ extern struct t_config_option *irc_config_look_hide_nickserv_pwd;
|
||||
extern struct t_config_option *irc_config_look_highlight_tags;
|
||||
extern struct t_config_option *irc_config_look_item_display_server;
|
||||
extern struct t_config_option *irc_config_look_msgbuffer_fallback;
|
||||
extern struct t_config_option *irc_config_look_nick_color_stop_chars;
|
||||
extern struct t_config_option *irc_config_look_notice_as_pv;
|
||||
extern struct t_config_option *irc_config_look_part_closes_buffer;
|
||||
extern struct t_config_option *irc_config_look_raw_messages;
|
||||
|
||||
+69
-18
@@ -90,15 +90,55 @@ irc_nick_is_nick (const char *string)
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_nick_find_color: find a color code for a nick
|
||||
* (according to nick letters)
|
||||
* irc_nick_strdup_for_color: duplicate a nick and stop at first char in list
|
||||
* (using option irc.look.nick_color_stop_chars)
|
||||
*/
|
||||
|
||||
const char *
|
||||
irc_nick_find_color (const char *nickname)
|
||||
char *
|
||||
irc_nick_strdup_for_color (const char *nickname)
|
||||
{
|
||||
int char_size, other_char_seen;
|
||||
char *result, *pos, utf_char[16];
|
||||
|
||||
result = malloc (strlen (nickname) + 1);
|
||||
pos = result;
|
||||
other_char_seen = 0;
|
||||
while (nickname[0])
|
||||
{
|
||||
char_size = weechat_utf8_char_size (nickname);
|
||||
memcpy (utf_char, nickname, char_size);
|
||||
utf_char[char_size] = '\0';
|
||||
|
||||
if (strstr (weechat_config_string (irc_config_look_nick_color_stop_chars),
|
||||
utf_char))
|
||||
{
|
||||
if (other_char_seen)
|
||||
{
|
||||
pos[0] = '\0';
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
other_char_seen = 1;
|
||||
}
|
||||
memcpy (pos, utf_char, char_size);
|
||||
pos += char_size;
|
||||
|
||||
nickname += char_size;
|
||||
}
|
||||
pos[0] = '\0';
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_nick_hash_color: hash a nickname to find color
|
||||
*/
|
||||
|
||||
int
|
||||
irc_nick_hash_color (const char *nickname)
|
||||
{
|
||||
int color;
|
||||
char color_name[64];
|
||||
const char *ptr_nick;
|
||||
|
||||
color = 0;
|
||||
@@ -108,8 +148,25 @@ irc_nick_find_color (const char *nickname)
|
||||
color += weechat_utf8_char_int (ptr_nick);
|
||||
ptr_nick = weechat_utf8_next_char (ptr_nick);
|
||||
}
|
||||
color = (color %
|
||||
weechat_config_integer (weechat_config_get ("weechat.look.color_nicks_number")));
|
||||
return (color %
|
||||
weechat_config_integer (weechat_config_get ("weechat.look.color_nicks_number")));
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_nick_find_color: find a color code for a nick
|
||||
* (according to nick letters)
|
||||
*/
|
||||
|
||||
const char *
|
||||
irc_nick_find_color (const char *nickname)
|
||||
{
|
||||
int color;
|
||||
char *nickname2, color_name[64];
|
||||
|
||||
nickname2 = irc_nick_strdup_for_color (nickname);
|
||||
color = irc_nick_hash_color ((nickname2) ? nickname2 : nickname);
|
||||
if (nickname2)
|
||||
free (nickname2);
|
||||
|
||||
snprintf (color_name, sizeof (color_name),
|
||||
"chat_nick_color%02d", color + 1);
|
||||
@@ -126,18 +183,12 @@ const char *
|
||||
irc_nick_find_color_name (const char *nickname)
|
||||
{
|
||||
int color;
|
||||
char color_name[128];
|
||||
const char *ptr_nick;
|
||||
char *nickname2, color_name[128];
|
||||
|
||||
color = 0;
|
||||
ptr_nick = nickname;
|
||||
while (ptr_nick && ptr_nick[0])
|
||||
{
|
||||
color += weechat_utf8_char_int (ptr_nick);
|
||||
ptr_nick = weechat_utf8_next_char (ptr_nick);
|
||||
}
|
||||
color = (color %
|
||||
weechat_config_integer (weechat_config_get ("weechat.look.color_nicks_number")));
|
||||
nickname2 = irc_nick_strdup_for_color (nickname);
|
||||
color = irc_nick_hash_color ((nickname2) ? nickname2 : nickname);
|
||||
if (nickname2)
|
||||
free (nickname2);
|
||||
|
||||
snprintf (color_name, sizeof (color_name),
|
||||
"weechat.color.chat_nick_color%02d", color + 1);
|
||||
|
||||
Reference in New Issue
Block a user