Extend display-message to work for control clients. GitHub issue 3449.
authornicm <nicm@openbsd.org>
Sun, 5 Feb 2023 21:15:32 +0000 (21:15 +0000)
committernicm <nicm@openbsd.org>
Sun, 5 Feb 2023 21:15:32 +0000 (21:15 +0000)
usr.bin/tmux/cmd-display-message.c
usr.bin/tmux/cmd-queue.c
usr.bin/tmux/server-client.c
usr.bin/tmux/tmux.1
usr.bin/tmux/tmux.h

index 0b2a734..1c9c19a 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-display-message.c,v 1.62 2022/11/03 08:33:57 nicm Exp $ */
+/* $OpenBSD: cmd-display-message.c,v 1.63 2023/02/05 21:15:32 nicm Exp $ */
 
 /*
  * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -68,9 +68,10 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
        struct window_pane      *wp = target->wp;
        const char              *template;
        char                    *msg, *cause;
-       int                      delay = -1, flags;
+       int                      delay = -1, flags, Nflag = args_has(args, 'N');
        struct format_tree      *ft;
        u_int                    count = args_count(args);
+       struct evbuffer         *evb;
 
        if (args_has(args, 'I')) {
                if (wp == NULL)
@@ -141,10 +142,15 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
                cmdq_error(item, "%s", msg);
        else if (args_has(args, 'p'))
                cmdq_print(item, "%s", msg);
-       else if (tc != NULL) {
-               status_message_set(tc, delay, 0, args_has(args, 'N'), "%s",
-                   msg);
-       }
+       else if (tc != NULL && (tc->flags & CLIENT_CONTROL)) {
+               evb = evbuffer_new();
+               if (evb == NULL)
+                       fatalx("out of memory");
+               evbuffer_add_printf(evb, "%%message %s", msg);
+               server_client_print(tc, 0, evb);
+               evbuffer_free(evb);
+       } else if (tc != NULL)
+               status_message_set(tc, delay, 0, Nflag, "%s", msg);
        free(msg);
 
        format_free(ft);
index cfeb48c..dc13d3a 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-queue.c,v 1.113 2023/01/03 11:43:24 nicm Exp $ */
+/* $OpenBSD: cmd-queue.c,v 1.114 2023/02/05 21:15:32 nicm Exp $ */
 
 /*
  * Copyright (c) 2013 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -826,68 +826,7 @@ cmdq_guard(struct cmdq_item *item, const char *guard, int flags)
 void
 cmdq_print_data(struct cmdq_item *item, int parse, struct evbuffer *evb)
 {
-       struct client                   *c = item->client;
-       void                            *data = EVBUFFER_DATA(evb);
-       size_t                           size = EVBUFFER_LENGTH(evb);
-       struct window_pane              *wp;
-       struct window_mode_entry        *wme;
-       char                            *sanitized, *msg, *line;
-
-       if (!parse) {
-               utf8_stravisx(&msg, data, size,
-                   VIS_OCTAL|VIS_CSTYLE|VIS_NOSLASH);
-               log_debug("%s: %s", __func__, msg);
-       } else {
-               msg = EVBUFFER_DATA(evb);
-               if (msg[size - 1] != '\0')
-                       evbuffer_add(evb, "", 1);
-       }
-
-       if (c == NULL)
-               goto out;
-
-       if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
-               if (~c->flags & CLIENT_UTF8) {
-                       sanitized = utf8_sanitize(msg);
-                       if (c->flags & CLIENT_CONTROL)
-                               control_write(c, "%s", sanitized);
-                       else
-                               file_print(c, "%s\n", sanitized);
-                       free(sanitized);
-               } else {
-                       if (c->flags & CLIENT_CONTROL)
-                               control_write(c, "%s", msg);
-                       else
-                               file_print(c, "%s\n", msg);
-               }
-               goto out;
-       }
-
-       wp = server_client_get_pane(c);
-       wme = TAILQ_FIRST(&wp->modes);
-       if (wme == NULL || wme->mode != &window_view_mode)
-               window_pane_set_mode(wp, NULL, &window_view_mode, NULL, NULL);
-       if (parse) {
-               do {
-                       line = evbuffer_readln(evb, NULL, EVBUFFER_EOL_LF);
-                       if (line != NULL) {
-                               window_copy_add(wp, 1, "%s", line);
-                               free(line);
-                       }
-               } while (line != NULL);
-
-               size = EVBUFFER_LENGTH(evb);
-               if (size != 0) {
-                       line = EVBUFFER_DATA(evb);
-                       window_copy_add(wp, 1, "%.*s", (int)size, line);
-               }
-       } else
-               window_copy_add(wp, 0, "%s", msg);
-
-out:
-       if (!parse)
-               free(msg);
-
+       server_client_print(item->client, parse, evb);
 }
 
 /* Show message from command. */
