From 3bdbf6e2e22650c585d087060d3dec948fcaebf0 Mon Sep 17 00:00:00 2001 From: nick black Date: Thu, 4 Nov 2021 07:15:21 -0400 Subject: [PATCH] [ncdirect_cursor_yx] simplify thanks to modern input system --- src/lib/direct.c | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/src/lib/direct.c b/src/lib/direct.c index f93e3daed..9419a697f 100644 --- a/src/lib/direct.c +++ b/src/lib/direct.c @@ -357,10 +357,8 @@ detect_cursor_inversion_wrapper(ncdirect* n, const char* u7, int* y, int* x){ */ // no terminfo capability for this. dangerous--it involves writing controls to -// the terminal, and then reading a response. many things can distupt this -// non-atomic procedure, leading to unexpected results. a garbage function. +// the terminal, and then reading a response. int ncdirect_cursor_yx(ncdirect* n, int* y, int* x){ - struct termios termio, oldtermios; // this is only meaningful for real terminals if(n->tcache.ttyfd < 0){ return -1; @@ -370,33 +368,14 @@ int ncdirect_cursor_yx(ncdirect* n, int* y, int* x){ fprintf(stderr, "Terminal doesn't support cursor reporting\n"); return -1; } - if(tcgetattr(n->tcache.ttyfd, &termio)){ - fprintf(stderr, "Couldn't get terminal info from %d (%s)\n", - n->tcache.ttyfd, strerror(errno)); - return -1; - } - memcpy(&oldtermios, &termio, sizeof(termio)); - // we might already be in cbreak mode from ncdirect_init(), but just in case - // it got changed by the client code since then, duck into cbreak mode anew. - termio.c_lflag &= ~(ICANON | ECHO); - if(tcsetattr(n->tcache.ttyfd, TCSAFLUSH, &termio)){ - fprintf(stderr, "Couldn't put terminal into cbreak mode via %d (%s)\n", - n->tcache.ttyfd, strerror(errno)); - return -1; - } - int ret, yval, xval; + int yval, xval; if(!y){ y = &yval; } if(!x){ x = &xval; } - ret = cursor_yx_get(n, u7, y, x); - if(tcsetattr(n->tcache.ttyfd, TCSANOW, &oldtermios)){ - fprintf(stderr, "Couldn't restore terminal mode on %d (%s)\n", - n->tcache.ttyfd, strerror(errno)); // don't return error for this - } - return ret; + return cursor_yx_get(n, u7, y, x); } int ncdirect_cursor_push(ncdirect* n){