osmq

openstreetmap for command line
git clone https://logand.com/git/osmq.git/
Log | Files | Refs

commit 6a6d4be618880c48ef80b4e49eca6ef56b2eff19
parent 09488bc877f5595366f232d0372c28e853c88fe9
Author: Tomas Hlavaty <tom@logand.com>
Date:   Sun,  8 Sep 2019 23:45:57 +0200

add timeout key

Diffstat:
Mosmtile.c | 30++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/osmtile.c b/osmtile.c @@ -179,9 +179,26 @@ static void screen_size(int *w, int *h) { #define min(x, y) (x < y ? x : y) -static unsigned char key(void) { - unsigned char c; - if(1 != fread(&c, 1, 1, stdin)) exit(0); +static unsigned char key(int timeout) { + unsigned char c = 0; // timeout key by default + if(timeout) { + fd_set fds; + FD_ZERO(&fds); + FD_SET(0, &fds); + struct timeval tv; + tv.tv_sec = 1; + tv.tv_usec = 0; + int z = select(1, &fds, NULL, NULL, &tv); + if(z < 0) { + perror("select()"); + exit(1); + } else if(z) { + /* FD_ISSET(0, &fds) will be true. */ + if(1 != fread(&c, 1, 1, stdin)) exit(0); + } + } else { + if(1 != fread(&c, 1, 1, stdin)) exit(0); + } return c; } @@ -212,6 +229,7 @@ static int tty(int argc, char *argv[]) { fprintf(stderr, "popen w3mimgdisplay failed\n"); exit(1); } + int full = 1; for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { char file[4096]; @@ -222,13 +240,13 @@ static int tty(int argc, char *argv[]) { } } pclose(p); - unsigned char c = key(); + unsigned char c = key(full ? 0 : 1); switch(c) { case 27: /* esc */ - c = key(); + c = key(0); switch(c) { case '[': - c = key(); + c = key(0); switch(c) { case 'A': goto up; case 'B': goto down;