From 05997f998877926e6eb39969349eef180b56cb21 Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 7 Feb 2020 01:05:27 -0500 Subject: [PATCH] notcurses-demo: accept -i to continue on demo failure --- doc/man/man1/notcurses-demo.1.md | 6 +++++- src/demo/demo.c | 18 +++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/doc/man/man1/notcurses-demo.1.md b/doc/man/man1/notcurses-demo.1.md index 7556ed86d..a12eeb89c 100644 --- a/doc/man/man1/notcurses-demo.1.md +++ b/doc/man/man1/notcurses-demo.1.md @@ -9,7 +9,7 @@ notcurses-demo - Show off some notcurses features # SYNOPSIS **notcurses-demo** [**-h|--help**] [**-p path**] [**-d delaymult**] - [**-l loglevel**] [**-kHVc**] demospec + [**-l loglevel**] [**-f renderfile**] [**-ikHVc**] demospec # DESCRIPTION @@ -48,12 +48,16 @@ At any time, press 'q' to quit. The demo is best run in at least a 80x45 termina **-l loglevel**: Log everything (high log level) or nothing (log level 0) to stderr. +**-f renderfile**: Render each frame to **renderfile** in addition to the screen. + **-H**: Launch a HUD with running timers for each demo. This HUD can be moved or closed with the mouse. **-k**: Inhibit use of the alternate screen. Necessary if you want the output left on your terminal after the program exits. **-c**: Do not attempt to seed the PRNG. This is useful when benchmarking. +**-i**: Continue after a failing demo. + **-h**: Print a usage message, and exit with success. **-V**: Print the program name and version, and exit with success. diff --git a/src/demo/demo.c b/src/demo/demo.c index 9698f10a8..57010f143 100644 --- a/src/demo/demo.c +++ b/src/demo/demo.c @@ -149,7 +149,7 @@ usage(const char* exe, int status){ } static demoresult* -ext_demos(struct notcurses* nc, const char* spec){ +ext_demos(struct notcurses* nc, const char* spec, bool ignore_failures){ int ret = 0; results = malloc(sizeof(*results) * strlen(spec)); if(results == NULL){ @@ -176,7 +176,7 @@ ext_demos(struct notcurses* nc, const char* spec){ results[i].timens = nowns - prevns; prevns = nowns; results[i].result = ret; - if(ret){ + if(!ignore_failures){ break; } hud_completion_notify(&results[i]); @@ -188,14 +188,15 @@ ext_demos(struct notcurses* nc, const char* spec){ // specification, also returns NULL, heh. determine this by argv[optind]; // if it's NULL, there were valid options, but no spec. static const char* -handle_opts(int argc, char** argv, notcurses_options* opts, bool* use_hud){ +handle_opts(int argc, char** argv, notcurses_options* opts, bool* use_hud, + bool* ignore_failures){ strcpy(datadir, NOTCURSES_SHARE); char renderfile[PATH_MAX] = ""; bool constant_seed = false; int c; *use_hud = false; memset(opts, 0, sizeof(*opts)); - while((c = getopt(argc, argv, "HVhckl:r:d:f:p:")) != EOF){ + while((c = getopt(argc, argv, "HVhickl:r:d:f:p:")) != EOF){ switch(c){ case 'H': *use_hud = true; @@ -221,6 +222,9 @@ handle_opts(int argc, char** argv, notcurses_options* opts, bool* use_hud){ case 'c': constant_seed = true; break; + case 'i': + *ignore_failures = true; + break; case 'k': opts->inhibit_alternate_screen = true; break; @@ -393,9 +397,9 @@ int main(int argc, char** argv){ sigaddset(&sigmask, SIGWINCH); pthread_sigmask(SIG_SETMASK, &sigmask, NULL); notcurses_options nopts; - bool use_hud; const char* spec; - if((spec = handle_opts(argc, argv, &nopts, &use_hud)) == NULL){ + bool use_hud, ignore_failures; + if((spec = handle_opts(argc, argv, &nopts, &use_hud, &ignore_failures)) == NULL){ if(argv[optind] != NULL){ usage(*argv, EXIT_FAILURE); } @@ -437,7 +441,7 @@ int main(int argc, char** argv){ nanosleep(&demodelay, NULL); } } - if(ext_demos(nc, spec) == NULL){ + if(ext_demos(nc, spec, ignore_failures) == NULL){ goto err; } if(hud_destroy()){