diff options
author | nicm <nicm> | 2017-04-20 09:20:22 +0000 |
---|---|---|
committer | nicm <nicm> | 2017-04-20 09:20:22 +0000 |
commit | 0b44ad99b51606a8cab662e04cf043a8c4a3ca92 (patch) | |
tree | 06a3c095e0babd541df00c9cd80bac898724c984 /format.c | |
parent | f184c6f06c8bd63390ecec3fbe290b087f995ea7 (diff) | |
download | rtmux-0b44ad99b51606a8cab662e04cf043a8c4a3ca92.tar.gz rtmux-0b44ad99b51606a8cab662e04cf043a8c4a3ca92.tar.bz2 rtmux-0b44ad99b51606a8cab662e04cf043a8c4a3ca92.zip |
If a #() command doesn't exit, use its most recent line of output (it
must be a full line). Don't let it redraw the status line more than once
a second.
Requested by someone about 10 years ago...
Diffstat (limited to 'format.c')
-rw-r--r-- | format.c | 47 |
1 files changed, 38 insertions, 9 deletions
@@ -39,7 +39,6 @@ struct format_entry; typedef void (*format_cb)(struct format_tree *, struct format_entry *); -static void format_job_callback(struct job *); static char *format_job_get(struct format_tree *, const char *); static void format_job_timer(int, short, void *); @@ -83,6 +82,7 @@ struct format_job { time_t last; char *out; + int updated; struct job *job; int status; @@ -203,9 +203,35 @@ static const char *format_lower[] = { NULL /* z */ }; -/* Format job callback. */ +/* Format job update callback. */ static void -format_job_callback(struct job *job) +format_job_update(struct job *job) +{ + struct format_job *fj = job->data; + char *line; + time_t t; + struct client *c; + + if ((line = evbuffer_readline(job->event->input)) == NULL) + return; + fj->updated = 1; + + free(fj->out); + fj->out = line; + + log_debug("%s: %s: %s", __func__, fj->cmd, fj->out); + + t = time (NULL); + if (fj->status && fj->last != t) { + TAILQ_FOREACH(c, &clients, entry) + server_status_client(c); + fj->last = t; + } +} + +/* Format job complete callback. */ +static void +format_job_complete(struct job *job) { struct format_job *fj = job->data; char *line, *buf; @@ -213,7 +239,6 @@ format_job_callback(struct job *job) struct client *c; fj->job = NULL; - free(fj->out); buf = NULL; if ((line = evbuffer_readline(job->event->input)) == NULL) { @@ -224,15 +249,19 @@ format_job_callback(struct job *job) buf[len] = '\0'; } else buf = line; - fj->out = buf; + + if (*buf != '\0' || !fj->updated) { + free(fj->out); + fj->out = buf; + log_debug("%s: %s: %s", __func__, fj->cmd, fj->out); + } else + free(buf); if (fj->status) { TAILQ_FOREACH(c, &clients, entry) server_status_client(c); fj->status = 0; } - - log_debug("%s: %s: %s", __func__, fj->cmd, fj->out); } /* Find a job. */ @@ -267,8 +296,8 @@ format_job_get(struct format_tree *ft, const char *cmd) t = time(NULL); if (fj->job == NULL && (force || fj->last != t)) { - fj->job = job_run(expanded, NULL, NULL, format_job_callback, - NULL, fj); + fj->job = job_run(expanded, NULL, NULL, format_job_update, + format_job_complete, NULL, fj); if (fj->job == NULL) { free(fj->out); xasprintf(&fj->out, "<'%s' didn't start>", fj->cmd); |