summaryrefslogtreecommitdiffstats
path: root/screen-write.c
diff options
context:
space:
mode:
Diffstat (limited to 'screen-write.c')
-rw-r--r--screen-write.c156
1 files changed, 153 insertions, 3 deletions
diff --git a/screen-write.c b/screen-write.c
index ee3a31a1..d51f4c4d 100644
--- a/screen-write.c
+++ b/screen-write.c
@@ -1011,6 +1011,11 @@ screen_write_alignmenttest(struct screen_write_ctx *ctx)
memcpy(&gc, &grid_default_cell, sizeof gc);
utf8_set(&gc.data, 'E');
+#ifdef ENABLE_SIXEL
+ if (image_free_all(s) && ctx->wp != NULL)
+ ctx->wp->flags |= PANE_REDRAW;
+#endif
+
for (yy = 0; yy < screen_size_y(s); yy++) {
for (xx = 0; xx < screen_size_x(s); xx++)
grid_view_set_cell(s->grid, xx, yy, &gc);
@@ -1045,6 +1050,11 @@ screen_write_insertcharacter(struct screen_write_ctx *ctx, u_int nx, u_int bg)
if (s->cx > screen_size_x(s) - 1)
return;
+#ifdef ENABLE_SIXEL
+ if (image_check_line(s, s->cy, 1) && ctx->wp != NULL)
+ ctx->wp->flags |= PANE_REDRAW;
+#endif
+
screen_write_initctx(ctx, &ttyctx, 0);
ttyctx.bg = bg;
@@ -1073,6 +1083,11 @@ screen_write_deletecharacter(struct screen_write_ctx *ctx, u_int nx, u_int bg)
if (s->cx > screen_size_x(s) - 1)
return;
+#ifdef ENABLE_SIXEL
+ if (image_check_line(s, s->cy, 1) && ctx->wp != NULL)
+ ctx->wp->flags |= PANE_REDRAW;
+#endif
+
screen_write_initctx(ctx, &ttyctx, 0);
ttyctx.bg = bg;
@@ -1101,6 +1116,11 @@ screen_write_clearcharacter(struct screen_write_ctx *ctx, u_int nx, u_int bg)
if (s->cx > screen_size_x(s) - 1)
return;
+#ifdef ENABLE_SIXEL
+ if (image_check_line(s, s->cy, 1) && ctx->wp != NULL)
+ ctx->wp->flags |= PANE_REDRAW;
+#endif
+
screen_write_initctx(ctx, &ttyctx, 0);
ttyctx.bg = bg;
@@ -1119,9 +1139,18 @@ screen_write_insertline(struct screen_write_ctx *ctx, u_int ny, u_int bg)
struct grid *gd = s->grid;
struct tty_ctx ttyctx;
+#ifdef ENABLE_SIXEL
+ u_int sy = screen_size_y(s);
+#endif
+
if (ny == 0)
ny = 1;
+#ifdef ENABLE_SIXEL
+ if (image_check_line(s, s->cy, sy - s->cy) && ctx->wp != NULL)
+ ctx->wp->flags |= PANE_REDRAW;
+#endif
+
if (s->cy < s->rupper || s->cy > s->rlower) {
if (ny > screen_size_y(s) - s->cy)
ny = screen_size_y(s) - s->cy;
@@ -1165,13 +1194,19 @@ screen_write_deleteline(struct screen_write_ctx *ctx, u_int ny, u_int bg)
struct screen *s = ctx->s;
struct grid *gd = s->grid;
struct tty_ctx ttyctx;
+ u_int sy = screen_size_y(s);
if (ny == 0)
ny = 1;
+#ifdef ENABLE_SIXEL
+ if (image_check_line(s, s->cy, sy - s->cy) && ctx->wp != NULL)
+ ctx->wp->flags |= PANE_REDRAW;
+#endif
+
if (s->cy < s->rupper || s->cy > s->rlower) {
- if (ny > screen_size_y(s) - s->cy)
- ny = screen_size_y(s) - s->cy;
+ if (ny > sy - s->cy)
+ ny = sy - s->cy;
if (ny == 0)
return;
@@ -1217,6 +1252,11 @@ screen_write_clearline(struct screen_write_ctx *ctx, u_int bg)
if (gl->cellsize == 0 && COLOUR_DEFAULT(bg))
return;
+#ifdef ENABLE_SIXEL
+ if (image_check_line(s, s->cy, 1) && ctx->wp != NULL)
+ ctx->wp->flags |= PANE_REDRAW;
+#endif
+
grid_view_clear(s->grid, 0, s->cy, sx, 1, bg);
screen_write_collect_clear(ctx, s->cy, 1);
@@ -1246,6 +1286,11 @@ screen_write_clearendofline(struct screen_write_ctx *ctx, u_int bg)
if (s->cx > sx - 1 || (s->cx >= gl->cellsize && COLOUR_DEFAULT(bg)))
return;
+#ifdef ENABLE_SIXEL
+ if (image_check_line(s, s->cy, 1) && ctx->wp != NULL)
+ ctx->wp->flags |= PANE_REDRAW;
+#endif
+
grid_view_clear(s->grid, s->cx, s->cy, sx - s->cx, 1, bg);
before = screen_write_collect_trim(ctx, s->cy, s->cx, sx - s->cx, NULL);
@@ -1273,6 +1318,11 @@ screen_write_clearstartofline(struct screen_write_ctx *ctx, u_int bg)
return;
}
+#ifdef ENABLE_SIXEL
+ if (image_check_line(s, s->cy, 1) && ctx->wp != NULL)
+ ctx->wp->flags |= PANE_REDRAW;
+#endif
+
if (s->cx > sx - 1)
grid_view_clear(s->grid, 0, s->cy, sx, 1, bg);
else
@@ -1320,6 +1370,11 @@ screen_write_reverseindex(struct screen_write_ctx *ctx, u_int bg)
struct screen *s = ctx->s;
struct tty_ctx ttyctx;
+#ifdef ENABLE_SIXEL
+ if (image_free_all(s) && ctx->wp != NULL)
+ ctx->wp->flags |= PANE_REDRAW;
+#endif
+
if (s->cy == s->rupper) {
grid_view_scroll_region_down(s->grid, s->rupper, s->rlower, bg);
screen_write_collect_flush(ctx, 0, __func__);
@@ -1363,13 +1418,15 @@ screen_write_linefeed(struct screen_write_ctx *ctx, int wrapped, u_int bg)
struct screen *s = ctx->s;
struct grid *gd = s->grid;
struct grid_line *gl;
+ int redraw = 0;
+ u_int rupper = s->rupper, rlower = s->rlower;
gl = grid_get_line(gd, gd->hsize + s->cy);
if (wrapped)
gl->flags |= GRID_LINE_WRAPPED;
log_debug("%s: at %u,%u (region %u-%u)", __func__, s->cx, s->cy,
- s->rupper, s->rlower);
+ rupper, rlower);
if (bg != ctx->bg) {
screen_write_collect_flush(ctx, 1, __func__);
@@ -1377,6 +1434,14 @@ screen_write_linefeed(struct screen_write_ctx *ctx, int wrapped, u_int bg)
}
if (s->cy == s->rlower) {
+#ifdef ENABLE_SIXEL
+ if (rlower == screen_size_y(s) - 1)
+ redraw = image_scroll_up(s, 1);
+ else
+ redraw = image_check_line(s, rupper, rlower - rupper);
+ if (redraw && ctx->wp != NULL)
+ ctx->wp->flags |= PANE_REDRAW;
+#endif
grid_view_scroll_region_up(gd, s->rupper, s->rlower, bg);
screen_write_collect_scroll(ctx, bg);
ctx->scrolled++;
@@ -1402,6 +1467,11 @@ screen_write_scrollup(struct screen_write_ctx *ctx, u_int lines, u_int bg)
ctx->bg = bg;
}
+#ifdef ENABLE_SIXEL
+ if (image_scroll_up(s, lines) && ctx->wp != NULL)
+ ctx->wp->flags |= PANE_REDRAW;
+#endif
+
for (i = 0; i < lines; i++) {
grid_view_scroll_region_up(gd, s->rupper, s->rlower, bg);
screen_write_collect_scroll(ctx, bg);
@@ -1426,6 +1496,11 @@ screen_write_scrolldown(struct screen_write_ctx *ctx, u_int lines, u_int bg)
else if (lines > s->rlower - s->rupper + 1)
lines = s->rlower - s->rupper + 1;
+#ifdef ENABLE_SIXEL
+ if (image_free_all(s) && ctx->wp != NULL)
+ ctx->wp->flags |= PANE_REDRAW;
+#endif
+
for (i = 0; i < lines; i++)
grid_view_scroll_region_down(gd, s->rupper, s->rlower, bg);
@@ -1450,6 +1525,11 @@ screen_write_clearendofscreen(struct screen_write_ctx *ctx, u_int bg)
struct tty_ctx ttyctx;
u_int sx = screen_size_x(s), sy = screen_size_y(s);
+#ifdef ENABLE_SIXEL
+ if (image_check_line(s, s->cy, sy - s->cy) && ctx->wp != NULL)
+ ctx->wp->flags |= PANE_REDRAW;
+#endif
+
screen_write_initctx(ctx, &ttyctx, 1);
ttyctx.bg = bg;
@@ -1479,6 +1559,11 @@ screen_write_clearstartofscreen(struct screen_write_ctx *ctx, u_int bg)
struct tty_ctx ttyctx;
u_int sx = screen_size_x(s);
+#ifdef ENABLE_SIXEL
+ if (image_check_line(s, 0, s->cy - 1) && ctx->wp != NULL)
+ ctx->wp->flags |= PANE_REDRAW;
+#endif
+
screen_write_initctx(ctx, &ttyctx, 1);
ttyctx.bg = bg;
@@ -1502,6 +1587,11 @@ screen_write_clearscreen(struct screen_write_ctx *ctx, u_int bg)
struct tty_ctx ttyctx;
u_int sx = screen_size_x(s), sy = screen_size_y(s);
+#ifdef ENABLE_SIXEL
+ if (image_free_all(s) && ctx->wp != NULL)
+ ctx->wp->flags |= PANE_REDRAW;
+#endif
+
screen_write_initctx(ctx, &ttyctx, 1);
ttyctx.bg = bg;
@@ -1770,6 +1860,11 @@ screen_write_collect_end(struct screen_write_ctx *ctx)
}
}
+#ifdef ENABLE_SIXEL
+ if (image_check_area(s, s->cx, s->cy, ci->used, 1) && ctx->wp != NULL)
+ ctx->wp->flags |= PANE_REDRAW;
+#endif
+
grid_view_set_cells(s->grid, s->cx, s->cy, &ci->gc, cl->data + ci->x,
ci->used);
screen_write_set_cursor(ctx, s->cx + ci->used, -1);
@@ -2157,6 +2252,61 @@ screen_write_rawstring(struct screen_write_ctx *ctx, u_char *str, u_int len,
tty_write(tty_cmd_rawstring, &ttyctx);
}
+#ifdef ENABLE_SIXEL
+/* Write a SIXEL image. */
+void
+screen_write_sixelimage(struct screen_write_ctx *ctx, struct sixel_image *si,
+ u_int bg)
+{
+ struct screen *s = ctx->s;
+ struct grid *gd = s->grid;
+ struct tty_ctx ttyctx;
+ u_int x, y, sx, sy, cx = s->cx, cy = s->cy, i, lines;
+ struct sixel_image *new;
+
+ sixel_size_in_cells(si, &x, &y);
+ if (x > screen_size_x(s) || y > screen_size_y(s)) {
+ if (x > screen_size_x(s) - cx)
+ sx = screen_size_x(s) - cx;
+ else
+ sx = x;
+ if (y > screen_size_y(s) - 1)
+ sy = screen_size_y(s) - 1;
+ else
+ sy = y;
+ new = sixel_scale(si, 0, 0, 0, y - sy, sx, sy, 1);
+ sixel_free(si);
+ si = new;
+ sixel_size_in_cells(si, &x, &y);
+ }
+
+ sy = screen_size_y(s) - cy;
+ if (sy < y) {
+ lines = y - sy + 1;
+ if (image_scroll_up(s, lines) && ctx->wp != NULL)
+ ctx->wp->flags |= PANE_REDRAW;
+ for (i = 0; i < lines; i++) {
+ grid_view_scroll_region_up(gd, 0, screen_size_y(s) - 1,
+ bg);
+ screen_write_collect_scroll(ctx, bg);
+ }
+ ctx->scrolled += lines;
+ if (lines > cy)
+ screen_write_cursormove(ctx, -1, 0, 0);
+ else
+ screen_write_cursormove(ctx, -1, cy - lines, 0);
+ }
+ screen_write_collect_flush(ctx, 0, __func__);
+
+ screen_write_initctx(ctx, &ttyctx, 0);
+ ttyctx.ptr = image_store(s, si);
+
+ tty_write(tty_cmd_sixelimage, &ttyctx);
+
+ screen_write_cursormove(ctx, 0, cy + y, 0);
+}
+#endif
+
/* Turn alternate screen on. */
void
screen_write_alternateon(struct screen_write_ctx *ctx, struct grid_cell *gc,