summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2019-11-30 09:17:18 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2019-11-30 09:17:18 +0000
commitb1904c9b8db514133d3372aac13b2ff0b2093cc3 (patch)
treea093a5353f2431b35550c7fde258fa7547f754e6
parent5d8dbcdf3d76d0e69b8f2d21eff48f819dcec199 (diff)
Store SIXELs as a box for the moment.
-rw-r--r--screen-write.c16
-rw-r--r--sixel.c34
-rw-r--r--tmux.h1
-rw-r--r--tty.c6
4 files changed, 55 insertions, 2 deletions
diff --git a/screen-write.c b/screen-write.c
index 5047bb72..441487d5 100644
--- a/screen-write.c
+++ b/screen-write.c
@@ -1676,7 +1676,21 @@ screen_write_rawstring(struct screen_write_ctx *ctx, u_char *str, u_int len)
void
screen_write_sixelimage(struct screen_write_ctx *ctx, struct sixel_image *si)
{
- struct tty_ctx ttyctx;
+ struct tty_ctx ttyctx;
+ struct screen *s = ctx->s, *image;
+ u_int sx = screen_size_x(s), sy = screen_size_y(s);
+
+ image = sixel_to_screen(si);
+ if (image == NULL)
+ return;
+
+ sx = sx - s->cx;
+ if (sx > screen_size_x(image))
+ sx = screen_size_x(image);
+ sy = sy - s->cx;
+ if (sy > screen_size_x(image))
+ sy = screen_size_x(image);
+ screen_write_fast_copy(ctx, image, 0, 0, sx, sy);
screen_write_initctx(ctx, &ttyctx);
ttyctx.ptr = si;
diff --git a/sixel.c b/sixel.c
index 1246ec43..3d544b83 100644
--- a/sixel.c
+++ b/sixel.c
@@ -517,3 +517,37 @@ sixel_print(struct sixel_image *si, struct sixel_image *map, size_t *size)
free(contains);
return (buf);
}
+
+struct screen *
+sixel_to_screen(struct sixel_image *si)
+{
+ struct screen *s;
+ struct screen_write_ctx ctx;
+ struct grid_cell gc;
+ u_int x, y, sx, sy;
+
+ sixel_size_in_cells(si, &sx, &sy);
+
+ s = xmalloc(sizeof *s);
+ screen_init(s, sx, sy, 0);
+
+ memcpy(&gc, &grid_default_cell, sizeof gc);
+ gc.attr |= (GRID_ATTR_CHARSET|GRID_ATTR_DIM);
+ utf8_set(&gc.data, '~');
+
+ screen_write_start(&ctx, NULL, s);
+ if (sx == 1 || sy == 1) {
+ for (y = 0; y < sy; y++) {
+ for (x = 0; x < sx; x++)
+ grid_view_set_cell(s->grid, x, y, &gc);
+ }
+ } else {
+ screen_write_box(&ctx, sx, sy);
+ for (y = 1; y < sy - 1; y++) {
+ for (x = 1; x < sx - 1; x++)
+ grid_view_set_cell(s->grid, x, y, &gc);
+ }
+ }
+ screen_write_stop(&ctx);
+ return (s);
+}
diff --git a/tmux.h b/tmux.h
index 35427c39..ae1ccbbd 100644
--- a/tmux.h
+++ b/tmux.h
@@ -2714,5 +2714,6 @@ struct sixel_image *sixel_scale(struct sixel_image *, u_int, u_int, u_int,
u_int, u_int, u_int);
char *sixel_print(struct sixel_image *, struct sixel_image *,
size_t *);
+struct screen *sixel_to_screen(struct sixel_image *);
#endif /* TMUX_H */
diff --git a/tty.c b/tty.c
index 0f99ebd5..b52e91f3 100644
--- a/tty.c
+++ b/tty.c
@@ -1884,8 +1884,10 @@ tty_cmd_sixelimage(struct tty *tty, const struct tty_ctx *ctx)
u_int cx = s->cx, cy = s->cy, sx, sy;
u_int i, j, x, y, rx, ry;
- if ((~flags & TERM_SIXEL) && tty_term_has(tty->term, TTYC_SXL))
+ if ((~flags & TERM_SIXEL) && !tty_term_has(tty->term, TTYC_SXL)) {
+ wp->flags |= PANE_REDRAW;
return;
+ }
if (tty->xpixel == 0 || tty->ypixel == 0)
return;
@@ -1906,6 +1908,8 @@ tty_cmd_sixelimage(struct tty *tty, const struct tty_ctx *ctx)
data = sixel_print(new, si, &size);
if (data != NULL) {
log_debug("%s: %zu bytes: %s", __func__, size, data);
+ tty_region_off(tty);
+ tty_margin_off(tty);
tty_cursor(tty, x, y);
tty->flags |= TTY_NOBLOCK;