index e4ab945..a28cf5a 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: server-client.c,v 1.399 2023/01/16 11:26:14 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.400 2023/02/05 21:15:32 nicm Exp $ */
 
 /*
  * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
+#include <vis.h>
 
 #include "tmux.h"
 
@@ -3239,3 +3240,69 @@ server_client_remove_pane(struct window_pane *wp)
                }
        }
 }
+
+/* Print to a client. */
+void
+server_client_print(struct client *c, int parse, struct evbuffer *evb)
+{
+       void                            *data = EVBUFFER_DATA(evb);
+       size_t                           size = EVBUFFER_LENGTH(evb);
+       struct window_pane              *wp;
+       struct window_mode_entry        *wme;
+       char                            *sanitized, *msg, *line;
+
+       if (!parse) {
+               utf8_stravisx(&msg, data, size,
+                   VIS_OCTAL|VIS_CSTYLE|VIS_NOSLASH);
+               log_debug("%s: %s", __func__, msg);
+       } else {
+               msg = EVBUFFER_DATA(evb);
+               if (msg[size - 1] != '\0')
+                       evbuffer_add(evb, "", 1);
+       }
+
+       if (c == NULL)
+               goto out;
+
+       if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
+               if (~c->flags & CLIENT_UTF8) {
+                       sanitized = utf8_sanitize(msg);
+                       if (c->flags & CLIENT_CONTROL)
+                               control_write(c, "%s", sanitized);
+                       else
+                               file_print(c, "%s\n", sanitized);
+                       free(sanitized);
+               } else {
+                       if (c->flags & CLIENT_CONTROL)
+                               control_write(c, "%s", msg);
+                       else
+                               file_print(c, "%s\n", msg);
+               }
+               goto out;
+       }
+
+       wp = server_client_get_pane(c);
+       wme = TAILQ_FIRST(&wp->modes);
+       if (wme == NULL || wme->mode != &window_view_mode)
+               window_pane_set_mode(wp, NULL, &window_view_mode, NULL, NULL);
+       if (parse) {
+               do {
+                       line = evbuffer_readln(evb, NULL, EVBUFFER_EOL_LF);
+                       if (line != NULL) {
+                               window_copy_add(wp, 1, "%s", line);
+                               free(line);
+                       }
+               } while (line != NULL);
+
+               size = EVBUFFER_LENGTH(evb);
+               if (size != 0) {
+                       line = EVBUFFER_DATA(evb);
+                       window_copy_add(wp, 1, "%.*s", (int)size, line);
+               }
+       } else
+               window_copy_add(wp, 0, "%s", msg);
+
+out:
+       if (!parse)
+               free(msg);
+}
index 3963a49..29089e9 100644 (file)
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.913 2023/01/23 09:33:51 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.914 2023/02/05 21:15:33 nicm Exp $
 .\"
 .\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
 .\"
@@ -14,7 +14,7 @@
 .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
 .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\"
-.Dd $Mdocdate: January 23 2023 $
+.Dd $Mdocdate: February 5 2023 $
 .Dt TMUX 1
 .Os
 .Sh NAME
@@ -6627,6 +6627,10 @@ The window's visible layout is
 .Ar window-visible-layout
 and the window flags are
 .Ar window-flags .
+.It Ic %message Ar message
+A message sent with the
+.Ic display-message
+command.
 .It Ic %output Ar pane-id Ar value
 A window pane produced output.
 .Ar value
index ad2e792..12f61fc 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.1193 2023/01/20 21:36:00 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.1194 2023/02/05 21:15:33 nicm Exp $ */
 
 /*
  * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -2678,6 +2678,7 @@ struct client_window *server_client_add_client_window(struct client *, u_int);
 struct window_pane *server_client_get_pane(struct client *);
 void    server_client_set_pane(struct client *, struct window_pane *);
 void    server_client_remove_pane(struct window_pane *);
+void    server_client_print(struct client *, int, struct evbuffer *);
 
 /* server-fn.c */
 void    server_redraw_client(struct client *);