diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2017-01-22 19:00:02 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2017-01-22 19:00:02 +0000 |
commit | c9a142cb13c3766e481ec485464e18e5ededa083 (patch) | |
tree | 6c43eca26e1856db4e2a730045ed7fe81873e5db | |
parent | 14dd9c3d585f73f28531179d1257a2a88fe7b4ba (diff) |
Accept the OSC 52 escape sequence inside tmux to add a new buffer, from
harry dot gindi at live dot com.
-rw-r--r-- | usr.bin/tmux/input.c | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/usr.bin/tmux/input.c b/usr.bin/tmux/input.c index 44b72b3876e..e5d5233ef54 100644 --- a/usr.bin/tmux/input.c +++ b/usr.bin/tmux/input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: input.c,v 1.107 2017/01/07 15:28:13 nicm Exp $ */ +/* $OpenBSD: input.c,v 1.108 2017/01/22 19:00:01 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -18,6 +18,9 @@ #include <sys/types.h> +#include <netinet/in.h> + +#include <resolv.h> #include <stdlib.h> #include <string.h> #include <time.h> @@ -106,6 +109,7 @@ static void input_set_state(struct window_pane *, static void input_reset_cell(struct input_ctx *); static void input_osc_4(struct window_pane *, const char *); +static void input_osc_52(struct window_pane *, const char *); static void input_osc_104(struct window_pane *, const char *); /* Transition entry/exit handlers. */ @@ -1862,6 +1866,9 @@ input_exit_osc(struct input_ctx *ictx) case 4: input_osc_4(ictx->wp, p); break; + case 52: + input_osc_52(ictx->wp, p); + break; case 12: if (*p != '?') /* ? is colour request */ screen_set_cursor_colour(ictx->ctx.s, p); @@ -2011,6 +2018,40 @@ bad: free(copy); } +/* Handle the OSC 52 sequence for setting the clipboard. */ +static void +input_osc_52(struct window_pane *wp, const char *p) +{ + char *end; + size_t len; + u_char *out; + int outlen; + struct screen_write_ctx ctx; + + if ((end = strchr(p, ';')) == NULL) + return; + end++; + if (*end == '\0') + return; + + len = (strlen(end) / 4) * 3; + if (len == 0) + return; + + out = xmalloc(len); + if ((outlen = b64_pton(end, out, len)) == -1) { + free(out); + return; + } + + if (options_get_number(global_options, "set-clipboard")) { + screen_write_start(&ctx, wp, NULL); + screen_write_setselection(&ctx, out, outlen); + screen_write_stop(&ctx); + } + paste_add(out, outlen); +} + /* Handle the OSC 104 sequence for unsetting (multiple) palette entries. */ static void input_osc_104(struct window_pane *wp, const char *p) |