mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-20 03:25:47 +00:00
notcurses-view: always check for ready input #997
This commit is contained in:
parent
25a192c7ba
commit
089bb6e44f
@ -101,32 +101,41 @@ auto perframe(struct ncvisual* ncv, struct ncvisual_options* vopts,
|
||||
int dimx, dimy, oldx, oldy;
|
||||
nc.get_term_dim(&dimy, &dimx);
|
||||
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);
|
||||
if(absnow > nsnow){
|
||||
ns_to_timespec(absnow - nsnow, &interval);
|
||||
char32_t keyp;
|
||||
while((keyp = nc.getc(&interval, nullptr, nullptr)) != (char32_t)-1){
|
||||
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;
|
||||
char32_t keyp;
|
||||
bool gotinput;
|
||||
do{
|
||||
gotinput = false;
|
||||
struct timespec interval;
|
||||
clock_gettime(CLOCK_MONOTONIC, &interval);
|
||||
uint64_t nsnow = timespec_to_ns(&interval);
|
||||
if(absnow > nsnow){
|
||||
ns_to_timespec(absnow - nsnow, &interval);
|
||||
keyp = nc.getc(&interval, nullptr, nullptr);
|
||||
}else{
|
||||
keyp = nc.getc();
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user