diff --git a/server-client.c b/server-client.c index ccddee7a..048a138b 100644 --- a/server-client.c +++ b/server-client.c @@ -1636,3 +1636,34 @@ server_client_push_stderr(struct client *c) log_debug("%s: client %p, queued", __func__, c); } } + +/* Add to client message log. */ +void +server_client_add_message(struct client *c, const char *fmt, ...) +{ + struct message_entry *msg, *msg1; + char *s; + va_list ap; + u_int limit; + + va_start(ap, fmt); + xvasprintf(&s, fmt, ap); + va_end(ap); + + log_debug("%s: message %s", c->tty.path, s); + + msg = xcalloc(1, sizeof *msg); + msg->msg_time = time(NULL); + msg->msg_num = c->message_next++; + msg->msg = s; + TAILQ_INSERT_TAIL(&c->message_log, msg, entry); + + limit = options_get_number(global_options, "message-limit"); + TAILQ_FOREACH_SAFE(msg, &c->message_log, entry, msg1) { + if (msg->msg_num + limit >= c->message_next) + break; + free(msg->msg); + TAILQ_REMOVE(&c->message_log, msg, entry); + free(msg); + } +} diff --git a/status.c b/status.c index 6cc1ee37..a8fe2032 100644 --- a/status.c +++ b/status.c @@ -562,13 +562,9 @@ status_print(struct client *c, struct winlink *wl, time_t t, void status_message_set(struct client *c, const char *fmt, ...) { - struct timeval tv; - struct message_entry *msg, *msg1; - va_list ap; - int delay; - u_int limit; - - limit = options_get_number(global_options, "message-limit"); + struct timeval tv; + va_list ap; + int delay; status_message_clear(c); @@ -576,19 +572,7 @@ status_message_set(struct client *c, const char *fmt, ...) xvasprintf(&c->message_string, fmt, ap); va_end(ap); - msg = xcalloc(1, sizeof *msg); - msg->msg_time = time(NULL); - msg->msg_num = c->message_next++; - msg->msg = xstrdup(c->message_string); - TAILQ_INSERT_TAIL(&c->message_log, msg, entry); - - TAILQ_FOREACH_SAFE(msg, &c->message_log, entry, msg1) { - if (msg->msg_num + limit >= c->message_next) - break; - free(msg->msg); - TAILQ_REMOVE(&c->message_log, msg, entry); - free(msg); - } + server_client_add_message(c, "%s", c->message_string); delay = options_get_number(c->session->options, "display-time"); if (delay > 0) { diff --git a/tmux.1 b/tmux.1 index 2bb56e6b..1ba22ab6 100644 --- a/tmux.1 +++ b/tmux.1 @@ -838,7 +838,7 @@ is used, .Fl x and .Fl y -specify the size of the initial window (80 by 24 if not given). +specify the size of the initial window. .Pp If run from a terminal, any .Xr termios 4 diff --git a/tmux.h b/tmux.h index 3b58246b..b54edf3e 100644 --- a/tmux.h +++ b/tmux.h @@ -1830,6 +1830,8 @@ void server_client_exec(struct client *, const char *); void server_client_loop(void); void server_client_push_stdout(struct client *); void server_client_push_stderr(struct client *); +void printflike(2, 3) server_client_add_message(struct client *, const char *, + ...); /* server-fn.c */ void server_fill_environ(struct session *, struct environ *);