diff options
| -rw-r--r-- | chat.c | 3 | ||||
| -rw-r--r-- | chat.h | 3 | ||||
| -rw-r--r-- | chatte.1 | 6 | ||||
| -rw-r--r-- | ui.c | 24 | 
4 files changed, 32 insertions, 4 deletions
@@ -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); @@ -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); @@ -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 @@ -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();  	}  | 
