mirror of
https://github.com/tmux/tmux.git
synced 2025-04-14 07:18:49 +00:00
Preserve trailing spaces with capture-pane -J, from George Nachman.
This commit is contained in:
parent
e2e85650ac
commit
e85f764f23
@ -31,8 +31,8 @@ enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmd_q *);
|
|||||||
|
|
||||||
const struct cmd_entry cmd_capture_pane_entry = {
|
const struct cmd_entry cmd_capture_pane_entry = {
|
||||||
"capture-pane", "capturep",
|
"capture-pane", "capturep",
|
||||||
"b:CeE:JpS:t:", 0, 0,
|
"ab:CeE:JpqS:t:", 0, 0,
|
||||||
"[-CeJp] [-b buffer-index] [-E end-line] [-S start-line]"
|
"[-aCeJpq] [-b buffer-index] [-E end-line] [-S start-line]"
|
||||||
CMD_TARGET_PANE_USAGE,
|
CMD_TARGET_PANE_USAGE,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
@ -50,67 +50,82 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
|||||||
struct screen *s;
|
struct screen *s;
|
||||||
struct grid *gd;
|
struct grid *gd;
|
||||||
int buffer, n, with_codes, escape_c0, join_lines;
|
int buffer, n, with_codes, escape_c0, join_lines;
|
||||||
u_int i, limit, top, bottom, tmp;
|
u_int i, limit, top, bottom, tmp, sx;
|
||||||
size_t len, linelen;
|
size_t len, linelen;
|
||||||
struct grid_cell *gc;
|
struct grid_cell *gc;
|
||||||
const struct grid_line *gl;
|
const struct grid_line *gl;
|
||||||
|
|
||||||
if (cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp) == NULL)
|
if (cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
s = &wp->base;
|
|
||||||
gd = s->grid;
|
if (args_has(args, 'a')) {
|
||||||
|
s = NULL;
|
||||||
|
gd = wp->saved_grid;
|
||||||
|
sx = screen_size_x(&wp->base);
|
||||||
|
if (gd == NULL && !args_has(args, 'q')) {
|
||||||
|
cmdq_error(cmdq, "no alternate screen");
|
||||||
|
return (CMD_RETURN_ERROR);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
s = &wp->base;
|
||||||
|
sx = screen_size_x(s);
|
||||||
|
gd = s->grid;
|
||||||
|
}
|
||||||
|
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
len = 0;
|
len = 0;
|
||||||
|
|
||||||
n = args_strtonum(args, 'S', INT_MIN, SHRT_MAX, &cause);
|
if (gd != NULL) {
|
||||||
if (cause != NULL) {
|
n = args_strtonum(args, 'S', INT_MIN, SHRT_MAX, &cause);
|
||||||
top = gd->hsize;
|
if (cause != NULL) {
|
||||||
free(cause);
|
top = gd->hsize;
|
||||||
} else if (n < 0 && (u_int) -n > gd->hsize)
|
free(cause);
|
||||||
top = 0;
|
} else if (n < 0 && (u_int) -n > gd->hsize)
|
||||||
else
|
top = 0;
|
||||||
top = gd->hsize + n;
|
else
|
||||||
if (top > gd->hsize + gd->sy - 1)
|
top = gd->hsize + n;
|
||||||
top = gd->hsize + gd->sy - 1;
|
if (top > gd->hsize + gd->sy - 1)
|
||||||
|
top = gd->hsize + gd->sy - 1;
|
||||||
|
|
||||||
n = args_strtonum(args, 'E', INT_MIN, SHRT_MAX, &cause);
|
n = args_strtonum(args, 'E', INT_MIN, SHRT_MAX, &cause);
|
||||||
if (cause != NULL) {
|
if (cause != NULL) {
|
||||||
bottom = gd->hsize + gd->sy - 1;
|
bottom = gd->hsize + gd->sy - 1;
|
||||||
free(cause);
|
free(cause);
|
||||||
} else if (n < 0 && (u_int) -n > gd->hsize)
|
} else if (n < 0 && (u_int) -n > gd->hsize)
|
||||||
bottom = 0;
|
bottom = 0;
|
||||||
else
|
else
|
||||||
bottom = gd->hsize + n;
|
bottom = gd->hsize + n;
|
||||||
if (bottom > gd->hsize + gd->sy - 1)
|
if (bottom > gd->hsize + gd->sy - 1)
|
||||||
bottom = gd->hsize + gd->sy - 1;
|
bottom = gd->hsize + gd->sy - 1;
|
||||||
|
|
||||||
if (bottom < top) {
|
if (bottom < top) {
|
||||||
tmp = bottom;
|
tmp = bottom;
|
||||||
bottom = top;
|
bottom = top;
|
||||||
top = tmp;
|
top = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
with_codes = args_has(args, 'e');
|
with_codes = args_has(args, 'e');
|
||||||
escape_c0 = args_has(args, 'C');
|
escape_c0 = args_has(args, 'C');
|
||||||
join_lines = args_has(args, 'J');
|
join_lines = args_has(args, 'J');
|
||||||
|
|
||||||
gc = NULL;
|
gc = NULL;
|
||||||
for (i = top; i <= bottom; i++) {
|
for (i = top; i <= bottom; i++) {
|
||||||
line = grid_string_cells(s->grid, 0, i, screen_size_x(s),
|
line = grid_string_cells(gd, 0, i, sx, &gc, with_codes,
|
||||||
&gc, with_codes, escape_c0);
|
escape_c0, !join_lines);
|
||||||
linelen = strlen(line);
|
linelen = strlen(line);
|
||||||
|
|
||||||
buf = xrealloc(buf, 1, len + linelen + 1);
|
buf = xrealloc(buf, 1, len + linelen + 1);
|
||||||
memcpy(buf + len, line, linelen);
|
memcpy(buf + len, line, linelen);
|
||||||
len += linelen;
|
len += linelen;
|
||||||
|
|
||||||
gl = grid_peek_line(s->grid, i);
|
gl = grid_peek_line(gd, i);
|
||||||
if (!join_lines || !(gl->flags & GRID_LINE_WRAPPED))
|
if (!join_lines || !(gl->flags & GRID_LINE_WRAPPED))
|
||||||
buf[len++] = '\n';
|
buf[len++] = '\n';
|
||||||
|
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
|
} else
|
||||||
|
buf = xstrdup("");
|
||||||
|
|
||||||
if (args_has(args, 'p')) {
|
if (args_has(args, 'p')) {
|
||||||
c = cmdq->client;
|
c = cmdq->client;
|
||||||
|
@ -234,5 +234,5 @@ grid_view_string_cells(struct grid *gd, u_int px, u_int py, u_int nx)
|
|||||||
px = grid_view_x(gd, px);
|
px = grid_view_x(gd, px);
|
||||||
py = grid_view_y(gd, py);
|
py = grid_view_y(gd, py);
|
||||||
|
|
||||||
return (grid_string_cells(gd, px, py, nx, NULL, 0, 0));
|
return (grid_string_cells(gd, px, py, nx, NULL, 0, 0, 0));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user