mirror of
https://github.com/tmux/tmux.git
synced 2026-02-09 04:48:47 +00:00
Add a function to convert a screen to a string, from Michael Grant.
This commit is contained in:
71
screen.c
71
screen.c
@@ -744,3 +744,74 @@ screen_mode_to_string(int mode)
|
||||
tmp[strlen(tmp) - 1] = '\0';
|
||||
return (tmp);
|
||||
}
|
||||
|
||||
const char *
|
||||
screen_print(struct screen *s)
|
||||
{
|
||||
static char *buf;
|
||||
static size_t len = 16384;
|
||||
const char *acs;
|
||||
u_int x, y;
|
||||
int n;
|
||||
size_t last = 0;
|
||||
struct utf8_data ud;
|
||||
struct grid_line *gl;
|
||||
struct grid_cell_entry *gce;
|
||||
|
||||
if (buf == NULL)
|
||||
buf = xmalloc(len);
|
||||
|
||||
for (y = 0; y < screen_hsize(s) + s->grid->sy; y++) {
|
||||
n = snprintf(buf + last, len - last, "%.4d \"", y);
|
||||
if (n <= 0 || (u_int)n >= len - last)
|
||||
goto out;
|
||||
last += n;
|
||||
|
||||
gl = &s->grid->linedata[y];
|
||||
for (x = 0; x < gl->cellused; x++) {
|
||||
gce = &gl->celldata[x];
|
||||
if (gce->flags & GRID_FLAG_PADDING)
|
||||
continue;
|
||||
|
||||
if (~gce->flags & GRID_FLAG_EXTENDED) {
|
||||
if (last + 2 >= len)
|
||||
goto out;
|
||||
buf[last++] = gce->data.data;
|
||||
} else if (gce->flags & GRID_FLAG_TAB) {
|
||||
if (last + 2 >= len)
|
||||
goto out;
|
||||
buf[last++] = '\t';
|
||||
} else if (gce->flags & GRID_ATTR_CHARSET) {
|
||||
acs = tty_acs_get(NULL, gce->data.data);
|
||||
if (acs != NULL)
|
||||
n = strlen(acs);
|
||||
else {
|
||||
acs = &gce->data.data;
|
||||
n = 1;
|
||||
}
|
||||
if (last + n + 1 >= len)
|
||||
goto out;
|
||||
memcpy(buf + last, acs, n);
|
||||
last += n;
|
||||
} else {
|
||||
utf8_to_data(gl->extddata[gce->offset].data,
|
||||
&ud);
|
||||
if (ud.size > 0) {
|
||||
if (last + ud.size + 1 >= len)
|
||||
goto out;
|
||||
memcpy(buf + last, ud.data, ud.size);
|
||||
last += ud.size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (last + 3 >= len)
|
||||
goto out;
|
||||
buf[last++] = '"';
|
||||
buf[last++] = '\n';
|
||||
}
|
||||
|
||||
out:
|
||||
buf[last] = '\0';
|
||||
return (buf);
|
||||
}
|
||||
|
||||
1
tmux.h
1
tmux.h
@@ -3176,6 +3176,7 @@ void screen_select_cell(struct screen *, struct grid_cell *,
|
||||
void screen_alternate_on(struct screen *, struct grid_cell *, int);
|
||||
void screen_alternate_off(struct screen *, struct grid_cell *, int);
|
||||
const char *screen_mode_to_string(int);
|
||||
const char *screen_print(struct screen *);
|
||||
|
||||
/* window.c */
|
||||
extern struct windows windows;
|
||||
|
||||
Reference in New Issue
Block a user