notcurses-demo: accept -i to continue on demo failure

pull/327/head
nick black 5 years ago
parent dfe4a99446
commit 05997f9988
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -9,7 +9,7 @@ notcurses-demo - Show off some notcurses features
# SYNOPSIS # SYNOPSIS
**notcurses-demo** [**-h|--help**] [**-p path**] [**-d delaymult**] **notcurses-demo** [**-h|--help**] [**-p path**] [**-d delaymult**]
[**-l loglevel**] [**-kHVc**] demospec [**-l loglevel**] [**-f renderfile**] [**-ikHVc**] demospec
# DESCRIPTION # 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. **-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. **-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. **-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. **-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. **-h**: Print a usage message, and exit with success.
**-V**: Print the program name and version, and exit with success. **-V**: Print the program name and version, and exit with success.

@ -149,7 +149,7 @@ usage(const char* exe, int status){
} }
static demoresult* static demoresult*
ext_demos(struct notcurses* nc, const char* spec){ ext_demos(struct notcurses* nc, const char* spec, bool ignore_failures){
int ret = 0; int ret = 0;
results = malloc(sizeof(*results) * strlen(spec)); results = malloc(sizeof(*results) * strlen(spec));
if(results == NULL){ if(results == NULL){
@ -176,7 +176,7 @@ ext_demos(struct notcurses* nc, const char* spec){
results[i].timens = nowns - prevns; results[i].timens = nowns - prevns;
prevns = nowns; prevns = nowns;
results[i].result = ret; results[i].result = ret;
if(ret){ if(!ignore_failures){
break; break;
} }
hud_completion_notify(&results[i]); 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]; // specification, also returns NULL, heh. determine this by argv[optind];
// if it's NULL, there were valid options, but no spec. // if it's NULL, there were valid options, but no spec.
static const char* 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); strcpy(datadir, NOTCURSES_SHARE);
char renderfile[PATH_MAX] = ""; char renderfile[PATH_MAX] = "";
bool constant_seed = false; bool constant_seed = false;
int c; int c;
*use_hud = false; *use_hud = false;
memset(opts, 0, sizeof(*opts)); 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){ switch(c){
case 'H': case 'H':
*use_hud = true; *use_hud = true;
@ -221,6 +222,9 @@ handle_opts(int argc, char** argv, notcurses_options* opts, bool* use_hud){
case 'c': case 'c':
constant_seed = true; constant_seed = true;
break; break;
case 'i':
*ignore_failures = true;
break;
case 'k': case 'k':
opts->inhibit_alternate_screen = true; opts->inhibit_alternate_screen = true;
break; break;
@ -393,9 +397,9 @@ int main(int argc, char** argv){
sigaddset(&sigmask, SIGWINCH); sigaddset(&sigmask, SIGWINCH);
pthread_sigmask(SIG_SETMASK, &sigmask, NULL); pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
notcurses_options nopts; notcurses_options nopts;
bool use_hud;
const char* spec; 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){ if(argv[optind] != NULL){
usage(*argv, EXIT_FAILURE); usage(*argv, EXIT_FAILURE);
} }
@ -437,7 +441,7 @@ int main(int argc, char** argv){
nanosleep(&demodelay, NULL); nanosleep(&demodelay, NULL);
} }
} }
if(ext_demos(nc, spec) == NULL){ if(ext_demos(nc, spec, ignore_failures) == NULL){
goto err; goto err;
} }
if(hud_destroy()){ if(hud_destroy()){

Loading…
Cancel
Save