aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-06-06 11:59:46 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-06-06 11:59:46 +0000
commit21e90314200b558412e38fb913b8f7471baf7139 (patch)
treea437b2926e0f7dc2c25e82549f288e1e57fd1b47
parentsixel: fix asan runtime warning: left shift of 255 by 24 cannot... (diff)
sixel: don't erase image when printing text *next* to it.
-rw-r--r--CHANGELOG.md1
-rw-r--r--sixel.c23
-rw-r--r--terminal.h1
3 files changed, 20 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 922ccfff..ef18f4d4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -52,6 +52,7 @@
`0x0` terminal size (https://codeberg.org/dnkl/foot/issues/20).
* Glyphs overflowing into surrounding cells
(https://codeberg.org/dnkl/foot/issues/21).
+* Sixel images being erased when printing text next to them.
### Security
diff --git a/sixel.c b/sixel.c
index afac727b..476bf188 100644
--- a/sixel.c
+++ b/sixel.c
@@ -1,6 +1,7 @@
#include "sixel.h"
#include <string.h>
+#include <limits.h>
#define LOG_MODULE "sixel"
#define LOG_ENABLE_DBG 0
@@ -69,8 +70,8 @@ sixel_erase(struct terminal *term, struct sixel *sixel)
sixel_destroy(sixel);
}
-void
-sixel_delete_at_row(struct terminal *term, int _row)
+static void
+sixel_delete_at_point(struct terminal *term, int _row, int col)
{
if (likely(tll_length(term->grid->sixel_images) == 0))
return;
@@ -83,13 +84,23 @@ sixel_delete_at_row(struct terminal *term, int _row)
const int six_end = six_start + six->rows - 1;
if (row >= six_start && row <= six_end) {
- sixel_erase(term, six);
- tll_remove(term->grid->sixel_images, it);
+ const int col_end = six->pos.col + six->cols;
+
+ if (col < col_end) {
+ sixel_erase(term, six);
+ tll_remove(term->grid->sixel_images, it);
+ }
}
}
}
void
+sixel_delete_at_row(struct terminal *term, int _row)
+{
+ sixel_delete_at_point(term, _row, INT_MAX);
+}
+
+void
sixel_delete_in_range(struct terminal *term, int _start, int _end)
{
assert(_end >= _start);
@@ -121,7 +132,8 @@ sixel_delete_in_range(struct terminal *term, int _start, int _end)
void
sixel_delete_at_cursor(struct terminal *term)
{
- sixel_delete_at_row(term, term->grid->cursor.point.row);
+ sixel_delete_at_point(
+ term, term->grid->cursor.point.row, term->grid->cursor.point.col);
}
void
@@ -137,6 +149,7 @@ sixel_unhook(struct terminal *term)
.width = term->sixel.image.width,
.height = term->sixel.image.height,
.rows = (term->sixel.image.height + term->cell_height - 1) / term->cell_height,
+ .cols = (term->sixel.image.width + term->cell_width - 1) / term->cell_width,
.pos = (struct coord){
term->grid->cursor.point.col,
(term->grid->offset + term->grid->cursor.point.row) & (term->grid->num_rows - 1)},
diff --git a/terminal.h b/terminal.h
index 295db8e8..eecebbf6 100644
--- a/terminal.h
+++ b/terminal.h
@@ -96,6 +96,7 @@ struct sixel {
int width;
int height;
int rows;
+ int cols;
struct coord pos;
};