diff --git a/src/lib/internal.h b/src/lib/internal.h index df88adcbc..5979ca14f 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -128,6 +128,8 @@ typedef struct rasterstate { bool bgpalelidable; bool fgdefelidable; bool bgdefelidable; + // are we in a pixel graphics mode? + bool pixelmode; } rasterstate; // Tablets are the toplevel entitites within an ncreel. Each corresponds to diff --git a/src/lib/render.c b/src/lib/render.c index ef1a66e64..3cf8af2a0 100644 --- a/src/lib/render.c +++ b/src/lib/render.c @@ -579,22 +579,58 @@ ncfputc(char c, FILE* out){ #endif } +static int +enter_pixel_mode(notcurses* nc, FILE* out){ + if(!nc->rstate.pixelmode){ + if(term_emit("\ePq", out, false)){ + return -1; + } + } + nc->rstate.pixelmode = true; + return 0; +} + +static int +leave_pixel_mode(notcurses* nc, FILE* out){ + if(term_emit("\e\\", out, false)){ + return -1; + } + nc->rstate.pixelmode = false; + return 0; +} + // write the nccell's UTF-8 extended grapheme cluster to the provided FILE*. static int -term_putc(FILE* out, const egcpool* e, const nccell* c){ - if(cell_simple_p(c)){ -//fprintf(stderr, "[%.4s] %08x\n", (const char*)&c->gcluster, c->gcluster); } - // we must not have any 'cntrl' characters at this point - if(c->gcluster == 0){ - if(ncfputc(' ', out) == EOF){ +term_putc(notcurses* nc, FILE* out, const egcpool* e, const nccell* c){ + if(cell_pixels_p(c)){ + if(!nc->rstate.pixelmode){ + if(enter_pixel_mode(nc, out)){ + return -1; + } + if(ncfputs(egcpool_extended_gcluster(e, c), out) == EOF){ return -1; } - }else if(ncfputs((const char*)&c->gcluster, out) == EOF){ - return -1; } }else{ - if(ncfputs(egcpool_extended_gcluster(e, c), out) == EOF){ - return -1; + if(nc->rstate.pixelmode){ + if(leave_pixel_mode(nc, out)){ + return -1; + } + } + if(cell_simple_p(c)){ + //fprintf(stderr, "[%.4s] %08x\n", (const char*)&c->gcluster, c->gcluster); } + // we must not have any 'cntrl' characters at this point + if(c->gcluster == 0){ + if(ncfputc(' ', out) == EOF){ + return -1; + } + }else if(ncfputs((const char*)&c->gcluster, out) == EOF){ + return -1; + } + }else{ + if(ncfputs(egcpool_extended_gcluster(e, c), out) == EOF){ + return -1; + } } } return 0; @@ -1027,7 +1063,7 @@ notcurses_rasterize_inner(notcurses* nc, const ncpile* p, FILE* out){ nc->rstate.bgpalelidable = false; } //fprintf(stderr, "RAST %08x [%s] to %d/%d cols: %u %016lx\n", srccell->gcluster, pool_extended_gcluster(&nc->pool, srccell), y, x, srccell->width, srccell->channels); - if(term_putc(out, &nc->pool, srccell)){ + if(term_putc(nc, out, &nc->pool, srccell)){ return -1; } ++nc->rstate.x;