From a4896720e7eef92cfa10fdc81a84b4e5fd819a8c Mon Sep 17 00:00:00 2001 From: nick black Date: Tue, 19 Oct 2021 18:05:46 -0400 Subject: [PATCH] [keller] if we expect success, but fail, error out #2278 --- src/demo/keller.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/demo/keller.c b/src/demo/keller.c index cc5daf339..00f181e69 100644 --- a/src/demo/keller.c +++ b/src/demo/keller.c @@ -1,17 +1,22 @@ #include "demo.h" +static bool truefxn(const struct notcurses* nc){ (void)nc; return true; } + // show it with each blitter, with a legend static int visualize(struct notcurses* nc, struct ncvisual* ncv){ struct timespec kdelay; timespec_div(&demodelay, 2, &kdelay); - ncblitter_e bs[] = { - NCBLIT_BRAILLE, - NCBLIT_1x1, - NCBLIT_2x1, - NCBLIT_2x2, - NCBLIT_3x2, - NCBLIT_PIXEL, + const struct { + ncblitter_e b; + bool (*f)(const struct notcurses*); + } bs[] = { + { NCBLIT_BRAILLE, notcurses_canbraille, }, + { NCBLIT_1x1, truefxn, }, // everyone can do spaces + { NCBLIT_2x1, notcurses_canhalfblock, }, + { NCBLIT_2x2, notcurses_canquadrant, }, + { NCBLIT_3x2, notcurses_cansextant, }, + { NCBLIT_PIXEL, notcurses_canpixel, }, }; struct ncplane* stdn = notcurses_stdplane(nc); ncplane_set_fg_rgb(stdn, 0xffffff); @@ -25,7 +30,7 @@ visualize(struct notcurses* nc, struct ncvisual* ncv){ struct ncvisual_options vopts = { .n = notcurses_stdplane(nc), .scaling = NCSCALE_SCALE, - .blitter = bs[i], + .blitter = bs[i].b, .flags = NCVISUAL_OPTION_NODEGRADE | NCVISUAL_OPTION_HORALIGNED | NCVISUAL_OPTION_VERALIGNED @@ -47,11 +52,14 @@ visualize(struct notcurses* nc, struct ncvisual* ncv){ } //fprintf(stderr, "X: %d truex: %d scalex: %d\n", vopts.x, truex, scalex); if(!n){ + if(bs[i].f(nc)){ + return -1; + } ncplane_on_styles(stdn, NCSTYLE_ITALIC); ncplane_printf_aligned(stdn, ncplane_dim_y(stdn) / 2 - 1, NCALIGN_CENTER, "not available"); ncplane_off_styles(stdn, NCSTYLE_ITALIC); } - const char* name = notcurses_str_blitter(bs[i]); + const char* name = notcurses_str_blitter(bs[i].b); ncplane_printf_aligned(stdn, ncplane_dim_y(stdn) / 2 - 3, NCALIGN_CENTER, "%sblitter", name); int ret = demo_render(nc); if(ret){