Skip to content

Commit

Permalink
paste_send_pane can be merged into cmd-paste-buffer.c now.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicm committed Aug 29, 2015
1 parent b569585 commit 373ef85
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 37 deletions.
31 changes: 27 additions & 4 deletions cmd-paste-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
struct window_pane *wp;
struct session *s;
struct paste_buffer *pb;
const char *sepstr, *bufname;
const char *sepstr, *bufname, *bufdata, *bufend, *line;
size_t seplen, bufsize;
int bracket = args_has(args, 'p');

if (cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp) == NULL)
return (CMD_RETURN_ERROR);
Expand All @@ -67,18 +69,39 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
}
}

if (pb != NULL) {
if (pb != NULL && ~wp->flags & PANE_INPUTOFF) {
sepstr = args_get(args, 's');
if (sepstr == NULL) {
if (args_has(args, 'r'))
sepstr = "\n";
else
sepstr = "\r";
}
paste_send_pane(pb, wp, sepstr, args_has(args, 'p'));
seplen = strlen(sepstr);

if (bracket && (wp->screen->mode & MODE_BRACKETPASTE))
bufferevent_write(wp->event, "\033[200~", 6);

bufdata = paste_buffer_data(pb, &bufsize);
bufend = bufdata + bufsize;

for (;;) {
line = memchr(bufdata, '\n', bufend - bufdata);
if (line == NULL)
break;

bufferevent_write(wp->event, bufdata, line - bufdata);
bufferevent_write(wp->event, sepstr, seplen);

bufdata = line + 1;
}
if (bufdata != bufend)
bufferevent_write(wp->event, bufdata, bufend - bufdata);

if (bracket && (wp->screen->mode & MODE_BRACKETPASTE))
bufferevent_write(wp->event, "\033[201~", 6);
}

/* Delete the buffer if -d. */
if (args_has(args, 'd')) {
if (bufname == NULL)
paste_free_top();
Expand Down
4 changes: 2 additions & 2 deletions cmd-save-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
struct client *c = cmdq->client;
struct session *s;
struct paste_buffer *pb;
const char *path, *bufname, *bufdata;
char *start, *end, *msg;
const char *path, *bufname, *bufdata, *start, *end;
char *msg;
size_t size, used, msglen, bufsize;
int cwd, fd;
FILE *f;
Expand Down
29 changes: 0 additions & 29 deletions paste.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,32 +319,3 @@ paste_make_sample(struct paste_buffer *pb, int utf8flag)
strlcpy(buf + width, "...", 4);
return (buf);
}

/* Paste into a window pane, filtering '\n' according to separator. */
void
paste_send_pane(struct paste_buffer *pb, struct window_pane *wp,
const char *sep, int bracket)
{
const char *data = pb->data, *end = data + pb->size, *lf;
size_t seplen;

if (wp->flags & PANE_INPUTOFF)
return;

if (bracket && (wp->screen->mode & MODE_BRACKETPASTE))
bufferevent_write(wp->event, "\033[200~", 6);

seplen = strlen(sep);
while ((lf = memchr(data, '\n', end - data)) != NULL) {
if (lf != data)
bufferevent_write(wp->event, data, lf - data);
bufferevent_write(wp->event, sep, seplen);
data = lf + 1;
}

if (end != data)
bufferevent_write(wp->event, data, end - data);

if (bracket && (wp->screen->mode & MODE_BRACKETPASTE))
bufferevent_write(wp->event, "\033[201~", 6);
}
2 changes: 0 additions & 2 deletions tmux.h
Original file line number Diff line number Diff line change
Expand Up @@ -1452,8 +1452,6 @@ void paste_add(char *, size_t);
int paste_rename(const char *, const char *, char **);
int paste_set(char *, size_t, const char *, char **);
char *paste_make_sample(struct paste_buffer *, int);
void paste_send_pane(struct paste_buffer *, struct window_pane *,
const char *, int);

/* format.c */
struct format_tree;
Expand Down

0 comments on commit 373ef85

Please sign in to comment.