ncdirect: fix style transitions #890

pull/887/head
nick black 4 years ago
parent 963ac742fb
commit b315c31141
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -500,32 +500,41 @@ ncdirect_style_emit(ncdirect* n, const char* sgr, unsigned stylebits, FILE* out)
}
int ncdirect_styles_on(ncdirect* n, unsigned stylebits){
n->attrword |= stylebits;
if(ncdirect_style_emit(n, n->tcache.sgr, n->attrword, n->ttyfp)){
return 0;
uint32_t attrword = n->attrword | stylebits;
if(ncdirect_style_emit(n, n->tcache.sgr, attrword, n->ttyfp) == 0){
if(term_setstyle(n->ttyfp, n->attrword, attrword, NCSTYLE_ITALIC,
n->tcache.italics, n->tcache.italoff) == 0){
n->attrword = attrword;
return 0;
}
}
return term_setstyle(n->ttyfp, n->attrword, stylebits, NCSTYLE_ITALIC,
n->tcache.italics, n->tcache.italoff);
return -1;
}
// turn off any specified stylebits
int ncdirect_styles_off(ncdirect* n, unsigned stylebits){
n->attrword &= ~stylebits;
if(ncdirect_style_emit(n, n->tcache.sgr, n->attrword, n->ttyfp)){
return 0;
uint32_t attrword = n->attrword & ~stylebits;
if(ncdirect_style_emit(n, n->tcache.sgr, attrword, n->ttyfp) == 0){
if(term_setstyle(n->ttyfp, n->attrword, attrword, NCSTYLE_ITALIC,
n->tcache.italics, n->tcache.italoff) == 0){
n->attrword = attrword;
return 0;
}
}
return term_setstyle(n->ttyfp, n->attrword, stylebits, NCSTYLE_ITALIC,
n->tcache.italics, n->tcache.italoff);
return -1;
}
// set the current stylebits to exactly those provided
int ncdirect_styles_set(ncdirect* n, unsigned stylebits){
n->attrword = stylebits;
if(ncdirect_style_emit(n, n->tcache.sgr, n->attrword, n->ttyfp)){
return 0;
uint32_t attrword = stylebits;
if(ncdirect_style_emit(n, n->tcache.sgr, attrword, n->ttyfp) == 0){
if(term_setstyle(n->ttyfp, n->attrword, attrword, NCSTYLE_ITALIC,
n->tcache.italics, n->tcache.italoff) == 0){
n->attrword = attrword;
return 0;
}
}
return term_setstyle(n->ttyfp, n->attrword, stylebits, NCSTYLE_ITALIC,
n->tcache.italics, n->tcache.italoff);
return -1;
}
int ncdirect_palette_size(const ncdirect* nc){

@ -31,6 +31,12 @@ print_gb(struct ncdirect* nc, int r, int total){
static int
print_rgb(struct ncdirect* nc, int total){
if(random() % 2){
ncdirect_styles_off(nc, NCSTYLE_ITALIC);
}
if(random() % 16 == 0){
ncdirect_styles_on(nc, NCSTYLE_ITALIC);
}
for(int r = 0 ; r <= total && r < 256 ; r += 4){
if(print_gb(nc, r, total)){
return -1;

Loading…
Cancel
Save