Add -I highlight option and /highlight

master
C. McEnroe 2021-01-16 14:04:53 -05:00
parent 5a490945ea
commit 063f2aaa0c
4 changed files with 74 additions and 19 deletions

View File

@ -11,6 +11,7 @@
.Op Fl Relv .Op Fl Relv
.Op Fl C Ar copy .Op Fl C Ar copy
.Op Fl H Ar hash .Op Fl H Ar hash
.Op Fl I Ar highlight
.Op Fl N Ar notify .Op Fl N Ar notify
.Op Fl O Ar open .Op Fl O Ar open
.Op Fl S Ar bind .Op Fl S Ar bind
@ -94,6 +95,34 @@ To use only colors from
the 16-color terminal set, the 16-color terminal set,
use 0,15. use 0,15.
. .
.It Fl I Ar pattern , Cm highlight = Ar pattern
Add a case-insensitive message highlight pattern,
which may contain
.Ql * ,
.Ql \&?
and
.Ql []
wildcards as in
.Xr sh 1 .
The format of the pattern is as follows:
.Bd -ragged -offset indent
.Ar nick Ns Oo Ar !user@host
.Oo Ar command
.Oo Ar channel
.Oo Ar message
.Oc Oc Oc Oc
.Ed
.Pp
The commands which can be filtered are:
.Sy INVITE ,
.Sy JOIN ,
.Sy NICK ,
.Sy NOTICE ,
.Sy PART ,
.Sy PRIVMSG ,
.Sy QUIT ,
.Sy SETNAME .
.
.It Fl N Ar util , Cm notify = Ar util .It Fl N Ar util , Cm notify = Ar util
Send notifications using a utility. Send notifications using a utility.
Use more than once to add arguments to Use more than once to add arguments to
@ -176,7 +205,7 @@ Connect to
.Ar host . .Ar host .
. .
.It Fl i Ar pattern , Cm ignore = Ar pattern .It Fl i Ar pattern , Cm ignore = Ar pattern
Add a case-insensitive message filtering pattern, Add a case-insensitive message ignore pattern,
which may contain which may contain
.Ql * , .Ql * ,
.Ql \&? .Ql \&?
@ -422,8 +451,13 @@ List the server help for a topic.
Try Try
.Ic /help index .Ic /help index
for a list of topics. for a list of topics.
.It Ic /highlight Op Ar pattern
List message highlight patterns
or temporarily add a pattern.
To permanently add a pattern, use
.Fl I .
.It Ic /ignore Op Ar pattern .It Ic /ignore Op Ar pattern
List message filtering patterns List message ignore patterns
or temporarily add a pattern. or temporarily add a pattern.
To permanently add a pattern, use To permanently add a pattern, use
.Fl i . .Fl i .
@ -438,8 +472,10 @@ Open the most recent URL from
.Ar nick .Ar nick
or matching or matching
.Ar substring . .Ar substring .
.It Ic /unhighlight Ar pattern
Temporarily remove a message highlight pattern.
.It Ic /unignore Ar pattern .It Ic /unignore Ar pattern
Temporarily remove a message filtering pattern. Temporarily remove a message ignore pattern.
.It Ic /window Ar name .It Ic /window Ar name
Switch to window by name. Switch to window by name.
.It Ic /window Ar num , Ic / Ns Ar num .It Ic /window Ar num , Ic / Ns Ar num

2
chat.c
View File

