[ncdirect_cursor_yx] simplify thanks to modern input system

This commit is contained in:
nick black 2021-11-04 07:15:21 -04:00
parent cf8dad7a1c
commit 3bdbf6e2e2

View File

@ -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){