diff --git a/src/lib/direct.cpp b/src/lib/direct.cpp index 9865feeb8..3556934ce 100644 --- a/src/lib/direct.cpp +++ b/src/lib/direct.cpp @@ -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){ diff --git a/src/poc/dirgb.c b/src/poc/dirgb.c index be77951ef..44dce5dd3 100644 --- a/src/poc/dirgb.c +++ b/src/poc/dirgb.c @@ -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;