summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortopcat001 <anindya49@hotmail.com>2023-08-15 13:57:08 -0700
committertopcat001 <anindya49@hotmail.com>2023-08-15 13:57:08 -0700
commitad98233066b72547aee7fa0c87838847ee7f1ece (patch)
tree54b161b5d64d531423a5f32f6b4236df907b28ed
parent312d83252c27fc4d09d09d121bf7573336e3cdca (diff)
Better text placeholder.
-rw-r--r--image.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/image.c b/image.c
index 7135c6a3..20ef104a 100644
--- a/image.c
+++ b/image.c
@@ -19,6 +19,7 @@
#include <sys/types.h>
#include <stdlib.h>
+#include <string.h>
#include "tmux.h"
@@ -50,6 +51,36 @@ image_free_all(struct screen *s)
return (redraw);
}
+/* Create text placeholder for an image. */
+static void
+image_fallback(char **ret, u_int sx, u_int sy)
+{
+ char *buf, *label;
+ u_int py, size, lsize;
+
+ /* Placeholder label. */
+ lsize = xasprintf(&label, "Sixel image (%ux%u)\n", sx, sy);
+ size = (sx + 2) * sy + 1;
+ if (lsize > size)
+ size = lsize;
+
+ /* Each placeholder line has \r\n at the end. */
+ *ret = buf = xmalloc(size);
+ for (py = 0; py < sy; py++) {
+ memset(buf, '+', sx);
+ buf += sx;
+ snprintf(buf, 3, "\r\n");
+ buf += 2;
+ }
+
+ /* Print the label.*/
+ if (size == lsize)
+ memcpy(*ret, label, lsize);
+ else
+ memcpy(*ret, label, lsize - 1);
+ free(label);
+}
+
struct image*
image_store(struct screen *s, struct sixel_image *si)
{
@@ -63,8 +94,7 @@ image_store(struct screen *s, struct sixel_image *si)
im->py = s->cy;
sixel_size_in_cells(si, &im->sx, &im->sy);
- /* XXX Fallback mode: This can be abstracted further. */
- xasprintf(&im->fallback, "Sixel image (%ux%u)\n", im->sx, im->sy);
+ image_fallback(&im->fallback, im->sx, im->sy);
TAILQ_INSERT_TAIL(&s->images, im, entry);
@@ -135,6 +165,9 @@ image_scroll_up(struct screen *s, u_int lines)
im->py = 0;
sixel_size_in_cells(im->data, &im->sx, &im->sy);
+
+ free(im->fallback);
+ image_fallback(&im->fallback, im->sx, im->sy);
redraw = 1;
}
return (redraw);