summaryrefslogtreecommitdiffstats
path: root/cmd-paste-buffer.c
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2012-03-07 13:36:19 +0000
committerTiago Cunha <tcunha@gmx.com>2012-03-07 13:36:19 +0000
commit3275e9bd5b4f9d8aa3961d3468fcd6765191fcc3 (patch)
treed4250d114482e2b2101db7428b742702d9a4a48d /cmd-paste-buffer.c
parent9d79a56402850ac35c57e35fe39990d84e1fd5fa (diff)
Sync OpenBSD patchset 1037:
Support "bracketed paste" mode. This adds a -p flag to paste-buffer - if this is used and the application has requested bracketed pastes, then tmux surrounds the pasted text by \033[200~ and \033[201~. Applications like vim can (apparently) use this to avoid, for example, indenting the text. From Ailin Nemui.
Diffstat (limited to 'cmd-paste-buffer.c')
-rw-r--r--cmd-paste-buffer.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/cmd-paste-buffer.c b/cmd-paste-buffer.c
index f163da5b..00fc57b1 100644
--- a/cmd-paste-buffer.c
+++ b/cmd-paste-buffer.c
@@ -29,13 +29,13 @@
int cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *);
-void cmd_paste_buffer_filter(
- struct window_pane *, const char *, size_t, const char *);
+void cmd_paste_buffer_filter(struct window_pane *,
+ const char *, size_t, const char *, int bracket);
const struct cmd_entry cmd_paste_buffer_entry = {
"paste-buffer", "pasteb",
- "db:rs:t:", 0, 0,
- "[-dr] [-s separator] [-b buffer-index] [-t target-pane]",
+ "db:prs:t:", 0, 0,
+ "[-dpr] [-s separator] [-b buffer-index] [-t target-pane]",
0,
NULL,
NULL,
@@ -52,6 +52,7 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
const char *sepstr;
char *cause;
int buffer;
+ int pflag;
if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL)
return (-1);
@@ -85,7 +86,9 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
else
sepstr = "\r";
}
- cmd_paste_buffer_filter(wp, pb->data, pb->size, sepstr);
+ pflag = args_has(args, 'p') &&
+ (wp->screen->mode & MODE_BRACKETPASTE);
+ cmd_paste_buffer_filter(wp, pb->data, pb->size, sepstr, pflag);
}
/* Delete the buffer if -d. */
@@ -101,13 +104,16 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
/* Add bytes to a buffer and filter '\n' according to separator. */
void
-cmd_paste_buffer_filter(
- struct window_pane *wp, const char *data, size_t size, const char *sep)
+cmd_paste_buffer_filter(struct window_pane *wp,
+ const char *data, size_t size, const char *sep, int bracket)
{
const char *end = data + size;
const char *lf;
size_t seplen;
+ if (bracket)
+ bufferevent_write(wp->event, "\033[200~", 6);
+
seplen = strlen(sep);
while ((lf = memchr(data, '\n', end - data)) != NULL) {
if (lf != data)
@@ -118,4 +124,7 @@ cmd_paste_buffer_filter(
if (end != data)
bufferevent_write(wp->event, data, end - data);
+
+ if (bracket)
+ bufferevent_write(wp->event, "\033[201~", 6);
}