summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/cmd-paste-buffer.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2012-03-03 09:43:24 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2012-03-03 09:43:24 +0000
commit4290d0074c3a62f29fee68911f28828f92246a23 (patch)
tree6278f75d11c4c3a2867ff5dd179528cd8ec7b669 /usr.bin/tmux/cmd-paste-buffer.c
parent10be96f2d3f09efc66492720718c3dedc5ed5657 (diff)
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 'usr.bin/tmux/cmd-paste-buffer.c')
-rw-r--r--usr.bin/tmux/cmd-paste-buffer.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/usr.bin/tmux/cmd-paste-buffer.c b/usr.bin/tmux/cmd-paste-buffer.c
index abe116f9f37..e2fe0129d3d 100644
--- a/usr.bin/tmux/cmd-paste-buffer.c
+++ b/usr.bin/tmux/cmd-paste-buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-paste-buffer.c,v 1.16 2011/01/04 00:42:47 nicm Exp $ */
+/* $OpenBSD: cmd-paste-buffer.c,v 1.17 2012/03/03 09:43:22 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -30,13 +30,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,
@@ -53,6 +53,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);
@@ -86,7 +87,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. */
@@ -102,13 +105,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)
@@ -119,4 +125,7 @@ cmd_paste_buffer_filter(
if (end != data)
bufferevent_write(wp->event, data, end - data);
+
+ if (bracket)
+ bufferevent_write(wp->event, "\033[201~", 6);
}