demo: hook up restart demos/ctrl+r #338

This commit is contained in:
nick black 2020-02-12 13:37:02 -05:00
parent 87acdbeb68
commit 11ca32a1e8
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
3 changed files with 21 additions and 4 deletions

View File

@ -31,11 +31,18 @@ static const char DEFAULT_DEMO[] = "ixethbcgrwuvlfsjo";
#endif
atomic_bool interrupted = ATOMIC_VAR_INIT(false);
// checked following demos, whether aborted, failed, or otherwise
static atomic_bool restart_demos = ATOMIC_VAR_INIT(false);
void interrupt_demo(void){
atomic_store(&interrupted, true);
}
void interrupt_and_restart_demos(void){
atomic_store(&restart_demos, true);
atomic_store(&interrupted, true);
}
const demoresult* demoresult_lookup(int idx){
if(idx < 0 || idx >= democount){
return NULL;
@ -448,9 +455,13 @@ int main(int argc, char** argv){
nanosleep(&demodelay, NULL);
}
}
if(ext_demos(nc, spec, ignore_failures) == NULL){
goto err;
}
do{
restart_demos = false;
interrupted = false;
if(ext_demos(nc, spec, ignore_failures) == NULL){
goto err;
}
}while(restart_demos);
if(hud_destroy()){
goto err;
}

View File

@ -55,6 +55,7 @@ int stop_input(void);
// if 'q' is pressed at any time during the demo, gracefully interrupt/exit
void interrupt_demo(void);
void interrupt_and_restart_demos(void);
// demos should not call notcurses_getc() directly, as it's being monitored by
// the toplevel event listener. instead, call this intermediate API. just

View File

@ -120,6 +120,10 @@ bool menu_or_hud_key(struct notcurses *nc, const struct ncinput *ni){
about_toggle(nc);
return true;
}
if(ni->id == 'R' && !ni->alt && ni->ctrl){
interrupt_and_restart_demos();
return true;
}
if(!menu){
return false;
}
@ -135,7 +139,8 @@ bool menu_or_hud_key(struct notcurses *nc, const struct ncinput *ni){
ncmenu_rollup(menu);
return true;
}else if(strcmp(sel, MENUSTR_RESTART) == 0){
// FIXME
interrupt_and_restart_demos();
return true;
}
}
return false;