From 8f9646c19411b6dd67a561c67e89acf032d331e6 Mon Sep 17 00:00:00 2001 From: nick black Date: Wed, 29 Jul 2020 00:58:41 -0400 Subject: [PATCH] zoo: delay + handle input for multiselector #628 --- src/demo/zoo.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/demo/zoo.c b/src/demo/zoo.c index 62f81bf93..d542a1577 100644 --- a/src/demo/zoo.c +++ b/src/demo/zoo.c @@ -63,13 +63,13 @@ multiselector_demo(struct notcurses* nc, struct ncplane* n, int dimx, int y){ struct timespec swoopdelay; timespec_div(&demodelay, dimx / 3, &swoopdelay); int length = ncplane_dim_x(mplane); + ncinput ni; for(int i = 0 ; i < dimx - (length + 1) ; ++i){ if(demo_render(nc)){ ncmultiselector_destroy(mselector); return NULL; } ncplane_move_yx(mplane, y, i); - ncinput ni; char32_t wc = demo_getc(nc, &swoopdelay, &ni); if(wc == (char32_t)-1){ ncmultiselector_destroy(mselector); @@ -78,6 +78,23 @@ multiselector_demo(struct notcurses* nc, struct ncplane* n, int dimx, int y){ ncmultiselector_offer_input(mselector, &ni); } } + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + uint64_t cur = timespec_to_ns(&ts); + uint64_t targ = cur + GIG; + do{ + struct timespec rel; + ns_to_timespec(targ - cur, &rel); + char32_t wc = demo_getc(nc, &rel, &ni); + if(wc == (char32_t)-1){ + ncmultiselector_destroy(mselector); + return NULL; + }else if(wc){ + ncmultiselector_offer_input(mselector, &ni); + } + clock_gettime(CLOCK_MONOTONIC, &ts); + cur = timespec_to_ns(&ts); + }while(cur < targ); return mselector; }