diff --git a/options-table.c b/options-table.c index 42d50335..c068cc48 100644 --- a/options-table.c +++ b/options-table.c @@ -1,4 +1,4 @@ -/* $Id: options-table.c,v 1.9 2011-05-18 20:30:14 tcunha Exp $ */ +/* $Id: options-table.c,v 1.10 2011-05-22 16:23:07 tcunha Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott @@ -74,6 +74,11 @@ const struct options_table_entry server_options_table[] = { .default_num = 0 /* overridden in main() */ }, + { .name = "set-clipboard", + .type = OPTIONS_TABLE_FLAG, + .default_num = 1 + }, + { .name = NULL } }; @@ -359,7 +364,8 @@ const struct options_table_entry session_options_table[] = { { .name = "terminal-overrides", .type = OPTIONS_TABLE_STRING, - .default_str = "*88col*:colors=88,*256col*:colors=256,xterm*:XT" + .default_str = "*88col*:colors=88,*256col*:colors=256" + ",xterm*:XT:Ms=\\E]52;%p1%s;%p2%s\\007" }, { .name = "update-environment", diff --git a/screen-write.c b/screen-write.c index 8bb6b141..bf518687 100644 --- a/screen-write.c +++ b/screen-write.c @@ -1,4 +1,4 @@ -/* $Id: screen-write.c,v 1.96 2011-04-18 21:06:49 nicm Exp $ */ +/* $Id: screen-write.c,v 1.97 2011-05-22 16:23:07 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1194,6 +1194,18 @@ screen_write_overwrite(struct screen_write_ctx *ctx, u_int width) } } +void +screen_write_setselection(struct screen_write_ctx *ctx, u_char *str, u_int len) +{ + struct tty_ctx ttyctx; + + screen_write_initctx(ctx, &ttyctx, 0); + ttyctx.ptr = str; + ttyctx.num = len; + + tty_write(tty_cmd_setselection, &ttyctx); +} + void screen_write_rawstring(struct screen_write_ctx *ctx, u_char *str, u_int len) { diff --git a/tmux.1 b/tmux.1 index 74b31499..e3fa54f2 100644 --- a/tmux.1 +++ b/tmux.1 @@ -1,4 +1,4 @@ -.\" $Id: tmux.1,v 1.313 2011-05-18 20:35:36 tcunha Exp $ +.\" $Id: tmux.1,v 1.314 2011-05-22 16:23:07 tcunha Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -1709,6 +1709,28 @@ Available server options are: Set the number of buffers; as new buffers are added to the top of the stack, old ones are removed from the bottom if necessary to maintain this maximum length. +.It Xo Ic set-clipboard +.Op Ic on | off +.Xc +Attempt to set the terminal clipboard content using the +\ee]52;...\e007 +.Xr xterm 1 +escape sequences. +This option is on by default if there is an +.Em \&Ms +entry in the +.Xr terminfo 5 +description for the client terminal. +Note that this feature needs to be enabled in +.Xr xterm 1 +by setting the resource: +.Bd -literal -offset indent +disallowedWindowOps: 20,21,SetXprop +.Ed +.Pp +Or changing this property from the +.Xr xterm 1 +interactive menu when required. .It Ic escape-time Ar time Set the time in milliseconds for which .Nm @@ -2800,6 +2822,21 @@ If the command doesn't return success, the exit status is also displayed. .D1 (alias: Ic info ) Show server information and terminal details. .El +.Sh TERMINFO EXTENSIONS +.Nm +understands some extensions to +.Xr terminfo 5 : +.Bl -tag -width Ds +.It Em \&Ms +This sequence can be used by +.Nm +to store the current buffer in the host terminal's selection (clipboard). +See the +.Em set-clipboard +option above and the +.Xr xterm 1 +man page. +.El .Sh FILES .Bl -tag -width "/etc/tmux.confXXX" -compact .It Pa ~/.tmux.conf diff --git a/tmux.h b/tmux.h index d1f1e4da..4d0bb878 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.624 2011-05-18 20:35:36 tcunha Exp $ */ +/* $Id: tmux.h,v 1.625 2011-05-22 16:23:07 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -304,6 +304,7 @@ enum tty_code_code { TTYC_KUP5, TTYC_KUP6, TTYC_KUP7, + TTYC_MS, /* modify xterm(1) selection */ TTYC_OP, /* orig_pair, op */ TTYC_REV, /* enter_reverse_mode, mr */ TTYC_RI, /* scroll_reverse, sr */ @@ -1409,6 +1410,7 @@ void tty_cursor(struct tty *, u_int, u_int); void tty_putcode(struct tty *, enum tty_code_code); void tty_putcode1(struct tty *, enum tty_code_code, int); void tty_putcode2(struct tty *, enum tty_code_code, int, int); +void tty_putcode_ptr2(struct tty *, enum tty_code_code, const void *, const void *); void tty_puts(struct tty *, const char *); void tty_putc(struct tty *, u_char); void tty_pututf8(struct tty *, const struct grid_utf8 *); @@ -1440,6 +1442,7 @@ void tty_cmd_insertline(struct tty *, const struct tty_ctx *); void tty_cmd_linefeed(struct tty *, const struct tty_ctx *); void tty_cmd_utf8character(struct tty *, const struct tty_ctx *); void tty_cmd_reverseindex(struct tty *, const struct tty_ctx *); +void tty_cmd_setselection(struct tty *, const struct tty_ctx *); void tty_cmd_rawstring(struct tty *, const struct tty_ctx *); /* tty-term.c */ @@ -1452,6 +1455,8 @@ const char *tty_term_string(struct tty_term *, enum tty_code_code); const char *tty_term_string1(struct tty_term *, enum tty_code_code, int); const char *tty_term_string2( struct tty_term *, enum tty_code_code, int, int); +const char *tty_term_ptr2( + struct tty_term *, enum tty_code_code, const void *, const void *); int tty_term_number(struct tty_term *, enum tty_code_code); int tty_term_flag(struct tty_term *, enum tty_code_code); @@ -1820,6 +1825,7 @@ void screen_write_clearstartofscreen(struct screen_write_ctx *); void screen_write_clearscreen(struct screen_write_ctx *); void screen_write_cell(struct screen_write_ctx *, const struct grid_cell *, const struct utf8_data *); +void screen_write_setselection(struct screen_write_ctx *, u_char *, u_int); void screen_write_rawstring(struct screen_write_ctx *, u_char *, u_int); /* screen-redraw.c */ diff --git a/tty-term.c b/tty-term.c index 35639e7e..f987ab34 100644 --- a/tty-term.c +++ b/tty-term.c @@ -1,4 +1,4 @@ -/* $Id: tty-term.c,v 1.48 2011-05-18 20:28:43 tcunha Exp $ */ +/* $Id: tty-term.c,v 1.49 2011-05-22 16:23:07 tcunha Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -166,6 +166,7 @@ const struct tty_term_code_entry tty_term_codes[NTTYCODE] = { { TTYC_KUP5, TTYCODE_STRING, "kUP5" }, { TTYC_KUP6, TTYCODE_STRING, "kUP6" }, { TTYC_KUP7, TTYCODE_STRING, "kUP7" }, + { TTYC_MS, TTYCODE_STRING, "Ms" }, { TTYC_OP, TTYCODE_STRING, "op" }, { TTYC_REV, TTYCODE_STRING, "rev" }, { TTYC_RI, TTYCODE_STRING, "ri" }, @@ -493,6 +494,12 @@ tty_term_string1(struct tty_term *term, enum tty_code_code code, int a) const char * tty_term_string2(struct tty_term *term, enum tty_code_code code, int a, int b) +{ + return (tparm((char *) tty_term_string(term, code), a, b)); +} + +const char * +tty_term_ptr2(struct tty_term *term, enum tty_code_code code, const void *a, const void *b) { return (tparm((char *) tty_term_string(term, code), a, b, 0, 0, 0, 0, 0, 0, 0)); } diff --git a/tty.c b/tty.c index ea37f6d3..021e8a25 100644 --- a/tty.c +++ b/tty.c @@ -1,4 +1,4 @@ -/* $Id: tty.c,v 1.209 2011-05-18 20:28:43 tcunha Exp $ */ +/* $Id: tty.c,v 1.210 2011-05-22 16:23:07 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -19,8 +19,11 @@ #include #include +#include + #include #include +#include #include #include #include @@ -311,6 +314,13 @@ tty_putcode2(struct tty *tty, enum tty_code_code code, int a, int b) tty_puts(tty, tty_term_string2(tty->term, code, a, b)); } +void +tty_putcode_ptr2(struct tty *tty, enum tty_code_code code, const void *a, const void *b) +{ + if (a != NULL && b != NULL) + tty_puts(tty, tty_term_ptr2(tty->term, code, a, b)); +} + void tty_puts(struct tty *tty, const char *s) { @@ -938,6 +948,24 @@ tty_cmd_utf8character(struct tty *tty, const struct tty_ctx *ctx) tty_draw_line(tty, wp->screen, ctx->ocy, wp->xoff, wp->yoff); } +void +tty_cmd_setselection(struct tty *tty, const struct tty_ctx *ctx) +{ + char *buf; + size_t off; + + if (!tty_term_has(tty->term, TTYC_MS)) + return; + + off = 4 * ((ctx->num + 2) / 3) + 1; /* storage for base64 */ + buf = xmalloc(off); + + b64_ntop(ctx->ptr, ctx->num, buf, off); + tty_putcode_ptr2(tty, TTYC_MS, "", buf); + + xfree(buf); +} + void tty_cmd_rawstring(struct tty *tty, const struct tty_ctx *ctx) { diff --git a/window-copy.c b/window-copy.c index c3b8fd04..5c734af9 100644 --- a/window-copy.c +++ b/window-copy.c @@ -1,4 +1,4 @@ -/* $Id: window-copy.c,v 1.132 2011-05-18 20:35:36 tcunha Exp $ */ +/* $Id: window-copy.c,v 1.133 2011-05-22 16:23:07 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1345,6 +1345,9 @@ window_copy_copy_selection(struct window_pane *wp) } off--; /* remove final \n */ + if (options_get_number(&global_options, "set-clipboard")) + screen_write_setselection(&wp->ictx.ctx, buf, off); + /* Add the buffer to the stack. */ limit = options_get_number(&global_options, "buffer-limit"); paste_add(&global_buffers, buf, off, limit);