From da628ebd885da1ae921ab1b254cd3253a87ea396 Mon Sep 17 00:00:00 2001 From: bptato Date: Thu, 18 Feb 2021 20:27:48 +0100 Subject: Fix small images on kitty --- terms.c | 63 +++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 28 deletions(-) (limited to 'terms.c') diff --git a/terms.c b/terms.c index 45c5f86..3c42275 100644 --- a/terms.c +++ b/terms.c @@ -576,7 +576,6 @@ put_image_kitty(char *url, int x, int y, int w, int h, int sx, int sy, int sw, "w=%d,h=%d,c=%d,r=%d;", w, h, x, y, sx, sy, sw, sh, cols, rows); - writestr(buf->ptr); cbuf = GC_MALLOC_ATOMIC(3072); i = 0; @@ -591,36 +590,44 @@ put_image_kitty(char *url, int x, int y, int w, int h, int sx, int sy, int sw, if (!base64) return; - buf = Sprintf("%s\x1b\\", base64); + if (c == EOF) + buf = Sprintf("\x1b_Gf=100,s=%d,v=%d,a=T,m=0,X=%d,Y=%d,x=%d,y=%d," + "w=%d,h=%d,c=%d,r=%d;", + w, h, x, y, sx, sy, sw, sh, cols, rows); writestr(buf->ptr); - i = 0; - base64 = NULL; - while ((c = fgetc(fp)) != EOF) { - if (!i && base64) { - buf = Sprintf("\x1b_Gm=1;%s\x1b\\", base64); - writestr(buf->ptr); - } - cbuf[i] = c; - ++i; - if (i == 3072) { - base64 = base64_encode(cbuf, i); - if (!base64) - return; - - i = 0; - } - } - - if (i) { - base64 = base64_encode(cbuf, i); - if (!base64) - return; - } + buf = Sprintf("%s\x1b\\", base64); + writestr(buf->ptr); - if (base64) { - buf = Sprintf("\x1b_Gm=0;%s\x1b\\", base64); - writestr(buf->ptr); + if (c != EOF) { + i = 0; + base64 = NULL; + while ((c = fgetc(fp)) != EOF) { + if (!i && base64) { + buf = Sprintf("\x1b_Gm=1;%s\x1b\\", base64); + writestr(buf->ptr); + } + cbuf[i] = c; + ++i; + if (i == 3072) { + base64 = base64_encode(cbuf, i); + if (!base64) + return; + + i = 0; + } + } + + if (i) { + base64 = base64_encode(cbuf, i); + if (!base64) + return; + } + + if (base64) { + buf = Sprintf("\x1b_Gm=0;%s\x1b\\", base64); + writestr(buf->ptr); + } } MOVE(Currentbuf->cursorY, Currentbuf->cursorX); } -- cgit v1.2.3