diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2010-06-15 14:13:59 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2010-06-15 14:13:59 +0200 |
commit | de49e31965b0d0c8357a181335bc8210f1e69a45 (patch) | |
tree | 7fb3a78facfbd07a94829a6294eff87f39970726 /src | |
parent | 44c95288ab28f9ccc5a6901226a987222000c66f (diff) | |
download | weechat-de49e31965b0d0c8357a181335bc8210f1e69a45.zip |
Add IRC info "irc_nick_color_name" to get color name of a nick
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/irc/irc-info.c | 9 | ||||
-rw-r--r-- | src/plugins/irc/irc-nick.c | 31 | ||||
-rw-r--r-- | src/plugins/irc/irc-nick.h | 1 |
3 files changed, 39 insertions, 2 deletions
diff --git a/src/plugins/irc/irc-info.c b/src/plugins/irc/irc-info.c index 0e437a37b..6ad2dc584 100644 --- a/src/plugins/irc/irc-info.c +++ b/src/plugins/irc/irc-info.c @@ -102,6 +102,10 @@ irc_info_get_info_cb (void *data, const char *info_name, { return irc_nick_find_color (arguments); } + else if (weechat_strcasecmp (info_name, "irc_nick_color_name") == 0) + { + return irc_nick_find_color_name (arguments); + } else if (weechat_strcasecmp (info_name, "irc_buffer") == 0) { if (arguments && arguments[0]) @@ -456,7 +460,10 @@ irc_info_init () weechat_hook_info ("irc_nick_from_host", N_("get nick from IRC host"), N_("IRC host (like `:nick!name@server.com`)"), &irc_info_get_info_cb, NULL); - weechat_hook_info ("irc_nick_color", N_("get nick color"), + weechat_hook_info ("irc_nick_color", N_("get nick color code"), + N_("nickname"), + &irc_info_get_info_cb, NULL); + weechat_hook_info ("irc_nick_color_name", N_("get nick color name"), N_("nickname"), &irc_info_get_info_cb, NULL); weechat_hook_info ("irc_buffer", N_("get buffer pointer for an IRC server/channel/nick"), diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c index 5c474440a..9ea273910 100644 --- a/src/plugins/irc/irc-nick.c +++ b/src/plugins/irc/irc-nick.c @@ -90,7 +90,8 @@ irc_nick_is_nick (const char *string) } /* - * irc_nick_find_color: find a color for a nick (according to nick letters) + * irc_nick_find_color: find a color code for a nick + * (according to nick letters) */ const char * @@ -117,6 +118,34 @@ irc_nick_find_color (const char *nickname) } /* + * irc_nick_find_color_name: find a color name for a nick + * (according to nick letters) + */ + +const char * +irc_nick_find_color_name (const char *nickname) +{ + int color; + char color_name[128]; + const char *ptr_nick; + + 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"))); + + snprintf (color_name, sizeof (color_name), + "weechat.color.chat_nick_color%02d", color + 1); + + return weechat_config_color (weechat_config_get (color_name)); +} + +/* * irc_nick_get_gui_infos: get GUI infos for a nick (sort_index, prefix, * prefix color) */ diff --git a/src/plugins/irc/irc-nick.h b/src/plugins/irc/irc-nick.h index 12773dd19..43334207b 100644 --- a/src/plugins/irc/irc-nick.h +++ b/src/plugins/irc/irc-nick.h @@ -70,6 +70,7 @@ 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 const char *irc_nick_find_color (const char *nickname); +extern const char *irc_nick_find_color_name (const char *nickname); extern void irc_nick_get_gui_infos (struct t_irc_server *server, struct t_irc_nick *nick, char *prefix, int *prefix_color, |