about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-01-16 14:04:53 -0500
committerJune McEnroe <june@causal.agency>2021-01-16 14:15:00 -0500
commit063f2aaa0c578ee54209b1ce31b0f584af583488 (patch)
treefdfa23847d747b08f8aa0b52b32462f43e9adab9
parentRename ignore code to filter (diff)
downloadcatgirl-063f2aaa0c578ee54209b1ce31b0f584af583488.tar.gz
catgirl-063f2aaa0c578ee54209b1ce31b0f584af583488.zip
Add -I highlight option and /highlight
Diffstat (limited to '')
-rw-r--r--catgirl.142
-rw-r--r--chat.c2
-rw-r--r--command.c40
-rw-r--r--handle.c9
4 files changed, 74 insertions, 19 deletions
diff --git a/catgirl.1 b/catgirl.1
index ce3215e..a7efeb3 100644
--- a/catgirl.1
+++ b/catgirl.1
@@ -11,6 +11,7 @@
 .Op Fl Relv
 .Op Fl C Ar copy
 .Op Fl H Ar hash
+.Op Fl I Ar highlight
 .Op Fl N Ar notify
 .Op Fl O Ar open
 .Op Fl S Ar bind
@@ -94,6 +95,34 @@ To use only colors from
 the 16-color terminal set,
 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
 Send notifications using a utility.
 Use more than once to add arguments to
@@ -176,7 +205,7 @@ Connect to
 .Ar host .
 .
 .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
 .Ql * ,
 .Ql \&?
@@ -422,8 +451,13 @@ List the server help for a topic.
 Try
 .Ic /help index
 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
-List message filtering patterns
+List message ignore patterns
 or temporarily add a pattern.
 To permanently add a pattern, use
 .Fl i .
@@ -438,8 +472,10 @@ Open the most recent URL from
 .Ar nick
 or matching
 .Ar substring .
+.It Ic /unhighlight Ar pattern
+Temporarily remove a message highlight pattern.
 .It Ic /unignore Ar pattern
-Temporarily remove a message filtering pattern.
+Temporarily remove a message ignore pattern.
 .It Ic /window Ar name
 Switch to window by name.
 .It Ic /window Ar num , Ic / Ns Ar num
diff --git a/chat.c b/chat.c
index cdea9a0..ebffe46 100644
--- a/chat.c
+++ b/chat.c
@@ -199,6 +199,7 @@ int main(int argc, char *argv[]) {
 		{ .val = '!', .name = "insecure", no_argument },
 		{ .val = 'C', .name = "copy", required_argument },
 		{ .val = 'H', .name = "hash", required_argument },
+		{ .val = 'I', .name = "highlight", required_argument },
 		{ .val = 'N', .name = "notify", required_argument },
 		{ .val = 'O', .name = "open", required_argument },
 		{ .val = 'R', .name = "restrict", no_argument },
@@ -234,6 +235,7 @@ int main(int argc, char *argv[]) {
 			break; case '!': insecure = true;
 			break; case 'C': utilPush(&urlCopyUtil, optarg);
 			break; case 'H': parseHash(optarg);
+			break; case 'I': filterAdd(Hot, optarg);
 			break; case 'N': utilPush(&uiNotifyUtil, optarg);
 			break; case 'O': utilPush(&urlOpenUtil, optarg);
 			break; case 'R': self.restricted = true;
diff --git a/command.c b/command.c
index f266878..998d9a2 100644
--- a/command.c
+++ b/command.c
@@ -386,20 +386,20 @@ static void commandCopy(uint id, char *params) {
 	urlCopyMatch(id, params);
 }
 
-static void commandIgnore(uint id, char *params) {
+static void commandFilter(enum Heat heat, uint id, char *params) {
 	if (params) {
-		struct Filter filter = filterAdd(Ice, params);
+		struct Filter filter = filterAdd(heat, params);
 		uiFormat(
-			id, Cold, NULL, "Ignoring \3%02d%s %s %s %s",
-			Brown, filter.mask,
+			id, Cold, NULL, "%sing \3%02d%s %s %s %s",
+			(heat == Hot ? "Highlight" : "Ignor"), Brown, filter.mask,
 			(filter.cmd ?: ""), (filter.chan ?: ""), (filter.mesg ?: "")
 		);
 	} else {
 		for (size_t i = 0; i < FilterCap && filters[i].mask; ++i) {
-			if (filters[i].heat != Ice) continue;
+			if (filters[i].heat != heat) continue;
 			uiFormat(
-				Network, Warm, NULL, "Ignoring \3%02d%s %s %s %s",
-				Brown, filters[i].mask,
+				Network, Warm, NULL, "%sing \3%02d%s %s %s %s",
+				(heat == Hot ? "Highlight" : "Ignor"), Brown, filters[i].mask,
 				(filters[i].cmd ?: ""), (filters[i].chan ?: ""),
 				(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;
-	struct Filter filter = filterParse(Ice, params);
+	struct Filter filter = filterParse(heat, params);
 	bool found = filterRemove(filter);
 	uiFormat(
-		id, Cold, NULL, "%s ignoring \3%02d%s %s %s %s",
-		(found ? "No longer" : "Not"), Brown, filter.mask,
-		(filter.cmd ?: ""), (filter.chan ?: ""), (filter.mesg ?: "")
+		id, Cold, NULL, "%s %sing \3%02d%s %s %s %s",
+		(found ? "No longer" : "Not"), (heat == Hot ? "highlight" : "ignor"),
+		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) {
 	execID = id;
 
@@ -479,6 +493,7 @@ static const struct Handler {
 	{ "/except", commandExcept, 0 },
 	{ "/exec", commandExec, Multiline | Restricted },
 	{ "/help", commandHelp, 0 },
+	{ "/highlight", commandHighlight, 0 },
 	{ "/ignore", commandIgnore, 0 },
 	{ "/invex", commandInvex, 0 },
 	{ "/invite", commandInvite, 0 },
@@ -506,6 +521,7 @@ static const struct Handler {
 	{ "/topic", commandTopic, 0 },
 	{ "/unban", commandUnban, 0 },
 	{ "/unexcept", commandUnexcept, 0 },
+	{ "/unhighlight", commandUnhighlight, 0 },
 	{ "/unignore", commandUnignore, 0 },
 	{ "/uninvex", commandUninvex, 0 },
 	{ "/voice", commandVoice, 0 },
diff --git a/handle.c b/handle.c
index 702196b..ddf43e8 100644
--- a/handle.c
+++ b/handle.c
@@ -1198,8 +1198,9 @@ static void handlePrivmsg(struct Message *msg) {
 
 	bool notice = (msg->cmd[0] == 'N');
 	bool action = isAction(msg);
-	bool mention = !mine && isMention(msg);
-	enum Heat heat = filterCheck((mention || query ? Hot : Warm), id, msg);
+	bool highlight = !mine && isMention(msg);
+	enum Heat heat = filterCheck((highlight || query ? Hot : Warm), id, msg);
+	if (heat > Warm && !mine && !query) highlight = true;
 	if (!notice && !mine && heat > Ice) {
 		completeTouch(id, msg->nick, hash(msg->user));
 	}
@@ -1222,7 +1223,7 @@ static void handlePrivmsg(struct Message *msg) {
 		uiFormat(
 			id, heat, tagTime(msg),
 			"%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]
 		);
 	} else {
@@ -1231,7 +1232,7 @@ static void handlePrivmsg(struct Message *msg) {
 		uiFormat(
 			id, heat, tagTime(msg),
 			"%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]
 		);
 	}