Add notification with notify-send

master
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; const char *webirc = NULL;
int opt; 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) { switch (opt) {
break; case 'N': self.notify = true;
break; case 'W': webirc = optarg; break; case 'W': webirc = optarg;
break; case 'h': host = strdup(optarg); break; case 'h': host = strdup(optarg);
break; case 'j': selfJoin(optarg); break; case 'j': selfJoin(optarg);

3
chat.h
View File

@ -30,10 +30,11 @@
#define errx(...) do { uiHide(); errx(__VA_ARGS__); } while (0) #define errx(...) do { uiHide(); errx(__VA_ARGS__); } while (0)
struct { struct {
bool verbose;
char *nick; char *nick;
char *user; char *user;
char *join; char *join;
bool verbose;
bool notify;
} self; } self;
void selfNick(const char *nick); void selfNick(const char *nick);

View File

@ -8,7 +8,7 @@
. .
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl v .Op Fl Nv
.Op Fl W Ar pass .Op Fl W Ar pass
.Op Fl h Ar host .Op Fl h Ar host
.Op Fl j Ar chan .Op Fl j Ar chan
@ -27,6 +27,10 @@ which only supports TLS.
The arguments are as follows: The arguments are as follows:
. .
.Bl -tag -width Ds .Bl -tag -width Ds
.It Fl N
Send notifications with
.Xr notify-send 1 .
.
.It Fl W Ar pass .It Fl W Ar pass
Send Send
.Ql WEBIRC .Ql WEBIRC

24
ui.c
View File

@ -350,6 +350,28 @@ void uiCloseTag(struct Tag tag) {
viewClose(view); 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) { void uiLog(struct Tag tag, enum UIHeat heat, const wchar_t *line) {
struct View *view = viewTag(tag); struct View *view = viewTag(tag);
int lines = 1; int lines = 1;
@ -362,7 +384,7 @@ void uiLog(struct Tag tag, enum UIHeat heat, const wchar_t *line) {
} }
if (heat > UIWarm) { if (heat > UIWarm) {
view->hot = true; view->hot = true;
beep(); // TODO: Notify. notify(tag, line);
} }
uiStatus(); uiStatus();
} }