[kitty] clear all graphics on startup #1437

This commit is contained in:
nick black 2021-03-21 20:26:44 -04:00
parent 24dfb0626f
commit fd2875eae6
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
6 changed files with 31 additions and 12 deletions

View File

@ -683,7 +683,7 @@ ncdirect* ncdirect_core_init(const char* termtype, FILE* outfp, uint64_t flags){
if(ncvisual_init(NCLOGLEVEL_SILENT)){
goto err;
}
if(interrogate_terminfo(&ret->tcache, shortname_term, utf8)){
if(interrogate_terminfo(&ret->tcache, ret->ctermfd, shortname_term, utf8)){
goto err;
}
update_term_dimensions(ret->ctermfd, NULL, NULL, &ret->tcache);

View File

@ -320,6 +320,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_clear_all)(const struct notcurses* nc);
bool pixel_query_done; // have we yet performed pixel query?
bool sextants; // do we have (good, vetted) Unicode 13 sextant support?
bool braille; // do we have Braille support? (linux console does not)
@ -479,7 +480,7 @@ int terminfostr(char** gseq, const char* name);
// load |ti| from the terminfo database, which must already have been
// initialized. set |utf8| if we've verified UTF8 output encoding.
int interrogate_terminfo(tinfo* ti, const char* termname, unsigned utf8);
int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8);
void free_terminfo_cache(tinfo* ti);
@ -727,7 +728,9 @@ sprixel* sprixel_create(ncplane* n, const char* s, int bytes, int placey, int pl
int sprixelid, int dimy, int dimx, int pixy, int pixx);
API int sprite_wipe_cell(const notcurses* nc, sprixel* s, int y, int x);
int sprite_kitty_annihilate(const notcurses* nc, const ncpile* p, FILE* out, sprixel* s);
int sprite_kitty_clear_all(const notcurses* nc);
int sprite_sixel_annihilate(const notcurses* nc, const ncpile* p, FILE* out, sprixel* s);
int sprite_clear_all(const notcurses* nc);
static inline void
pool_release(egcpool* pool, nccell* c){

View File

@ -282,3 +282,7 @@ int kitty_blit(ncplane* nc, int linesize, const void* data, int begy, int begx,
}
return r;
}
int sprite_kitty_clear_all(const notcurses* nc){
return tty_emit("\e_Ga=d\e\\", nc->ttyfd);
}

View File

@ -1007,7 +1007,7 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
}
const char* shortname_term = termname();
// const char* longname_term = longname();
if(interrogate_terminfo(&ret->tcache, shortname_term, utf8)){
if(interrogate_terminfo(&ret->tcache, ret->ttyfd, shortname_term, utf8)){
goto err;
}
int dimy, dimx;
@ -1034,6 +1034,10 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
goto err;
}
if(ret->ttyfd >= 0){
if(sprite_clear_all(ret)){
free_plane(ret->stdplane);
goto err;
}
if(ret->tcache.smkx && tty_emit(ret->tcache.smkx, ret->ttyfd)){
free_plane(ret->stdplane);
goto err;

View File

@ -72,3 +72,10 @@ int sprite_wipe_cell(const notcurses* nc, sprixel* s, int ycell, int xcell){
}
return r;
}
int sprite_clear_all(const notcurses* nc){
if(!nc->tcache.pixel_clear_all){
return 0;
}
return nc->tcache.pixel_clear_all(nc);
}

View File

@ -62,6 +62,7 @@ apply_term_heuristics(tinfo* ti, const char* termname){
ti->sixel_supported = true;
ti->pixel_cell_wipe = sprite_kitty_cell_wipe;
ti->pixel_destroy = sprite_kitty_annihilate;
ti->pixel_clear_all = sprite_kitty_clear_all;
set_pixel_blitter(kitty_blit);
/*}else if(strstr(termname, "alacritty")){
ti->sextants = true; // alacritty https://github.com/alacritty/alacritty/issues/4409 */
@ -86,7 +87,7 @@ void free_terminfo_cache(tinfo* ti){
// termname is just the TERM environment variable. some details are not
// exposed via terminfo, and we must make heuristic decisions based on
// the detected terminal type, yuck :/.
int interrogate_terminfo(tinfo* ti, const char* termname, unsigned utf8){
int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8){
memset(ti, 0, sizeof(*ti));
ti->utf8 = utf8;
ti->RGBflag = query_rgb();
@ -150,25 +151,25 @@ int interrogate_terminfo(tinfo* ti, const char* termname, unsigned utf8){
// support for the style in that case.
int nocolor_stylemask = tigetnum("ncv");
if(nocolor_stylemask > 0){
if(nocolor_stylemask & WA_STANDOUT){ // ncv is composed of terminfo bits, not ours
if(nocolor_stylemask & A_STANDOUT){ // ncv is composed of terminfo bits, not ours
ti->standout = NULL;
}
if(nocolor_stylemask & WA_UNDERLINE){
if(nocolor_stylemask & A_UNDERLINE){
ti->uline = NULL;
}
if(nocolor_stylemask & WA_REVERSE){
if(nocolor_stylemask & A_REVERSE){
ti->reverse = NULL;
}
if(nocolor_stylemask & WA_BLINK){
if(nocolor_stylemask & A_BLINK){
ti->blink = NULL;
}
if(nocolor_stylemask & WA_DIM){
if(nocolor_stylemask & A_DIM){
ti->dim = NULL;
}
if(nocolor_stylemask & WA_BOLD){
if(nocolor_stylemask & A_BOLD){
ti->bold = NULL;
}
if(nocolor_stylemask & WA_ITALIC){
if(nocolor_stylemask & A_ITALIC){
ti->italics = NULL;
}
// can't do anything about struck! :/
@ -183,7 +184,7 @@ int interrogate_terminfo(tinfo* ti, const char* termname, unsigned utf8){
terminfostr(&ti->struckoff, "rmxx"); // cancel strikeout
// if the keypad neen't be explicitly enabled, smkx is not present
if(ti->smkx){
if(putp(tiparm(ti->smkx)) != OK){
if(tty_emit(tiparm(ti->smkx), fd) < 0){
fprintf(stderr, "Error entering keypad transmit mode\n");
return -1;
}