Add notification with notify-send

weechat-hashes
Curtis McEnroe 2018-10-28 02:44:09 -04:00
parent 36ec6cf258
commit 2eaa36a309
No known key found for this signature in database
GPG Key ID: CEA2F97ADCFCD77C
4 changed files with 32 additions and 4 deletions

3
chat.c
View File

@ -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);

3
chat.h
View File

@ -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);

View File

@ -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

24
ui.c
View File

@ -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();
}