mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-02 09:40:15 +00:00
demo: hook up restart demos/ctrl+r #338
This commit is contained in:
parent
87acdbeb68
commit
11ca32a1e8
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user