diff --git a/src/lib/render.c b/src/lib/render.c index 7d592a2f4..669cfeb68 100644 --- a/src/lib/render.c +++ b/src/lib/render.c @@ -656,20 +656,33 @@ term_fg_rgb8(bool RGBflag, const char* setaf, int colors, FILE* out, } static inline int -ncdirect_style_emit(const char* sgr, unsigned stylebits, FILE* out){ - return term_emit("sgr", tiparm(sgr, stylebits & NCSTYLE_STANDOUT, - stylebits & NCSTYLE_UNDERLINE, - stylebits & NCSTYLE_REVERSE, - stylebits & NCSTYLE_BLINK, - stylebits & NCSTYLE_DIM, - stylebits & NCSTYLE_BOLD, - stylebits & NCSTYLE_INVIS, - stylebits & NCSTYLE_PROTECT, 0), out, false); +ncdirect_style_emit(ncdirect* n, const char* sgr, unsigned stylebits, FILE* out){ + if(sgr == NULL){ + return -1; + } + int r = term_emit("sgr", tiparm(sgr, stylebits & NCSTYLE_STANDOUT, + stylebits & NCSTYLE_UNDERLINE, + stylebits & NCSTYLE_REVERSE, + stylebits & NCSTYLE_BLINK, + stylebits & NCSTYLE_DIM, + stylebits & NCSTYLE_BOLD, + stylebits & NCSTYLE_INVIS, + stylebits & NCSTYLE_PROTECT, 0), out, false); + // sgr resets colors, so set them back up if not defaults + if(r == 0){ + if(!n->fgdefault){ + r |= ncdirect_fg(n, n->fgrgb); + } + if(!n->bgdefault){ + r |= ncdirect_bg(n, n->bgrgb); + } + } + return r; } int ncdirect_styles_on(ncdirect* n, unsigned stylebits){ n->attrword |= stylebits; - if(ncdirect_style_emit(n->sgr, n->attrword, n->ttyfp)){ + if(ncdirect_style_emit(n, n->sgr, n->attrword, n->ttyfp)){ return 0; } return term_setstyle(n->ttyfp, n->attrword, stylebits, NCSTYLE_ITALIC, n->italics, n->italoff); @@ -678,7 +691,7 @@ int ncdirect_styles_on(ncdirect* n, unsigned stylebits){ // turn off any specified stylebits int ncdirect_styles_off(ncdirect* n, unsigned stylebits){ n->attrword &= ~stylebits; - if(ncdirect_style_emit(n->sgr, n->attrword, n->ttyfp)){ + if(ncdirect_style_emit(n, n->sgr, n->attrword, n->ttyfp)){ return 0; } return term_setstyle(n->ttyfp, n->attrword, stylebits, NCSTYLE_ITALIC, n->italics, n->italoff); @@ -687,7 +700,7 @@ int ncdirect_styles_off(ncdirect* n, unsigned stylebits){ // set the current stylebits to exactly those provided int ncdirect_styles_set(ncdirect* n, unsigned stylebits){ n->attrword = stylebits; - if(ncdirect_style_emit(n->sgr, n->attrword, n->ttyfp)){ + if(ncdirect_style_emit(n, n->sgr, n->attrword, n->ttyfp)){ return 0; } return term_setstyle(n->ttyfp, n->attrword, stylebits, NCSTYLE_ITALIC, n->italics, n->italoff); diff --git a/src/poc/direct.c b/src/poc/direct.c index c7f448d64..4ea67da04 100644 --- a/src/poc/direct.c +++ b/src/poc/direct.c @@ -48,8 +48,18 @@ int main(void){ fprintf(stderr, "Error stopping notcurses\n"); return EXIT_FAILURE; } - struct ncdirect* n; - if((n = ncdirect_init()) == NULL){ + struct ncdirect* n; // see bug #391 + if((n = ncdirect_init(NULL, stdout)) == NULL){ + return EXIT_FAILURE; } + ncdirect_fg(n, 0xff8080); + ncdirect_styles_on(n, NCSTYLE_STANDOUT); + printf(" erp erp \n"); + ncdirect_fg(n, 0x80ff80); + printf(" erp erp \n"); + ncdirect_styles_off(n, NCSTYLE_STANDOUT); + printf(" erp erp \n"); + ncdirect_fg(n, 0xff8080); + printf(" erp erp \n"); return EXIT_SUCCESS; } diff --git a/src/poc/dirgb.c b/src/poc/dirgb.c index e1c253f6e..06d6242fc 100644 --- a/src/poc/dirgb.c +++ b/src/poc/dirgb.c @@ -44,7 +44,7 @@ int main(void){ if(!setlocale(LC_ALL, "")){ return EXIT_FAILURE; } - struct ncdirect* nc = ncdirect_initmode(NULL, stdout); + struct ncdirect* nc = ncdirect_init(NULL, stdout); if(!nc){ return EXIT_FAILURE; }