From 05390016c0064d3eabd3a897b16ac60cb832ed06 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Fri, 25 Jan 2013 19:05:23 +0100 Subject: irc: add color in output of /names when result is on server buffer (channel not joined) (bug #38070) --- ChangeLog | 4 +- src/plugins/irc/irc-bar-item.c | 2 +- src/plugins/irc/irc-nick.c | 12 +++--- src/plugins/irc/irc-nick.h | 2 +- src/plugins/irc/irc-protocol.c | 98 ++++++++++++++++++++++++++++++------------ 5 files changed, 82 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index 48f92fc6b..32e3ab4f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,13 +1,15 @@ WeeChat ChangeLog ================= Sébastien Helleu -v0.4.1-dev, 2013-01-22 +v0.4.1-dev, 2013-01-25 Version 0.4.1 (under dev!) -------------------------- * guile: fix compilation with guile 2.0 +* irc: add color in output of /names when result is on server buffer (channel + not joined) (bug #38070) * perl: simplify code to load scripts * scripts: do not allow empty script name in function "register" diff --git a/src/plugins/irc/irc-bar-item.c b/src/plugins/irc/irc-bar-item.c index 1bfc76601..582e58fe9 100644 --- a/src/plugins/irc/irc-bar-item.c +++ b/src/plugins/irc/irc-bar-item.c @@ -493,7 +493,7 @@ irc_bar_item_input_prompt (void *data, struct t_gui_bar_item *item, if (ptr_nick->prefix[0] != ' ') { snprintf (str_prefix, sizeof (str_prefix), "%s%s", - weechat_color (irc_nick_get_prefix_color_name (server, ptr_nick)), + weechat_color (irc_nick_get_prefix_color_name (server, ptr_nick->prefix[0])), ptr_nick->prefix); } } diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c index 87bfa91c5..562185eb5 100644 --- a/src/plugins/irc/irc-nick.c +++ b/src/plugins/irc/irc-nick.c @@ -425,8 +425,7 @@ irc_nick_get_nicklist_group (struct t_irc_server *server, */ const char * -irc_nick_get_prefix_color_name (struct t_irc_server *server, - struct t_irc_nick *nick) +irc_nick_get_prefix_color_name (struct t_irc_server *server, char prefix) { static char *default_color = ""; const char *prefix_modes, *color; @@ -435,7 +434,7 @@ irc_nick_get_prefix_color_name (struct t_irc_server *server, if (irc_config_hashtable_nick_prefixes) { - index = irc_server_get_prefix_char_index (server, nick->prefix[0]); + index = irc_server_get_prefix_char_index (server, prefix); if (index >= 0) { mode[0] = ' '; @@ -507,7 +506,7 @@ irc_nick_nicklist_add (struct t_irc_server *server, nick->name, irc_nick_get_color_for_nicklist (server, nick), nick->prefix, - irc_nick_get_prefix_color_name (server, nick), + irc_nick_get_prefix_color_name (server, nick->prefix[0]), 1); } @@ -569,7 +568,7 @@ irc_nick_nicklist_set_prefix_color_all () { irc_nick_nicklist_set (ptr_channel, ptr_nick, "prefix_color", irc_nick_get_prefix_color_name (ptr_server, - ptr_nick)); + ptr_nick->prefix[0])); } } } @@ -922,7 +921,8 @@ irc_nick_mode_for_display (struct t_irc_server *server, struct t_irc_nick *nick, { str_prefix[0] = '\0'; } - str_prefix_color = weechat_color (irc_nick_get_prefix_color_name (server, nick)); + str_prefix_color = weechat_color (irc_nick_get_prefix_color_name (server, + nick->prefix[0])); } else { diff --git a/src/plugins/irc/irc-nick.h b/src/plugins/irc/irc-nick.h index 80483a03f..d2ab2aab9 100644 --- a/src/plugins/irc/irc-nick.h +++ b/src/plugins/irc/irc-nick.h @@ -56,7 +56,7 @@ extern int irc_nick_has_prefix_mode (struct t_irc_server *server, struct t_irc_nick *nick, char prefix_mode); extern const char *irc_nick_get_prefix_color_name (struct t_irc_server *server, - struct t_irc_nick *nick); + char prefix); extern void irc_nick_nicklist_set_prefix_color_all (); extern void irc_nick_nicklist_set_color_all (); extern struct t_irc_nick *irc_nick_new (struct t_irc_server *server, diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 29430e4d0..76891218c 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -3732,8 +3732,8 @@ IRC_PROTOCOL_CALLBACK(352) IRC_PROTOCOL_CALLBACK(353) { char *pos_channel, *pos_nick, *pos_nick_orig, *pos_host, *nickname; - char *prefixes; - int args, i, away; + char *prefixes, *str_nicks; + int args, i, away, length; struct t_irc_channel *ptr_channel; struct t_irc_nick *ptr_nick; @@ -3753,35 +3753,52 @@ IRC_PROTOCOL_CALLBACK(353) IRC_PROTOCOL_MIN_ARGS(args + 1); ptr_channel = irc_channel_search (server, pos_channel); + str_nicks = NULL; - if (ptr_channel && ptr_channel->nicks) + /* + * for a channel without buffer, prepare a string that will be built + * with nicks and colors (argc-args is the number of nicks) + */ + if (!ptr_channel) { - for (i = args; i < argc; i++) - { - pos_nick = (argv[i][0] == ':') ? argv[i] + 1 : argv[i]; - pos_nick_orig = pos_nick; + /* + * prefix color (16) + nick color (16) + reset color (16) = 48 bytes + * added for each nick + */ + length = strlen (argv_eol[args]) + ((argc - args) * (16 + 16 + 16)) + 1; + str_nicks = malloc (length); + if (str_nicks) + str_nicks[0] = '\0'; + } - /* skip prefix(es) */ - while (pos_nick[0] - && (irc_server_get_prefix_char_index (server, pos_nick[0]) >= 0)) - { - pos_nick++; - } + for (i = args; i < argc; i++) + { + pos_nick = (argv[i][0] == ':') ? argv[i] + 1 : argv[i]; + pos_nick_orig = pos_nick; - /* extract nick from host */ - pos_host = strchr (pos_nick, '!'); - if (pos_host) - nickname = weechat_strndup (pos_nick, pos_host - pos_nick); - else - nickname = strdup (pos_nick); + /* skip and save prefix(es) */ + while (pos_nick[0] + && (irc_server_get_prefix_char_index (server, pos_nick[0]) >= 0)) + { + pos_nick++; + } + prefixes = (pos_nick > pos_nick_orig) ? + weechat_strndup (pos_nick_orig, pos_nick - pos_nick_orig) : NULL; - /* add or update nick on channel */ - if (nickname) + /* extract nick from host */ + pos_host = strchr (pos_nick, '!'); + if (pos_host) + nickname = weechat_strndup (pos_nick, pos_host - pos_nick); + else + nickname = strdup (pos_nick); + + /* add or update nick on channel */ + if (nickname) + { + if (ptr_channel && ptr_channel->nicks) { ptr_nick = irc_nick_search (server, ptr_channel, nickname); away = (ptr_nick && ptr_nick->away) ? 1 : 0; - prefixes = (pos_nick > pos_nick_orig) ? - weechat_strndup (pos_nick_orig, pos_nick - pos_nick_orig) : NULL; if (!irc_nick_new (server, ptr_channel, nickname, prefixes, away)) { @@ -3791,11 +3808,36 @@ IRC_PROTOCOL_CALLBACK(353) weechat_prefix ("error"), IRC_PLUGIN_NAME, nickname, ptr_channel->name); } - free (nickname); + } + else if (!ptr_channel && str_nicks) + { + if (str_nicks[0]) + { + strcat (str_nicks, IRC_COLOR_RESET); + strcat (str_nicks, " "); + } if (prefixes) - free (prefixes); + { + strcat (str_nicks, + weechat_color (irc_nick_get_prefix_color_name (server, + prefixes[0]))); + strcat (str_nicks, prefixes); + } + if (weechat_config_boolean (irc_config_look_color_nicks_in_names)) + { + if (irc_server_strcasecmp (server, nickname, server->nick) == 0) + strcat (str_nicks, IRC_COLOR_CHAT_NICK_SELF); + else + strcat (str_nicks, irc_nick_find_color (nickname)); + } + else + strcat (str_nicks, IRC_COLOR_RESET); + strcat (str_nicks, nickname); } + free (nickname); } + if (prefixes) + free (prefixes); } if (!ptr_channel) @@ -3812,11 +3854,13 @@ IRC_PROTOCOL_CALLBACK(353) IRC_COLOR_RESET, IRC_COLOR_CHAT_DELIMITERS, IRC_COLOR_RESET, - (argv_eol[args][0] == ':') ? - argv_eol[args] + 1 : argv_eol[args], + (str_nicks) ? str_nicks : "", IRC_COLOR_CHAT_DELIMITERS); } + if (str_nicks) + free (str_nicks); + return WEECHAT_RC_OK; } -- cgit v1.2.3