irc: add color in output of /names when result is on server buffer (channel not joined) (bug #38070)

This commit is contained in:
Sebastien Helleu 2013-01-25 19:05:23 +01:00
parent 62e9a1715b
commit 05390016c0
5 changed files with 83 additions and 37 deletions

View File

@ -1,13 +1,15 @@
WeeChat ChangeLog
=================
Sébastien Helleu <flashcode@flashtux.org>
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"

View File

@ -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);
}
}

View File

@ -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
{

View File

@ -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,

View File

@ -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++)
/*
* 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';
}
for (i = args; i < argc; i++)
{
pos_nick = (argv[i][0] == ':') ? argv[i] + 1 : argv[i];
pos_nick_orig = pos_nick;
/* skip and save prefix(es) */
while (pos_nick[0]
&& (irc_server_get_prefix_char_index (server, pos_nick[0]) >= 0))
{
pos_nick = (argv[i][0] == ':') ? argv[i] + 1 : argv[i];
pos_nick_orig = pos_nick;
pos_nick++;
}
prefixes = (pos_nick > pos_nick_orig) ?
weechat_strndup (pos_nick_orig, pos_nick - pos_nick_orig) : NULL;
/* skip prefix(es) */
while (pos_nick[0]
&& (irc_server_get_prefix_char_index (server, pos_nick[0]) >= 0))
{
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);
/* 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)
/* 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);
if (prefixes)
free (prefixes);
}
else if (!ptr_channel && str_nicks)
{
if (str_nicks[0])
{
strcat (str_nicks, IRC_COLOR_RESET);
strcat (str_nicks, " ");
}
if (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;
}