send DA following XTSMGRAPHICS #1469

pull/1730/head
nick black 3 years ago committed by Nick Black
parent 60c030e232
commit b432166f66

@ -364,22 +364,34 @@ err:
// FIXME need unit tests on this // FIXME need unit tests on this
// FIXME can read a character not intended for it // FIXME can read a character not intended for it
// we'll get a trailing Device Attributes response, because we write
// XTSMGRAPHICS followed by a DA query, in case the former isn't supported
// (we'd otherwise hang looking for input).
static int static int
read_xtsmgraphics_reply(int fd, int* val2){ read_xtsmgraphics_reply(int fd, int* val2){
char in; char in;
// return is of the form CSI ? Pi ; 0 ; Pv S // return is of the form CSI ? Pi ; Ps ; Pv S
// Pi: 1 color registers, 2 sixel, 3 regis
// Pa: 1 read, 2 reset, 3 set to Pv, 4 read maximum
// Pv: n for color registers, width;height for geometry
// Ps: 0 success, 1 bad Pi, 2 bad Pa, 3 failure
enum { enum {
WANT_CSI, WANT_CSI,
WANT_QMARK, WANT_QMARK,
WANT_PI,
WANT_SEMI1, WANT_SEMI1,
WANT_SEMI2, WANT_SEMI2,
WANT_PV1, WANT_PV1,
WANT_PV2, WANT_PV2,
DONE DONE,
} state = WANT_CSI; } state = WANT_CSI;
int pv = 0; int pv = 0;
int pi = 0;
while(read(fd, &in, 1) == 1){ while(read(fd, &in, 1) == 1){
//fprintf(stderr, "READ: %c 0x%02x\n", in, in); //fprintf(stderr, "READ: %c 0x%02x\n", in, in);
if(in == 'c'){ // should match the end of DA
break;
}
switch(state){ switch(state){
case WANT_CSI: case WANT_CSI:
if(in == NCKEY_ESC){ if(in == NCKEY_ESC){
@ -388,6 +400,16 @@ read_xtsmgraphics_reply(int fd, int* val2){
break; break;
case WANT_QMARK: case WANT_QMARK:
if(in == '?'){ if(in == '?'){
state = WANT_PI;
}
break;
case WANT_PI:
if(!isdigit(in)){
break;
}
pi *= 10;
pi += in - '0';
if(pi >= 1 && pi <= 3){
state = WANT_SEMI1; state = WANT_SEMI1;
} }
break; break;
@ -424,12 +446,11 @@ read_xtsmgraphics_reply(int fd, int* val2){
default: default:
break; break;
} }
}
if(state == DONE){ if(state == DONE){
if(pv >= 0 && (!val2 || *val2 >= 0)){ if(pv >= 0 && (!val2 || *val2 >= 0)){
return pv; return pv;
} }
break;
}
} }
return -1; return -1;
} }

Loading…
Cancel
Save