mirror of https://github.com/tmux/tmux.git
Better text placeholder.
parent
312d83252c
commit
ad98233066
37
image.c
37
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);
|
||||
|
|
Loading…
Reference in New Issue