term_setstyles: verify sgr presence before using it #1344

This commit is contained in:
nick black 2021-03-15 01:59:57 -04:00
parent 70059297c0
commit 79b73cff94
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

View File

@ -620,22 +620,27 @@ term_setstyles(FILE* out, notcurses* nc, const nccell* c){
// if only italics changed, don't emit any sgr escapes. xor of current and
// target ought have all 0s in the lower 8 bits if only italics changed.
if((cellattr ^ nc->rstate.curattr) & 0xfful){
normalized = true; // FIXME this is pretty conservative
// if everything's 0, emit the shorter sgr0
if(nc->tcache.sgr0 && ((cellattr & NCSTYLE_MASK) == 0)){
if(term_emit(nc->tcache.sgr0, out, false) < 0){
ret = -1;
}else{
normalized = true;
}
}else if(nc->tcache.sgr){
if(term_emit(tiparm(nc->tcache.sgr, cellattr & NCSTYLE_STANDOUT,
cellattr & NCSTYLE_UNDERLINE,
cellattr & NCSTYLE_REVERSE,
cellattr & NCSTYLE_BLINK,
cellattr & NCSTYLE_DIM,
cellattr & NCSTYLE_BOLD,
cellattr & NCSTYLE_INVIS,
cellattr & NCSTYLE_PROTECT, 0),
out, false) < 0){
ret = -1;
}else{
normalized = true;
}
}else if(term_emit(tiparm(nc->tcache.sgr, cellattr & NCSTYLE_STANDOUT,
cellattr & NCSTYLE_UNDERLINE,
cellattr & NCSTYLE_REVERSE,
cellattr & NCSTYLE_BLINK,
cellattr & NCSTYLE_DIM,
cellattr & NCSTYLE_BOLD,
cellattr & NCSTYLE_INVIS,
cellattr & NCSTYLE_PROTECT, 0),
out, false) < 0){
ret = -1;
}
// sgr will blow away italics/struck if they were set beforehand
nc->rstate.curattr &= !(NCSTYLE_ITALIC | NCSTYLE_STRUCK);