textplay: need render to a new plane

This commit is contained in:
nick black 2021-04-30 09:33:19 -04:00
parent e21f3585dc
commit 467c8d0e72
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

View File

@ -9,6 +9,7 @@ static const uint32_t NANOSEC = 1000000000ull / 60; // 60 cps
static struct notcurses* static struct notcurses*
init(void){ init(void){
struct notcurses_options opts = { struct notcurses_options opts = {
.loglevel = NCLOGLEVEL_DEBUG,
.margin_t = MARGIN, .margin_t = MARGIN,
.margin_r = MARGIN, .margin_r = MARGIN,
.margin_b = MARGIN, .margin_b = MARGIN,
@ -64,7 +65,7 @@ textplay(struct notcurses* nc, struct ncplane* tplane, struct ncvisual* ncv){
struct ncplane* stdn = notcurses_stdplane(nc); struct ncplane* stdn = notcurses_stdplane(nc);
ncplane_set_scrolling(tplane, true); ncplane_set_scrolling(tplane, true);
struct ncvisual_options vopts = { struct ncvisual_options vopts = {
.n = stdn, .n = ncplane_dup(stdn, NULL),
.scaling = NCSCALE_STRETCH, .scaling = NCSCALE_STRETCH,
.blitter = NCBLIT_PIXEL, .blitter = NCBLIT_PIXEL,
}; };
@ -77,7 +78,6 @@ textplay(struct notcurses* nc, struct ncplane* tplane, struct ncvisual* ncv){
ncplane_erase(tplane); ncplane_erase(tplane);
char* tmp = realloc(buf, buflen + 1); char* tmp = realloc(buf, buflen + 1);
if(tmp == NULL){ if(tmp == NULL){
free(buf);
return -1; return -1;
} }
buf = tmp; buf = tmp;
@ -85,15 +85,12 @@ textplay(struct notcurses* nc, struct ncplane* tplane, struct ncvisual* ncv){
buf[buflen++] = '\0'; buf[buflen++] = '\0';
int pt = ncplane_puttext(tplane, 0, NCALIGN_LEFT, buf, NULL); int pt = ncplane_puttext(tplane, 0, NCALIGN_LEFT, buf, NULL);
if(pt < 0){ if(pt < 0){
free(buf); goto err;
return -1;
} }
if(colorize(tplane)){ if(colorize(tplane)){
free(buf); goto err;
return -1;
} }
if(notcurses_render(nc)){ if(notcurses_render(nc)){
free(buf);
return -1; return -1;
} }
struct timespec ts = { struct timespec ts = {
@ -105,7 +102,13 @@ textplay(struct notcurses* nc, struct ncplane* tplane, struct ncvisual* ncv){
ncvisual_decode(ncv); ncvisual_decode(ncv);
} }
} }
ncplane_destroy(vopts.n);
return 0; return 0;
err:
ncplane_destroy(vopts.n);
free(buf);
return -1;
} }
static struct ncplane* static struct ncplane*