1
0
mirror of https://github.com/irssi/irssi.git synced 2024-07-07 02:54:19 -04:00

/HILIGHT changed. -nick option now tells to hilight only the nick, not

the whole line. -mask option matches the text for nick mask (it didn't
even work before).


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@391 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2000-06-28 21:47:13 +00:00 committed by cras
parent dc22d8830d
commit 95b74de316
6 changed files with 64 additions and 56 deletions

View File

@ -858,12 +858,13 @@
mask, so you could for example show your friends' nicks with
different color.
/HILIGHT [-nick | -regexp | -word] [-color <color>]
/HILIGHT [-mask | -regexp | -word] [-nick] [-color <color>]
[-level <level>] [-channels <channels>] <text>
-nick: Match only for nick, <text> is a nick mask
-mask: Match only for nick, <text> is a nick mask
-regexp: <text> is a regular expression
-word: <text> must match to full words
-nick: Hilight only the nick, not the whole line
-color: Print the reply with <color> - see below
-level: Match only for <level> messages, default is
publics,msgs,notices,actions

View File

@ -49,7 +49,8 @@ static void hilight_add_config(HILIGHT_REC *rec)
iconfig_node_set_str(node, "text", rec->text);
if (rec->level > 0) config_node_set_int(node, "level", rec->level);
if (rec->color) iconfig_node_set_str(node, "color", rec->color);
if (rec->nickmask) config_node_set_bool(node, "nickmask", TRUE);
if (rec->nick) config_node_set_bool(node, "nick", TRUE);
if (rec->nickmask) config_node_set_bool(node, "mask", TRUE);
if (rec->fullword) config_node_set_bool(node, "fullword", TRUE);
if (rec->regexp) config_node_set_bool(node, "regexp", TRUE);
@ -140,28 +141,26 @@ static void sig_print_text(WINDOW_REC *window, SERVER_REC *server, const char *c
}
}
static void sig_print_text_stripped(WINDOW_REC *window, SERVER_REC *server, const char *channel, gpointer plevel, const char *str)
char *hilight_match(const char *channel, const char *nickmask, int level, const char *str)
{
GSList *tmp;
char *color, *newstr;
int len, level, best_match;
const char *color;
int len, best_match;
g_return_if_fail(str != NULL);
level = GPOINTER_TO_INT(plevel);
if (level & (MSGLEVEL_NOHILIGHT|MSGLEVEL_HILIGHT)) return;
g_return_val_if_fail(str != NULL, NULL);
color = NULL; best_match = 0;
for (tmp = hilights; tmp != NULL; tmp = tmp->next) {
HILIGHT_REC *rec = tmp->data;
if (rec->nickmask)
continue;
if ((level & (rec->level > 0 ? rec->level : DEFAULT_HILIGHT_CHECK_LEVEL)) == 0)
continue;
if (rec->channels != NULL && strarray_find(rec->channels, channel) == -1)
if (rec->channels != NULL && (channel == NULL || strarray_find(rec->channels, channel) == -1))
continue;
if (rec->regexp) {
if (rec->nickmask) {
if (nickmask == NULL || !match_wildcards(rec->text, nickmask))
continue;
} else if (rec->regexp) {
if (!regexp_match(str, rec->text))
continue;
} else if (rec->fullword) {
@ -179,19 +178,36 @@ static void sig_print_text_stripped(WINDOW_REC *window, SERVER_REC *server, cons
}
}
if (best_match > 0) {
hilight_next = FALSE;
if (best_match == 0)
return NULL;
signal_emit("print text stripped", 5, window, server, channel, GINT_TO_POINTER(level | MSGLEVEL_HILIGHT), str);
signal_stop();
if (color == NULL) color = settings_get_str("hilight_color");
return g_strconcat(isdigit(*color) ? "\003" : "", color, NULL);
}
if (color == NULL) color = "\00316";
newstr = g_strconcat(isdigit(*color) ? "\003" : "", color, str, NULL);
signal_emit("print text", 5, window, server, channel, GINT_TO_POINTER(level | MSGLEVEL_HILIGHT), newstr);
g_free(newstr);
static void sig_print_text_stripped(WINDOW_REC *window, SERVER_REC *server, const char *channel, gpointer plevel, const char *str)
{
char *newstr, *color;
int level;
hilight_next = TRUE;
}
g_return_if_fail(str != NULL);
level = GPOINTER_TO_INT(plevel);
if (level & (MSGLEVEL_NOHILIGHT|MSGLEVEL_HILIGHT)) return;
color = hilight_match(channel, NULL, level, str);
if (color == NULL) return;
hilight_next = FALSE;
signal_emit("print text stripped", 5, window, server, channel, GINT_TO_POINTER(level | MSGLEVEL_HILIGHT), str);
signal_stop();
newstr = g_strconcat(color, str, NULL);
signal_emit("print text", 5, window, server, channel, GINT_TO_POINTER(level | MSGLEVEL_HILIGHT), newstr);
g_free(newstr);
hilight_next = TRUE;
}
static void read_hilight_config(void)
@ -270,7 +286,7 @@ static void cmd_hilight_show(void)
static void cmd_hilight(const char *data)
{
/* /HILIGHT [-nick | -regexp | -word] [-color <color>] [-level <level>] [-channels <channels>] <text> */
/* /HILIGHT [-nick] [-mask | -regexp | -word] [-color <color>] [-level <level>] [-channels <channels>] <text> */
GHashTable *optlist;
HILIGHT_REC *rec;
char *colorarg, *levelarg, *chanarg, *text;
@ -312,7 +328,8 @@ static void cmd_hilight(const char *data)
}
hilights = g_slist_append(hilights, rec);
rec->nickmask = g_hash_table_lookup(optlist, "nick") != NULL;
rec->nick = g_hash_table_lookup(optlist, "nick") != NULL;
rec->nickmask = g_hash_table_lookup(optlist, "mask") != NULL;
rec->fullword = g_hash_table_lookup(optlist, "word") != NULL;
rec->regexp = g_hash_table_lookup(optlist, "regexp") != NULL;
@ -355,6 +372,7 @@ void hilight_text_init(void)
hilight_next = FALSE;
read_hilight_config();
settings_add_str("misc", "hilight_color", "8");
signal_add_first("print text", (SIGNAL_FUNC) sig_print_text);
signal_add_first("print text stripped", (SIGNAL_FUNC) sig_print_text_stripped);
@ -362,7 +380,7 @@ void hilight_text_init(void)
command_bind("hilight", NULL, (SIGNAL_FUNC) cmd_hilight);
command_bind("dehilight", NULL, (SIGNAL_FUNC) cmd_dehilight);
command_set_options("hilight", "-color -level -channels nick word regexp");
command_set_options("hilight", "-color -level -channels nick mask word regexp");
}
void hilight_text_deinit(void)

View File

@ -9,6 +9,7 @@ typedef struct {
char *color; /* if starts with number, \003 is automatically
inserted before it. */
int nick:1; /* hilight only the nick, not a full line - works only with msgs. */
int nickmask:1; /* `text 'is a nick mask - colorify the nick */
int fullword:1; /* match `text' only for full words */
int regexp:1; /* `text' is a regular expression */
@ -16,6 +17,8 @@ typedef struct {
extern GSList *hilights;
char *hilight_match(const char *channel, const char *nickmask, int level, const char *str);
void hilight_text_init(void);
void hilight_text_deinit(void);

View File

@ -53,7 +53,9 @@ static void msg_beep_check(IRC_SERVER_REC *server, int level)
}
}
static void print_channel_msg(IRC_SERVER_REC *server, const char *msg, const char *nick, const char *addr, const char *target)
static void print_channel_msg(IRC_SERVER_REC *server, const char *msg,
const char *nick, const char *addr,
const char *target)
{
CHANNEL_REC *chanrec;
NICK_REC *nickrec;
@ -62,7 +64,7 @@ static void print_channel_msg(IRC_SERVER_REC *server, const char *msg, const cha
chanrec = channel_find(server, target);
for_me = irc_nick_match(server->nick, msg);
color = irc_hilight_find_nick(target, nick, addr);
color = irc_hilight_find_nick(target, nick, addr, MSGLEVEL_PUBLIC, msg);
nickrec = chanrec == NULL ? NULL : nicklist_find(chanrec, nick);
nickmode = (!settings_get_bool("show_nickmode") || nickrec == NULL) ? "" :

View File

@ -19,36 +19,19 @@
*/
#include "module.h"
#include "settings.h"
#include "hilight-text.h"
char *irc_hilight_find_nick(const char *channel, const char *nick, const char *address)
char *irc_hilight_find_nick(const char *channel, const char *nick,
const char *address, int level, const char *msg)
{
GSList *tmp;
char *color;
int len, best_match;
char *color, *mask;
g_return_val_if_fail(channel != NULL, NULL);
g_return_val_if_fail(nick != NULL, NULL);
g_return_val_if_fail(address != NULL, NULL);
mask = g_strdup_printf("%s!%s", nick, address);
color = hilight_match(channel, mask, level, msg);
g_free(mask);
color = NULL; best_match = 0;
for (tmp = hilights; tmp != NULL; tmp = tmp->next) {
HILIGHT_REC *rec = tmp->data;
if (!rec->nickmask)
continue;
len = strlen(rec->text);
if (best_match < len) {
best_match = len;
color = rec->color;
}
}
if (best_match == 0)
return NULL;
if (color == NULL) color = "\00316";
return g_strconcat(isdigit(*color) ? "\003" : "", color, NULL);
return color;
}

View File

@ -1,6 +1,7 @@
#ifndef __IRC_HILIGHT_TEXT_H
#define __IRC_HILIGHT_TEXT_H
char *irc_hilight_find_nick(const char *channel, const char *nick, const char *address);
char *irc_hilight_find_nick(const char *channel, const char *nick,
const char *address, int level, const char *msg);
#endif