summaryrefslogtreecommitdiffstats
path: root/cmd-capture-pane.c
diff options
context:
space:
mode:
authornicm <nicm>2014-05-13 07:34:35 +0000
committernicm <nicm>2014-05-13 07:34:35 +0000
commit3dbacbb62b033c04185fb87da5b0622f0aafee86 (patch)
treedde33fb1890f249c21d2e5f93943a1e30314f261 /cmd-capture-pane.c
parentf4ffaf5a7fad4c02ad2d08c7b2c80fdec21b64a9 (diff)
Add support for named buffers. If you don't name a buffer, things work
much as before - buffers are automatically named "buffer0000", "buffer0001" and so on and ordered as a stack. Buffers can be named explicitly when creating ("loadb -b foo" etc) or renamed ("setb -b buffer0000 -n foo"). If buffers are named explicitly, they are not deleted when buffer-limit is reached. Diff from J Raynor.
Diffstat (limited to 'cmd-capture-pane.c')
-rw-r--r--cmd-capture-pane.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/cmd-capture-pane.c b/cmd-capture-pane.c
index 759063d1..c6a80ebd 100644
--- a/cmd-capture-pane.c
+++ b/cmd-capture-pane.c
@@ -38,7 +38,7 @@ char *cmd_capture_pane_history(struct args *, struct cmd_q *,
const struct cmd_entry cmd_capture_pane_entry = {
"capture-pane", "capturep",
"ab:CeE:JpPqS:t:", 0, 0,
- "[-aCeJpPq] [-b buffer-index] [-E end-line] [-S start-line]"
+ "[-aCeJpPq] " CMD_BUFFER_USAGE " [-E end-line] [-S start-line]"
CMD_TARGET_PANE_USAGE,
0,
NULL,
@@ -165,8 +165,7 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_q *cmdq)
struct client *c;
struct window_pane *wp;
char *buf, *cause;
- int buffer;
- u_int limit;
+ const char *bufname;
size_t len;
if (cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp) == NULL)
@@ -192,23 +191,15 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_q *cmdq)
evbuffer_add(c->stdout_data, "\n", 1);
server_push_stdout(c);
} else {
- limit = options_get_number(&global_options, "buffer-limit");
- if (!args_has(args, 'b')) {
- paste_add(buf, len, limit);
- return (CMD_RETURN_NORMAL);
- }
- buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
- if (cause != NULL) {
- cmdq_error(cmdq, "buffer %s", cause);
- free(buf);
- free(cause);
- return (CMD_RETURN_ERROR);
- }
+ bufname = NULL;
+ if (args_has(args, 'b'))
+ bufname = args_get(args, 'b');
- if (paste_replace(buffer, buf, len) != 0) {
- cmdq_error(cmdq, "no buffer %d", buffer);
+ if (paste_set(buf, len, bufname, &cause) != 0) {
+ cmdq_error(cmdq, "%s", cause);
free(buf);
+ free(cause);
return (CMD_RETURN_ERROR);
}
}