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

This commit is contained in:
nick black 2020-02-07 01:05:27 -05:00
parent dfe4a99446
commit 05997f9988
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
2 changed files with 16 additions and 8 deletions

View File

@ -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.

View File

@ -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()){