term_setstyles: verify sgr presence before using it #1344

pull/1415/head
nick black 4 years ago
parent 70059297c0
commit 79b73cff94
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -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);

Loading…
Cancel
Save