From 7e497c7f2303b29b0f44fe360a78c44ca86b87f9 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 7 Dec 2022 09:44:44 +0000 Subject: Process escape sequences in show-buffer, GitHub issue 3401. --- cmd-queue.c | 96 +++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 71 insertions(+), 25 deletions(-) (limited to 'cmd-queue.c') diff --git a/cmd-queue.c b/cmd-queue.c index 8325e2e8..8ed3673b 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "tmux.h" @@ -823,43 +824,88 @@ cmdq_guard(struct cmdq_item *item, const char *guard, int flags) /* Show message from command. */ void -cmdq_print(struct cmdq_item *item, const char *fmt, ...) +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; - va_list ap; - char *tmp, *msg; - - va_start(ap, fmt); - xvasprintf(&msg, fmt, ap); - va_end(ap); + char *sanitized, *msg, *line; - log_debug("%s: %s", __func__, msg); + if (!parse) { + utf8_stravisx(&msg, data, size, VIS_OCTAL|VIS_CSTYLE|VIS_TAB); + log_debug("%s: %s", __func__, msg); + } else { + msg = EVBUFFER_DATA(evb); + if (msg[size - 1] != '\0') + evbuffer_add(evb, "", 1); + } if (c == NULL) - /* nothing */; - else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) { + goto out; + + if (c->session == NULL || (c->flags & CLIENT_CONTROL)) { if (~c->flags & CLIENT_UTF8) { - tmp = msg; - msg = utf8_sanitize(tmp); - free(tmp); + 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); } - if (c->flags & CLIENT_CONTROL) - control_write(c, "%s", msg); - else - file_print(c, "%s\n", msg); - } else { - 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); + 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); - } - free(msg); +out: + if (!parse) + free(msg); + +} + +/* Show message from command. */ +void +cmdq_print(struct cmdq_item *item, const char *fmt, ...) +{ + va_list ap; + struct evbuffer *evb; + + evb = evbuffer_new(); + if (evb == NULL) + fatalx("out of memory"); + + va_start(ap, fmt); + evbuffer_add_vprintf(evb, fmt, ap); + va_end(ap); + + cmdq_print_data(item, 0, evb); + evbuffer_free(evb); } /* Show error from command. */ -- cgit From 70ff8cfe1e06987501a55a32df31d1f69acd2f99 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Wed, 7 Dec 2022 12:30:36 +0000 Subject: No vis.h in portable. --- cmd-queue.c | 1 - 1 file changed, 1 deletion(-) (limited to 'cmd-queue.c') diff --git a/cmd-queue.c b/cmd-queue.c index 8ed3673b..9f6b4650 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -24,7 +24,6 @@ #include #include #include -#include #include "tmux.h" -- cgit From 7cb48fc40b178d0b7bf281dee6799fa0e3745c70 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 16 Dec 2022 08:22:05 +0000 Subject: Do not escape tabs in output (iTerm2 needs them). GitHub issue 3414. --- cmd-queue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd-queue.c') diff --git a/cmd-queue.c b/cmd-queue.c index 8ed3673b..827630d7 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -834,7 +834,7 @@ cmdq_print_data(struct cmdq_item *item, int parse, struct evbuffer *evb) char *sanitized, *msg, *line; if (!parse) { - utf8_stravisx(&msg, data, size, VIS_OCTAL|VIS_CSTYLE|VIS_TAB); + utf8_stravisx(&msg, data, size, VIS_OCTAL|VIS_CSTYLE); log_debug("%s: %s", __func__, msg); } else { msg = EVBUFFER_DATA(evb); -- cgit From a41a92744188ec5c8a8d4ddc100ec15b52d04603 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 3 Jan 2023 11:43:24 +0000 Subject: Query the client terminal for foreground and background colours and if OSC 10 or 11 is received but no colour has been set inside tmux, return the colour from the first attached client (probably most people will have all light or or all dark terminals). --- cmd-queue.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cmd-queue.c') diff --git a/cmd-queue.c b/cmd-queue.c index 827630d7..bf1dbdaf 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -834,7 +834,8 @@ cmdq_print_data(struct cmdq_item *item, int parse, struct evbuffer *evb) char *sanitized, *msg, *line; if (!parse) { - utf8_stravisx(&msg, data, size, VIS_OCTAL|VIS_CSTYLE); + utf8_stravisx(&msg, data, size, + VIS_OCTAL|VIS_CSTYLE|VIS_NOSLASH); log_debug("%s: %s", __func__, msg); } else { msg = EVBUFFER_DATA(evb); -- cgit