From f4268d8d18e57952b046c1bb6ab2aeeac145c310 Mon Sep 17 00:00:00 2001 From: Araki Ken Date: Tue, 29 Jan 2013 00:27:27 +0900 Subject: Support remote image by OSC 5379 show_picture sequence. --- terms.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'terms.c') diff --git a/terms.c b/terms.c index 672262c..30a67e3 100644 --- a/terms.c +++ b/terms.c @@ -466,6 +466,56 @@ writestr(char *s) #define MOVE(line,column) writestr(tgoto(T_cm,column,line)); +void +put_image(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh) +{ + Str buf; + char *size ; + + if (w > 0 && h > 0) + size = Sprintf("%dx%d",w,h)->ptr; + else + size = ""; + + MOVE(y,x); + buf = Sprintf("\x1b]5379;show_picture %s %s %dx%d+%d+%d\x07",url,size,sw,sh,sx,sy); + writestr(buf->ptr); + MOVE(Currentbuf->cursorY,Currentbuf->cursorX); +} + +int +get_pixel_per_cell(int *ppc, int *ppl) +{ + fd_set rfd; + struct timeval tval; + char buf[100]; + ssize_t len; + int wp,hp,wc,hc; + + fputs("\x1b[14t\x1b[18t",ttyf); flush_tty(); + + tval.tv_usec = 10000; /* 0.1 sec */ + tval.tv_sec = 0; + FD_SET(tty,&rfd); + if (select(tty+1,&rfd,NULL,NULL,&tval) < 0 || ! FD_ISSET(tty,&rfd)) { + return 0; + } + + if ((len = read(tty,buf,sizeof(buf)-1)) <= 0) { + return 0; + } + buf[len] = '\0'; + + if (sscanf(buf,"\x1b[4;%d;%dt\x1b[8;%d;%dt",&hp,&wp,&hc,&wc) != 4) { + return 0; + } + + *ppc = wp / wc; + *ppl = hp / hc; + + return 1; +} + #ifdef USE_MOUSE #define W3M_TERM_INFO(name, title, mouse) name, title, mouse #define NEED_XTERM_ON (1) -- cgit v1.2.3 From 147ef0048b9a50122e7865f36c97616b94ada76f Mon Sep 17 00:00:00 2001 From: Araki Ken Date: Sat, 2 Feb 2013 16:32:37 +0900 Subject: - Adjust the image size to the terminal cell size. - If the image size is specified in html source, skip to load the image. --- terms.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) (limited to 'terms.c') diff --git a/terms.c b/terms.c index 30a67e3..a915c0a 100644 --- a/terms.c +++ b/terms.c @@ -489,31 +489,40 @@ get_pixel_per_cell(int *ppc, int *ppl) fd_set rfd; struct timeval tval; char buf[100]; + char *p; ssize_t len; + ssize_t left; int wp,hp,wc,hc; + int i; fputs("\x1b[14t\x1b[18t",ttyf); flush_tty(); - tval.tv_usec = 10000; /* 0.1 sec */ - tval.tv_sec = 0; - FD_SET(tty,&rfd); - if (select(tty+1,&rfd,NULL,NULL,&tval) < 0 || ! FD_ISSET(tty,&rfd)) { - return 0; - } + p = buf; + left = sizeof(buf) - 1; + for (i = 0; i < 5; i++) { + tval.tv_usec = 100000; /* 0.1 sec */ + tval.tv_sec = 0; + FD_SET(tty,&rfd); + if (select(tty+1,&rfd,NULL,NULL,&tval) <= 0 || ! FD_ISSET(tty,&rfd)) { + continue; + } - if ((len = read(tty,buf,sizeof(buf)-1)) <= 0) { - return 0; - } - buf[len] = '\0'; + if ((len = read(tty,p,left)) <= 0) { + return 0; + } + p[len] = '\0'; - if (sscanf(buf,"\x1b[4;%d;%dt\x1b[8;%d;%dt",&hp,&wp,&hc,&wc) != 4) { - return 0; - } + if (sscanf(buf,"\x1b[4;%d;%dt\x1b[8;%d;%dt",&hp,&wp,&hc,&wc) == 4) { + *ppc = wp / wc; + *ppl = hp / hc; - *ppc = wp / wc; - *ppl = hp / hc; + return 1; + } + p = buf + len; + left -= len; + } - return 1; + return 0; } #ifdef USE_MOUSE -- cgit v1.2.3 From a95a17897125a4268864b6a67e4fdb79fa5439a3 Mon Sep 17 00:00:00 2001 From: Araki Ken Date: Mon, 11 Mar 2013 21:57:49 +0900 Subject: * terms.c: Change time to wait for the response of "\x1b[14t\x1b[18t" from 0.1 sec to 0.5 sec. * image.c: - clearImage() works. - Use cached image files created by w3m in getImage(). * file.c: Hack for alignment. --- terms.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'terms.c') diff --git a/terms.c b/terms.c index a915c0a..9d9b3e1 100644 --- a/terms.c +++ b/terms.c @@ -500,7 +500,7 @@ get_pixel_per_cell(int *ppc, int *ppl) p = buf; left = sizeof(buf) - 1; for (i = 0; i < 5; i++) { - tval.tv_usec = 100000; /* 0.1 sec */ + tval.tv_usec = 500000; /* 0.5 sec */ tval.tv_sec = 0; FD_SET(tty,&rfd); if (select(tty+1,&rfd,NULL,NULL,&tval) <= 0 || ! FD_ISSET(tty,&rfd)) { -- cgit v1.2.3 From f941b1d562cee6a08001e164a1e37d0a925e438b Mon Sep 17 00:00:00 2001 From: Araki Ken Date: Thu, 14 Mar 2013 05:18:13 +0900 Subject: * terms.c: Clear fd_set by FD_ZERO() before select(). --- terms.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'terms.c') diff --git a/terms.c b/terms.c index 9d9b3e1..6533712 100644 --- a/terms.c +++ b/terms.c @@ -499,17 +499,16 @@ get_pixel_per_cell(int *ppc, int *ppl) p = buf; left = sizeof(buf) - 1; - for (i = 0; i < 5; i++) { - tval.tv_usec = 500000; /* 0.5 sec */ + for (i = 0; i < 10; i++) { + tval.tv_usec = 200000; /* 0.2 sec * 10 */ tval.tv_sec = 0; + FD_ZERO(&rfd); FD_SET(tty,&rfd); - if (select(tty+1,&rfd,NULL,NULL,&tval) <= 0 || ! FD_ISSET(tty,&rfd)) { + if (select(tty+1,&rfd,NULL,NULL,&tval) <= 0 || ! FD_ISSET(tty,&rfd)) continue; - } - if ((len = read(tty,p,left)) <= 0) { - return 0; - } + if ((len = read(tty,p,left)) <= 0) + continue; p[len] = '\0'; if (sscanf(buf,"\x1b[4;%d;%dt\x1b[8;%d;%dt",&hp,&wp,&hc,&wc) == 4) { @@ -518,7 +517,7 @@ get_pixel_per_cell(int *ppc, int *ppl) return 1; } - p = buf + len; + p += len; left -= len; } -- cgit v1.2.3 From 2fe66f3a6f1b1fd28424a2f14beebdd535e9d17b Mon Sep 17 00:00:00 2001 From: Araki Ken Date: Mon, 22 Sep 2014 20:16:39 +0900 Subject: Add -sixel option which supports image processing by img2sixel. --- terms.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'terms.c') diff --git a/terms.c b/terms.c index 6533712..53d604c 100644 --- a/terms.c +++ b/terms.c @@ -467,7 +467,7 @@ writestr(char *s) #define MOVE(line,column) writestr(tgoto(T_cm,column,line)); void -put_image(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh) +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 ; @@ -483,6 +483,22 @@ put_image(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh) MOVE(Currentbuf->cursorY,Currentbuf->cursorX); } +void +put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh) +{ + Str buf; + + MOVE(y,x); + flush_tty(); + buf = Sprintf("img2sixel -l disable -c %dx%d+%d+%d -w %d -h %d %s 2>/dev/null", + sw*pixel_per_char_i, sh*pixel_per_line_i, + sx*pixel_per_char_i, sy*pixel_per_line_i, + w*pixel_per_char_i, h*pixel_per_line_i, + url); + system(buf->ptr); + MOVE(Currentbuf->cursorY,Currentbuf->cursorX); +} + int get_pixel_per_cell(int *ppc, int *ppl) { -- cgit v1.2.3 From e8b2d473586c23c82c7d6fd65d29fba9e11d883a Mon Sep 17 00:00:00 2001 From: Araki Ken Date: Wed, 24 Sep 2014 20:09:18 +0900 Subject: system() -> fork()&execvp() --- terms.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'terms.c') diff --git a/terms.c b/terms.c index 53d604c..66d0ff8 100644 --- a/terms.c +++ b/terms.c @@ -12,6 +12,7 @@ #include #include "config.h" #include +#include #ifdef HAVE_SYS_SELECT_H #include #endif @@ -486,16 +487,40 @@ put_image_osc5379(char *url, int x, int y, int w, int h, int sx, int sy, int sw, void put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh) { - Str buf; + pid_t pid; MOVE(y,x); flush_tty(); - buf = Sprintf("img2sixel -l disable -c %dx%d+%d+%d -w %d -h %d %s 2>/dev/null", - sw*pixel_per_char_i, sh*pixel_per_line_i, - sx*pixel_per_char_i, sy*pixel_per_line_i, - w*pixel_per_char_i, h*pixel_per_line_i, - url); - system(buf->ptr); + + if ((pid = fork()) == 0) { + char *argv[11]; + char digit[2][11+1]; + char clip[44+3+1]; + + close(STDERR_FILENO); + argv[0] = "img2sixel"; + argv[1] = "-l"; + argv[2] = "disable"; + argv[3] = "-w"; + sprintf(digit[0], "%d", w*pixel_per_char_i); + argv[4] = digit[0]; + argv[5] = "-h"; + sprintf(digit[1], "%d", h*pixel_per_line_i); + argv[6] = digit[1]; + argv[7] = "-c"; + sprintf(clip, "%dx%d+%d+%d", sw*pixel_per_char_i, sh*pixel_per_line_i, + sx*pixel_per_char_i, sy*pixel_per_line_i); + argv[8] = clip; + argv[9] = url; + argv[10] = NULL; + execvp(argv[0],argv); + exit(0); + } + else if (pid > 0) { + int status; + waitpid(pid, &status, 0); + } + MOVE(Currentbuf->cursorY,Currentbuf->cursorX); } -- cgit v1.2.3 From 4a9c976e32a6bab9dbac4380803e5eb92f601284 Mon Sep 17 00:00:00 2001 From: Araki Ken Date: Thu, 25 Sep 2014 23:21:41 +0900 Subject: Show the first frame of animation gif files. --- terms.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) (limited to 'terms.c') diff --git a/terms.c b/terms.c index 66d0ff8..5f0e638 100644 --- a/terms.c +++ b/terms.c @@ -484,6 +484,89 @@ put_image_osc5379(char *url, int x, int y, int w, int h, int sx, int sy, int sw, 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) +{ + int fd; + + if ((fd = open(path, O_WRONLY|O_CREAT, 0600)) >= 0) { + write(fd, header, header_size) ; + write(fd, body, body_size) ; + write(fd, "\x3b" , 1) ; + close(fd) ; + } +} + +static u_char * +skip_gif_header(u_char *p) +{ + /* Header */ + p += 10; + + if (*(p) & 0x80) { + p += (3 * (2 << ((*p) & 0x7))); + } + p += 3; + + return p; +} + +static void +save_first_animation_frame(const char *path) +{ + int fd; + struct stat st; + u_char *header; + size_t header_size; + u_char *body; + u_char *p; + ssize_t len; + + if ((fd = open( path, O_RDONLY)) < 0) { + return 0; + } + + if (fstat( fd, &st) != 0 || ! (header = GC_malloc( st.st_size))){ + close( fd); + return 0; + } + + len = read(fd, header, st.st_size); + close(fd); + + /* Header */ + + if (len != st.st_size || strncmp(header, "GIF89a", 6) != 0) { + return 0; + } + + p = skip_gif_header(header); + header_size = p - header; + + /* Application Extension */ + if (p[0] == 0x21 && p[1] == 0xff) { + p += 19; + } + + /* Other blocks */ + body = NULL; + while (p + 2 < header + st.st_size) { + if (*(p++) == 0x21 && *(p++) == 0xf9 && *(p++) == 0x04) { + if( body) { + /* Graphic Control Extension */ + save_gif(path, header, header_size, body, p - 3 - body); + break; + } + else { + /* skip the first frame. */ + } + body = p - 3; + } + } + + return 1; +} + void put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh) { @@ -492,6 +575,10 @@ put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, i MOVE(y,x); flush_tty(); + if (!strstr(url, "://")) { + save_first_animation_frame(url); + } + if ((pid = fork()) == 0) { char *argv[11]; char digit[2][11+1]; -- cgit v1.2.3 From 4459dbe26e18850c43d78974ba4aeb50258fa028 Mon Sep 17 00:00:00 2001 From: Araki Ken Date: Sat, 27 Sep 2014 21:25:42 +0900 Subject: img2sixel exits by Ctrl+C. Enable GIF Animation if 'I' is pressed to show it. --- terms.c | 54 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 11 deletions(-) (limited to 'terms.c') diff --git a/terms.c b/terms.c index 5f0e638..dc00764 100644 --- a/terms.c +++ b/terms.c @@ -511,7 +511,7 @@ skip_gif_header(u_char *p) return p; } -static void +static Str save_first_animation_frame(const char *path) { int fd; @@ -521,14 +521,21 @@ save_first_animation_frame(const char *path) u_char *body; u_char *p; ssize_t len; + Str new_path; + + new_path = Strnew_charp(path); + Strcat_charp(new_path, "-1"); + if (stat(new_path->ptr, &st) == 0) { + return new_path; + } if ((fd = open( path, O_RDONLY)) < 0) { - return 0; + return NULL; } if (fstat( fd, &st) != 0 || ! (header = GC_malloc( st.st_size))){ close( fd); - return 0; + return NULL; } len = read(fd, header, st.st_size); @@ -537,7 +544,7 @@ save_first_animation_frame(const char *path) /* Header */ if (len != st.st_size || strncmp(header, "GIF89a", 6) != 0) { - return 0; + return NULL; } p = skip_gif_header(header); @@ -554,7 +561,7 @@ save_first_animation_frame(const char *path) if (*(p++) == 0x21 && *(p++) == 0xf9 && *(p++) == 0x04) { if( body) { /* Graphic Control Extension */ - save_gif(path, header, header_size, body, p - 3 - body); + save_gif(new_path->ptr, header, header_size, body, p - 3 - body); break; } else { @@ -564,30 +571,48 @@ save_first_animation_frame(const char *path) } } - return 1; + return new_path; } +void ttymode_set(int mode, int imode); + void put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh) { pid_t pid; + int do_anim; + MySignalHandler(*volatile previntr) (SIGNAL_ARG); + MySignalHandler(*volatile prevquit) (SIGNAL_ARG); + MySignalHandler(*volatile prevstop) (SIGNAL_ARG); MOVE(y,x); flush_tty(); - if (!strstr(url, "://")) { - save_first_animation_frame(url); - } + do_anim = (x == 0 && y == 0 && sx == 0 && sy == 0) ; + + previntr = mySignal(SIGINT, SIG_IGN); + prevquit = mySignal(SIGQUIT, SIG_IGN); + prevstop = mySignal(SIGTSTP, SIG_IGN); if ((pid = fork()) == 0) { char *argv[11]; char digit[2][11+1]; char clip[44+3+1]; + Str str_url; + + close(STDERR_FILENO); /* Don't output error message. */ + if (do_anim) { + writestr("\x1b[?80h"); + } + else if (!strstr(url, "://") && strcmp(url+strlen(url)-4, ".gif") == 0 && + (str_url = save_first_animation_frame(url))) { + url = str_url->ptr; + } + ttymode_set(ISIG, 1); - close(STDERR_FILENO); argv[0] = "img2sixel"; argv[1] = "-l"; - argv[2] = "disable"; + argv[2] = do_anim ? "auto" : "disable"; argv[3] = "-w"; sprintf(digit[0], "%d", w*pixel_per_char_i); argv[4] = digit[0]; @@ -606,6 +631,13 @@ put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, i else if (pid > 0) { int status; waitpid(pid, &status, 0); + ttymode_set(ISIG, 0); + mySignal(SIGINT, previntr); + mySignal(SIGQUIT, prevquit); + mySignal(SIGTSTP, prevstop); + if (do_anim) { + writestr("\x1b[?80l"); + } } MOVE(Currentbuf->cursorY,Currentbuf->cursorX); -- cgit v1.2.3 From 0c25fd96f7d077e14eac2f8579b7d5c3abfc8f78 Mon Sep 17 00:00:00 2001 From: Araki Ken Date: Sat, 27 Sep 2014 21:36:12 +0900 Subject: Show GIF (except animation GIF) correctly. --- terms.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'terms.c') diff --git a/terms.c b/terms.c index dc00764..50114db 100644 --- a/terms.c +++ b/terms.c @@ -562,7 +562,7 @@ save_first_animation_frame(const char *path) if( body) { /* Graphic Control Extension */ save_gif(new_path->ptr, header, header_size, body, p - 3 - body); - break; + return new_path; } else { /* skip the first frame. */ @@ -571,7 +571,7 @@ save_first_animation_frame(const char *path) } } - return new_path; + return NULL; } void ttymode_set(int mode, int imode); -- cgit v1.2.3 From 3f3906151bfb2b6138a6950c2ea2c2f0aee03ad6 Mon Sep 17 00:00:00 2001 From: Araki Ken Date: Sun, 28 Sep 2014 15:09:09 +0900 Subject: Support GNU screen. --- terms.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'terms.c') diff --git a/terms.c b/terms.c index 50114db..1ce9e2f 100644 --- a/terms.c +++ b/terms.c @@ -595,7 +595,7 @@ put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, i prevstop = mySignal(SIGTSTP, SIG_IGN); if ((pid = fork()) == 0) { - char *argv[11]; + char *argv[12]; char digit[2][11+1]; char clip[44+3+1]; Str str_url; @@ -610,6 +610,7 @@ put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, i } ttymode_set(ISIG, 1); + argv[0] = "img2sixel"; argv[1] = "-l"; argv[2] = do_anim ? "auto" : "disable"; @@ -624,7 +625,13 @@ put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, i sx*pixel_per_char_i, sy*pixel_per_line_i); argv[8] = clip; argv[9] = url; - argv[10] = NULL; + if (getenv("TERM") && strcmp(getenv("TERM"), "screen")) { + argv[10] = "-P"; + argv[11] = NULL; + } + else { + argv[10] = NULL; + } execvp(argv[0],argv); exit(0); } -- cgit v1.2.3 From 78ae4478dfb943e64fcdc0cef15fe170557952d6 Mon Sep 17 00:00:00 2001 From: Araki Ken Date: Sun, 28 Sep 2014 15:36:50 +0900 Subject: Fix. --- terms.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'terms.c') diff --git a/terms.c b/terms.c index 1ce9e2f..7c88b20 100644 --- a/terms.c +++ b/terms.c @@ -625,7 +625,7 @@ put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, i sx*pixel_per_char_i, sy*pixel_per_line_i); argv[8] = clip; argv[9] = url; - if (getenv("TERM") && strcmp(getenv("TERM"), "screen")) { + if (getenv("TERM") && strcmp(getenv("TERM"), "screen") == 0) { argv[10] = "-P"; argv[11] = NULL; } -- cgit v1.2.3 From df84882eb344b846c783dac9e160b014a6efb5c5 Mon Sep 17 00:00:00 2001 From: Araki Ken Date: Mon, 6 Oct 2014 07:27:36 +0900 Subject: ttymode_set() -> ttymode_reset(). --- terms.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'terms.c') diff --git a/terms.c b/terms.c index 7c88b20..1c90b58 100644 --- a/terms.c +++ b/terms.c @@ -575,6 +575,7 @@ save_first_animation_frame(const char *path) } void ttymode_set(int mode, int imode); +void ttymode_reset(int mode, int imode); void put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh) @@ -608,8 +609,7 @@ put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, i (str_url = save_first_animation_frame(url))) { url = str_url->ptr; } - ttymode_set(ISIG, 1); - + ttymode_set(ISIG, 0); argv[0] = "img2sixel"; argv[1] = "-l"; @@ -638,7 +638,7 @@ put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, i else if (pid > 0) { int status; waitpid(pid, &status, 0); - ttymode_set(ISIG, 0); + ttymode_reset(ISIG, 0); mySignal(SIGINT, previntr); mySignal(SIGQUIT, prevquit); mySignal(SIGTSTP, prevstop); @@ -662,6 +662,20 @@ get_pixel_per_cell(int *ppc, int *ppl) int wp,hp,wc,hc; int i; + /* screen replaces ws.ws_col and ws.ws_row alone. */ +#if 0 +#ifdef TIOCGWINSZ + struct winsize ws; + if (ioctl(tty, TIOCGWINSZ, &ws) == 0 && ws.ws_ypixel > 0 && ws.ws_row > 0 && + ws.ws_xpixel > 0 && ws.ws_col > 0) { + *ppc = ws.ws_xpixel / ws.ws_col; + *ppl = ws.ws_ypixel / ws.ws_row; + + return 1; + } +#endif +#endif + fputs("\x1b[14t\x1b[18t",ttyf); flush_tty(); p = buf; -- cgit v1.2.3 From f64d6bb89909bf3c7062ec09ace369c89f24c28e Mon Sep 17 00:00:00 2001 From: Araki Ken Date: Sat, 11 Oct 2014 15:46:47 +0900 Subject: If SCREEN_VARIANT=sixel on GNU screen, exec img2sixel without -P option. --- terms.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'terms.c') diff --git a/terms.c b/terms.c index 1c90b58..1545157 100644 --- a/terms.c +++ b/terms.c @@ -625,7 +625,8 @@ put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, i sx*pixel_per_char_i, sy*pixel_per_line_i); argv[8] = clip; argv[9] = url; - if (getenv("TERM") && strcmp(getenv("TERM"), "screen") == 0) { + if (getenv("TERM") && strcmp(getenv("TERM"), "screen") == 0 && + (!getenv("SCREEN_VARIANT") || strcmp(getenv("SCREEN_VARIANT"), "sixel") != 0)) { argv[10] = "-P"; argv[11] = NULL; } -- cgit v1.2.3 From 982a8feab0928185053d83592ebe7fff28829b90 Mon Sep 17 00:00:00 2001 From: Araki Ken Date: Mon, 20 Oct 2014 22:36:37 +0900 Subject: * Add n_terminal_image argument to put_image_{sixel|osc5379}(). * Use struct winsize to calculate ppc and ppl. --- terms.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'terms.c') diff --git a/terms.c b/terms.c index 1545157..7028f3d 100644 --- a/terms.c +++ b/terms.c @@ -468,7 +468,7 @@ writestr(char *s) #define MOVE(line,column) writestr(tgoto(T_cm,column,line)); void -put_image_osc5379(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh) +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) { Str buf; char *size ; @@ -578,10 +578,10 @@ void ttymode_set(int mode, int imode); void ttymode_reset(int mode, int imode); void -put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh) +put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh, int n_terminal_image) { pid_t pid; - int do_anim; + int do_anim; MySignalHandler(*volatile previntr) (SIGNAL_ARG); MySignalHandler(*volatile prevquit) (SIGNAL_ARG); MySignalHandler(*volatile prevstop) (SIGNAL_ARG); @@ -589,7 +589,7 @@ put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, i MOVE(y,x); flush_tty(); - do_anim = (x == 0 && y == 0 && sx == 0 && sy == 0) ; + do_anim = (n_terminal_image == 1 && x == 0 && y == 0 && sx == 0 && sy == 0); previntr = mySignal(SIGINT, SIG_IGN); prevquit = mySignal(SIGQUIT, SIG_IGN); @@ -663,18 +663,14 @@ get_pixel_per_cell(int *ppc, int *ppl) int wp,hp,wc,hc; int i; - /* screen replaces ws.ws_col and ws.ws_row alone. */ -#if 0 #ifdef TIOCGWINSZ struct winsize ws; if (ioctl(tty, TIOCGWINSZ, &ws) == 0 && ws.ws_ypixel > 0 && ws.ws_row > 0 && ws.ws_xpixel > 0 && ws.ws_col > 0) { *ppc = ws.ws_xpixel / ws.ws_col; *ppl = ws.ws_ypixel / ws.ws_row; - return 1; } -#endif #endif fputs("\x1b[14t\x1b[18t",ttyf); flush_tty(); @@ -694,10 +690,14 @@ get_pixel_per_cell(int *ppc, int *ppl) p[len] = '\0'; if (sscanf(buf,"\x1b[4;%d;%dt\x1b[8;%d;%dt",&hp,&wp,&hc,&wc) == 4) { - *ppc = wp / wc; - *ppl = hp / hc; - - return 1; + if (wp > 0 && wc > 0 && hp > 0 && hc > 0) { + *ppc = wp / wc; + *ppl = hp / hc; + return 1; + } + else { + return 0; + } } p += len; left -= len; -- cgit v1.2.3 From 2e8def7ab6eb7ca9bb5160071a041cc25c919928 Mon Sep 17 00:00:00 2001 From: Araki Ken Date: Sun, 16 Nov 2014 04:07:05 +0900 Subject: Add README.sixel. W3M_IMG2SIXEL environmental variable enables to specify options of img2sixel. --- terms.c | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) (limited to 'terms.c') diff --git a/terms.c b/terms.c index 7028f3d..79996f1 100644 --- a/terms.c +++ b/terms.c @@ -596,7 +596,9 @@ put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, i prevstop = mySignal(SIGTSTP, SIG_IGN); if ((pid = fork()) == 0) { - char *argv[12]; + char *env; + int n = 0; + char *argv[20]; char digit[2][11+1]; char clip[44+3+1]; Str str_url; @@ -611,28 +613,41 @@ put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, i } ttymode_set(ISIG, 0); - argv[0] = "img2sixel"; - argv[1] = "-l"; - argv[2] = do_anim ? "auto" : "disable"; - argv[3] = "-w"; + if ((env = getenv("W3M_IMG2SIXEL"))) { + char *p; + env = Strnew_charp(env)->ptr; + while (n < 8 && (p = strchr(env, ' '))) { + *p = '\0'; + if (*env != '\0') { + argv[n++] = env; + } + env = p+1; + } + if (*env != '\0') { + argv[n++] = env; + } + } + else { + argv[n++] = "img2sixel"; + } + argv[n++] = "-l"; + argv[n++] = do_anim ? "auto" : "disable"; + argv[n++] = "-w"; sprintf(digit[0], "%d", w*pixel_per_char_i); - argv[4] = digit[0]; - argv[5] = "-h"; + argv[n++] = digit[0]; + argv[n++] = "-h"; sprintf(digit[1], "%d", h*pixel_per_line_i); - argv[6] = digit[1]; - argv[7] = "-c"; + argv[n++] = digit[1]; + argv[n++] = "-c"; sprintf(clip, "%dx%d+%d+%d", sw*pixel_per_char_i, sh*pixel_per_line_i, sx*pixel_per_char_i, sy*pixel_per_line_i); - argv[8] = clip; - argv[9] = url; + argv[n++] = clip; + argv[n++] = url; if (getenv("TERM") && strcmp(getenv("TERM"), "screen") == 0 && (!getenv("SCREEN_VARIANT") || strcmp(getenv("SCREEN_VARIANT"), "sixel") != 0)) { - argv[10] = "-P"; - argv[11] = NULL; - } - else { - argv[10] = NULL; + argv[n++] = "-P"; } + argv[n++] = NULL; execvp(argv[0],argv); exit(0); } -- cgit v1.2.3