aboutsummaryrefslogtreecommitdiff
path: root/format.c
diff options
context:
space:
mode:
authornicm <nicm>2017-04-20 09:20:22 +0000
committernicm <nicm>2017-04-20 09:20:22 +0000
commit0b44ad99b51606a8cab662e04cf043a8c4a3ca92 (patch)
tree06a3c095e0babd541df00c9cd80bac898724c984 /format.c
parentf184c6f06c8bd63390ecec3fbe290b087f995ea7 (diff)
downloadrtmux-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.c47
1 files changed, 38 insertions, 9 deletions
diff --git a/format.c b/format.c
index 269d506a..5c85f1ff 100644
--- a/format.c
+++ b/format.c
@@ -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);