Handle iTerm2 images more efficiently
This commit is contained in:
@@ -2013,7 +2013,7 @@ base64_encode(const unsigned char *src, size_t len)
|
|||||||
{
|
{
|
||||||
unsigned char *w, *at;
|
unsigned char *w, *at;
|
||||||
const unsigned char *in, *endw;
|
const unsigned char *in, *endw;
|
||||||
int j;
|
unsigned long j;
|
||||||
size_t k;
|
size_t k;
|
||||||
|
|
||||||
k = len;
|
k = len;
|
||||||
@@ -2024,7 +2024,9 @@ base64_encode(const unsigned char *src, size_t len)
|
|||||||
if (k + 1 < len)
|
if (k + 1 < len)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
w = GC_MALLOC_ATOMIC_IGNORE_OFF_PAGE(k + 1);
|
w = GC_MALLOC_ATOMIC(k + 1);
|
||||||
|
if (!w)
|
||||||
|
return NULL;
|
||||||
w[k] = 0;
|
w[k] = 0;
|
||||||
|
|
||||||
at = w;
|
at = w;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/time.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
|
void
|
||||||
put_image_iterm2(char *url, int x, int y, int w, int h)
|
put_image_iterm2(char *url, int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
Str buf, filecontent;
|
Str buf;
|
||||||
const char *base64;
|
char *base64, *cbuf;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
int c, i;
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
if (stat(url, &st))
|
||||||
|
return;
|
||||||
|
|
||||||
fp = fopen(url, "r");
|
fp = fopen(url, "r");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
return;
|
return;
|
||||||
filecontent = Strfgetall(fp);
|
|
||||||
|
|
||||||
base64 = base64_encode(filecontent->ptr, filecontent->length);
|
|
||||||
if (!base64)
|
|
||||||
return;
|
|
||||||
|
|
||||||
MOVE(y,x);
|
|
||||||
buf = Sprintf("\x1b]1337;"
|
buf = Sprintf("\x1b]1337;"
|
||||||
"File="
|
"File="
|
||||||
"name=%s;"
|
"name=%s;"
|
||||||
@@ -511,8 +511,39 @@ put_image_iterm2(char *url, int x, int y, int w, int h)
|
|||||||
"height=%d;"
|
"height=%d;"
|
||||||
"preserveAspectRatio=0;"
|
"preserveAspectRatio=0;"
|
||||||
"inline=1"
|
"inline=1"
|
||||||
":%s\a", url, filecontent->length, w, h, base64);
|
":", url, st.st_size, w, h);
|
||||||
|
|
||||||
|
MOVE(y,x);
|
||||||
|
|
||||||
writestr(buf->ptr);
|
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);
|
MOVE(Currentbuf->cursorY,Currentbuf->cursorX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user