mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-10 17:49:03 -04:00
panelreel-demo: support abort vs fail
This commit is contained in:
parent
6a7d7a750c
commit
a120e40816
@ -262,8 +262,9 @@ close_pipes(int* pipes){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct panelreel*
|
static int
|
||||||
panelreel_demo_core(struct notcurses* nc, int efdr, int efdw, tabletctx** tctxs){
|
panelreel_demo_core(struct notcurses* nc, int efdr, int efdw){
|
||||||
|
tabletctx* tctxs = NULL;
|
||||||
bool done = false;
|
bool done = false;
|
||||||
int x = 8, y = 4;
|
int x = 8, y = 4;
|
||||||
panelreel_options popts = {
|
panelreel_options popts = {
|
||||||
@ -287,16 +288,16 @@ panelreel_demo_core(struct notcurses* nc, int efdr, int efdw, tabletctx** tctxs)
|
|||||||
channels_set_fg_rgb(&popts.borderchan, 136, 23, 152);
|
channels_set_fg_rgb(&popts.borderchan, 136, 23, 152);
|
||||||
channels_set_bg_rgb(&popts.borderchan, 0, 0, 0);
|
channels_set_bg_rgb(&popts.borderchan, 0, 0, 0);
|
||||||
if(channels_set_fg_alpha(&popts.bgchannel, CELL_ALPHA_TRANSPARENT)){
|
if(channels_set_fg_alpha(&popts.bgchannel, CELL_ALPHA_TRANSPARENT)){
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
if(channels_set_bg_alpha(&popts.bgchannel, CELL_ALPHA_TRANSPARENT)){
|
if(channels_set_bg_alpha(&popts.bgchannel, CELL_ALPHA_TRANSPARENT)){
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
struct ncplane* w = notcurses_stdplane(nc);
|
struct ncplane* w = notcurses_stdplane(nc);
|
||||||
struct panelreel* pr = panelreel_create(w, &popts, efdw);
|
struct panelreel* pr = panelreel_create(w, &popts, efdw);
|
||||||
if(pr == NULL){
|
if(pr == NULL){
|
||||||
fprintf(stderr, "Error creating panelreel\n");
|
fprintf(stderr, "Error creating panelreel\n");
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
// Press a for a new panel above the current, c for a new one below the
|
// Press a for a new panel above the current, c for a new one below the
|
||||||
// current, and b for a new block at arbitrary placement.
|
// current, and b for a new block at arbitrary placement.
|
||||||
@ -317,10 +318,11 @@ panelreel_demo_core(struct notcurses* nc, int efdr, int efdw, tabletctx** tctxs)
|
|||||||
while(id < dimy / 8u){
|
while(id < dimy / 8u){
|
||||||
newtablet = new_tabletctx(pr, &id);
|
newtablet = new_tabletctx(pr, &id);
|
||||||
if(newtablet == NULL){
|
if(newtablet == NULL){
|
||||||
return NULL;
|
panelreel_destroy(pr);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
newtablet->next = *tctxs;
|
newtablet->next = tctxs;
|
||||||
*tctxs = newtablet;
|
tctxs = newtablet;
|
||||||
}
|
}
|
||||||
do{
|
do{
|
||||||
ncplane_styles_set(w, 0);
|
ncplane_styles_set(w, 0);
|
||||||
@ -351,13 +353,13 @@ panelreel_demo_core(struct notcurses* nc, int efdr, int efdw, tabletctx** tctxs)
|
|||||||
case NCKEY_RIGHT: ++x; if(panelreel_move(pr, x, y)){ --x; } break;
|
case NCKEY_RIGHT: ++x; if(panelreel_move(pr, x, y)){ --x; } break;
|
||||||
case NCKEY_UP: panelreel_prev(pr); break;
|
case NCKEY_UP: panelreel_prev(pr); break;
|
||||||
case NCKEY_DOWN: panelreel_next(pr); break;
|
case NCKEY_DOWN: panelreel_next(pr); break;
|
||||||
case NCKEY_DEL: kill_active_tablet(pr, tctxs); break;
|
case NCKEY_DEL: kill_active_tablet(pr, &tctxs); break;
|
||||||
default:
|
default:
|
||||||
ncplane_printf_yx(w, 3, 2, "Unknown keycode (0x%x)\n", rw);
|
ncplane_printf_yx(w, 3, 2, "Unknown keycode (0x%x)\n", rw);
|
||||||
}
|
}
|
||||||
if(newtablet){
|
if(newtablet){
|
||||||
newtablet->next = *tctxs;
|
newtablet->next = tctxs;
|
||||||
*tctxs = newtablet;
|
tctxs = newtablet;
|
||||||
}
|
}
|
||||||
struct timespec cur;
|
struct timespec cur;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &cur);
|
clock_gettime(CLOCK_MONOTONIC, &cur);
|
||||||
@ -366,32 +368,27 @@ panelreel_demo_core(struct notcurses* nc, int efdr, int efdw, tabletctx** tctxs)
|
|||||||
}
|
}
|
||||||
//panelreel_validate(w, pr); // do what, if not assert()ing? FIXME
|
//panelreel_validate(w, pr); // do what, if not assert()ing? FIXME
|
||||||
}while(!done);
|
}while(!done);
|
||||||
return pr;
|
while(tctxs){
|
||||||
|
kill_tablet(&tctxs);
|
||||||
|
}
|
||||||
|
if(panelreel_destroy(pr)){
|
||||||
|
fprintf(stderr, "Error destroying panelreel\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return done ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int panelreel_demo(struct notcurses* nc){
|
int panelreel_demo(struct notcurses* nc){
|
||||||
tabletctx* tctxs = NULL;
|
|
||||||
int pipes[2];
|
int pipes[2];
|
||||||
// freebsd doesn't have eventfd :/
|
// freebsd doesn't have eventfd :/
|
||||||
if(pipe2(pipes, O_CLOEXEC | O_NONBLOCK)){
|
if(pipe2(pipes, O_CLOEXEC | O_NONBLOCK)){
|
||||||
fprintf(stderr, "Error creating pipe (%s)\n", strerror(errno));
|
fprintf(stderr, "Error creating pipe (%s)\n", strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
struct panelreel* pr;
|
int ret = panelreel_demo_core(nc, pipes[0], pipes[1]);
|
||||||
if((pr = panelreel_demo_core(nc, pipes[0], pipes[1], &tctxs)) == NULL){
|
|
||||||
close_pipes(pipes);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
while(tctxs){
|
|
||||||
kill_tablet(&tctxs);
|
|
||||||
}
|
|
||||||
close_pipes(pipes);
|
close_pipes(pipes);
|
||||||
if(panelreel_destroy(pr)){
|
|
||||||
fprintf(stderr, "Error destroying panelreel\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(demo_render(nc)){
|
if(demo_render(nc)){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user