Example #1
0
/*
 *     Start or end bold mode
 *
 * Result: escape sequence to go into or out of reverse color is output
 *
 *     (This is only called when there is a reverse color.)
 *
 * Arg   state = ON   set bold
 *               OFF  set normal
 */
void
flip_rev_color(int state)
{
    if((rev_color_state = state) == TRUE)
      (void)pico_set_colorp(the_rev_color, PSC_NONE);
    else
      pico_set_normal_color();
}
Example #2
0
/*
 * 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);
}
Example #3
0
/*----------------------------------------------------------------------
  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();

}