summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/input.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2022-03-08 12:01:20 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2022-03-08 12:01:20 +0000
commit9d6f739176cb81ec9ec55f2b9b2d723238a8e907 (patch)
treeff837ad37e6ff0a528c393a16759f3d469eecbb6 /usr.bin/tmux/input.c
parent82818afa790bf3421e5c9dfc381f4a9c70cdcd80 (diff)
Add argument to refresh-client -l to forward clipboard to a pane. GitHub
issue 3068.
Diffstat (limited to 'usr.bin/tmux/input.c')
-rw-r--r--usr.bin/tmux/input.c49
1 files changed, 29 insertions, 20 deletions
diff --git a/usr.bin/tmux/input.c b/usr.bin/tmux/input.c
index 14d8d575594..86f6b60c51e 100644
--- a/usr.bin/tmux/input.c
+++ b/usr.bin/tmux/input.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: input.c,v 1.199 2022/02/15 13:11:29 nicm Exp $ */
+/* $OpenBSD: input.c,v 1.200 2022/03/08 12:01:19 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -2682,8 +2682,8 @@ input_osc_52(struct input_ctx *ictx, const char *p)
{
struct window_pane *wp = ictx->wp;
char *end;
- const char *buf;
- size_t len;
+ const char *buf = NULL;
+ size_t len = 0;
u_char *out;
int outlen, state;
struct screen_write_ctx ctx;
@@ -2703,26 +2703,12 @@ input_osc_52(struct input_ctx *ictx, const char *p)
log_debug("%s: %s", __func__, end);
if (strcmp(end, "?") == 0) {
- if ((pb = paste_get_top(NULL)) != NULL) {
+ if ((pb = paste_get_top(NULL)) != NULL)
buf = paste_buffer_data(pb, &len);
- outlen = 4 * ((len + 2) / 3) + 1;
- out = xmalloc(outlen);
- if ((outlen = b64_ntop(buf, len, out, outlen)) == -1) {
- free(out);
- return;
- }
- } else {
- outlen = 0;
- out = NULL;
- }
- bufferevent_write(ictx->event, "\033]52;;", 6);
- if (outlen != 0)
- bufferevent_write(ictx->event, out, outlen);
if (ictx->input_end == INPUT_END_BEL)
- bufferevent_write(ictx->event, "\007", 1);
+ input_reply_clipboard(ictx->event, buf, len, "\007");
else
- bufferevent_write(ictx->event, "\033\\", 2);
- free(out);
+ input_reply_clipboard(ictx->event, buf, len, "\033\\");
return;
}
@@ -2780,3 +2766,26 @@ input_osc_104(struct input_ctx *ictx, const char *p)
screen_write_fullredraw(&ictx->ctx);
free(copy);
}
+
+void
+input_reply_clipboard(struct bufferevent *bev, const char *buf, size_t len,
+ const char *end)
+{
+ char *out = NULL;
+ size_t outlen = 0;
+
+ if (buf != NULL && len != 0) {
+ outlen = 4 * ((len + 2) / 3) + 1;
+ out = xmalloc(outlen);
+ if ((outlen = b64_ntop(buf, len, out, outlen)) == -1) {
+ free(out);
+ return;
+ }
+ }
+
+ bufferevent_write(bev, "\033]52;;", 6);
+ if (outlen != 0)
+ bufferevent_write(bev, out, outlen);
+ bufferevent_write(bev, end, strlen(end));
+ free(out);
+}