Make set-clipboard a three-state option so tmux itself can ignore the

sequencess.
pull/956/head
nicm 2017-06-03 17:43:01 +00:00
parent 493a1846d0
commit 3442066054
4 changed files with 37 additions and 13 deletions

15
input.c
View File

@ -2103,9 +2103,13 @@ input_osc_52(struct window_pane *wp, const char *p)
char *end; char *end;
size_t len; size_t len;
u_char *out; u_char *out;
int outlen; int outlen, state;
struct screen_write_ctx ctx; struct screen_write_ctx ctx;
state = options_get_number(global_options, "set-clipboard");
if (state != 2)
return;
if ((end = strchr(p, ';')) == NULL) if ((end = strchr(p, ';')) == NULL)
return; return;
end++; end++;
@ -2122,11 +2126,10 @@ input_osc_52(struct window_pane *wp, const char *p)
return; return;
} }
if (options_get_number(global_options, "set-clipboard")) { screen_write_start(&ctx, wp, NULL);
screen_write_start(&ctx, wp, NULL); screen_write_setselection(&ctx, out, outlen);
screen_write_setselection(&ctx, out, outlen); screen_write_stop(&ctx);
screen_write_stop(&ctx);
}
paste_add(out, outlen); paste_add(out, outlen);
} }

View File

@ -54,6 +54,9 @@ static const char *options_table_bell_action_list[] = {
static const char *options_table_pane_status_list[] = { static const char *options_table_pane_status_list[] = {
"off", "top", "bottom", NULL "off", "top", "bottom", NULL
}; };
static const char *options_table_set_clipboard_list[] = {
"off", "external", "on", NULL
};
/* Top-level options. */ /* Top-level options. */
const struct options_table_entry options_table[] = { const struct options_table_entry options_table[] = {
@ -118,8 +121,9 @@ const struct options_table_entry options_table[] = {
}, },
{ .name = "set-clipboard", { .name = "set-clipboard",
.type = OPTIONS_TABLE_FLAG, .type = OPTIONS_TABLE_CHOICE,
.scope = OPTIONS_TABLE_SERVER, .scope = OPTIONS_TABLE_SERVER,
.choices = options_table_set_clipboard_list,
.default_num = 1 .default_num = 1
}, },

25
tmux.1
View File

@ -2398,17 +2398,34 @@ Set the number of error or information messages to save in the message log for
each client. each client.
The default is 100. The default is 100.
.It Xo Ic set-clipboard .It Xo Ic set-clipboard
.Op Ic on | off .Op Ic on | external | off
.Xc .Xc
Attempt to set the terminal clipboard content using the Attempt to set the terminal clipboard content using the
\ee]52;...\e007 \ee]52;...\e007
.Xr xterm 1 .Xr xterm 1
escape sequences. escape sequences, if there is an
This option is on by default if there is an
.Em \&Ms .Em \&Ms
entry in the entry in the
.Xr terminfo 5 .Xr terminfo 5
description for the client terminal. description.
If set to
.Ic on ,
.Nm
will both accept the escape sequence to create a buffer and attempt to set
the terminal clipboard.
If set to
.Ic external ,
.Nm
will attempt to set the terminal clipboard but ignore attempts
by applications to set
.Nm
buffers.
If
.Ic off ,
.Nm
will neither accept the clipboard escape sequence nor attempt to set the
clipboard.
.Pp
Note that this feature needs to be enabled in Note that this feature needs to be enabled in
.Xr xterm 1 .Xr xterm 1
by setting the resource: by setting the resource:

View File

@ -1629,7 +1629,7 @@ window_copy_copy_buffer(struct window_pane *wp, const char *bufname, void *buf,
{ {
struct screen_write_ctx ctx; struct screen_write_ctx ctx;
if (options_get_number(global_options, "set-clipboard")) { if (options_get_number(global_options, "set-clipboard") != 0) {
screen_write_start(&ctx, wp, NULL); screen_write_start(&ctx, wp, NULL);
screen_write_setselection(&ctx, buf, len); screen_write_setselection(&ctx, buf, len);
screen_write_stop(&ctx); screen_write_stop(&ctx);
@ -1686,7 +1686,7 @@ window_copy_append_selection(struct window_pane *wp, const char *bufname)
if (buf == NULL) if (buf == NULL)
return; return;
if (options_get_number(global_options, "set-clipboard")) { if (options_get_number(global_options, "set-clipboard") != 0) {
screen_write_start(&ctx, wp, NULL); screen_write_start(&ctx, wp, NULL);
screen_write_setselection(&ctx, buf, len); screen_write_setselection(&ctx, buf, len);
screen_write_stop(&ctx); screen_write_stop(&ctx);