cmd-capture-pane.c revision 1.1 1 1.1 jmmv /* $Id: cmd-capture-pane.c,v 1.1 2011/03/10 09:15:36 jmmv Exp $ */
2 1.1 jmmv
3 1.1 jmmv /*
4 1.1 jmmv * Copyright (c) 2009 Jonathan Alvarado <radobobo (at) users.sourceforge.net>
5 1.1 jmmv *
6 1.1 jmmv * Permission to use, copy, modify, and distribute this software for any
7 1.1 jmmv * purpose with or without fee is hereby granted, provided that the above
8 1.1 jmmv * copyright notice and this permission notice appear in all copies.
9 1.1 jmmv *
10 1.1 jmmv * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 1.1 jmmv * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 1.1 jmmv * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 1.1 jmmv * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 1.1 jmmv * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 1.1 jmmv * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 1.1 jmmv * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 1.1 jmmv */
18 1.1 jmmv
19 1.1 jmmv #include <sys/types.h>
20 1.1 jmmv
21 1.1 jmmv #include <string.h>
22 1.1 jmmv
23 1.1 jmmv #include "tmux.h"
24 1.1 jmmv
25 1.1 jmmv /*
26 1.1 jmmv * Write the entire contents of a pane to a buffer.
27 1.1 jmmv */
28 1.1 jmmv
29 1.1 jmmv int cmd_capture_pane_exec(struct cmd *, struct cmd_ctx *);
30 1.1 jmmv
31 1.1 jmmv const struct cmd_entry cmd_capture_pane_entry = {
32 1.1 jmmv "capture-pane", "capturep",
33 1.1 jmmv CMD_BUFFER_PANE_USAGE,
34 1.1 jmmv 0, "",
35 1.1 jmmv cmd_buffer_init,
36 1.1 jmmv cmd_buffer_parse,
37 1.1 jmmv cmd_capture_pane_exec,
38 1.1 jmmv cmd_buffer_free,
39 1.1 jmmv cmd_buffer_print
40 1.1 jmmv };
41 1.1 jmmv
42 1.1 jmmv int
43 1.1 jmmv cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
44 1.1 jmmv {
45 1.1 jmmv struct cmd_buffer_data *data = self->data;
46 1.1 jmmv struct window_pane *wp;
47 1.1 jmmv char *buf, *line;
48 1.1 jmmv struct screen *s;
49 1.1 jmmv struct session *sess;
50 1.1 jmmv u_int i, limit;
51 1.1 jmmv size_t len, linelen;
52 1.1 jmmv
53 1.1 jmmv if (cmd_find_pane(ctx, data->target, &sess, &wp) == NULL)
54 1.1 jmmv return (-1);
55 1.1 jmmv s = &wp->base;
56 1.1 jmmv
57 1.1 jmmv buf = NULL;
58 1.1 jmmv len = 0;
59 1.1 jmmv
60 1.1 jmmv for (i = 0; i < screen_size_y(s); i++) {
61 1.1 jmmv line = grid_view_string_cells(s->grid, 0, i, screen_size_x(s));
62 1.1 jmmv linelen = strlen(line);
63 1.1 jmmv
64 1.1 jmmv buf = xrealloc(buf, 1, len + linelen + 1);
65 1.1 jmmv memcpy(buf + len, line, linelen);
66 1.1 jmmv len += linelen;
67 1.1 jmmv buf[len++] = '\n';
68 1.1 jmmv
69 1.1 jmmv xfree(line);
70 1.1 jmmv }
71 1.1 jmmv
72 1.1 jmmv limit = options_get_number(&sess->options, "buffer-limit");
73 1.1 jmmv if (data->buffer == -1) {
74 1.1 jmmv paste_add(&sess->buffers, buf, len, limit);
75 1.1 jmmv return (0);
76 1.1 jmmv }
77 1.1 jmmv if (paste_replace(&sess->buffers, data->buffer, buf, len) != 0) {
78 1.1 jmmv ctx->error(ctx, "no buffer %d", data->buffer);
79 1.1 jmmv xfree(buf);
80 1.1 jmmv return (-1);
81 1.1 jmmv }
82 1.1 jmmv return (0);
83 1.1 jmmv }
84