From 0f79ac570295bdf894cc24bd71607bbd0c5dc01d Mon Sep 17 00:00:00 2001 From: nick black Date: Tue, 18 Aug 2020 06:26:05 -0400 Subject: [PATCH] zoo: fade out the widgets #835 --- src/demo/demo.c | 1 + src/demo/zoo.c | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/demo/demo.c b/src/demo/demo.c index 27e2df335..d5795608f 100644 --- a/src/demo/demo.c +++ b/src/demo/demo.c @@ -102,6 +102,7 @@ static struct { { "zoo", zoo_demo, false, }, }; +// FIXME stylize this a little static void usage(const char* exe, int status){ FILE* out = status == EXIT_SUCCESS ? stdout : stderr; diff --git a/src/demo/zoo.c b/src/demo/zoo.c index 0560203ff..030f2342a 100644 --- a/src/demo/zoo.c +++ b/src/demo/zoo.c @@ -368,8 +368,6 @@ reader_thread(void* vmarsh){ pthread_mutex_unlock(lock); if(collect_input){ ret = riser_collect_input(nc, &demodelay); - }else{ - ret = clock_nanosleep(CLOCK_MONOTONIC, 0, &demodelay, NULL); } if(ret < 0){ return THREAD_RETURN_NEGATIVE; @@ -417,13 +415,12 @@ reader_demo(struct notcurses* nc, pthread_t* tid, pthread_mutex_t* lock){ } static int -zap_reader(pthread_t tid, struct ncreader* reader, unsigned cancel){ +zap_reader(pthread_t tid, unsigned cancel){ if(cancel){ pthread_cancel(tid); } void* res; int ret = pthread_join(tid, &res); - ncreader_destroy(reader, NULL); if(res == THREAD_RETURN_NEGATIVE){ return -1; }else if(res == THREAD_RETURN_POSITIVE){ @@ -460,15 +457,29 @@ int zoo_demo(struct notcurses* nc){ if(mselector == NULL || ret){ goto err; } - ret |= zap_reader(readertid, reader, false); // let the thread do its thang + ret |= zap_reader(readertid, false); // let the thread do its thang ret |= pthread_mutex_destroy(&lock); + if(notcurses_canfade(nc)){ + if(ncplane_fadeout(ncselector_plane(selector), &demodelay, demo_fader, NULL)){ + goto err; + } + if(ncplane_fadeout(ncmultiselector_plane(mselector), &demodelay, demo_fader, NULL)){ + goto err; + } + }else{ + if( (ret = demo_nanosleep(nc, &demodelay)) ){ + goto err; + } + } + ncreader_destroy(reader, NULL); ncselector_destroy(selector, NULL); ncmultiselector_destroy(mselector); return ret; err: - zap_reader(readertid, reader, true); + zap_reader(readertid, true); pthread_mutex_destroy(&lock); + ncreader_destroy(reader, NULL); ncselector_destroy(selector, NULL); ncmultiselector_destroy(mselector); return ret ? ret : -1;