osmq

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

commit a486e2eaaabcd0dfc7a41346af4be1a5522629f9
parent 8af353ea6c8ef5c093442ecc248c03fa4c267850
Author: Tomas Hlavaty <tom@logand.com>
Date:   Fri, 13 Sep 2019 00:10:30 +0200

handle raw tty in shell

Diffstat:
Mosmq | 7+++++++
Mosmtile.c | 14+-------------
2 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/osmq b/osmq @@ -11,6 +11,13 @@ read \ -r \ 'map([.lat, .lon, .display_name] | join(" ")) | join("\n")' \ | fzf -0 -1 --with-nth=3..) +stty raw -echo +tput civis +function finish { + tput cnorm + stty -raw echo +} +trap finish EXIT osmtile \ tty \ "${OSMQ_CACHE:-$HOME/.cache/osmq}" \ diff --git a/osmtile.c b/osmtile.c @@ -120,13 +120,6 @@ static void run(char *args[]) { fail(1, "exec %s failed\n", *args); } -static void cleanup(void) { - char *args1[] = {"tput", "cnorm", NULL}; - run(args1); - char *args2[] = {"stty", "-raw", "echo", NULL}; - run(args2); -} - static int cached_file(int z, int x, int y, char *dir, char file[4096]) { int max = (1 << z) - 1; if(x < 0) x = max; @@ -153,6 +146,7 @@ static int cached_file(int z, int x, int y, char *dir, char file[4096]) { } static void screen_size(int *w, int *h) { + // TODO popen r stty size -> w h FILE *f = fopen("/sys/class/graphics/fb0/virtual_size", "r"); if(!f) fail(1, "unknown screen\n"); if(2 != fscanf(f, "%d,%d", w, h)) fail(1, "unknown screen size\n"); @@ -187,12 +181,6 @@ static unsigned char key(int timeout) { static int main_tty(int argc, char *argv[]) { int width, height; screen_size(&width, &height); - // popen r stty size -> w h - char *args0a[] = {"stty", "raw", "-echo", NULL}; - run(args0a); - char *args0b[] = {"tput", "civis", NULL}; - run(args0b); - atexit(cleanup); char *dir = argv[0]; if(!dir) fail(1, "unexpected dir %s\n", dir); int z0 = zoom_from_string(argv[1]);