mirror of
https://github.com/tmate-io/tmate.git
synced 2024-12-19 05:10:42 +01:00
Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code
This commit is contained in:
commit
8e3767e344
@ -31,8 +31,8 @@ enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmd_ctx *);
|
|||||||
|
|
||||||
const struct cmd_entry cmd_capture_pane_entry = {
|
const struct cmd_entry cmd_capture_pane_entry = {
|
||||||
"capture-pane", "capturep",
|
"capture-pane", "capturep",
|
||||||
"eb:E:pS:t:", 0, 0,
|
"b:CeE:JpS:t:", 0, 0,
|
||||||
"[-ep] [-b buffer-index] [-E end-line] [-S start-line]"
|
"[-CeJp] [-b buffer-index] [-E end-line] [-S start-line]"
|
||||||
CMD_TARGET_PANE_USAGE,
|
CMD_TARGET_PANE_USAGE,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
@ -49,10 +49,11 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
char *buf, *line, *cause;
|
char *buf, *line, *cause;
|
||||||
struct screen *s;
|
struct screen *s;
|
||||||
struct grid *gd;
|
struct grid *gd;
|
||||||
int buffer, n, with_codes;
|
int buffer, n, with_codes, escape_c0, join_lines;
|
||||||
u_int i, limit, top, bottom, tmp;
|
u_int i, limit, top, bottom, tmp;
|
||||||
size_t len, linelen;
|
size_t len, linelen;
|
||||||
struct grid_cell *gc;
|
struct grid_cell *gc;
|
||||||
|
const struct grid_line *gl;
|
||||||
|
|
||||||
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
@ -90,17 +91,23 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
top = tmp;
|
top = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
gc = NULL;
|
|
||||||
with_codes = args_has(args, 'e');
|
with_codes = args_has(args, 'e');
|
||||||
|
escape_c0 = args_has(args, 'C');
|
||||||
|
join_lines = args_has(args, 'J');
|
||||||
|
|
||||||
|
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(s->grid, 0, i, screen_size_x(s),
|
||||||
&gc, with_codes);
|
&gc, with_codes, escape_c0);
|
||||||
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;
|
||||||
buf[len++] = '\n';
|
|
||||||
|
gl = grid_peek_line(s->grid, i);
|
||||||
|
if (!join_lines || !(gl->flags & GRID_LINE_WRAPPED))
|
||||||
|
buf[len++] = '\n';
|
||||||
|
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
|
@ -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));
|
return (grid_string_cells(gd, px, py, nx, NULL, 0, 0));
|
||||||
}
|
}
|
||||||
|
56
grid.c
56
grid.c
@ -77,7 +77,7 @@ void grid_reflow_move(struct grid *, u_int *, struct grid_line *);
|
|||||||
size_t grid_string_cells_fg(const struct grid_cell *, int *);
|
size_t grid_string_cells_fg(const struct grid_cell *, int *);
|
||||||
size_t grid_string_cells_bg(const struct grid_cell *, int *);
|
size_t grid_string_cells_bg(const struct grid_cell *, int *);
|
||||||
void grid_string_cells_code(const struct grid_cell *,
|
void grid_string_cells_code(const struct grid_cell *,
|
||||||
const struct grid_cell *, char *, size_t);
|
const struct grid_cell *, char *, size_t, int);
|
||||||
|
|
||||||
/* Create a new grid. */
|
/* Create a new grid. */
|
||||||
struct grid *
|
struct grid *
|
||||||
@ -234,6 +234,15 @@ grid_expand_line(struct grid *gd, u_int py, u_int sx)
|
|||||||
gl->cellsize = sx;
|
gl->cellsize = sx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Peek at grid line. */
|
||||||
|
const struct grid_line *
|
||||||
|
grid_peek_line(struct grid *gd, u_int py)
|
||||||
|
{
|
||||||
|
if (grid_check_y(gd, py) != 0)
|
||||||
|
return (NULL);
|
||||||
|
return (&gd->linedata[py]);
|
||||||
|
}
|
||||||
|
|
||||||
/* Get cell for reading. */
|
/* Get cell for reading. */
|
||||||
const struct grid_cell *
|
const struct grid_cell *
|
||||||
grid_peek_cell(struct grid *gd, u_int px, u_int py)
|
grid_peek_cell(struct grid *gd, u_int px, u_int py)
|
||||||
@ -485,7 +494,7 @@ grid_string_cells_bg(const struct grid_cell *gc, int *values)
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
grid_string_cells_code(const struct grid_cell *lastgc,
|
grid_string_cells_code(const struct grid_cell *lastgc,
|
||||||
const struct grid_cell *gc, char *buf, size_t len)
|
const struct grid_cell *gc, char *buf, size_t len, int escape_c0)
|
||||||
{
|
{
|
||||||
int oldc[16], newc[16], s[32];
|
int oldc[16], newc[16], s[32];
|
||||||
size_t noldc, nnewc, n, i;
|
size_t noldc, nnewc, n, i;
|
||||||
@ -542,7 +551,10 @@ grid_string_cells_code(const struct grid_cell *lastgc,
|
|||||||
/* If there are any parameters, append an SGR code. */
|
/* If there are any parameters, append an SGR code. */
|
||||||
*buf = '\0';
|
*buf = '\0';
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
strlcat(buf, "\033[", len);
|
if (escape_c0)
|
||||||
|
strlcat(buf, "\\033[", len);
|
||||||
|
else
|
||||||
|
strlcat(buf, "\033[", len);
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
if (i + 1 < n)
|
if (i + 1 < n)
|
||||||
xsnprintf(tmp, sizeof tmp, "%d;", s[i]);
|
xsnprintf(tmp, sizeof tmp, "%d;", s[i]);
|
||||||
@ -554,22 +566,31 @@ grid_string_cells_code(const struct grid_cell *lastgc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Append shift in/shift out if needed. */
|
/* Append shift in/shift out if needed. */
|
||||||
if ((attr & GRID_ATTR_CHARSET) && !(lastattr & GRID_ATTR_CHARSET))
|
if ((attr & GRID_ATTR_CHARSET) && !(lastattr & GRID_ATTR_CHARSET)) {
|
||||||
strlcat(buf, "\016", len); /* SO */
|
if (escape_c0)
|
||||||
if (!(attr & GRID_ATTR_CHARSET) && (lastattr & GRID_ATTR_CHARSET))
|
strlcat(buf, "\\016", len); /* SO */
|
||||||
strlcat(buf, "\017", len); /* SI */
|
else
|
||||||
|
strlcat(buf, "\016", len); /* SO */
|
||||||
|
}
|
||||||
|
if (!(attr & GRID_ATTR_CHARSET) && (lastattr & GRID_ATTR_CHARSET)) {
|
||||||
|
if (escape_c0)
|
||||||
|
strlcat(buf, "\\017", len); /* SI */
|
||||||
|
else
|
||||||
|
strlcat(buf, "\017", len); /* SI */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert cells into a string. */
|
/* Convert cells into a string. */
|
||||||
char *
|
char *
|
||||||
grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
|
grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
|
||||||
struct grid_cell **lastgc, int with_codes)
|
struct grid_cell **lastgc, int with_codes, int escape_c0)
|
||||||
{
|
{
|
||||||
const struct grid_cell *gc;
|
const struct grid_cell *gc;
|
||||||
static struct grid_cell lastgc1;
|
static struct grid_cell lastgc1;
|
||||||
struct utf8_data ud;
|
struct utf8_data ud;
|
||||||
|
const char* data;
|
||||||
char *buf, code[128];
|
char *buf, code[128];
|
||||||
size_t len, off, codelen;
|
size_t len, off, size, codelen;
|
||||||
u_int xx;
|
u_int xx;
|
||||||
|
|
||||||
GRID_DEBUG(gd, "px=%u, py=%u, nx=%u", px, py, nx);
|
GRID_DEBUG(gd, "px=%u, py=%u, nx=%u", px, py, nx);
|
||||||
@ -590,13 +611,21 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
|
|||||||
grid_cell_get(gc, &ud);
|
grid_cell_get(gc, &ud);
|
||||||
|
|
||||||
if (with_codes) {
|
if (with_codes) {
|
||||||
grid_string_cells_code(*lastgc, gc, code, sizeof code);
|
grid_string_cells_code(*lastgc, gc, code, sizeof code,
|
||||||
|
escape_c0);
|
||||||
codelen = strlen(code);
|
codelen = strlen(code);
|
||||||
memcpy(*lastgc, gc, sizeof *gc);
|
memcpy(*lastgc, gc, sizeof *gc);
|
||||||
} else
|
} else
|
||||||
codelen = 0;
|
codelen = 0;
|
||||||
|
|
||||||
while (len < off + ud.size + codelen + 1) {
|
data = ud.data;
|
||||||
|
size = ud.size;
|
||||||
|
if (escape_c0 && size == 1 && *data == '\\') {
|
||||||
|
data = "\\";
|
||||||
|
size = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (len < off + size + codelen + 1) {
|
||||||
buf = xrealloc(buf, 2, len);
|
buf = xrealloc(buf, 2, len);
|
||||||
len *= 2;
|
len *= 2;
|
||||||
}
|
}
|
||||||
@ -605,13 +634,14 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
|
|||||||
memcpy(buf + off, code, codelen);
|
memcpy(buf + off, code, codelen);
|
||||||
off += codelen;
|
off += codelen;
|
||||||
}
|
}
|
||||||
memcpy(buf + off, ud.data, ud.size);
|
memcpy(buf + off, data, size);
|
||||||
off += ud.size;
|
off += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (off > 0 && buf[off - 1] == ' ')
|
while (off > 0 && buf[off - 1] == ' ')
|
||||||
off--;
|
off--;
|
||||||
buf[off] = '\0';
|
buf[off] = '\0';
|
||||||
|
|
||||||
return (buf);
|
return (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
tmux.1
7
tmux.1
@ -1067,7 +1067,12 @@ is given, the output goes to stdout, otherwise to the buffer specified with
|
|||||||
or a new buffer if omitted.
|
or a new buffer if omitted.
|
||||||
If
|
If
|
||||||
.Fl e
|
.Fl e
|
||||||
is given, the output includes escape sequences for text and background attributes.
|
is given, the output includes escape sequences for text and background
|
||||||
|
attributes.
|
||||||
|
.Fl C
|
||||||
|
also escapes non-printable characters as octal \\xxx.
|
||||||
|
.Fl J
|
||||||
|
joins wrapped lines.
|
||||||
.Pp
|
.Pp
|
||||||
.Fl S
|
.Fl S
|
||||||
and
|
and
|
||||||
|
3
tmux.h
3
tmux.h
@ -1969,6 +1969,7 @@ void grid_scroll_history(struct grid *);
|
|||||||
void grid_scroll_history_region(struct grid *, u_int, u_int);
|
void grid_scroll_history_region(struct grid *, u_int, u_int);
|
||||||
void grid_expand_line(struct grid *, u_int, u_int);
|
void grid_expand_line(struct grid *, u_int, u_int);
|
||||||
const struct grid_cell *grid_peek_cell(struct grid *, u_int, u_int);
|
const struct grid_cell *grid_peek_cell(struct grid *, u_int, u_int);
|
||||||
|
const struct grid_line *grid_peek_line(struct grid *, u_int);
|
||||||
struct grid_cell *grid_get_cell(struct grid *, u_int, u_int);
|
struct grid_cell *grid_get_cell(struct grid *, u_int, u_int);
|
||||||
void grid_set_cell(struct grid *, u_int, u_int, const struct grid_cell *);
|
void grid_set_cell(struct grid *, u_int, u_int, const struct grid_cell *);
|
||||||
void grid_clear(struct grid *, u_int, u_int, u_int, u_int);
|
void grid_clear(struct grid *, u_int, u_int, u_int, u_int);
|
||||||
@ -1976,7 +1977,7 @@ void grid_clear_lines(struct grid *, u_int, u_int);
|
|||||||
void grid_move_lines(struct grid *, u_int, u_int, u_int);
|
void grid_move_lines(struct grid *, u_int, u_int, u_int);
|
||||||
void grid_move_cells(struct grid *, u_int, u_int, u_int, u_int);
|
void grid_move_cells(struct grid *, u_int, u_int, u_int, u_int);
|
||||||
char *grid_string_cells(struct grid *, u_int, u_int, u_int,
|
char *grid_string_cells(struct grid *, u_int, u_int, u_int,
|
||||||
struct grid_cell **, int);
|
struct grid_cell **, int, int);
|
||||||
void grid_duplicate_lines(
|
void grid_duplicate_lines(
|
||||||
struct grid *, u_int, struct grid *, u_int, u_int);
|
struct grid *, u_int, struct grid *, u_int, u_int);
|
||||||
u_int grid_reflow(struct grid *, struct grid *, u_int);
|
u_int grid_reflow(struct grid *, struct grid *, u_int);
|
||||||
|
Loading…
Reference in New Issue
Block a user