|
|
|
@ -953,29 +953,40 @@ char* termdesc_longterm(const tinfo* ti){
|
|
|
|
|
// on the response, easy peasy.
|
|
|
|
|
// FIXME still, we ought reuse buffer, and pass on any excess reads...
|
|
|
|
|
static int
|
|
|
|
|
locate_cursor_simple(int fd, const char* u7, int* cursor_y, int* cursor_x){
|
|
|
|
|
locate_cursor_simple(tinfo* ti, const char* u7, int* cursor_y, int* cursor_x){
|
|
|
|
|
if(ti->qterm == TERMINAL_MSTERMINAL){
|
|
|
|
|
return locate_cursor(ti, cursor_y, cursor_x);
|
|
|
|
|
}
|
|
|
|
|
char* buf = malloc(BUFSIZ);
|
|
|
|
|
if(buf == NULL){
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if(tty_emit(u7, fd)){
|
|
|
|
|
loginfo("sending cursor report request\n");
|
|
|
|
|
if(tty_emit(u7, ti->ttyfd)){
|
|
|
|
|
free(buf);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
ssize_t r;
|
|
|
|
|
// FIXME rigourize for multiple reads
|
|
|
|
|
if((r = read(fd, buf, BUFSIZ - 1)) > 0){
|
|
|
|
|
do{
|
|
|
|
|
if((r = read(ti->input.infd, buf, BUFSIZ - 1)) > 0){
|
|
|
|
|
buf[r] = '\0';
|
|
|
|
|
if(sscanf(buf, "\e[%d;%dR", cursor_y, cursor_x) != 2){
|
|
|
|
|
loginfo("Not a cursor location report: %s\n", buf);
|
|
|
|
|
loginfo("not a cursor location report: %s\n", buf);
|
|
|
|
|
free(buf);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
--*cursor_y;
|
|
|
|
|
--*cursor_x;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}while(errno == EAGAIN || errno == EWOULDBLOCK || errno == EBUSY || errno == EINTR);
|
|
|
|
|
if(r < 0){
|
|
|
|
|
logerror("error reading cursor location from %d (%s)\n", ti->input.infd, strerror(errno));
|
|
|
|
|
free(buf);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
free(buf);
|
|
|
|
|
loginfo("Located cursor with %d: %d/%d\n", fd, *cursor_y, *cursor_x);
|
|
|
|
|
loginfo("located cursor with %d: %d/%d\n", ti->ttyfd, *cursor_y, *cursor_x);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -983,14 +994,28 @@ locate_cursor_simple(int fd, const char* u7, int* cursor_y, int* cursor_x){
|
|
|
|
|
// is valid, we can just camp there. otherwise, we need dance with potential
|
|
|
|
|
// user input looking at infd.
|
|
|
|
|
int locate_cursor(tinfo* ti, int* cursor_y, int* cursor_x){
|
|
|
|
|
if(ti->qterm != TERMINAL_MSTERMINAL){
|
|
|
|
|
#ifdef __MINGW64__
|
|
|
|
|
if(ti->qterm == TERMINAL_MSTERMINAL){
|
|
|
|
|
if(ti->outhandle){
|
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO conbuf;
|
|
|
|
|
if(!GetConsoleScreenBufferInfo(ti->outhandle, &conbuf)){
|
|
|
|
|
logerror("couldn't get cursor info\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
*cursor_y = conbuf.dwCursorPosition.Y;
|
|
|
|
|
*cursor_x = conbuf.dwCursorPosition.X;
|
|
|
|
|
loginfo("got a report from y=%d x=%d\n", *cursor_y, *cursor_x);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
const char* u7 = get_escape(ti, ESCAPE_U7);
|
|
|
|
|
if(u7 == NULL){
|
|
|
|
|
logwarn("No support in terminfo\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if(ti->ttyfd >= 0){
|
|
|
|
|
return locate_cursor_simple(ti->ttyfd, u7, cursor_y, cursor_x);
|
|
|
|
|
return locate_cursor_simple(ti, u7, cursor_y, cursor_x);
|
|
|
|
|
}
|
|
|
|
|
int fd = ti->input.infd;
|
|
|
|
|
if(fd < 0){
|
|
|
|
@ -1033,15 +1058,3 @@ int locate_cursor(tinfo* ti, int* cursor_y, int* cursor_x){
|
|
|
|
|
free(clr);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
#ifdef __MINGW64__
|
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO conbuf;
|
|
|
|
|
if(!GetConsoleScreenBufferInfo(ti->outhandle, &conbuf)){
|
|
|
|
|
logerror("couldn't get cursor info\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
*cursor_y = conbuf.dwCursorPosition.Y;
|
|
|
|
|
*cursor_x = conbuf.dwCursorPosition.X;
|
|
|
|
|
loginfo("got a report from y=%d x=%d\n", *cursor_y, *cursor_x);
|
|
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|