notcurses-view: always check for ready input #997

This commit is contained in:
nick black 2020-09-13 18:57:43 -04:00
parent 25a192c7ba
commit 089bb6e44f
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

View File

@ -101,32 +101,41 @@ auto perframe(struct ncvisual* ncv, struct ncvisual_options* vopts,
int dimx, dimy, oldx, oldy; int dimx, dimy, oldx, oldy;
nc.get_term_dim(&dimy, &dimx); nc.get_term_dim(&dimy, &dimx);
ncplane_dim_yx(vopts->n, &oldy, &oldx); ncplane_dim_yx(vopts->n, &oldy, &oldx);
struct timespec interval;
clock_gettime(CLOCK_MONOTONIC, &interval);
uint64_t nsnow = timespec_to_ns(&interval);
uint64_t absnow = timespec_to_ns(abstime); uint64_t absnow = timespec_to_ns(abstime);
if(absnow > nsnow){ char32_t keyp;
ns_to_timespec(absnow - nsnow, &interval); bool gotinput;
char32_t keyp; do{
while((keyp = nc.getc(&interval, nullptr, nullptr)) != (char32_t)-1){ gotinput = false;
if(keyp == ' '){ struct timespec interval;
if((keyp = nc.getc(true)) == (char32_t)-1){ clock_gettime(CLOCK_MONOTONIC, &interval);
return -1; uint64_t nsnow = timespec_to_ns(&interval);
} if(absnow > nsnow){
} ns_to_timespec(absnow - nsnow, &interval);
// if we just hit a non-space character to unpause, interpret it keyp = nc.getc(&interval, nullptr, nullptr);
if(keyp == ' '){ // space for unpause }else{
continue; keyp = nc.getc();
}
if(keyp == NCKey::Resize){
return 0;
}else if(keyp >= '0' && keyp <= '8'){ // FIXME eliminate ctrl/alt
vopts->blitter = static_cast<ncblitter_e>(keyp - '0');
continue;
}
return 1;
} }
} if(keyp == (char32_t)-1){
break;
}
gotinput = true;
if(keyp == ' '){
if((keyp = nc.getc(true)) == (char32_t)-1){
return -1;
}
}
// if we just hit a non-space character to unpause, interpret it
if(keyp == ' '){ // space for unpause
continue;
}
if(keyp == NCKey::Resize){
return 0;
}else if(keyp >= '0' && keyp <= '8'){ // FIXME eliminate ctrl/alt
vopts->blitter = static_cast<ncblitter_e>(keyp - '0');
continue;
}
return 1;
}while(gotinput);
return 0; return 0;
} }