From 089bb6e44f918813b78142cb3be47c2067ffb472 Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 13 Sep 2020 18:57:43 -0400 Subject: [PATCH] notcurses-view: always check for ready input #997 --- src/view/view.cpp | 57 +++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/src/view/view.cpp b/src/view/view.cpp index 42914826a..18823d5fc 100644 --- a/src/view/view.cpp +++ b/src/view/view.cpp @@ -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(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(keyp - '0'); + continue; + } + return 1; + }while(gotinput); return 0; }