Esempio n. 1
0
/* append text to the end of 'f' with attribute 'attr' and color
 * 'color'
 */
void owl_fmtext_append_attr(owl_fmtext *f, const char *text, char attr, short fgcolor, short bgcolor)
{
  char attrbuff[6];
  int newlen, a = 0, fg = 0, bg = 0;
  
  if (attr != OWL_FMTEXT_ATTR_NONE) a=1;
  if (fgcolor != OWL_COLOR_DEFAULT) fg=1;
  if (bgcolor != OWL_COLOR_DEFAULT) bg=1;

  /* Plane-16 characters in UTF-8 are 4 bytes long. */
  newlen = strlen(f->textbuff) + strlen(text) + (8 * (a + fg + bg));
  _owl_fmtext_realloc(f, newlen);

  /* Set attributes */
  if (a)
    strncat(f->textbuff, attrbuff,
	    g_unichar_to_utf8(OWL_FMTEXT_UC_ATTR | attr, attrbuff));
  if (fg)
    strncat(f->textbuff, attrbuff,
	    g_unichar_to_utf8(OWL_FMTEXT_UC_FGCOLOR | fgcolor, attrbuff));
  if (bg)
    strncat(f->textbuff, attrbuff,
	    g_unichar_to_utf8(OWL_FMTEXT_UC_BGCOLOR | bgcolor, attrbuff));
  
  strcat(f->textbuff, text);

  /* Reset attributes */
  if (bg) strcat(f->textbuff, OWL_FMTEXT_UTF8_BGDEFAULT);
  if (fg) strcat(f->textbuff, OWL_FMTEXT_UTF8_FGDEFAULT);
  if (a)  strcat(f->textbuff, OWL_FMTEXT_UTF8_ATTR_NONE);
  f->textlen=newlen;
}
Esempio n. 2
0
/* Internal function.  Append text from 'in' between index 'start' and
 * 'stop', inclusive, to the end of 'f'. This function works with
 * bytes.
 */
void _owl_fmtext_append_fmtext(owl_fmtext *f, owl_fmtext *in, int start, int stop) /*noproto*/
{
  char attrbuff[6];
  int newlen, a = 0, fg = 0, bg = 0;
  char attr = 0;
  short fgcolor = OWL_COLOR_DEFAULT;
  short bgcolor = OWL_COLOR_DEFAULT;

  _owl_fmtext_scan_attributes(in, start, &attr, &fgcolor, &bgcolor);
  if (attr != OWL_FMTEXT_ATTR_NONE) a=1;
  if (fgcolor != OWL_COLOR_DEFAULT) fg=1;
  if (bgcolor != OWL_COLOR_DEFAULT) bg=1;

  /* We will reset to defaults after appending the text. We may need
     to set initial attributes. */
  newlen=strlen(f->textbuff)+(stop-start+1) + (4 * (a + fg + bg)) + 12;
  _owl_fmtext_realloc(f, newlen);

  if (a) {
    memset(attrbuff,0,6);
    g_unichar_to_utf8(OWL_FMTEXT_UC_ATTR | attr, attrbuff);
    strcat(f->textbuff, attrbuff);      
  }
  if (fg) {
    memset(attrbuff,0,6);
    g_unichar_to_utf8(OWL_FMTEXT_UC_FGCOLOR | fgcolor, attrbuff);
    strcat(f->textbuff, attrbuff);      
  }
  if (bg) {
    memset(attrbuff,0,6);
    g_unichar_to_utf8(OWL_FMTEXT_UC_BGCOLOR | bgcolor, attrbuff);
    strcat(f->textbuff, attrbuff);      
  }

  strncat(f->textbuff, in->textbuff+start, stop-start+1);

  /* Reset attributes */
  strcat(f->textbuff, OWL_FMTEXT_UTF8_BGDEFAULT);
  strcat(f->textbuff, OWL_FMTEXT_UTF8_FGDEFAULT);
  strcat(f->textbuff, OWL_FMTEXT_UTF8_ATTR_NONE);

  f->textbuff[newlen]='\0';
  f->textlen=newlen;
}