diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2014-11-11 11:15:23 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2014-11-11 11:17:50 +0100 |
commit | 6f5f6da0ebd58c3c130130bb01b85b2986de35bc (patch) | |
tree | 00de57ee7a9180102d6c0e8501f4060a1a91d331 /src/plugins | |
parent | 9be4bc07b98f96f49654ac34f60dead862e6e675 (diff) | |
download | weechat-6f5f6da0ebd58c3c130130bb01b85b2986de35bc.zip |
irc: add infolist "irc_color_weechat"
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/irc/irc-color.c | 34 | ||||
-rw-r--r-- | src/plugins/irc/irc-color.h | 1 | ||||
-rw-r--r-- | src/plugins/irc/irc-info.c | 20 |
3 files changed, 55 insertions, 0 deletions
diff --git a/src/plugins/irc/irc-color.c b/src/plugins/irc/irc-color.c index 63cac5b73..c603a0f1a 100644 --- a/src/plugins/irc/irc-color.c +++ b/src/plugins/irc/irc-color.c @@ -806,6 +806,40 @@ irc_color_for_tags (const char *color) } /* + * Adds mapping between IRC color codes and WeeChat color names in an infolist. + * + * Returns: + * 1: OK + * 0: error + */ + +int +irc_color_weechat_add_to_infolist (struct t_infolist *infolist) +{ + struct t_infolist_item *ptr_item; + char str_color_irc[32]; + int i; + + if (!infolist) + return 0; + + for (i = 0; i < IRC_NUM_COLORS; i++) + { + ptr_item = weechat_infolist_new_item (infolist); + if (!ptr_item) + return 0; + + snprintf (str_color_irc, sizeof (str_color_irc), "%02d", i); + if (!weechat_infolist_new_var_string (ptr_item, "color_irc", str_color_irc)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "color_weechat", irc_color_to_weechat[i])) + return 0; + } + + return 1; +} + +/* * Ends IRC colors. */ diff --git a/src/plugins/irc/irc-color.h b/src/plugins/irc/irc-color.h index c1d2c8f78..a89569b15 100644 --- a/src/plugins/irc/irc-color.h +++ b/src/plugins/irc/irc-color.h @@ -109,6 +109,7 @@ extern char *irc_color_modifier_cb (void *data, const char *modifier, const char *modifier_data, const char *string); extern char *irc_color_for_tags (const char *color); +extern int irc_color_weechat_add_to_infolist (struct t_infolist *infolist); extern void irc_color_end (); #endif /* WEECHAT_IRC_COLOR_H */ diff --git a/src/plugins/irc/irc-info.c b/src/plugins/irc/irc-info.c index 0abc1f788..83ec5be01 100644 --- a/src/plugins/irc/irc-info.c +++ b/src/plugins/irc/irc-info.c @@ -26,6 +26,7 @@ #include "../weechat-plugin.h" #include "irc.h" #include "irc-channel.h" +#include "irc-color.h" #include "irc-config.h" #include "irc-ignore.h" #include "irc-message.h" @@ -563,6 +564,20 @@ irc_info_get_infolist_cb (void *data, const char *infolist_name, } } } + else if (weechat_strcasecmp (infolist_name, "irc_color_weechat") == 0) + { + ptr_infolist = weechat_infolist_new (); + if (ptr_infolist) + { + /* build list with all IRC colors */ + if (!irc_color_weechat_add_to_infolist (ptr_infolist)) + { + weechat_infolist_free (ptr_infolist); + return NULL; + } + return ptr_infolist; + } + } return NULL; } @@ -658,6 +673,11 @@ irc_info_init () N_("notify pointer (optional)"), N_("server name (wildcard \"*\" is allowed) (optional)"), &irc_info_get_infolist_cb, NULL); + weechat_hook_infolist ("irc_color_weechat", + N_("mapping between IRC color codes and WeeChat color names"), + NULL, + NULL, + &irc_info_get_infolist_cb, NULL); /* hdata hooks */ weechat_hook_hdata ("irc_nick", N_("irc nick"), |