mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-18 03:25:55 +00:00
ncdirect: preserve colors on sgr #391
This commit is contained in:
parent
bb579d0d05
commit
5a8107b788
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user