mirror of
https://github.com/tmux/tmux.git
synced 2026-06-20 17:25:57 +00:00
Add -H flag to capture-pane to show hyperlinks.
This commit is contained in:
@@ -29,18 +29,21 @@
|
|||||||
|
|
||||||
static enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmdq_item *);
|
static enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmdq_item *);
|
||||||
|
|
||||||
static char *cmd_capture_pane_append(char *, size_t *, char *, size_t);
|
static char *cmd_capture_pane_append(char *, size_t *, const char *,
|
||||||
|
size_t);
|
||||||
static char *cmd_capture_pane_pending(struct args *, struct window_pane *,
|
static char *cmd_capture_pane_pending(struct args *, struct window_pane *,
|
||||||
size_t *);
|
size_t *);
|
||||||
static char *cmd_capture_pane_history(struct args *, struct cmdq_item *,
|
static char *cmd_capture_pane_history(struct args *, struct cmdq_item *,
|
||||||
struct window_pane *, size_t *);
|
struct window_pane *, size_t *);
|
||||||
|
static char *cmd_capture_pane_hyperlinks(struct grid *, struct screen *,
|
||||||
|
u_int, u_int *, u_int *, size_t *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_capture_pane_entry = {
|
const struct cmd_entry cmd_capture_pane_entry = {
|
||||||
.name = "capture-pane",
|
.name = "capture-pane",
|
||||||
.alias = "capturep",
|
.alias = "capturep",
|
||||||
|
|
||||||
.args = { "ab:CeE:FJLMNpPqS:Tt:", 0, 0, NULL },
|
.args = { "ab:CeE:FHJLMNpPqS:Tt:", 0, 0, NULL },
|
||||||
.usage = "[-aCeFJLMNpPqT] " CMD_BUFFER_USAGE " [-E end-line] "
|
.usage = "[-aCeFHJLMNpPqT] " CMD_BUFFER_USAGE " [-E end-line] "
|
||||||
"[-S start-line] " CMD_TARGET_PANE_USAGE,
|
"[-S start-line] " CMD_TARGET_PANE_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
.target = { 't', CMD_FIND_PANE, 0 },
|
||||||
@@ -63,7 +66,8 @@ const struct cmd_entry cmd_clear_history_entry = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
cmd_capture_pane_append(char *buf, size_t *len, char *line, size_t linelen)
|
cmd_capture_pane_append(char *buf, size_t *len, const char *line,
|
||||||
|
size_t linelen)
|
||||||
{
|
{
|
||||||
buf = xrealloc(buf, *len + linelen + 1);
|
buf = xrealloc(buf, *len + linelen + 1);
|
||||||
memcpy(buf + *len, line, linelen);
|
memcpy(buf + *len, line, linelen);
|
||||||
@@ -103,6 +107,46 @@ cmd_capture_pane_pending(struct args *args, struct window_pane *wp,
|
|||||||
return (buf);
|
return (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
cmd_capture_pane_hyperlinks(struct grid *gd, struct screen *s, u_int py,
|
||||||
|
u_int *links, u_int *nlinks, size_t *len)
|
||||||
|
{
|
||||||
|
const struct grid_line *gl = grid_peek_line(gd, py);
|
||||||
|
struct grid_cell gc;
|
||||||
|
const char *uri;
|
||||||
|
char *line = xstrdup("");
|
||||||
|
u_int i, j;
|
||||||
|
|
||||||
|
*len = 0;
|
||||||
|
|
||||||
|
if (s->hyperlinks == NULL || (~gl->flags & GRID_LINE_HYPERLINK))
|
||||||
|
return (line);
|
||||||
|
|
||||||
|
for (i = 0; i < gl->cellused; i++) {
|
||||||
|
grid_get_cell(gd, i, py, &gc);
|
||||||
|
if (gc.link == 0)
|
||||||
|
continue;
|
||||||
|
for (j = 0; j < *nlinks; j++) {
|
||||||
|
if (links[j] == gc.link)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (j != *nlinks)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!hyperlinks_get(s->hyperlinks, gc.link, &uri, NULL, NULL))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (*nlinks == gd->sx)
|
||||||
|
break;
|
||||||
|
links[(*nlinks)++] = gc.link;
|
||||||
|
|
||||||
|
if (*len != 0)
|
||||||
|
line = cmd_capture_pane_append(line, len, " ", 1);
|
||||||
|
line = cmd_capture_pane_append(line, len, uri, strlen(uri));
|
||||||
|
}
|
||||||
|
return (line);
|
||||||
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
|
cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
|
||||||
struct window_pane *wp, size_t *len)
|
struct window_pane *wp, size_t *len)
|
||||||
@@ -113,9 +157,10 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
|
|||||||
struct grid_cell *gc = NULL;
|
struct grid_cell *gc = NULL;
|
||||||
struct window_mode_entry *wme;
|
struct window_mode_entry *wme;
|
||||||
int n, join_lines, number_lines, flags = 0;
|
int n, join_lines, number_lines, flags = 0;
|
||||||
int show_flags;
|
int show_flags, hyperlinks;
|
||||||
|
u_int *links = NULL, nlinks = 0;
|
||||||
u_int i, sx, top, bottom, tmp;
|
u_int i, sx, top, bottom, tmp;
|
||||||
char *cause, *buf, *line, b[64], *cp;
|
char *cause, *buf = NULL, *line, b[64], *cp;
|
||||||
const char *Sflag, *Eflag;
|
const char *Sflag, *Eflag;
|
||||||
size_t linelen;
|
size_t linelen;
|
||||||
|
|
||||||
@@ -195,11 +240,22 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
|
|||||||
flags |= GRID_STRING_TRIM_SPACES;
|
flags |= GRID_STRING_TRIM_SPACES;
|
||||||
number_lines = args_has(args, 'L');
|
number_lines = args_has(args, 'L');
|
||||||
show_flags = args_has(args, 'F');
|
show_flags = args_has(args, 'F');
|
||||||
|
hyperlinks = args_has(args, 'H');
|
||||||
|
if (hyperlinks)
|
||||||
|
links = xreallocarray(NULL, gd->sx, sizeof *links);
|
||||||
|
|
||||||
buf = NULL;
|
|
||||||
for (i = top; i <= bottom; i++) {
|
for (i = top; i <= bottom; i++) {
|
||||||
|
if (hyperlinks) {
|
||||||
|
line = cmd_capture_pane_hyperlinks(gd, s, i, links,
|
||||||
|
&nlinks, &linelen);
|
||||||
|
} else {
|
||||||
line = grid_string_cells(gd, 0, i, sx, &gc, flags, s);
|
line = grid_string_cells(gd, 0, i, sx, &gc, flags, s);
|
||||||
linelen = strlen(line);
|
linelen = strlen(line);
|
||||||
|
}
|
||||||
|
if (hyperlinks && linelen == 0) {
|
||||||
|
free(line);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (number_lines) {
|
if (number_lines) {
|
||||||
if (i >= gd->hsize)
|
if (i >= gd->hsize)
|
||||||
@@ -217,6 +273,8 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
|
|||||||
gl = grid_peek_line(gd, i);
|
gl = grid_peek_line(gd, i);
|
||||||
if (gl->flags & GRID_LINE_DEAD)
|
if (gl->flags & GRID_LINE_DEAD)
|
||||||
*cp++ = 'D';
|
*cp++ = 'D';
|
||||||
|
if (gl->flags & GRID_LINE_HYPERLINK)
|
||||||
|
*cp++ = 'H';
|
||||||
if (gl->flags & GRID_LINE_START_OUTPUT)
|
if (gl->flags & GRID_LINE_START_OUTPUT)
|
||||||
*cp++ = 'O';
|
*cp++ = 'O';
|
||||||
if (gl->flags & GRID_LINE_START_PROMPT)
|
if (gl->flags & GRID_LINE_START_PROMPT)
|
||||||
@@ -239,6 +297,9 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
|
|||||||
|
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
|
free(links);
|
||||||
|
if (buf == NULL)
|
||||||
|
buf = xstrdup("");
|
||||||
return (buf);
|
return (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,7 +322,7 @@ cmd_capture_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
len = 0;
|
len = 0;
|
||||||
if (args_has(args, 'P'))
|
if (args_has(args, 'P') && !args_has(args, 'H'))
|
||||||
buf = cmd_capture_pane_pending(args, wp, &len);
|
buf = cmd_capture_pane_pending(args, wp, &len);
|
||||||
else
|
else
|
||||||
buf = cmd_capture_pane_history(args, item, wp, &len);
|
buf = cmd_capture_pane_history(args, item, wp, &len);
|
||||||
|
|||||||
2
grid.c
2
grid.c
@@ -125,6 +125,8 @@ grid_extended_cell(struct grid_line *gl, struct grid_cell_entry *gce,
|
|||||||
else if (gce->offset >= gl->extdsize)
|
else if (gce->offset >= gl->extdsize)
|
||||||
fatalx("offset too big");
|
fatalx("offset too big");
|
||||||
gl->flags |= GRID_LINE_EXTENDED;
|
gl->flags |= GRID_LINE_EXTENDED;
|
||||||
|
if (gc->link != 0)
|
||||||
|
gl->flags |= GRID_LINE_HYPERLINK;
|
||||||
|
|
||||||
if (gc->flags & GRID_FLAG_TAB)
|
if (gc->flags & GRID_FLAG_TAB)
|
||||||
uc = gc->data.width;
|
uc = gc->data.width;
|
||||||
|
|||||||
12
tmux.1
12
tmux.1
@@ -2666,7 +2666,7 @@ but a different format may be specified with
|
|||||||
.Fl F .
|
.Fl F .
|
||||||
.Tg capturep
|
.Tg capturep
|
||||||
.It Xo Ic capture\-pane
|
.It Xo Ic capture\-pane
|
||||||
.Op Fl aeFLpPqCJMN
|
.Op Fl aeFHLpPqCJMN
|
||||||
.Op Fl b Ar buffer\-name
|
.Op Fl b Ar buffer\-name
|
||||||
.Op Fl E Ar end\-line
|
.Op Fl E Ar end\-line
|
||||||
.Op Fl S Ar start\-line
|
.Op Fl S Ar start\-line
|
||||||
@@ -2717,9 +2717,15 @@ is an unused line,
|
|||||||
.Ql O
|
.Ql O
|
||||||
is a line marked as output,
|
is a line marked as output,
|
||||||
.Ql P
|
.Ql P
|
||||||
is a line marked as a prompt and
|
is a line marked as a prompt,
|
||||||
.Ql X
|
.Ql X
|
||||||
is a line containing extended cells).
|
is a line containing extended cells and
|
||||||
|
.Ql H
|
||||||
|
is a line with hyperlinks).
|
||||||
|
With
|
||||||
|
.Fl H ,
|
||||||
|
only hyperlinks in the specified lines are captured.
|
||||||
|
Multiple hyperlinks on the same line are separated by spaces.
|
||||||
.Pp
|
.Pp
|
||||||
.Fl S
|
.Fl S
|
||||||
and
|
and
|
||||||
|
|||||||
1
tmux.h
1
tmux.h
@@ -771,6 +771,7 @@ struct colour_palette {
|
|||||||
#define GRID_LINE_DEAD 0x4
|
#define GRID_LINE_DEAD 0x4
|
||||||
#define GRID_LINE_START_PROMPT 0x8
|
#define GRID_LINE_START_PROMPT 0x8
|
||||||
#define GRID_LINE_START_OUTPUT 0x10
|
#define GRID_LINE_START_OUTPUT 0x10
|
||||||
|
#define GRID_LINE_HYPERLINK 0x20
|
||||||
|
|
||||||
/* Grid string flags. */
|
/* Grid string flags. */
|
||||||
#define GRID_STRING_WITH_SEQUENCES 0x1
|
#define GRID_STRING_WITH_SEQUENCES 0x1
|
||||||
|
|||||||
Reference in New Issue
Block a user