void pico_set_normal_color(void) { if(!_nfcolor || !_nbcolor || !pico_set_fg_color(_nfcolor) || !pico_set_bg_color(_nbcolor)){ (void)pico_set_fg_color(DEFAULT_NORM_FORE_RGB); (void)pico_set_bg_color(DEFAULT_NORM_BACK_RGB); } }
/* * Sets color to (fg,bg). * Flags == PSC_NONE No alternate default if fg,bg fails. * == PSC_NORM Set it to Normal color on failure. * == PSC_REV Set it to Reverse color on failure. * * If flag PSC_RET is set, returns an allocated copy of the previous * color pair, otherwise returns NULL. */ COLOR_PAIR * pico_set_colors(char *fg, char *bg, int flags) { int uc; COLOR_PAIR *cp = NULL, *rev = NULL; if(flags & PSC_RET) cp = pico_get_cur_color(); if(fg && !strcmp(fg, END_PSEUDO_REVERSE)){ EndInverse(); if(cp) free_color_pair(&cp); } else if(!((uc=pico_usingcolor()) && fg && bg && pico_set_fg_color(fg) && pico_set_bg_color(bg))){ if(uc && flags & PSC_NORM) pico_set_normal_color(); else if(flags & PSC_REV){ if((rev = pico_get_rev_color()) != NULL){ pico_set_fg_color(rev->fg); /* these will succeed */ pico_set_bg_color(rev->bg); } else{ StartInverse(); if(cp){ strncpy(cp->fg, END_PSEUDO_REVERSE, MAXCOLORLEN+1); cp->fg[MAXCOLORLEN] = '\0'; strncpy(cp->bg, END_PSEUDO_REVERSE, MAXCOLORLEN+1); cp->bg[MAXCOLORLEN] = '\0'; } } } } return(cp); }
int tbgcolor(int color) { if(!_color_inited) tinitcolor(); if(!_color_inited) return(-1); if((ANSI8_COLOR() && (color < 0 || color >= 8+COL_TRANS())) || (ANSI16_COLOR() && (color < 0 || color >= 16+COL_TRANS())) || (ANSI256_COLOR() && (color < 0 || color >= 256+COL_TRANS())) || (!ANSI_COLOR() && (color < 0 || color >= _colors+COL_TRANS()))) return(-1); if(ANSI_COLOR()){ char buf[20]; if(COL_TRANS() && color == pico_count_in_color_table()-1) snprintf(buf, sizeof(buf), "\033[49m"); else if(ANSI256_COLOR()) snprintf(buf, sizeof(buf), "\033[48;5;%dm", color); else{ if(color < 8) snprintf(buf, sizeof(buf), "\033[4%cm", color + '0'); else snprintf(buf, sizeof(buf), "\033[10%cm", (color-8) + '0'); } putpad(buf); } else if(COL_TRANS() && color == pico_count_in_color_table()-1 && _op){ char fg_color_was[MAXCOLORLEN+1]; fg_color_was[0] = '\0'; /* * Setting transparent (default) background color. * We don't know how to set only the default background color, * _op sets both foreground and background. So we need to * * get current foreground color * set default colors * if (current foreground was not default) reset it */ if(_last_fg_color && strncmp(_last_fg_color, MATCH_TRAN_COLOR, RGBLEN)){ strncpy(fg_color_was, _last_fg_color, sizeof(fg_color_was)); fg_color_was[sizeof(fg_color_was)-1] = '\0'; } putpad(_op); if(fg_color_was[0]){ _force_fg_color_change = 1; pico_set_fg_color(fg_color_was); } } else if(_setab) putpad(tparm(_setab, color)); else if(_setb) putpad(tparm(_setb, color)); else if(_scp){ /* set color pair method */ } return(0); }
void pico_set_nfg_color(void) { if(_nfcolor) (void)pico_set_fg_color(_nfcolor); }
/*---------------------------------------------------------------------- Output line of length len to the display observing embedded attributes Args: x -- column position on the screen y -- column position on the screen line -- text to be output length -- length of text to be output Result: text is output cursor position is updated ----------------------------------------------------------------------*/ void PutLine0n8b(int x, int y, register char *line, int length, HANDLE_S *handles) { unsigned char c; int is_inv = 0, is_bold = 0, is_uline = 0, is_fg = 0, is_bg = 0; #ifdef _WINDOWS int hkey = 0; #endif MoveCursor(x,y); while(length--){ c = (unsigned char) *line++; if(c == (unsigned char) TAG_EMBED && length){ length--; switch(*line++){ case TAG_INVON : StartInverse(); is_inv = 1; break; case TAG_INVOFF : EndInverse(); is_inv = 0; break; case TAG_BOLDON : StartBold(); is_bold = 1; break; case TAG_BOLDOFF : EndBold(); is_bold = 0; break; case TAG_ITALICON : /* express italic as uline in terminal */ case TAG_ULINEON : StartUnderline(); is_uline = 1; break; case TAG_ITALICOFF : /* express italic as uline in terminal */ case TAG_ULINEOFF : EndUnderline(); is_uline = 0; break; case TAG_HANDLE : length -= *line + 1; /* key length plus length tag */ if(handles){ int key, n, current_key = 0; for(key = 0, n = *line++; n; n--) /* forget Horner? */ key = (key * 10) + (*line++ - '0'); #if _WINDOWS hkey = key; #endif if(handles->using_is_used){ HANDLE_S *h; for(h = handles; h; h = h->next) if(h->is_used) break; if(h) current_key = h->key; } else current_key = handles->key; if(key == current_key){ COLOR_PAIR *curcolor = NULL; COLOR_PAIR *revcolor = NULL; if(handles->color_unseen && (curcolor = pico_get_cur_color()) && (colorcmp(curcolor->fg, ps_global->VAR_NORM_FORE_COLOR) || colorcmp(curcolor->bg, ps_global->VAR_NORM_BACK_COLOR)) && (revcolor = apply_rev_color(curcolor, ps_global->index_color_style))) (void) pico_set_colorp(revcolor, PSC_NONE); else{ if(pico_usingcolor() && ps_global->VAR_SLCTBL_FORE_COLOR && ps_global->VAR_SLCTBL_BACK_COLOR){ pico_set_normal_color(); } else EndBold(); StartInverse(); is_inv = 1; } if(curcolor) free_color_pair(&curcolor); if(revcolor) free_color_pair(&revcolor); } } else{ /* BUG: complain? */ line += *line + 1; } break; case TAG_FGCOLOR : if(length < RGBLEN){ dprint((9, "FGCOLOR not proper length, ignoring\n")); length = 0; break; } (void)pico_set_fg_color(line); is_fg = 1; length -= RGBLEN; line += RGBLEN; break; case TAG_BGCOLOR : if(length < RGBLEN){ dprint((9, "BGCOLOR not proper length, ignoring\n")); length = 0; break; } (void)pico_set_bg_color(line); is_bg = 1; length -= RGBLEN; line += RGBLEN; break; case TAG_EMBED: /* literal "embed" char */ Writechar(TAG_EMBED, 0); break; case TAG_STRIKEON : /* unsupported text markup */ case TAG_STRIKEOFF : case TAG_BIGON : case TAG_BIGOFF : case TAG_SMALLON : case TAG_SMALLOFF : default : /* Eat unrecognized tag - TAG_BIGON, etc */ break; } /* tag with handle, skip it */ } else Writechar(c, 0); } #if _WINDOWS_X if(hkey) { char *tmp_file = NULL, ext[32], mtype[128]; HANDLE_S *h; extern HANDLE_S *get_handle (HANDLE_S *, int); if((h = get_handle(handles, hkey)) && h->type == Attach){ ext[0] = '\0'; strncpy(mtype, body_type_names(h->h.attach->body->type), sizeof(mtype)); mtype[sizeof(mtype)-1] = '\0'; if (h->h.attach->body->subtype) { strncat (mtype, "/", sizeof(mtype)-strlen(mtype)-1); mtype[sizeof(mtype)-1] = '\0'; strncat (mtype, h->h.attach->body->subtype, sizeof(mtype)-strlen(mtype)-1); mtype[sizeof(mtype)-1] = '\0'; } if(!set_mime_extension_by_type(ext, mtype)){ char *p, *extp = NULL; if((p = get_filename_parameter(NULL, 0, h->h.attach->body, &extp)) != NULL){ if(extp){ strncpy(ext, extp, sizeof(ext)); ext[sizeof(ext)-1] = '\0'; } fs_give((void **) &p); } } if(ext[0] && (tmp_file = temp_nam_ext(NULL, "im", ext))){ FILE *f = our_fopen(tmp_file, "w"); mswin_registericon(x, h->key, tmp_file); fclose(f); our_unlink(tmp_file); fs_give((void **)&tmp_file); } } } #endif if(is_inv){ dprint((9, "INVERSE left on at end of line, turning off now\n")); EndInverse(); } if(is_bold){ dprint((9, "BOLD left on at end of line, turning off now\n")); EndBold(); } if(is_uline){ dprint((9, "UNDERLINE left on at end of line, turning off now\n")); EndUnderline(); } if(is_fg || is_bg) pico_set_normal_color(); }