diff options
author | bptato <nincsnevem662@gmail.com> | 2021-02-18 16:23:42 +0000 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2021-02-18 16:23:42 +0000 |
commit | de26f6156c2511df39981e2269672294e585ef8a (patch) | |
tree | da65af0e6e59afc9f0d6177df2e4ba519071e0c6 /terms.c | |
parent | Update ChangeLog (diff) | |
download | w3m-de26f6156c2511df39981e2269672294e585ef8a.tar.gz w3m-de26f6156c2511df39981e2269672294e585ef8a.zip |
Handle iTerm2 images more efficiently
Diffstat (limited to '')
-rw-r--r-- | terms.c | 49 |
1 files changed, 40 insertions, 9 deletions
@@ -6,6 +6,7 @@ #include <stdio.h> #include <signal.h> #include <sys/types.h> +#include <sys/stat.h> #include <fcntl.h> #include <errno.h> #include <sys/time.h> @@ -489,20 +490,19 @@ put_image_osc5379(char *url, int x, int y, int w, int h, int sx, int sy, int sw, void put_image_iterm2(char *url, int x, int y, int w, int h) { - Str buf, filecontent; - const char *base64; + Str buf; + char *base64, *cbuf; FILE *fp; + int c, i; + struct stat st; - fp = fopen(url, "r"); - if (!fp) + if (stat(url, &st)) return; - filecontent = Strfgetall(fp); - base64 = base64_encode(filecontent->ptr, filecontent->length); - if (!base64) + fp = fopen(url, "r"); + if (!fp) return; - MOVE(y,x); buf = Sprintf("\x1b]1337;" "File=" "name=%s;" @@ -511,8 +511,39 @@ put_image_iterm2(char *url, int x, int y, int w, int h) "height=%d;" "preserveAspectRatio=0;" "inline=1" - ":%s\a", url, filecontent->length, w, h, base64); + ":", url, st.st_size, w, h); + + MOVE(y,x); + writestr(buf->ptr); + + cbuf = GC_MALLOC_ATOMIC(3072); + i = 0; + while ((c = fgetc(fp)) != EOF) { + cbuf[i] = c; + Strcat_char(buf, c); + ++i; + if (i == 3072) { + base64 = base64_encode(cbuf, i); + if (!base64) { + writestr("\a"); + return; + } + writestr(base64); + i = 0; + } + } + + if (i) { + base64 = base64_encode(cbuf, i); + if (!base64) { + writestr("\a"); + return; + } + writestr(base64); + } + + writestr("\a"); MOVE(Currentbuf->cursorY,Currentbuf->cursorX); } |