Changeset 237d02c


Ignore:
Timestamp:
Feb 26, 2011, 12:58:30 AM (13 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.8, release-1.9
Children:
cb6c9e1
Parents:
7659079
git-author:
David Benjamin <davidben@mit.edu> (02/25/11 15:25:58)
git-committer:
David Benjamin <davidben@mit.edu> (02/26/11 00:58:30)
Message:
Remove default_{attrs,fgcolor,bgcolor} from owl_fmtext

They didn't quite behave when appending two owl_fmtexts together; what
does it mean to append a string whose default color is red to one whose
default color is blue? (And then you set the default to green
afterwards...)

Now owl_fmtext is merely a unicode string with formatting characters.
Default attributes are instead a property of how you view the string and
are passed to owl_fmtext_curs_waddstr. Which unfortunately means it has
a lot of arguments. :-/
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • fmtext.c

    r7659079 r237d02c  
    77{
    88  f->buff = g_string_new("");
    9   f->default_attrs = OWL_FMTEXT_ATTR_NONE;
    10   f->default_fgcolor = OWL_COLOR_DEFAULT;
    11   f->default_bgcolor = OWL_COLOR_DEFAULT;
    129}
    1310
     
    1714{
    1815  g_string_truncate(f->buff, 0);
    19   f->default_attrs = OWL_FMTEXT_ATTR_NONE;
    20   f->default_fgcolor = OWL_COLOR_DEFAULT;
    21   f->default_bgcolor = OWL_COLOR_DEFAULT;
    2216}
    2317
     
    10094}
    10195
    102 /* Add the attribute 'attr' to the default atts for the text in 'f' */
    103 void owl_fmtext_addattr(owl_fmtext *f, char attr)
    104 {
    105   /* add the attribute to all text */
    106   f->default_attrs |= attr;
    107 }
    108 
    109 /* Set the default foreground color for this fmtext to 'color'.
    110  * Only affects text that is colored default.
    111  */
    112 void owl_fmtext_colorize(owl_fmtext *f, int color)
    113 {
    114   f->default_fgcolor = color;
    115 }
    116 
    117 /* Set the default foreground color for this fmtext to 'color'.
    118  * Only affects text that is colored default.
    119  */
    120 void owl_fmtext_colorizebg(owl_fmtext *f, int color)
    121 {
    122   f->default_bgcolor = color;
    123 }
    124 
    12596/* Internal function. Parse attrbute character. */
    12697static void _owl_fmtext_update_attributes(gunichar c, char *attr, short *fgcolor, short *bgcolor)
     
    235206 * must already be initiatlized with curses
    236207 */
    237 static void _owl_fmtext_curs_waddstr(const owl_fmtext *f, WINDOW *w, int do_search)
     208static void _owl_fmtext_curs_waddstr(const owl_fmtext *f, WINDOW *w, int do_search, char default_attrs, short default_fgcolor, short default_bgcolor)
    238209{
    239210  /* char *tmpbuff; */
     
    250221  s = f->buff->str;
    251222  /* Set default attributes. */
    252   attr = f->default_attrs;
    253   fg = f->default_fgcolor;
    254   bg = f->default_bgcolor;
     223  attr = default_attrs;
     224  fg = default_fgcolor;
     225  bg = default_bgcolor;
    255226  _owl_fmtext_wattrset(w, attr);
    256227  _owl_fmtext_update_colorpair(fg, bg, &pair);
     
    295266      /* Deal with new attributes. Initialize to defaults, then
    296267         process all consecutive formatting characters. */
    297       attr = f->default_attrs;
    298       fg = f->default_fgcolor;
    299       bg = f->default_bgcolor;
     268      attr = default_attrs;
     269      fg = default_fgcolor;
     270      bg = default_bgcolor;
    300271      while (owl_fmtext_is_format_char(g_utf8_get_char(p))) {
    301272        _owl_fmtext_update_attributes(g_utf8_get_char(p), &attr, &fg, &bg);
    302273        p = g_utf8_next_char(p);
    303274      }
    304       _owl_fmtext_wattrset(w, attr | f->default_attrs);
    305       if (fg == OWL_COLOR_DEFAULT) fg = f->default_fgcolor;
    306       if (bg == OWL_COLOR_DEFAULT) bg = f->default_bgcolor;
     275      _owl_fmtext_wattrset(w, attr | default_attrs);
     276      if (fg == OWL_COLOR_DEFAULT) fg = default_fgcolor;
     277      if (bg == OWL_COLOR_DEFAULT) bg = default_bgcolor;
    307278      _owl_fmtext_update_colorpair(fg, bg, &pair);
    308279      _owl_fmtext_wcolor_set(w, pair);
     
    322293}
    323294
    324 void owl_fmtext_curs_waddstr(const owl_fmtext *f, WINDOW *w)
    325 {
    326   _owl_fmtext_curs_waddstr(f, w, 1);
    327 }
    328 
    329 void owl_fmtext_curs_waddstr_without_search(const owl_fmtext *f, WINDOW *w)
    330 {
    331   _owl_fmtext_curs_waddstr(f, w, 0);
     295void owl_fmtext_curs_waddstr(const owl_fmtext *f, WINDOW *w, char default_attrs, short default_fgcolor, short default_bgcolor)
     296{
     297  _owl_fmtext_curs_waddstr(f, w, 1, default_attrs, default_fgcolor, default_bgcolor);
     298}
     299
     300void owl_fmtext_curs_waddstr_without_search(const owl_fmtext *f, WINDOW *w, char default_attrs, short default_fgcolor, short default_bgcolor)
     301{
     302  _owl_fmtext_curs_waddstr(f, w, 0, default_attrs, default_fgcolor, default_bgcolor);
    332303}
    333304
     
    336307  int col = start, numcopied = 0;
    337308  char *ptr;
    338 
    339   /* Copy the default attributes. */
    340   out->default_attrs = in->default_attrs;
    341   out->default_fgcolor = in->default_fgcolor;
    342   out->default_bgcolor = in->default_bgcolor;
    343309
    344310  for (ptr = in->buff->str;
     
    387353  /* ptr1 now holds the starting point */
    388354
    389   /* copy the default attributes */
    390   out->default_attrs = in->default_attrs;
    391   out->default_fgcolor = in->default_fgcolor;
    392   out->default_bgcolor = in->default_bgcolor;
    393    
    394355  /* copy in the next 'lines' lines */
    395356  if (lines < 1) return(-1);
     
    415376  const char *ptr_s, *ptr_e, *ptr_c, *last;
    416377  int col, st, padding, chwidth;
    417 
    418   /* copy the default attributes */
    419   out->default_attrs = in->default_attrs;
    420   out->default_fgcolor = in->default_fgcolor;
    421   out->default_bgcolor = in->default_bgcolor;
    422378
    423379  last = in->buff->str + in->buff->len - 1;
     
    588544{
    589545  dst->buff = g_string_new(src->buff->str);
    590   dst->default_attrs = src->default_attrs;
    591   dst->default_fgcolor = src->default_fgcolor;
    592   dst->default_bgcolor = src->default_bgcolor;
    593546}
    594547
  • message.c

    r3472845 r237d02c  
    525525  owl_fmtext_truncate_lines(&(m->fmtext->fmtext), aline, bline-aline, &a);
    526526  owl_fmtext_truncate_cols(&a, acol, bcol, &b);
    527   owl_fmtext_colorize(&b, fgcolor);
    528   owl_fmtext_colorizebg(&b, bgcolor);
    529 
    530   owl_fmtext_curs_waddstr(&b, win);
     527
     528  owl_fmtext_curs_waddstr(&b, win, OWL_FMTEXT_ATTR_NONE, fgcolor, bgcolor);
    531529
    532530  owl_fmtext_cleanup(&a);
  • owl.h

    r7659079 r237d02c  
    276276typedef struct _owl_fmtext {
    277277  GString *buff;
    278   char default_attrs;
    279   short default_fgcolor;
    280   short default_bgcolor;
    281278} owl_fmtext;
    282279
  • viewwin.c

    rddbbcffa r237d02c  
    106106  owl_fmtext_truncate_cols(&fm1, v->rightshift, wincols-1+v->rightshift, &fm2);
    107107
    108   owl_fmtext_curs_waddstr(&fm2, curswin);
     108  owl_fmtext_curs_waddstr(&fm2, curswin, OWL_FMTEXT_ATTR_NONE, OWL_COLOR_DEFAULT, OWL_COLOR_DEFAULT);
    109109
    110110  owl_fmtext_cleanup(&fm1);
Note: See TracChangeset for help on using the changeset viewer.