diff options
author | C. McEnroe | 2020-02-12 20:12:34 -0500 |
---|---|---|
committer | C. McEnroe | 2020-02-12 20:12:34 -0500 |
commit | 180bbc7b38f814ff506bb25091a908f02ba32b5c (patch) | |
tree | 423b6fddd7fc39667ea6be4eed13665b034fc833 /ui.c | |
parent | 4198f67aa2149088cd49ad43f09a53b5c3276846 (diff) |
Add -N flag for notifications
Diffstat (limited to 'ui.c')
-rw-r--r-- | ui.c | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/ui.c b/ui.c index 97f81b3..0bf619d 100644 --- a/ui.c +++ b/ui.c @@ -530,6 +530,35 @@ static int wordWrap(WINDOW *win, const char *str) { return lines; } +struct Util uiNotifyUtil; +static void notify(size_t id, const char *str) { + if (!uiNotifyUtil.argc) return; + + struct Util util = uiNotifyUtil; + utilPush(&util, idNames[id]); + size_t len = 0; + char buf[1024] = ""; + while (*str && len < sizeof(buf)) { + size_t run; + struct Style style = Reset; + styleParse(&style, &str, &run); + len += snprintf(&buf[len], sizeof(buf) - len, "%.*s", (int)run, str); + str += run; + } + utilPush(&util, buf); + + pid_t pid = fork(); + if (pid < 0) err(EX_OSERR, "fork"); + if (pid) return; + + close(STDIN_FILENO); + dup2(procPipe[1], STDOUT_FILENO); + dup2(procPipe[1], STDERR_FILENO); + execvp(util.argv[0], (char *const *)util.argv); + warn("%s", util.argv[0]); + _exit(EX_CONFIG); +} + void uiWrite(size_t id, enum Heat heat, const time_t *src, const char *str) { struct Window *window = windowFor(id); time_t clock = (src ? *src : time(NULL)); @@ -548,7 +577,10 @@ void uiWrite(size_t id, enum Heat heat, const time_t *src, const char *str) { lines += wordWrap(window->pad, str); window->unreadLines += lines; if (window->scroll) windowScroll(window, lines); - if (heat > Warm) beep(); + if (window->mark && heat > Warm) { + beep(); + notify(id, str); + } } void uiFormat( |