Changeset 8fa9562


Ignore:
Timestamp:
Jan 20, 2007, 9:49:55 PM (17 years ago)
Author:
Alejandro R. Sedeño <asedeno@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
575877f
Parents:
212764e
Message:
Added background color support to owl.

If we run out of color pairs during a painting of the screen, further
background colors will be silently dropped. I'm hoping this doesn't
happen often. The used pair list is reset with each draw, so only
what's actually on screen matters.
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    r12e5f17 r8fa9562  
    503503  OWLCMD_ARGS("filter", owl_command_filter, OWL_CTX_ANY,
    504504              "create a message filter",
    505               "filter <name> [ -c color ] [ <expression> ... ]",
     505              "filter <name> [ -c fgcolor ] [ -b bgcolor ] [ <expression> ... ]",
    506506              "The filter command creates a filter with the specified name,\n"
    507507              "or if one already exists it is replaced.  Example filter\n"
     
    533533              "    false\n"
    534534              "Spaces must be present before and after parenthesis.  If the\n"
    535               "optional color argument is used it specifies the color that\n"
     535              "optional color arguments are used they specifies the colors that\n"
    536536              "messages matching this filter should be displayed in.\n\n"
    537537              "SEE ALSO: view, viewclass, viewuser\n"),
    538538
    539539  OWLCMD_ARGS("colorview", owl_command_colorview, OWL_CTX_INTERACTIVE,
    540               "change the color on the current filter",
    541               "colorview <color>",
    542               "The color of messages in the current filter will be changed\n"
    543               "to <color>.  Use the 'show colors' command for a list\n"
     540              "change the colors on the current filter",
     541              "colorview <fgcolor> [<bgcolor>]",
     542              "The colors of messages in the current filter will be changed\n"
     543              "to <fgcolor>,<bgcolor>.  Use the 'show colors' command for a list\n"
    544544              "of valid colors.\n\n"
    545545              "SEE ALSO: 'show colors'\n"),
     
    547547  OWLCMD_ARGS("colorclass", owl_command_colorclass, OWL_CTX_INTERACTIVE,
    548548              "create a filter to color messages of the given class name",
    549               "colorclass <class> <color>",
     549              "colorclass <class> <fgcolor> [<bgcolor>]",
    550550              "A filter will be created to color messages in <class>"
    551               "in <color>.  Use the 'show colors' command for a list\n"
     551              "in <fgcolor>,<bgcolor>.  Use the 'show colors' command for a list\n"
    552552              "of valid colors.\n\n"
    553553              "SEE ALSO: 'show colors'\n"),
     
    22532253char *owl_command_colorview(int argc, char **argv, char *buff)
    22542254{
    2255   if (argc!=2) {
     2255  if (argc < 2 || argc > 3) {
    22562256    owl_function_makemsg("Wrong number of arguments to colorview command");
    22572257    return NULL;
    22582258  }
    2259   owl_function_color_current_filter(argv[1]);
     2259  owl_function_color_current_filter(argv[1], (argc == 3 ? argv[2] : NULL));
    22602260  return NULL;
    22612261}
     
    22652265  char *filtname;
    22662266 
    2267   if (argc!=3) {
     2267  if (argc < 3 || argc > 4) {
    22682268    owl_function_makemsg("Wrong number of arguments to colorclass command");
    22692269    return NULL;
     
    22712271
    22722272  filtname=owl_function_classinstfilt(argv[1], NULL);
    2273   (void) owl_function_color_filter(filtname, argv[2]);
     2273  (void) owl_function_color_filter(filtname, argv[2], (argc == 4 ? argv[3] : NULL));
    22742274  return NULL;
    22752275}
  • filter.c

    r446aa2b r8fa9562  
    2121  f->name=owl_strdup(name);
    2222  f->polarity=0;
    23   f->color=OWL_COLOR_DEFAULT;
     23  f->fgcolor=OWL_COLOR_DEFAULT;
     24  f->bgcolor=OWL_COLOR_DEFAULT;
    2425  f->cachedmsgid=-1;
    2526
    2627  /* first take arguments that have to come first */
    2728  /* set the color */
    28   if (argc>=2 && !strcmp(argv[0], "-c")) {
     29  while ( argc>=2 && ( !strcmp(argv[0], "-c") ||
     30                       !strcmp(argv[0], "-b") ) ) {
    2931    if (owl_util_string_to_color(argv[1])==-1) {
    3032      owl_function_error("The color '%s' is not available, using default.", argv[1]);
    3133    } else {
    32       f->color=owl_util_string_to_color(argv[1]);
     34      switch (argv[0][1]) {
     35      case 'c':
     36        f->fgcolor=owl_util_string_to_color(argv[1]);
     37        break;
     38      case 'b':
     39        f->bgcolor=owl_util_string_to_color(argv[1]);
     40        break;
     41      }
    3342    }
    3443    argc-=2;
     
    159168}
    160169
    161 void owl_filter_set_color(owl_filter *f, int color)
    162 {
    163   f->color=color;
    164 }
    165 
    166 int owl_filter_get_color(owl_filter *f)
    167 {
    168   return(f->color);
     170void owl_filter_set_fgcolor(owl_filter *f, int color)
     171{
     172  f->fgcolor=color;
     173}
     174
     175int owl_filter_get_fgcolor(owl_filter *f)
     176{
     177  return(f->fgcolor);
     178}
     179
     180void owl_filter_set_bgcolor(owl_filter *f, int color)
     181{
     182  f->bgcolor=color;
     183}
     184
     185int owl_filter_get_bgcolor(owl_filter *f)
     186{
     187  return(f->bgcolor);
    169188}
    170189
     
    196215  strcat(out, ": ");
    197216
    198   if (f->color!=OWL_COLOR_DEFAULT) {
     217  if (f->fgcolor!=OWL_COLOR_DEFAULT) {
    199218    strcat(out, "-c ");
    200     strcat(out, owl_util_color_to_string(f->color));
     219    strcat(out, owl_util_color_to_string(f->fgcolor));
     220    strcat(out, " ");
     221  }
     222  if (f->bgcolor!=OWL_COLOR_DEFAULT) {
     223    strcat(out, "-b ");
     224    strcat(out, owl_util_color_to_string(f->bgcolor));
    201225    strcat(out, " ");
    202226  }
  • fmtext.c

    ra0a5179 r8fa9562  
    1111  f->textbuff=owl_strdup("");
    1212  f->fmbuff=owl_malloc(5);
    13   f->colorbuff=owl_malloc(5);
     13  f->fgcolorbuff=owl_malloc(5);
     14  f->bgcolorbuff=owl_malloc(5);
    1415  f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE;
    15   f->colorbuff[0]=OWL_COLOR_DEFAULT;
     16  f->fgcolorbuff[0]=OWL_COLOR_DEFAULT;
     17  f->bgcolorbuff[0]=OWL_COLOR_DEFAULT;
    1618}
    1719
     
    4143 * to index 'last
    4244 */
    43 void _owl_fmtext_set_color(owl_fmtext *f, int color, int first, int last)
     45void _owl_fmtext_set_fgcolor(owl_fmtext *f, int color, int first, int last)
    4446{
    4547  int i;
    4648  for (i=first; i<=last; i++) {
    47     f->colorbuff[i]=(unsigned char) color;
     49    f->fgcolorbuff[i]=(unsigned char) color;
     50  }
     51}
     52
     53void _owl_fmtext_set_bgcolor(owl_fmtext *f, int color, int first, int last)
     54{
     55  int i;
     56  for (i=first; i<=last; i++) {
     57    f->bgcolorbuff[i]=(unsigned char) color;
    4858  }
    4959}
     
    5262 * 'color'
    5363 */
    54 void owl_fmtext_append_attr(owl_fmtext *f, char *text, int attr, int color)
     64void owl_fmtext_append_attr(owl_fmtext *f, char *text, int attr, int fgcolor, int bgcolor)
    5565{
    5666  int newlen;
     
    5969  f->textbuff=owl_realloc(f->textbuff, newlen+2);
    6070  f->fmbuff=owl_realloc(f->fmbuff, newlen+2);
    61   f->colorbuff=owl_realloc(f->colorbuff, newlen+2);
     71  f->fgcolorbuff=owl_realloc(f->fgcolorbuff, newlen+2);
     72  f->bgcolorbuff=owl_realloc(f->bgcolorbuff, newlen+2);
    6273
    6374  strcat(f->textbuff, text);
    6475  _owl_fmtext_set_attr(f, attr, f->textlen, newlen);
    65   _owl_fmtext_set_color(f, color, f->textlen, newlen);
     76  _owl_fmtext_set_fgcolor(f, fgcolor, f->textlen, newlen);
     77  _owl_fmtext_set_bgcolor(f, bgcolor, f->textlen, newlen);
    6678  f->textlen=newlen;
    6779}
     
    7082void owl_fmtext_append_normal(owl_fmtext *f, char *text)
    7183{
    72   owl_fmtext_append_attr(f, text, OWL_FMTEXT_ATTR_NONE, OWL_COLOR_DEFAULT);
     84  owl_fmtext_append_attr(f, text, OWL_FMTEXT_ATTR_NONE, OWL_COLOR_DEFAULT, OWL_COLOR_DEFAULT);
    7385}
    7486
    7587/* Append normal text 'text' to 'f' with color 'color' */
    76 void owl_fmtext_append_normal_color(owl_fmtext *f, char *text, int color)
    77 {
    78   owl_fmtext_append_attr(f, text, OWL_FMTEXT_ATTR_NONE, color);
     88void owl_fmtext_append_normal_color(owl_fmtext *f, char *text, int fgcolor, int bgcolor)
     89{
     90  owl_fmtext_append_attr(f, text, OWL_FMTEXT_ATTR_NONE, fgcolor, bgcolor);
    7991}
    8092
     
    8294void owl_fmtext_append_bold(owl_fmtext *f, char *text)
    8395{
    84   owl_fmtext_append_attr(f, text, OWL_FMTEXT_ATTR_BOLD, OWL_COLOR_DEFAULT);
     96  owl_fmtext_append_attr(f, text, OWL_FMTEXT_ATTR_BOLD, OWL_COLOR_DEFAULT, OWL_COLOR_DEFAULT);
    8597}
    8698
     
    88100void owl_fmtext_append_reverse(owl_fmtext *f, char *text)
    89101{
    90   owl_fmtext_append_attr(f, text, OWL_FMTEXT_ATTR_REVERSE, OWL_COLOR_DEFAULT);
     102  owl_fmtext_append_attr(f, text, OWL_FMTEXT_ATTR_REVERSE, OWL_COLOR_DEFAULT, OWL_COLOR_DEFAULT);
    91103}
    92104
     
    94106void owl_fmtext_append_reversebold(owl_fmtext *f, char *text)
    95107{
    96   owl_fmtext_append_attr(f, text, OWL_FMTEXT_ATTR_REVERSE | OWL_FMTEXT_ATTR_BOLD, OWL_COLOR_DEFAULT);
     108  owl_fmtext_append_attr(f, text, OWL_FMTEXT_ATTR_REVERSE | OWL_FMTEXT_ATTR_BOLD, OWL_COLOR_DEFAULT, OWL_COLOR_DEFAULT);
    97109}
    98110
     
    114126void owl_fmtext_colorize(owl_fmtext *f, int color)
    115127{
    116   /* everywhere the color is OWL_COLOR_DEFAULT, change it to be 'color' */
     128  /* everywhere the fgcolor is OWL_COLOR_DEFAULT, change it to be 'color' */
    117129  int i, j;
    118130
    119131  j=f->textlen;
    120132  for(i=0; i<j; i++) {
    121     if (f->colorbuff[i]==OWL_COLOR_DEFAULT) f->colorbuff[i] = color;
     133    if (f->fgcolorbuff[i]==OWL_COLOR_DEFAULT) f->fgcolorbuff[i] = color;
     134  }
     135}
     136
     137void owl_fmtext_colorizebg(owl_fmtext *f, int color)
     138{
     139  /* everywhere the bgcolor is OWL_COLOR_DEFAULT, change it to be 'color' */
     140  int i, j;
     141
     142  j=f->textlen;
     143  for(i=0; i<j; i++) {
     144    if (f->bgcolorbuff[i]==OWL_COLOR_DEFAULT) f->bgcolorbuff[i] = color;
    122145  }
    123146}
     
    133156  f->textbuff=owl_realloc(f->textbuff, newlen+1);
    134157  f->fmbuff=owl_realloc(f->fmbuff, newlen+1);
    135   f->colorbuff=owl_realloc(f->colorbuff, newlen+1);
     158  f->fgcolorbuff=owl_realloc(f->fgcolorbuff, newlen+1);
     159  f->bgcolorbuff=owl_realloc(f->bgcolorbuff, newlen+1);
    136160
    137161  strncat(f->textbuff, in->textbuff+start, stop-start+1);
     
    139163  for (i=start; i<=stop; i++) {
    140164    f->fmbuff[f->textlen+(i-start)]=in->fmbuff[i];
    141     f->colorbuff[f->textlen+(i-start)]=in->colorbuff[i];
     165    f->fgcolorbuff[f->textlen+(i-start)]=in->fgcolorbuff[i];
     166    f->bgcolorbuff[f->textlen+(i-start)]=in->bgcolorbuff[i];
    142167  }
    143168  f->textlen=newlen;
     
    174199{
    175200  char *tmpbuff;
    176   int position, trans1, trans2, len, lastsame;
     201  int position, trans1, trans2, trans3, len, lastsame;
    177202
    178203  if (w==NULL) {
     
    188213    /* find the last char with the current format and color */
    189214    trans1=owl_util_find_trans(f->fmbuff+position, len-position);
    190     trans2=owl_util_find_trans(f->colorbuff+position, len-position);
    191 
    192     if (trans1<trans2) {
    193       lastsame=position+trans1;
    194     } else {
    195       lastsame=position+trans2;
    196     }
     215    trans2=owl_util_find_trans(f->fgcolorbuff+position, len-position);
     216    trans3=owl_util_find_trans(f->bgcolorbuff+position, len-position);
     217
     218    lastsame = (trans1 < trans2) ? trans1 : trans2;
     219    lastsame = (lastsame < trans3) ? lastsame : trans3;
     220    lastsame += position;
    197221
    198222    /* set the format */
     
    211235    /* warning, this is sort of a hack */
    212236    if (owl_global_get_hascolors(&g)) {
    213       if (f->colorbuff[position]!=OWL_COLOR_DEFAULT) {
    214         wattron(w, COLOR_PAIR(f->colorbuff[position]));
     237      int pair, fg, bg;
     238      fg = f->fgcolorbuff[position];
     239      bg = f->bgcolorbuff[position];
     240      owl_function_debugmsg("waddstr: fg(%i) bg(%i).", fg, bg);
     241
     242      pair = owl_fmtext_get_colorpair(fg, bg);
     243      if (pair != -1) {
     244        wattron(w, COLOR_PAIR(pair));
    215245      }
    216246    }
     
    355385  dst->textbuff=owl_malloc(mallocsize);
    356386  dst->fmbuff=owl_malloc(mallocsize);
    357   dst->colorbuff=owl_malloc(mallocsize);
     387  dst->fgcolorbuff=owl_malloc(mallocsize);
     388  dst->bgcolorbuff=owl_malloc(mallocsize);
    358389  memcpy(dst->textbuff, src->textbuff, src->textlen+1);
    359390  memcpy(dst->fmbuff, src->fmbuff, src->textlen);
    360   memcpy(dst->colorbuff, src->colorbuff, src->textlen);
     391  memcpy(dst->fgcolorbuff, src->fgcolorbuff, src->textlen);
     392  memcpy(dst->bgcolorbuff, src->bgcolorbuff, src->textlen);
    361393}
    362394
     
    415447    if (!ptr) {
    416448      /* add all the rest of the text and exit */
    417       owl_fmtext_append_attr(f, txtptr, curattrs, curcolor);
     449      owl_fmtext_append_attr(f, txtptr, curattrs, curcolor, OWL_COLOR_DEFAULT);
    418450      return;
    419451    } else if (ptr[0]=='@') {
     
    422454      strncpy(buff, txtptr, ptr-txtptr);
    423455      buff[ptr-txtptr]='\0';
    424       owl_fmtext_append_attr(f, buff, curattrs, curcolor);
     456      owl_fmtext_append_attr(f, buff, curattrs, curcolor, OWL_COLOR_DEFAULT);
    425457      owl_free(buff);
    426458
     
    432464      /* if we've hit our max stack depth, print the @ and move on */
    433465      if (stacksize==32) {
    434         owl_fmtext_append_attr(f, "@", curattrs, curcolor);
     466        owl_fmtext_append_attr(f, "@", curattrs, curcolor, OWL_COLOR_DEFAULT);
    435467        txtptr++;
    436468        continue;
     
    439471      /* if it's an @@, print an @ and continue */
    440472      if (txtptr[1]=='@') {
    441         owl_fmtext_append_attr(f, "@", curattrs, curcolor);
     473        owl_fmtext_append_attr(f, "@", curattrs, curcolor, OWL_COLOR_DEFAULT);
    442474        txtptr+=2;
    443475        continue;
     
    447479      tmpptr=strpbrk(txtptr, "(<[{ ");
    448480      if (!tmpptr || tmpptr[0]==' ') {
    449         owl_fmtext_append_attr(f, "@", curattrs, curcolor);
     481        owl_fmtext_append_attr(f, "@", curattrs, curcolor, OWL_COLOR_DEFAULT);
    450482        txtptr++;
    451483        continue;
     
    524556         * but zwgc seems to be smarter about some screw cases than I am
    525557         */
    526         owl_fmtext_append_attr(f, "@", curattrs, curcolor);
     558        owl_fmtext_append_attr(f, "@", curattrs, curcolor, OWL_COLOR_DEFAULT);
    527559        txtptr++;
    528560        continue;
     
    534566      strncpy(buff, txtptr, ptr-txtptr);
    535567      buff[ptr-txtptr]='\0';
    536       owl_fmtext_append_attr(f, buff, curattrs, curcolor);
     568      owl_fmtext_append_attr(f, buff, curattrs, curcolor, OWL_COLOR_DEFAULT);
    537569      owl_free(buff);
    538570
     
    545577        buff[0]=ptr[0];
    546578        buff[1]='\0';
    547         owl_fmtext_append_attr(f, buff, curattrs, curcolor);
     579        owl_fmtext_append_attr(f, buff, curattrs, curcolor, OWL_COLOR_DEFAULT);
    548580        owl_free(buff);
    549581        txtptr++;
     
    570602        buff[0]=ptr[0];
    571603        buff[1]='\0';
    572         owl_fmtext_append_attr(f, buff, curattrs, curcolor);
     604        owl_fmtext_append_attr(f, buff, curattrs, curcolor, OWL_COLOR_DEFAULT);
    573605        owl_free(buff);
    574606        txtptr++;
     
    580612      strncpy(buff, txtptr, ptr-txtptr+1);
    581613      buff[ptr-txtptr+1]='\0';
    582       owl_fmtext_append_attr(f, buff, curattrs, curcolor);
     614      owl_fmtext_append_attr(f, buff, curattrs, curcolor, OWL_COLOR_DEFAULT);
    583615      owl_free(buff);
    584616      txtptr=ptr+1;
     
    621653  if (f->textbuff) owl_free(f->textbuff);
    622654  if (f->fmbuff) owl_free(f->fmbuff);
    623   if (f->colorbuff) owl_free(f->colorbuff);
    624 }
    625 
     655  if (f->fgcolorbuff) owl_free(f->fgcolorbuff);
     656  if (f->bgcolorbuff) owl_free(f->bgcolorbuff);
     657}
     658
     659/*** Color Pair manager ***/
     660void owl_fmtext_init_colorpair_mgr(owl_colorpair_mgr *cpmgr)
     661{
     662  // This could be a bitarray if we wanted to save memory.
     663  int i, j, colors;
     664  cpmgr->used = owl_malloc(COLOR_PAIRS * sizeof(char));
     665  memset(cpmgr->used, 0, COLOR_PAIRS * sizeof(char));
     666
     667  colors = COLORS + 1; // 1 to account for "default".
     668  cpmgr->pairs = owl_malloc(colors * sizeof(int*));
     669  for(i = 0; i < colors; i++) {
     670    // Because we're going to have a pair set for any fg and the
     671    // default bg, we don't need to account for default here.
     672    cpmgr->pairs[i] = owl_malloc(COLORS * sizeof(int));
     673    for(j = 0; j < COLORS; j++) {
     674      cpmgr->pairs[i][j] = -1;
     675    }
     676  }
     677}
     678
     679/* Reset used list */
     680void owl_fmtext_reset_colorpairs()
     681{
     682  memset(owl_global_get_colorpair_mgr(&g)->used, 0, COLOR_PAIRS * sizeof(char)); 
     683}
     684
     685/* Assign pairs by request */
     686int owl_fmtext_get_colorpair(int fg, int bg)
     687{
     688  owl_colorpair_mgr *cpmgr;
     689  short pair, i;
     690  if (fg == OWL_COLOR_DEFAULT) fg = -1;
     691  if (bg == OWL_COLOR_DEFAULT) {
     692    pair = fg;
     693  } else {
     694    cpmgr = owl_global_get_colorpair_mgr(&g);
     695    pair = cpmgr->pairs[fg+1][bg];
     696    if (pair != -1) {
     697      short oldfg, oldbg;
     698      pair_content(pair, &oldfg, &oldbg);
     699      if (cpmgr->pairs[oldfg+1][oldbg] == pair) {
     700        cpmgr->pairs[oldfg+1][oldbg] = -1;
     701      }
     702      init_pair(pair, fg, bg);
     703      cpmgr->pairs[fg+1][bg] = pair;
     704      cpmgr->used[pair] = 1;
     705    } else {
     706      // Skip the first COLORS, sicne they're static.
     707      for(i = COLORS; i < COLOR_PAIRS; i++) {
     708        if (0 == cpmgr->used[i]) {
     709          pair = i;
     710          break;
     711        }
     712      }
     713      if (pair != -1) {
     714        short oldfg, oldbg;
     715        pair_content(pair, &oldfg, &oldbg);
     716        if (cpmgr->pairs[oldfg+1][oldbg] == pair) {
     717          cpmgr->pairs[oldfg+1][oldbg] = -1;
     718        }
     719        init_pair(pair, fg, bg);
     720        cpmgr->pairs[fg+1][bg] = pair;
     721        cpmgr->used[pair] = 1;
     722      } else {
     723        // Fail to skipping background.
     724        pair = fg;
     725      }
     726    }
     727  }
     728  return pair;
     729}
  • functions.c

    r8203afd r8fa9562  
    24542454      return;
    24552455    }
    2456     owl_filter_set_color(f, owl_util_string_to_color(argv[3]));
     2456    owl_filter_set_fgcolor(f, owl_util_string_to_color(argv[3]));
     2457    owl_global_set_needrefresh(&g);
     2458    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
     2459    return;
     2460  }
     2461  if (argc==4 && !strcmp(argv[2], "-b")) {
     2462    f=owl_global_get_filter(&g, argv[1]);
     2463    if (!f) {
     2464      owl_function_error("The filter '%s' does not exist.", argv[1]);
     2465      return;
     2466    }
     2467    if (owl_util_string_to_color(argv[3])==-1) {
     2468      owl_function_error("The color '%s' is not available.", argv[3]);
     2469      return;
     2470    }
     2471    owl_filter_set_bgcolor(f, owl_util_string_to_color(argv[3]));
    24572472    owl_global_set_needrefresh(&g);
    24582473    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
     
    25452560    owl_fmtext_append_normal(&fm, "   ");
    25462561    if (owl_global_get_hascolors(&g)) {
    2547       owl_fmtext_append_normal_color(&fm, owl_filter_get_name(f), owl_filter_get_color(f));
     2562      owl_fmtext_append_normal_color(&fm, owl_filter_get_name(f), owl_filter_get_fgcolor(f), owl_filter_get_bgcolor(f));
    25482563    } else {
    25492564      owl_fmtext_append_normal(&fm, owl_filter_get_name(f));
     
    29242939 * be 'color'
    29252940 */
    2926 void owl_function_color_current_filter(char *color)
     2941void owl_function_color_current_filter(char *fgcolor, char *bgcolor)
    29272942{
    29282943  char *name;
    29292944
    29302945  name=owl_view_get_filtname(owl_global_get_current_view(&g));
    2931   owl_function_color_filter(name, color);
     2946  owl_function_color_filter(name, fgcolor, bgcolor);
    29322947}
    29332948
     
    29362951 * the "all" filter, return -2.  Return 0 on success
    29372952 */
    2938 int owl_function_color_filter(char *filtname, char *color)
     2953int owl_function_color_filter(char *filtname, char *fgcolor, char *bgcolor)
    29392954{
    29402955  owl_filter *f;
     
    29522967  }
    29532968
    2954   if (owl_util_string_to_color(color)==-1) {
    2955     owl_function_error("No color named '%s' avilable.");
     2969  if (owl_util_string_to_color(fgcolor)==-1) {
     2970    owl_function_error("No color named '%s' avilable.", fgcolor);
    29562971    return(-1);
    29572972  }
    2958   owl_filter_set_color(f, owl_util_string_to_color(color));
     2973
     2974
     2975  if (bgcolor != NULL) {
     2976    if (owl_util_string_to_color(bgcolor)==-1) {
     2977      owl_function_error("No color named '%s' avilable.", bgcolor);
     2978      return(-1);
     2979    }
     2980    owl_filter_set_bgcolor(f, owl_util_string_to_color(bgcolor));
     2981  }
     2982  owl_filter_set_fgcolor(f, owl_util_string_to_color(fgcolor));
     2983 
    29592984  owl_global_set_needrefresh(&g);
    29602985  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
     
    29682993  owl_fmtext_init_null(&fm);
    29692994  owl_fmtext_append_normal(&fm, "default: ");
    2970   owl_fmtext_append_normal_color(&fm, "default\n", OWL_COLOR_DEFAULT);
     2995  owl_fmtext_append_normal_color(&fm, "default\n", OWL_COLOR_DEFAULT, OWL_COLOR_DEFAULT);
    29712996
    29722997  owl_fmtext_append_normal(&fm,"red:      ");
    2973   owl_fmtext_append_normal_color(&fm, "red\n", OWL_COLOR_RED);
     2998  owl_fmtext_append_normal_color(&fm, "red\n", OWL_COLOR_RED, OWL_COLOR_DEFAULT);
    29742999
    29753000  owl_fmtext_append_normal(&fm,"green:    ");
    2976   owl_fmtext_append_normal_color(&fm, "green\n", OWL_COLOR_GREEN);
     3001  owl_fmtext_append_normal_color(&fm, "green\n", OWL_COLOR_GREEN, OWL_COLOR_DEFAULT);
    29773002
    29783003  owl_fmtext_append_normal(&fm,"yellow:   ");
    2979   owl_fmtext_append_normal_color(&fm, "yellow\n", OWL_COLOR_YELLOW);
     3004  owl_fmtext_append_normal_color(&fm, "yellow\n", OWL_COLOR_YELLOW, OWL_COLOR_DEFAULT);
    29803005
    29813006  owl_fmtext_append_normal(&fm,"blue:     ");
    2982   owl_fmtext_append_normal_color(&fm, "blue\n", OWL_COLOR_BLUE);
     3007  owl_fmtext_append_normal_color(&fm, "blue\n", OWL_COLOR_BLUE, OWL_COLOR_DEFAULT);
    29833008
    29843009  owl_fmtext_append_normal(&fm,"magenta:  ");
    2985   owl_fmtext_append_normal_color(&fm, "magenta\n", OWL_COLOR_MAGENTA);
     3010  owl_fmtext_append_normal_color(&fm, "magenta\n", OWL_COLOR_MAGENTA, OWL_COLOR_DEFAULT);
    29863011
    29873012  owl_fmtext_append_normal(&fm,"cyan:     ");
    2988   owl_fmtext_append_normal_color(&fm, "cyan\n", OWL_COLOR_CYAN);
     3013  owl_fmtext_append_normal_color(&fm, "cyan\n", OWL_COLOR_CYAN, OWL_COLOR_DEFAULT);
    29893014
    29903015  owl_fmtext_append_normal(&fm,"white:    ");
    2991   owl_fmtext_append_normal_color(&fm, "white\n", OWL_COLOR_WHITE);
     3016  owl_fmtext_append_normal_color(&fm, "white\n", OWL_COLOR_WHITE, OWL_COLOR_DEFAULT);
    29923017
    29933018  owl_function_popless_fmtext(&fm);
  • global.c

    rcb769bb r8fa9562  
    6464  }
    6565  g->colorpairs=COLOR_PAIRS;
     66  owl_fmtext_init_colorpair_mgr(&(g->cpmgr));
    6667  g->debug=OWL_DEBUG;
    6768  g->searchactive=0;
     
    592593}
    593594
     595owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
     596  return(&(g->cpmgr));
     597}
     598
    594599/* puntlist */
    595600
  • mainwin.c

    r37eab7f r8fa9562  
    1414  int i, p, q, lines, isfull, viewsize;
    1515  int x, y, savey, recwinlines, start;
    16   int topmsg, curmsg, color;
     16  int topmsg, curmsg, fgcolor, bgcolor;
    1717  WINDOW *recwin;
    1818  owl_view *v;
     
    2424  curmsg=owl_global_get_curmsg(&g);
    2525  v=owl_global_get_current_view(&g);
     26  owl_fmtext_reset_colorpairs();
    2627
    2728  if (v==NULL) {
     
    7273
    7374    /* if we match filters set the color */
    74     color=OWL_COLOR_DEFAULT;
     75    fgcolor=OWL_COLOR_DEFAULT;
     76    bgcolor=OWL_COLOR_DEFAULT;
    7577    filtlist=owl_global_get_filterlist(&g);
    7678    q=owl_list_get_size(filtlist);
     
    7880      f=owl_list_get_element(filtlist, p);
    7981      if (owl_filter_message_match(f, m)) {
    80         if (owl_filter_get_color(f)!=OWL_COLOR_DEFAULT) color=owl_filter_get_color(f);
     82        if (owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) fgcolor=owl_filter_get_fgcolor(f);
     83        if (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT) bgcolor=owl_filter_get_bgcolor(f);
    8184      }
    8285    }
     
    9295                               owl_global_get_rightshift(&g),
    9396                               owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
    94                                color);
     97                               fgcolor, bgcolor);
    9598    } else {
    9699      /* otherwise print the whole thing */
     
    100103                               owl_global_get_rightshift(&g),
    101104                               owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
    102                                color);
     105                               fgcolor, bgcolor);
    103106    }
    104107
  • message.c

    rf4d32cd r8fa9562  
    516516}
    517517
    518 void owl_message_curs_waddstr(owl_message *m, WINDOW *win, int aline, int bline, int acol, int bcol, int color)
     518void owl_message_curs_waddstr(owl_message *m, WINDOW *win, int aline, int bline, int acol, int bcol, int fgcolor, int bgcolor)
    519519{
    520520  owl_fmtext a, b;
     
    528528  owl_fmtext_truncate_lines(&(m->fmtext), aline, bline-aline+1, &a);
    529529  owl_fmtext_truncate_cols(&a, acol, bcol, &b);
    530   if (color!=OWL_COLOR_DEFAULT) {
    531     owl_fmtext_colorize(&b, color);
     530  if (fgcolor!=OWL_COLOR_DEFAULT) {
     531    owl_fmtext_colorize(&b, fgcolor);
     532  }
     533  if (bgcolor!=OWL_COLOR_DEFAULT) {
     534    owl_fmtext_colorizebg(&b, bgcolor);
    532535  }
    533536
  • owl.c

    r212764e r8fa9562  
    177177  /* define simple color pairs */
    178178  if (has_colors() && COLOR_PAIRS>=8) {
    179     init_pair(OWL_COLOR_BLACK,   COLOR_BLACK,   -1);
    180     init_pair(OWL_COLOR_RED,     COLOR_RED,     -1);
    181     init_pair(OWL_COLOR_GREEN,   COLOR_GREEN,   -1);
    182     init_pair(OWL_COLOR_YELLOW,  COLOR_YELLOW,  -1);
    183     init_pair(OWL_COLOR_BLUE,    COLOR_BLUE,    -1);
    184     init_pair(OWL_COLOR_MAGENTA, COLOR_MAGENTA, -1);
    185     init_pair(OWL_COLOR_CYAN,    COLOR_CYAN,    -1);
    186     init_pair(OWL_COLOR_WHITE,   COLOR_WHITE,   -1);
     179    int bg = COLOR_BLACK;
     180#ifdef HAVE_USE_DEFAULT_COLORS
     181    bg = -1;
     182#endif
     183    init_pair(OWL_COLOR_BLACK,   COLOR_BLACK,   bg);
     184    init_pair(OWL_COLOR_RED,     COLOR_RED,     bg);
     185    init_pair(OWL_COLOR_GREEN,   COLOR_GREEN,   bg);
     186    init_pair(OWL_COLOR_YELLOW,  COLOR_YELLOW,  bg);
     187    init_pair(OWL_COLOR_BLUE,    COLOR_BLUE,    bg);
     188    init_pair(OWL_COLOR_MAGENTA, COLOR_MAGENTA, bg);
     189    init_pair(OWL_COLOR_CYAN,    COLOR_CYAN,    bg);
     190    init_pair(OWL_COLOR_WHITE,   COLOR_WHITE,   bg);
    187191  }
    188192
  • owl.h

    rcb769bb r8fa9562  
    252252  char *textbuff;
    253253  char *fmbuff;
    254   char *colorbuff;
     254  char *fgcolorbuff;
     255  char *bgcolorbuff;
    255256} owl_fmtext;
    256257
     
    415416  int polarity;
    416417  owl_filterelement * root;
    417   int color;
     418  int fgcolor;
     419  int bgcolor;
    418420  int cachedmsgid;  /* cached msgid: should move into view eventually */
    419421} owl_filter;
     
    513515  owl_list errlist;
    514516} owl_errqueue;
     517
     518typedef struct _owl_colorpair_mgr {
     519  char *used;
     520  int **pairs;
     521} owl_colorpair_mgr;
    515522
    516523typedef struct _owl_global {
     
    556563  int hascolors;
    557564  int colorpairs;
     565  owl_colorpair_mgr cpmgr;
    558566  int searchactive;
    559567  int newmsgproc_pid;
  • perl/modules/jabber.pl

    re1b197e8 r8fa9562  
    7373
    7474    $muc->Leave();
    75    
    7675    $self->{_BARNOWL_MUCS} = [grep {$_->BaseJID ne $muc->BaseJID} $self->MUCs];
    7776}
     
    427426        $client->SetPresenceCallBacks(
    428427            available    => sub { BarnOwl::Jabber::process_presence_available(@_) },
    429 #            unavailable  => sub { BarnOwl::Jabber::process_presence_available(@_) },
     428            unavailable  => sub { BarnOwl::Jabber::process_presence_available(@_) },
    430429            subscribe    => sub { BarnOwl::Jabber::process_presence_subscribe(@_) },
    431430            subscribed   => sub { BarnOwl::Jabber::process_presence_subscribed(@_) },
     
    10071006    }
    10081007    $props{replysendercmd} = $props{replycmd} = "jwrite $from -i $sid";
    1009     if(BarnOwl::getvar('debug') eq 'on') {
     1008#    if(BarnOwl::getvar('debug') eq 'on') {
    10101009        BarnOwl::queue_message(BarnOwl::Message->new(%props));
    1011     }
     1010#    }
    10121011}
    10131012
Note: See TracChangeset for help on using the changeset viewer.