about summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--chat.c3
-rw-r--r--chat.h3
-rw-r--r--chatte.16
-rw-r--r--ui.c24
4 files changed, 32 insertions, 4 deletions
diff --git a/chat.c b/chat.c
index c7a3229..014076b 100644
--- a/chat.c
+++ b/chat.c
@@ -65,8 +65,9 @@ int main(int argc, char *argv[]) {
 	const char *webirc = NULL;
 
 	int opt;
-	while (0 < (opt = getopt(argc, argv, "W:h:j:l:n:p:u:vw:"))) {
+	while (0 < (opt = getopt(argc, argv, "NW:h:j:l:n:p:u:vw:"))) {
 		switch (opt) {
+			break; case 'N': self.notify = true;
 			break; case 'W': webirc = optarg;
 			break; case 'h': host = strdup(optarg);
 			break; case 'j': selfJoin(optarg);
diff --git a/chat.h b/chat.h
index 5502665..cb05124 100644
--- a/chat.h
+++ b/chat.h
@@ -30,10 +30,11 @@
 #define errx(...) do { uiHide(); errx(__VA_ARGS__); } while (0)
 
 struct {
-	bool verbose;
 	char *nick;
 	char *user;
 	char *join;
+	bool verbose;
+	bool notify;
 } self;
 
 void selfNick(const char *nick);
diff --git a/chatte.1 b/chatte.1
index a0824fe..c8420ee 100644
--- a/chatte.1
+++ b/chatte.1
@@ -8,7 +8,7 @@
 .
 .Sh SYNOPSIS
 .Nm
-.Op Fl v
+.Op Fl Nv
 .Op Fl W Ar pass
 .Op Fl h Ar host
 .Op Fl j Ar chan
@@ -27,6 +27,10 @@ which only supports TLS.
 The arguments are as follows:
 .
 .Bl -tag -width Ds
+.It Fl N
+Send notifications with
+.Xr notify-send 1 .
+.
 .It Fl W Ar pass
 Send
 .Ql WEBIRC
diff --git a/ui.c b/ui.c
index c4d83bc..6075217 100644
--- a/ui.c
+++ b/ui.c
@@ -350,6 +350,28 @@ void uiCloseTag(struct Tag tag) {
 	viewClose(view);
 }
 
+static void notify(struct Tag tag, const wchar_t *line) {
+	beep();
+	if (!self.notify) return;
+
+	char buf[256];
+	size_t cap = sizeof(buf);
+
+	struct Format format = { .str = line };
+	formatReset(&format);
+	while (formatParse(&format, NULL)) {
+		int len = snprintf(
+			&buf[sizeof(buf) - cap], cap,
+			"%.*ls", (int)format.len, format.str
+		);
+		if (len < 0) err(EX_OSERR, "snprintf");
+		if ((size_t)len >= cap) break;
+		cap -= len;
+	}
+
+	eventPipe((const char *[]) { "notify-send", tag.name, buf, NULL });
+}
+
 void uiLog(struct Tag tag, enum UIHeat heat, const wchar_t *line) {
 	struct View *view = viewTag(tag);
 	int lines = 1;
@@ -362,7 +384,7 @@ void uiLog(struct Tag tag, enum UIHeat heat, const wchar_t *line) {
 		}
 		if (heat > UIWarm) {
 			view->hot = true;
-			beep(); // TODO: Notify.
+			notify(tag, line);
 		}
 		uiStatus();
 	}