From 9b38fe515c6b40f21751aed7e89be99988397342 Mon Sep 17 00:00:00 2001 From: nick black Date: Wed, 21 Apr 2021 20:28:37 -0400 Subject: [PATCH] ncdirect_stream: need to call new pixel_remove #1537 --- src/lib/direct.c | 16 +++++++++++++++- src/lib/internal.h | 2 ++ src/lib/kitty.c | 9 ++++++++- src/lib/terminfo.c | 2 ++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/lib/direct.c b/src/lib/direct.c index 53518eefb..77cb7cc0a 100644 --- a/src/lib/direct.c +++ b/src/lib/direct.c @@ -558,6 +558,7 @@ ncdirect_render_visual(ncdirect* n, ncvisual* ncv, ncblitter_e blitfxn, free_plane(ncdv); return NULL; } + ncdv->sprite = bargs.u.pixel.spx; } if(ncvisual_blit(ncv, disprows, dispcols, ncdv, bset, leny, lenx, &bargs)){ free_plane(ncdv); @@ -1139,6 +1140,8 @@ int ncdirect_stream(ncdirect* n, const char* filename, ncstreamcb streamer, // starting position *after displaying one frame* so as to effect any // necessary scrolling. int y = -1, x = -1; + int lastid = -1; + int thisid = -1; do{ if(y > 0){ ncdirect_cursor_up(n, y); @@ -1154,9 +1157,20 @@ int ncdirect_stream(ncdirect* n, const char* filename, ncstreamcb streamer, return -1; } ncplane_dim_yx(v, &y, &x); + if(v->sprite){ + thisid = v->sprite->id; + } ncdirect_raster_frame(n, v, (vopts->flags & NCVISUAL_OPTION_HORALIGNED) ? vopts->x : 0); + if(lastid > -1){ + if(n->tcache.pixel_remove){ + if(n->tcache.pixel_remove(lastid, n->ttyfp)){ + ncvisual_destroy(ncv); + return -1; + } + } + } streamer(ncv, vopts, NULL, curry); - // FIXME need to issue a kitty-kill when appropriate, how? + lastid = thisid; }while(ncvisual_decode(ncv) == 0); ncvisual_destroy(ncv); return 0; diff --git a/src/lib/internal.h b/src/lib/internal.h index ee9b8d7f2..2982383dc 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -447,6 +447,7 @@ typedef struct tinfo { // means leaving out the pixels (and likely resizes the string). for kitty, // this means dialing down their alpha to 0 (in equivalent space). int (*pixel_cell_wipe)(const struct notcurses* nc, sprixel* s, int y, int x); + int (*pixel_remove)(int id, FILE* out); // kitty only, issue actual delete command int (*pixel_init)(int fd); // called when support is detected int (*pixel_draw)(const struct notcurses* n, const struct ncpile* p, sprixel* s, FILE* out); int (*pixel_shutdown)(int fd); // called during context shutdown @@ -935,6 +936,7 @@ int sprixel_load(sprixel* spx, char* s, int bytes, int placey, int placex, int pixy, int pixx, int parse_start); int sixel_delete(const notcurses* nc, const ncpile* p, FILE* out, sprixel* s); int kitty_delete(const notcurses* nc, const ncpile* p, FILE* out, sprixel* s); +int kitty_remove(int id, FILE* out); int kitty_init(int fd); int sixel_init(int fd); int sprite_init(const notcurses* nc); diff --git a/src/lib/kitty.c b/src/lib/kitty.c index 16f59624d..d3b994e5a 100644 --- a/src/lib/kitty.c +++ b/src/lib/kitty.c @@ -372,12 +372,19 @@ int kitty_blit(ncplane* n, int linesize, const void* data, return 1; } +int kitty_remove(int id, FILE* out){ + if(fprintf(out, "\e_Ga=d,d=i,i=%d\e\\", id) < 0){ + return -1; + } + return 0; +} + // removes the kitty bitmap graphic identified by s->id, and damages those // cells which weren't SPRIXCEL_OPAQUE int kitty_delete(const notcurses* nc, const ncpile* p, FILE* out, sprixel* s){ (void)p; (void)nc; - if(fprintf(out, "\e_Ga=d,d=i,i=%d\e\\", s->id) < 0){ + if(kitty_remove(s->id, out)){ return -1; } //fprintf(stderr, "MOVED FROM: %d/%d\n", s->movedfromy, s->movedfromx); diff --git a/src/lib/terminfo.c b/src/lib/terminfo.c index aadcc65fb..6c8faa703 100644 --- a/src/lib/terminfo.c +++ b/src/lib/terminfo.c @@ -64,6 +64,7 @@ apply_term_heuristics(tinfo* ti, const char* termname){ ti->pixel_cell_wipe = kitty_wipe; ti->pixel_destroy = kitty_delete; ti->pixel_init = kitty_init; + ti->pixel_remove = kitty_remove; ti->pixel_draw = kitty_draw; ti->pixel_shutdown = kitty_shutdown; ti->sprixel_height_factor = 1; @@ -342,6 +343,7 @@ setup_sixel(tinfo* ti){ ti->pixel_draw = sixel_draw; ti->sixel_maxx = 4096; // whee! ti->sixel_maxy = 4096; + ti->pixel_remove = NULL; ti->pixel_destroy = sixel_delete; ti->pixel_cell_wipe = sixel_wipe; ti->pixel_shutdown = sixel_shutdown;