@ -199,6 +199,7 @@ int main(int argc, char *argv[]) {
{ .val = '!', .name = "insecure", no_argument }, { .val = '!', .name = "insecure", no_argument },
{ .val = 'C', .name = "copy", required_argument }, { .val = 'C', .name = "copy", required_argument },
{ .val = 'H', .name = "hash", required_argument }, { .val = 'H', .name = "hash", required_argument },
{ .val = 'I', .name = "highlight", required_argument },
{ .val = 'N', .name = "notify", required_argument }, { .val = 'N', .name = "notify", required_argument },
{ .val = 'O', .name = "open", required_argument }, { .val = 'O', .name = "open", required_argument },
{ .val = 'R', .name = "restrict", no_argument }, { .val = 'R', .name = "restrict", no_argument },
@ -234,6 +235,7 @@ int main(int argc, char *argv[]) {
break; case '!': insecure = true; break; case '!': insecure = true;
break; case 'C': utilPush(&urlCopyUtil, optarg); break; case 'C': utilPush(&urlCopyUtil, optarg);
break; case 'H': parseHash(optarg); break; case 'H': parseHash(optarg);
break; case 'I': filterAdd(Hot, optarg);
break; case 'N': utilPush(&uiNotifyUtil, optarg); break; case 'N': utilPush(&uiNotifyUtil, optarg);
break; case 'O': utilPush(&urlOpenUtil, optarg); break; case 'O': utilPush(&urlOpenUtil, optarg);
break; case 'R': self.restricted = true; break; case 'R': self.restricted = true;

View File

@ -386,20 +386,20 @@ static void commandCopy(uint id, char *params) {
urlCopyMatch(id, params); urlCopyMatch(id, params);
} }
static void commandIgnore(uint id, char *params) { static void commandFilter(enum Heat heat, uint id, char *params) {
if (params) { if (params) {
struct Filter filter = filterAdd(Ice, params); struct Filter filter = filterAdd(heat, params);
uiFormat( uiFormat(
id, Cold, NULL, "Ignoring \3%02d%s %s %s %s", id, Cold, NULL, "%sing \3%02d%s %s %s %s",
Brown, filter.mask, (heat == Hot ? "Highlight" : "Ignor"), Brown, filter.mask,
(filter.cmd ?: ""), (filter.chan ?: ""), (filter.mesg ?: "") (filter.cmd ?: ""), (filter.chan ?: ""), (filter.mesg ?: "")
); );
} else { } else {
for (size_t i = 0; i < FilterCap && filters[i].mask; ++i) { for (size_t i = 0; i < FilterCap && filters[i].mask; ++i) {
if (filters[i].heat != Ice) continue; if (filters[i].heat != heat) continue;
uiFormat( uiFormat(
Network, Warm, NULL, "Ignoring \3%02d%s %s %s %s", Network, Warm, NULL, "%sing \3%02d%s %s %s %s",
Brown, filters[i].mask, (heat == Hot ? "Highlight" : "Ignor"), Brown, filters[i].mask,
(filters[i].cmd ?: ""), (filters[i].chan ?: ""), (filters[i].cmd ?: ""), (filters[i].chan ?: ""),
(filters[i].mesg ?: "") (filters[i].mesg ?: "")
); );
@ -407,17 +407,31 @@ static void commandIgnore(uint id, char *params) {
} }
} }
static void commandUnignore(uint id, char *params) { static void commandUnfilter(enum Heat heat, uint id, char *params) {
if (!params) return; if (!params) return;
struct Filter filter = filterParse(Ice, params); struct Filter filter = filterParse(heat, params);
bool found = filterRemove(filter); bool found = filterRemove(filter);
uiFormat( uiFormat(
id, Cold, NULL, "%s ignoring \3%02d%s %s %s %s", id, Cold, NULL, "%s %sing \3%02d%s %s %s %s",
(found ? "No longer" : "Not"), Brown, filter.mask, (found ? "No longer" : "Not"), (heat == Hot ? "highlight" : "ignor"),
(filter.cmd ?: ""), (filter.chan ?: ""), (filter.mesg ?: "") Brown, filter.mask, (filter.cmd ?: ""), (filter.chan ?: ""),
(filter.mesg ?: "")
); );
} }
static void commandHighlight(uint id, char *params) {
commandFilter(Hot, id, params);
}
static void commandIgnore(uint id, char *params) {
commandFilter(Ice, id, params);
}
static void commandUnhighlight(uint id, char *params) {
commandUnfilter(Hot, id, params);
}
static void commandUnignore(uint id, char *params) {
commandUnfilter(Hot, id, params);
}
static void commandExec(uint id, char *params) { static void commandExec(uint id, char *params) {
execID = id; execID = id;
@ -479,6 +493,7 @@ static const struct Handler {
{ "/except", commandExcept, 0 }, { "/except", commandExcept, 0 },
{ "/exec", commandExec, Multiline | Restricted }, { "/exec", commandExec, Multiline | Restricted },
{ "/help", commandHelp, 0 }, { "/help", commandHelp, 0 },
{ "/highlight", commandHighlight, 0 },
{ "/ignore", commandIgnore, 0 }, { "/ignore", commandIgnore, 0 },
{ "/invex", commandInvex, 0 }, { "/invex", commandInvex, 0 },
{ "/invite", commandInvite, 0 }, { "/invite", commandInvite, 0 },
@ -506,6 +521,7 @@ static const struct Handler {
{ "/topic", commandTopic, 0 }, { "/topic", commandTopic, 0 },
{ "/unban", commandUnban, 0 }, { "/unban", commandUnban, 0 },
{ "/unexcept", commandUnexcept, 0 }, { "/unexcept", commandUnexcept, 0 },
{ "/unhighlight", commandUnhighlight, 0 },
{ "/unignore", commandUnignore, 0 }, { "/unignore", commandUnignore, 0 },
{ "/uninvex", commandUninvex, 0 }, { "/uninvex", commandUninvex, 0 },
{ "/voice", commandVoice, 0 }, { "/voice", commandVoice, 0 },

View File

@ -1198,8 +1198,9 @@ static void handlePrivmsg(struct Message *msg) {
bool notice = (msg->cmd[0] == 'N'); bool notice = (msg->cmd[0] == 'N');
bool action = isAction(msg); bool action = isAction(msg);
bool mention = !mine && isMention(msg); bool highlight = !mine && isMention(msg);
enum Heat heat = filterCheck((mention || query ? Hot : Warm), id, msg); enum Heat heat = filterCheck((highlight || query ? Hot : Warm), id, msg);
if (heat > Warm && !mine && !query) highlight = true;
if (!notice && !mine && heat > Ice) { if (!notice && !mine && heat > Ice) {
completeTouch(id, msg->nick, hash(msg->user)); completeTouch(id, msg->nick, hash(msg->user));
} }
@ -1222,7 +1223,7 @@ static void handlePrivmsg(struct Message *msg) {
uiFormat( uiFormat(
id, heat, tagTime(msg), id, heat, tagTime(msg),
"%s\35\3%d* %s\17\35\t%s%s", "%s\35\3%d* %s\17\35\t%s%s",
(mention ? "\26" : ""), hash(msg->user), msg->nick, (highlight ? "\26" : ""), hash(msg->user), msg->nick,
buf, msg->params[1] buf, msg->params[1]
); );
} else { } else {
@ -1231,7 +1232,7 @@ static void handlePrivmsg(struct Message *msg) {
uiFormat( uiFormat(
id, heat, tagTime(msg), id, heat, tagTime(msg),
"%s\3%d<%s>\17\t%s%s", "%s\3%d<%s>\17\t%s%s",
(mention ? "\26" : ""), hash(msg->user), msg->nick, (highlight ? "\26" : ""), hash(msg->user), msg->nick,
buf, msg->params[1] buf, msg->params[1]
); );
} }