|
|
@ -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
|
|
|
|
// no terminfo capability for this. dangerous--it involves writing controls to
|
|
|
|
// the terminal, and then reading a response. many things can distupt this
|
|
|
|
// the terminal, and then reading a response.
|
|
|
|
// non-atomic procedure, leading to unexpected results. a garbage function.
|
|
|
|
|
|
|
|
int ncdirect_cursor_yx(ncdirect* n, int* y, int* x){
|
|
|
|
int ncdirect_cursor_yx(ncdirect* n, int* y, int* x){
|
|
|
|
struct termios termio, oldtermios;
|
|
|
|
|
|
|
|
// this is only meaningful for real terminals
|
|
|
|
// this is only meaningful for real terminals
|
|
|
|
if(n->tcache.ttyfd < 0){
|
|
|
|
if(n->tcache.ttyfd < 0){
|
|
|
|
return -1;
|
|
|
|
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");
|
|
|
|
fprintf(stderr, "Terminal doesn't support cursor reporting\n");
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(tcgetattr(n->tcache.ttyfd, &termio)){
|
|
|
|
int yval, xval;
|
|
|
|
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;
|
|
|
|
|
|
|
|
if(!y){
|
|
|
|
if(!y){
|
|
|
|
y = &yval;
|
|
|
|
y = &yval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!x){
|
|
|
|
if(!x){
|
|
|
|
x = &xval;
|
|
|
|
x = &xval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret = cursor_yx_get(n, u7, y, x);
|
|
|
|
return 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;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ncdirect_cursor_push(ncdirect* n){
|
|
|
|
int ncdirect_cursor_push(ncdirect* n){
|
|
|
|