From e4570e8b6e17382e1cc4984684f861524d5b02f4 Mon Sep 17 00:00:00 2001 From: bptato Date: Tue, 2 Feb 2021 22:14:46 +0100 Subject: Support iTerm2 graphics protocol, replace encodeB with base64_encode --- terms.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'terms.c') diff --git a/terms.c b/terms.c index a636ac0..966006a 100644 --- a/terms.c +++ b/terms.c @@ -469,7 +469,7 @@ writestr(char *s) #ifdef USE_IMAGE void -put_image_osc5379(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh, int n_terminal_image) +put_image_osc5379(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh) { Str buf; char *size ; @@ -485,6 +485,37 @@ put_image_osc5379(char *url, int x, int y, int w, int h, int sx, int sy, int sw, MOVE(Currentbuf->cursorY,Currentbuf->cursorX); } + +void +put_image_iterm2(char *url, int x, int y, int w, int h) +{ + Str buf, filecontent; + const char *base64; + FILE *fp; + + fp = fopen(url, "r"); + if (!fp) + return; + filecontent = Strfgetall(fp); + + base64 = base64_encode(filecontent->ptr, filecontent->length); + if (!base64) + return; + + MOVE(y,x); + buf = Sprintf("\x1b]1337;" + "File=" + "name=%s;" + "size=%d;" + "width=%d;" + "height=%d;" + "preserveAspectRatio=0;" + "inline=1" + ":%s\a", url, filecontent->length, w, h, base64); + writestr(buf->ptr); + MOVE(Currentbuf->cursorY,Currentbuf->cursorX); +} + static void save_gif(const char *path, u_char *header, size_t header_size, u_char *body, size_t body_size) { -- cgit v1.2.3