aboutsummaryrefslogtreecommitdiffstats
path: root/terms.c
diff options
context:
space:
mode:
authorAraki Ken <arakiken@users.sf.net>2013-02-02 07:32:37 +0000
committerTatsuya Kinoshita <tats@debian.org>2014-12-06 11:47:04 +0000
commit147ef0048b9a50122e7865f36c97616b94ada76f (patch)
tree89bd2d84ee3b5530530928fd929e0a4b38345130 /terms.c
parentSupport remote image by OSC 5379 show_picture sequence. (diff)
downloadw3m-147ef0048b9a50122e7865f36c97616b94ada76f.tar.gz
w3m-147ef0048b9a50122e7865f36c97616b94ada76f.zip
- Adjust the image size to the terminal cell size. - If the image size is specified in html source, skip to load the image.
Diffstat (limited to '')
-rw-r--r--terms.c41
1 files changed, 25 insertions, 16 deletions
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