Add notification with notify-send
parent
36ec6cf258
commit
2eaa36a309
3
chat.c
3
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);
|
||||
|
|
3
chat.h
3
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);
|
||||
|
|
6
chatte.1
6
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
|
||||
|
|
24
ui.c
24
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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue