[401] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[D-O-H] r538 - in trunk/owl: . perl/modules

daemon@ATHENA.MIT.EDU (asedeno@MIT.EDU)
Thu Oct 29 18:05:45 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
To: dirty-owl-hackers@mit.edu
From: asedeno@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Sat, 20 Jan 2007 21:49:55 -0500 (EST)

Author: asedeno
Date: 2007-01-20 21:49:55 -0500 (Sat, 20 Jan 2007)
New Revision: 538

Modified:
   trunk/owl/commands.c
   trunk/owl/filter.c
   trunk/owl/fmtext.c
   trunk/owl/functions.c
   trunk/owl/global.c
   trunk/owl/mainwin.c
   trunk/owl/message.c
   trunk/owl/owl.c
   trunk/owl/owl.h
   trunk/owl/perl/modules/jabber.pl
Log:
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.



Modified: trunk/owl/commands.c
===================================================================
--- trunk/owl/commands.c	2007-01-19 00:09:12 UTC (rev 537)
+++ trunk/owl/commands.c	2007-01-21 02:49:55 UTC (rev 538)
@@ -502,7 +502,7 @@
   
   OWLCMD_ARGS("filter", owl_command_filter, OWL_CTX_ANY,
 	      "create a message filter",
-	      "filter <name> [ -c color ] [ <expression> ... ]",
+	      "filter <name> [ -c fgcolor ] [ -b bgcolor ] [ <expression> ... ]",
 	      "The filter command creates a filter with the specified name,\n"
 	      "or if one already exists it is replaced.  Example filter\n"
 	      "syntax would be:\n\n"
@@ -532,23 +532,23 @@
 	      "    true\n"
 	      "    false\n"
 	      "Spaces must be present before and after parenthesis.  If the\n"
-	      "optional color argument is used it specifies the color that\n"
+	      "optional color arguments are used they specifies the colors that\n"
 	      "messages matching this filter should be displayed in.\n\n"
 	      "SEE ALSO: view, viewclass, viewuser\n"),
 
   OWLCMD_ARGS("colorview", owl_command_colorview, OWL_CTX_INTERACTIVE,
-	      "change the color on the current filter",
-	      "colorview <color>",
-	      "The color of messages in the current filter will be changed\n"
-	      "to <color>.  Use the 'show colors' command for a list\n"
+	      "change the colors on the current filter",
+	      "colorview <fgcolor> [<bgcolor>]",
+	      "The colors of messages in the current filter will be changed\n"
+	      "to <fgcolor>,<bgcolor>.  Use the 'show colors' command for a list\n"
 	      "of valid colors.\n\n"
 	      "SEE ALSO: 'show colors'\n"),
 
   OWLCMD_ARGS("colorclass", owl_command_colorclass, OWL_CTX_INTERACTIVE,
 	      "create a filter to color messages of the given class name",
-	      "colorclass <class> <color>",
+	      "colorclass <class> <fgcolor> [<bgcolor>]",
 	      "A filter will be created to color messages in <class>"
-	      "in <color>.  Use the 'show colors' command for a list\n"
+	      "in <fgcolor>,<bgcolor>.  Use the 'show colors' command for a list\n"
 	      "of valid colors.\n\n"
 	      "SEE ALSO: 'show colors'\n"),
 
@@ -2252,11 +2252,11 @@
 
 char *owl_command_colorview(int argc, char **argv, char *buff)
 {
-  if (argc!=2) {
+  if (argc < 2 || argc > 3) {
     owl_function_makemsg("Wrong number of arguments to colorview command");
     return NULL;
   }
-  owl_function_color_current_filter(argv[1]);
+  owl_function_color_current_filter(argv[1], (argc == 3 ? argv[2] : NULL));
   return NULL;
 }
 
@@ -2264,13 +2264,13 @@
 {
   char *filtname;
   
-  if (argc!=3) {
+  if (argc < 3 || argc > 4) {
     owl_function_makemsg("Wrong number of arguments to colorclass command");
     return NULL;
   }
 
   filtname=owl_function_classinstfilt(argv[1], NULL);
-  (void) owl_function_color_filter(filtname, argv[2]);
+  (void) owl_function_color_filter(filtname, argv[2], (argc == 4 ? argv[3] : NULL));
   return NULL;
 }
 

Modified: trunk/owl/filter.c
===================================================================
--- trunk/owl/filter.c	2007-01-19 00:09:12 UTC (rev 537)
+++ trunk/owl/filter.c	2007-01-21 02:49:55 UTC (rev 538)
@@ -20,16 +20,25 @@
 {
   f->name=owl_strdup(name);
   f->polarity=0;
-  f->color=OWL_COLOR_DEFAULT;
+  f->fgcolor=OWL_COLOR_DEFAULT;
+  f->bgcolor=OWL_COLOR_DEFAULT;
   f->cachedmsgid=-1;
 
   /* first take arguments that have to come first */
   /* set the color */
-  if (argc>=2 && !strcmp(argv[0], "-c")) {
+  while ( argc>=2 && ( !strcmp(argv[0], "-c") ||
+		       !strcmp(argv[0], "-b") ) ) {
     if (owl_util_string_to_color(argv[1])==-1) {
       owl_function_error("The color '%s' is not available, using default.", argv[1]);
     } else {
-      f->color=owl_util_string_to_color(argv[1]);
+      switch (argv[0][1]) {
+      case 'c':
+	f->fgcolor=owl_util_string_to_color(argv[1]);
+	break;
+      case 'b':
+	f->bgcolor=owl_util_string_to_color(argv[1]);
+	break;
+      }
     }
     argc-=2;
     argv+=2;
@@ -158,16 +167,26 @@
   f->polarity=1;
 }
 
-void owl_filter_set_color(owl_filter *f, int color)
+void owl_filter_set_fgcolor(owl_filter *f, int color)
 {
-  f->color=color;
+  f->fgcolor=color;
 }
 
-int owl_filter_get_color(owl_filter *f)
+int owl_filter_get_fgcolor(owl_filter *f)
 {
-  return(f->color);
+  return(f->fgcolor);
 }
 
+void owl_filter_set_bgcolor(owl_filter *f, int color)
+{
+  f->bgcolor=color;
+}
+
+int owl_filter_get_bgcolor(owl_filter *f)
+{
+  return(f->bgcolor);
+}
+
 void owl_filter_set_cachedmsgid(owl_filter *f, int cachedmsgid)
 {
   f->cachedmsgid=cachedmsgid;
@@ -195,11 +214,16 @@
   strcpy(out, owl_filter_get_name(f));
   strcat(out, ": ");
 
-  if (f->color!=OWL_COLOR_DEFAULT) {
+  if (f->fgcolor!=OWL_COLOR_DEFAULT) {
     strcat(out, "-c ");
-    strcat(out, owl_util_color_to_string(f->color));
+    strcat(out, owl_util_color_to_string(f->fgcolor));
     strcat(out, " ");
   }
+  if (f->bgcolor!=OWL_COLOR_DEFAULT) {
+    strcat(out, "-b ");
+    strcat(out, owl_util_color_to_string(f->bgcolor));
+    strcat(out, " ");
+  }
   if(!f->root) return;
   owl_filterelement_print(f->root, out);
   strcat(out, "\n");

Modified: trunk/owl/fmtext.c
===================================================================
--- trunk/owl/fmtext.c	2007-01-19 00:09:12 UTC (rev 537)
+++ trunk/owl/fmtext.c	2007-01-21 02:49:55 UTC (rev 538)
@@ -10,9 +10,11 @@
   f->textlen=0;
   f->textbuff=owl_strdup("");
   f->fmbuff=owl_malloc(5);
-  f->colorbuff=owl_malloc(5);
+  f->fgcolorbuff=owl_malloc(5);
+  f->bgcolorbuff=owl_malloc(5);
   f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE;
-  f->colorbuff[0]=OWL_COLOR_DEFAULT;
+  f->fgcolorbuff[0]=OWL_COLOR_DEFAULT;
+  f->bgcolorbuff[0]=OWL_COLOR_DEFAULT;
 }
 
 /* Internal function.  Set the attribute 'attr' from index 'first' to
@@ -40,60 +42,70 @@
 /* Internal function.  Set the color to be 'color' from index 'first'
  * to index 'last
  */
-void _owl_fmtext_set_color(owl_fmtext *f, int color, int first, int last)
+void _owl_fmtext_set_fgcolor(owl_fmtext *f, int color, int first, int last)
 {
   int i;
   for (i=first; i<=last; i++) {
-    f->colorbuff[i]=(unsigned char) color;
+    f->fgcolorbuff[i]=(unsigned char) color;
   }
 }
 
+void _owl_fmtext_set_bgcolor(owl_fmtext *f, int color, int first, int last)
+{
+  int i;
+  for (i=first; i<=last; i++) {
+    f->bgcolorbuff[i]=(unsigned char) color;
+  }
+}
+
 /* append text to the end of 'f' with attribute 'attr' and color
  * 'color'
  */
-void owl_fmtext_append_attr(owl_fmtext *f, char *text, int attr, int color)
+void owl_fmtext_append_attr(owl_fmtext *f, char *text, int attr, int fgcolor, int bgcolor)
 {
   int newlen;
 
   newlen=strlen(f->textbuff)+strlen(text);
   f->textbuff=owl_realloc(f->textbuff, newlen+2);
   f->fmbuff=owl_realloc(f->fmbuff, newlen+2);
-  f->colorbuff=owl_realloc(f->colorbuff, newlen+2);
+  f->fgcolorbuff=owl_realloc(f->fgcolorbuff, newlen+2);
+  f->bgcolorbuff=owl_realloc(f->bgcolorbuff, newlen+2);
 
   strcat(f->textbuff, text);
   _owl_fmtext_set_attr(f, attr, f->textlen, newlen);
-  _owl_fmtext_set_color(f, color, f->textlen, newlen);
+  _owl_fmtext_set_fgcolor(f, fgcolor, f->textlen, newlen);
+  _owl_fmtext_set_bgcolor(f, bgcolor, f->textlen, newlen);
   f->textlen=newlen;
 }
 
 /* Append normal, uncolored text 'text' to 'f' */
 void owl_fmtext_append_normal(owl_fmtext *f, char *text)
 {
-  owl_fmtext_append_attr(f, text, OWL_FMTEXT_ATTR_NONE, OWL_COLOR_DEFAULT);
+  owl_fmtext_append_attr(f, text, OWL_FMTEXT_ATTR_NONE, OWL_COLOR_DEFAULT, OWL_COLOR_DEFAULT);
 }
 
 /* Append normal text 'text' to 'f' with color 'color' */
-void owl_fmtext_append_normal_color(owl_fmtext *f, char *text, int color)
+void owl_fmtext_append_normal_color(owl_fmtext *f, char *text, int fgcolor, int bgcolor)
 {
-  owl_fmtext_append_attr(f, text, OWL_FMTEXT_ATTR_NONE, color);
+  owl_fmtext_append_attr(f, text, OWL_FMTEXT_ATTR_NONE, fgcolor, bgcolor);
 }
 
 /* Append bold text 'text' to 'f' */
 void owl_fmtext_append_bold(owl_fmtext *f, char *text)
 {
-  owl_fmtext_append_attr(f, text, OWL_FMTEXT_ATTR_BOLD, OWL_COLOR_DEFAULT);
+  owl_fmtext_append_attr(f, text, OWL_FMTEXT_ATTR_BOLD, OWL_COLOR_DEFAULT, OWL_COLOR_DEFAULT);
 }
 
 /* Append reverse video text 'text' to 'f' */
 void owl_fmtext_append_reverse(owl_fmtext *f, char *text)
 {
-  owl_fmtext_append_attr(f, text, OWL_FMTEXT_ATTR_REVERSE, OWL_COLOR_DEFAULT);
+  owl_fmtext_append_attr(f, text, OWL_FMTEXT_ATTR_REVERSE, OWL_COLOR_DEFAULT, OWL_COLOR_DEFAULT);
 }
 
 /* Append reversed and bold, uncolored text 'text' to 'f' */
 void owl_fmtext_append_reversebold(owl_fmtext *f, char *text)
 {
-  owl_fmtext_append_attr(f, text, OWL_FMTEXT_ATTR_REVERSE | OWL_FMTEXT_ATTR_BOLD, OWL_COLOR_DEFAULT);
+  owl_fmtext_append_attr(f, text, OWL_FMTEXT_ATTR_REVERSE | OWL_FMTEXT_ATTR_BOLD, OWL_COLOR_DEFAULT, OWL_COLOR_DEFAULT);
 }
 
 /* Add the attribute 'attr' to all text in 'f' */
@@ -113,15 +125,26 @@
  */
 void owl_fmtext_colorize(owl_fmtext *f, int color)
 {
-  /* everywhere the color is OWL_COLOR_DEFAULT, change it to be 'color' */
+  /* everywhere the fgcolor is OWL_COLOR_DEFAULT, change it to be 'color' */
   int i, j;
 
   j=f->textlen;
   for(i=0; i<j; i++) {
-    if (f->colorbuff[i]==OWL_COLOR_DEFAULT) f->colorbuff[i] = color;
+    if (f->fgcolorbuff[i]==OWL_COLOR_DEFAULT) f->fgcolorbuff[i] = color;
   }
 }
 
+void owl_fmtext_colorizebg(owl_fmtext *f, int color)
+{
+  /* everywhere the bgcolor is OWL_COLOR_DEFAULT, change it to be 'color' */
+  int i, j;
+
+  j=f->textlen;
+  for(i=0; i<j; i++) {
+    if (f->bgcolorbuff[i]==OWL_COLOR_DEFAULT) f->bgcolorbuff[i] = color;
+  }
+}
+
 /* Internal function.  Append text from 'in' between index 'start' and
  * 'stop' to the end of 'f'
  */
@@ -132,13 +155,15 @@
   newlen=strlen(f->textbuff)+(stop-start+1);
   f->textbuff=owl_realloc(f->textbuff, newlen+1);
   f->fmbuff=owl_realloc(f->fmbuff, newlen+1);
-  f->colorbuff=owl_realloc(f->colorbuff, newlen+1);
+  f->fgcolorbuff=owl_realloc(f->fgcolorbuff, newlen+1);
+  f->bgcolorbuff=owl_realloc(f->bgcolorbuff, newlen+1);
 
   strncat(f->textbuff, in->textbuff+start, stop-start+1);
   f->textbuff[newlen]='\0';
   for (i=start; i<=stop; i++) {
     f->fmbuff[f->textlen+(i-start)]=in->fmbuff[i];
-    f->colorbuff[f->textlen+(i-start)]=in->colorbuff[i];
+    f->fgcolorbuff[f->textlen+(i-start)]=in->fgcolorbuff[i];
+    f->bgcolorbuff[f->textlen+(i-start)]=in->bgcolorbuff[i];
   }
   f->textlen=newlen;
 }
@@ -173,7 +198,7 @@
 void owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w)
 {
   char *tmpbuff;
-  int position, trans1, trans2, len, lastsame;
+  int position, trans1, trans2, trans3, len, lastsame;
 
   if (w==NULL) {
     owl_function_debugmsg("Hit a null window in owl_fmtext_curs_waddstr.");
@@ -187,13 +212,12 @@
   while (position<=len) {
     /* find the last char with the current format and color */
     trans1=owl_util_find_trans(f->fmbuff+position, len-position);
-    trans2=owl_util_find_trans(f->colorbuff+position, len-position);
+    trans2=owl_util_find_trans(f->fgcolorbuff+position, len-position);
+    trans3=owl_util_find_trans(f->bgcolorbuff+position, len-position);
 
-    if (trans1<trans2) {
-      lastsame=position+trans1;
-    } else {
-      lastsame=position+trans2;
-    }
+    lastsame = (trans1 < trans2) ? trans1 : trans2;
+    lastsame = (lastsame < trans3) ? lastsame : trans3;
+    lastsame += position;
 
     /* set the format */
     wattrset(w, A_NORMAL);
@@ -210,8 +234,14 @@
     /* set the color */
     /* warning, this is sort of a hack */
     if (owl_global_get_hascolors(&g)) {
-      if (f->colorbuff[position]!=OWL_COLOR_DEFAULT) {
-	wattron(w, COLOR_PAIR(f->colorbuff[position]));
+      int pair, fg, bg;
+      fg = f->fgcolorbuff[position];
+      bg = f->bgcolorbuff[position];
+      owl_function_debugmsg("waddstr: fg(%i) bg(%i).", fg, bg);
+
+      pair = owl_fmtext_get_colorpair(fg, bg);
+      if (pair != -1) {
+	wattron(w, COLOR_PAIR(pair));
       }
     }
 
@@ -354,10 +384,12 @@
   dst->textlen=src->textlen;
   dst->textbuff=owl_malloc(mallocsize);
   dst->fmbuff=owl_malloc(mallocsize);
-  dst->colorbuff=owl_malloc(mallocsize);
+  dst->fgcolorbuff=owl_malloc(mallocsize);
+  dst->bgcolorbuff=owl_malloc(mallocsize);
   memcpy(dst->textbuff, src->textbuff, src->textlen+1);
   memcpy(dst->fmbuff, src->fmbuff, src->textlen);
-  memcpy(dst->colorbuff, src->colorbuff, src->textlen);
+  memcpy(dst->fgcolorbuff, src->fgcolorbuff, src->textlen);
+  memcpy(dst->bgcolorbuff, src->bgcolorbuff, src->textlen);
 }
 
 /* highlight all instances of "string".  Return the number of
@@ -414,14 +446,14 @@
     ptr=strpbrk(txtptr, "@{[<()>]}");
     if (!ptr) {
       /* add all the rest of the text and exit */
-      owl_fmtext_append_attr(f, txtptr, curattrs, curcolor);
+      owl_fmtext_append_attr(f, txtptr, curattrs, curcolor, OWL_COLOR_DEFAULT);
       return;
     } else if (ptr[0]=='@') {
       /* add the text up to this point then deal with the stack */
       buff=owl_malloc(ptr-txtptr+20);
       strncpy(buff, txtptr, ptr-txtptr);
       buff[ptr-txtptr]='\0';
-      owl_fmtext_append_attr(f, buff, curattrs, curcolor);
+      owl_fmtext_append_attr(f, buff, curattrs, curcolor, OWL_COLOR_DEFAULT);
       owl_free(buff);
 
       /* update pointer to point at the @ */
@@ -431,14 +463,14 @@
 
       /* if we've hit our max stack depth, print the @ and move on */
       if (stacksize==32) {
-	owl_fmtext_append_attr(f, "@", curattrs, curcolor);
+	owl_fmtext_append_attr(f, "@", curattrs, curcolor, OWL_COLOR_DEFAULT);
 	txtptr++;
 	continue;
       }
 
       /* if it's an @@, print an @ and continue */
       if (txtptr[1]=='@') {
-	owl_fmtext_append_attr(f, "@", curattrs, curcolor);
+	owl_fmtext_append_attr(f, "@", curattrs, curcolor, OWL_COLOR_DEFAULT);
 	txtptr+=2;
 	continue;
       }
@@ -446,7 +478,7 @@
       /* if there's no opener, print the @ and continue */
       tmpptr=strpbrk(txtptr, "(<[{ ");
       if (!tmpptr || tmpptr[0]==' ') {
-	owl_fmtext_append_attr(f, "@", curattrs, curcolor);
+	owl_fmtext_append_attr(f, "@", curattrs, curcolor, OWL_COLOR_DEFAULT);
 	txtptr++;
 	continue;
       }
@@ -523,7 +555,7 @@
 	/* if we didn't understand it, we'll print it.  This is different from zwgc
 	 * but zwgc seems to be smarter about some screw cases than I am
 	 */
-	owl_fmtext_append_attr(f, "@", curattrs, curcolor);
+	owl_fmtext_append_attr(f, "@", curattrs, curcolor, OWL_COLOR_DEFAULT);
 	txtptr++;
 	continue;
       }
@@ -533,7 +565,7 @@
       buff=owl_malloc(ptr-txtptr+20);
       strncpy(buff, txtptr, ptr-txtptr);
       buff[ptr-txtptr]='\0';
-      owl_fmtext_append_attr(f, buff, curattrs, curcolor);
+      owl_fmtext_append_attr(f, buff, curattrs, curcolor, OWL_COLOR_DEFAULT);
       owl_free(buff);
 
       /* now deal with the closer */
@@ -544,7 +576,7 @@
 	buff=owl_malloc(5);
 	buff[0]=ptr[0];
 	buff[1]='\0';
-	owl_fmtext_append_attr(f, buff, curattrs, curcolor);
+	owl_fmtext_append_attr(f, buff, curattrs, curcolor, OWL_COLOR_DEFAULT);
 	owl_free(buff);
 	txtptr++;
 	continue;
@@ -569,7 +601,7 @@
 	buff=owl_malloc(5);
 	buff[0]=ptr[0];
 	buff[1]='\0';
-	owl_fmtext_append_attr(f, buff, curattrs, curcolor);
+	owl_fmtext_append_attr(f, buff, curattrs, curcolor, OWL_COLOR_DEFAULT);
 	owl_free(buff);
 	txtptr++;
 	continue;
@@ -579,7 +611,7 @@
       buff=owl_malloc(ptr-txtptr+20);
       strncpy(buff, txtptr, ptr-txtptr+1);
       buff[ptr-txtptr+1]='\0';
-      owl_fmtext_append_attr(f, buff, curattrs, curcolor);
+      owl_fmtext_append_attr(f, buff, curattrs, curcolor, OWL_COLOR_DEFAULT);
       owl_free(buff);
       txtptr=ptr+1;
       continue;
@@ -620,6 +652,78 @@
 {
   if (f->textbuff) owl_free(f->textbuff);
   if (f->fmbuff) owl_free(f->fmbuff);
-  if (f->colorbuff) owl_free(f->colorbuff);
+  if (f->fgcolorbuff) owl_free(f->fgcolorbuff);
+  if (f->bgcolorbuff) owl_free(f->bgcolorbuff);
 }
 
+/*** Color Pair manager ***/
+void owl_fmtext_init_colorpair_mgr(owl_colorpair_mgr *cpmgr)
+{
+  // This could be a bitarray if we wanted to save memory.
+  int i, j, colors;
+  cpmgr->used = owl_malloc(COLOR_PAIRS * sizeof(char));
+  memset(cpmgr->used, 0, COLOR_PAIRS * sizeof(char));
+
+  colors = COLORS + 1; // 1 to account for "default".
+  cpmgr->pairs = owl_malloc(colors * sizeof(int*));
+  for(i = 0; i < colors; i++) {
+    // Because we're going to have a pair set for any fg and the
+    // default bg, we don't need to account for default here.
+    cpmgr->pairs[i] = owl_malloc(COLORS * sizeof(int));
+    for(j = 0; j < COLORS; j++) {
+      cpmgr->pairs[i][j] = -1;
+    }
+  }
+}
+
+/* Reset used list */
+void owl_fmtext_reset_colorpairs()
+{
+  memset(owl_global_get_colorpair_mgr(&g)->used, 0, COLOR_PAIRS * sizeof(char));  
+}
+
+/* Assign pairs by request */
+int owl_fmtext_get_colorpair(int fg, int bg)
+{
+  owl_colorpair_mgr *cpmgr;
+  short pair, i;
+  if (fg == OWL_COLOR_DEFAULT) fg = -1;
+  if (bg == OWL_COLOR_DEFAULT) {
+    pair = fg;
+  } else {
+    cpmgr = owl_global_get_colorpair_mgr(&g);
+    pair = cpmgr->pairs[fg+1][bg];
+    if (pair != -1) {
+      short oldfg, oldbg;
+      pair_content(pair, &oldfg, &oldbg);
+      if (cpmgr->pairs[oldfg+1][oldbg] == pair) {
+	cpmgr->pairs[oldfg+1][oldbg] = -1;
+      }
+      init_pair(pair, fg, bg);
+      cpmgr->pairs[fg+1][bg] = pair;
+      cpmgr->used[pair] = 1;
+    } else {
+      // Skip the first COLORS, sicne they're static.
+      for(i = COLORS; i < COLOR_PAIRS; i++) {
+	if (0 == cpmgr->used[i]) {
+	  pair = i;
+	  break;
+	}
+      }
+      if (pair != -1) {
+	short oldfg, oldbg;
+	pair_content(pair, &oldfg, &oldbg);
+	if (cpmgr->pairs[oldfg+1][oldbg] == pair) {
+	  cpmgr->pairs[oldfg+1][oldbg] = -1;
+	}
+	init_pair(pair, fg, bg);
+	cpmgr->pairs[fg+1][bg] = pair;
+	cpmgr->used[pair] = 1;
+      } else {
+	// Fail to skipping background.
+	pair = fg;
+      }
+    }
+  }
+  return pair;
+}

Modified: trunk/owl/functions.c
===================================================================
--- trunk/owl/functions.c	2007-01-19 00:09:12 UTC (rev 537)
+++ trunk/owl/functions.c	2007-01-21 02:49:55 UTC (rev 538)
@@ -2453,11 +2453,26 @@
       owl_function_error("The color '%s' is not available.", argv[3]);
       return;
     }
-    owl_filter_set_color(f, owl_util_string_to_color(argv[3]));
+    owl_filter_set_fgcolor(f, owl_util_string_to_color(argv[3]));
     owl_global_set_needrefresh(&g);
     owl_mainwin_redisplay(owl_global_get_mainwin(&g));
     return;
   }
+  if (argc==4 && !strcmp(argv[2], "-b")) {
+    f=owl_global_get_filter(&g, argv[1]);
+    if (!f) {
+      owl_function_error("The filter '%s' does not exist.", argv[1]);
+      return;
+    }
+    if (owl_util_string_to_color(argv[3])==-1) {
+      owl_function_error("The color '%s' is not available.", argv[3]);
+      return;
+    }
+    owl_filter_set_bgcolor(f, owl_util_string_to_color(argv[3]));
+    owl_global_set_needrefresh(&g);
+    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
+    return;
+  }
 
   /* create the filter and check for errors */
   f=owl_malloc(sizeof(owl_filter));
@@ -2544,7 +2559,7 @@
     f=owl_list_get_element(l, i);
     owl_fmtext_append_normal(&fm, "   ");
     if (owl_global_get_hascolors(&g)) {
-      owl_fmtext_append_normal_color(&fm, owl_filter_get_name(f), owl_filter_get_color(f));
+      owl_fmtext_append_normal_color(&fm, owl_filter_get_name(f), owl_filter_get_fgcolor(f), owl_filter_get_bgcolor(f));
     } else {
       owl_fmtext_append_normal(&fm, owl_filter_get_name(f));
     }
@@ -2923,19 +2938,19 @@
 /* Set the color of the current view's filter to
  * be 'color'
  */
-void owl_function_color_current_filter(char *color)
+void owl_function_color_current_filter(char *fgcolor, char *bgcolor)
 {
   char *name;
 
   name=owl_view_get_filtname(owl_global_get_current_view(&g));
-  owl_function_color_filter(name, color);
+  owl_function_color_filter(name, fgcolor, bgcolor);
 }
 
 /* Set the color of the filter 'filter' to be 'color'.  If the color
  * name does not exist, return -1, if the filter does not exist or is
  * the "all" filter, return -2.  Return 0 on success
  */
-int owl_function_color_filter(char *filtname, char *color)
+int owl_function_color_filter(char *filtname, char *fgcolor, char *bgcolor)
 {
   owl_filter *f;
 
@@ -2951,11 +2966,21 @@
     return(-2);
   }
 
-  if (owl_util_string_to_color(color)==-1) {
-    owl_function_error("No color named '%s' avilable.");
+  if (owl_util_string_to_color(fgcolor)==-1) {
+    owl_function_error("No color named '%s' avilable.", fgcolor);
     return(-1);
   }
-  owl_filter_set_color(f, owl_util_string_to_color(color));
+
+
+  if (bgcolor != NULL) {
+    if (owl_util_string_to_color(bgcolor)==-1) {
+      owl_function_error("No color named '%s' avilable.", bgcolor);
+      return(-1);
+    }
+    owl_filter_set_bgcolor(f, owl_util_string_to_color(bgcolor));
+  }
+  owl_filter_set_fgcolor(f, owl_util_string_to_color(fgcolor));
+  
   owl_global_set_needrefresh(&g);
   owl_mainwin_redisplay(owl_global_get_mainwin(&g));
   return(0);
@@ -2967,28 +2992,28 @@
 
   owl_fmtext_init_null(&fm);
   owl_fmtext_append_normal(&fm, "default: ");
-  owl_fmtext_append_normal_color(&fm, "default\n", OWL_COLOR_DEFAULT);
+  owl_fmtext_append_normal_color(&fm, "default\n", OWL_COLOR_DEFAULT, OWL_COLOR_DEFAULT);
 
   owl_fmtext_append_normal(&fm,"red:      ");
-  owl_fmtext_append_normal_color(&fm, "red\n", OWL_COLOR_RED);
+  owl_fmtext_append_normal_color(&fm, "red\n", OWL_COLOR_RED, OWL_COLOR_DEFAULT);
 
   owl_fmtext_append_normal(&fm,"green:    ");
-  owl_fmtext_append_normal_color(&fm, "green\n", OWL_COLOR_GREEN);
+  owl_fmtext_append_normal_color(&fm, "green\n", OWL_COLOR_GREEN, OWL_COLOR_DEFAULT);
 
   owl_fmtext_append_normal(&fm,"yellow:   ");
-  owl_fmtext_append_normal_color(&fm, "yellow\n", OWL_COLOR_YELLOW);
+  owl_fmtext_append_normal_color(&fm, "yellow\n", OWL_COLOR_YELLOW, OWL_COLOR_DEFAULT);
 
   owl_fmtext_append_normal(&fm,"blue:     ");
-  owl_fmtext_append_normal_color(&fm, "blue\n", OWL_COLOR_BLUE);
+  owl_fmtext_append_normal_color(&fm, "blue\n", OWL_COLOR_BLUE, OWL_COLOR_DEFAULT);
 
   owl_fmtext_append_normal(&fm,"magenta:  ");
-  owl_fmtext_append_normal_color(&fm, "magenta\n", OWL_COLOR_MAGENTA);
+  owl_fmtext_append_normal_color(&fm, "magenta\n", OWL_COLOR_MAGENTA, OWL_COLOR_DEFAULT);
 
   owl_fmtext_append_normal(&fm,"cyan:     ");
-  owl_fmtext_append_normal_color(&fm, "cyan\n", OWL_COLOR_CYAN);
+  owl_fmtext_append_normal_color(&fm, "cyan\n", OWL_COLOR_CYAN, OWL_COLOR_DEFAULT);
 
   owl_fmtext_append_normal(&fm,"white:    ");
-  owl_fmtext_append_normal_color(&fm, "white\n", OWL_COLOR_WHITE);
+  owl_fmtext_append_normal_color(&fm, "white\n", OWL_COLOR_WHITE, OWL_COLOR_DEFAULT);
 
   owl_function_popless_fmtext(&fm);
   owl_fmtext_free(&fm);

Modified: trunk/owl/global.c
===================================================================
--- trunk/owl/global.c	2007-01-19 00:09:12 UTC (rev 537)
+++ trunk/owl/global.c	2007-01-21 02:49:55 UTC (rev 538)
@@ -63,6 +63,7 @@
     g->hascolors=1;
   }
   g->colorpairs=COLOR_PAIRS;
+  owl_fmtext_init_colorpair_mgr(&(g->cpmgr));
   g->debug=OWL_DEBUG;
   g->searchactive=0;
   g->searchstring=NULL;
@@ -591,6 +592,10 @@
   return(g->colorpairs);
 }
 
+owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
+  return(&(g->cpmgr));
+}
+
 /* puntlist */
 
 owl_list *owl_global_get_puntlist(owl_global *g) {

Modified: trunk/owl/mainwin.c
===================================================================
--- trunk/owl/mainwin.c	2007-01-19 00:09:12 UTC (rev 537)
+++ trunk/owl/mainwin.c	2007-01-21 02:49:55 UTC (rev 538)
@@ -13,7 +13,7 @@
   owl_message *m;
   int i, p, q, lines, isfull, viewsize;
   int x, y, savey, recwinlines, start;
-  int topmsg, curmsg, color;
+  int topmsg, curmsg, fgcolor, bgcolor;
   WINDOW *recwin;
   owl_view *v;
   owl_list *filtlist;
@@ -23,6 +23,7 @@
   topmsg=owl_global_get_topmsg(&g);
   curmsg=owl_global_get_curmsg(&g);
   v=owl_global_get_current_view(&g);
+  owl_fmtext_reset_colorpairs();
 
   if (v==NULL) {
     owl_function_debugmsg("Hit a null window in owl_mainwin_redisplay.");
@@ -71,13 +72,15 @@
     }
 
     /* if we match filters set the color */
-    color=OWL_COLOR_DEFAULT;
+    fgcolor=OWL_COLOR_DEFAULT;
+    bgcolor=OWL_COLOR_DEFAULT;
     filtlist=owl_global_get_filterlist(&g);
     q=owl_list_get_size(filtlist);
     for (p=0; p<q; p++) {
       f=owl_list_get_element(filtlist, p);
       if (owl_filter_message_match(f, m)) {
-	if (owl_filter_get_color(f)!=OWL_COLOR_DEFAULT) color=owl_filter_get_color(f);
+	if (owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) fgcolor=owl_filter_get_fgcolor(f);
+	if (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT) bgcolor=owl_filter_get_bgcolor(f);
       }
     }
 
@@ -91,7 +94,7 @@
 			       start+recwinlines-y,
 			       owl_global_get_rightshift(&g),
 			       owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
-			       color);
+			       fgcolor, bgcolor);
     } else {
       /* otherwise print the whole thing */
       owl_message_curs_waddstr(m, owl_global_get_curs_recwin(&g),
@@ -99,7 +102,7 @@
 			       start+lines,
 			       owl_global_get_rightshift(&g),
 			       owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
-			       color);
+			       fgcolor, bgcolor);
     }
 
 

Modified: trunk/owl/message.c
===================================================================
--- trunk/owl/message.c	2007-01-19 00:09:12 UTC (rev 537)
+++ trunk/owl/message.c	2007-01-21 02:49:55 UTC (rev 538)
@@ -515,7 +515,7 @@
   return(m->hostname);
 }
 
-void owl_message_curs_waddstr(owl_message *m, WINDOW *win, int aline, int bline, int acol, int bcol, int color)
+void owl_message_curs_waddstr(owl_message *m, WINDOW *win, int aline, int bline, int acol, int bcol, int fgcolor, int bgcolor)
 {
   owl_fmtext a, b;
 
@@ -527,9 +527,12 @@
   
   owl_fmtext_truncate_lines(&(m->fmtext), aline, bline-aline+1, &a);
   owl_fmtext_truncate_cols(&a, acol, bcol, &b);
-  if (color!=OWL_COLOR_DEFAULT) {
-    owl_fmtext_colorize(&b, color);
+  if (fgcolor!=OWL_COLOR_DEFAULT) {
+    owl_fmtext_colorize(&b, fgcolor);
   }
+  if (bgcolor!=OWL_COLOR_DEFAULT) {
+    owl_fmtext_colorizebg(&b, bgcolor);
+  }
 
   if (owl_global_is_search_active(&g)) {
     owl_fmtext_search_and_highlight(&b, owl_global_get_search_string(&g));

Modified: trunk/owl/owl.c
===================================================================
--- trunk/owl/owl.c	2007-01-19 00:09:12 UTC (rev 537)
+++ trunk/owl/owl.c	2007-01-21 02:49:55 UTC (rev 538)
@@ -176,14 +176,18 @@
 
   /* define simple color pairs */
   if (has_colors() && COLOR_PAIRS>=8) {
-    init_pair(OWL_COLOR_BLACK,   COLOR_BLACK,   -1);
-    init_pair(OWL_COLOR_RED,     COLOR_RED,     -1);
-    init_pair(OWL_COLOR_GREEN,   COLOR_GREEN,   -1);
-    init_pair(OWL_COLOR_YELLOW,  COLOR_YELLOW,  -1);
-    init_pair(OWL_COLOR_BLUE,    COLOR_BLUE,    -1);
-    init_pair(OWL_COLOR_MAGENTA, COLOR_MAGENTA, -1);
-    init_pair(OWL_COLOR_CYAN,    COLOR_CYAN,    -1);
-    init_pair(OWL_COLOR_WHITE,   COLOR_WHITE,   -1);
+    int bg = COLOR_BLACK;
+#ifdef HAVE_USE_DEFAULT_COLORS
+    bg = -1;
+#endif
+    init_pair(OWL_COLOR_BLACK,   COLOR_BLACK,   bg);
+    init_pair(OWL_COLOR_RED,     COLOR_RED,     bg);
+    init_pair(OWL_COLOR_GREEN,   COLOR_GREEN,   bg);
+    init_pair(OWL_COLOR_YELLOW,  COLOR_YELLOW,  bg);
+    init_pair(OWL_COLOR_BLUE,    COLOR_BLUE,    bg);
+    init_pair(OWL_COLOR_MAGENTA, COLOR_MAGENTA, bg);
+    init_pair(OWL_COLOR_CYAN,    COLOR_CYAN,    bg);
+    init_pair(OWL_COLOR_WHITE,   COLOR_WHITE,   bg);
   }
 
   /* owl global init */

Modified: trunk/owl/owl.h
===================================================================
--- trunk/owl/owl.h	2007-01-19 00:09:12 UTC (rev 537)
+++ trunk/owl/owl.h	2007-01-21 02:49:55 UTC (rev 538)
@@ -251,7 +251,8 @@
   int textlen;
   char *textbuff;
   char *fmbuff;
-  char *colorbuff;
+  char *fgcolorbuff;
+  char *bgcolorbuff;
 } owl_fmtext;
 
 typedef struct _owl_list {
@@ -414,7 +415,8 @@
   char *name;
   int polarity;
   owl_filterelement * root;
-  int color;
+  int fgcolor;
+  int bgcolor;
   int cachedmsgid;  /* cached msgid: should move into view eventually */
 } owl_filter;
 
@@ -513,6 +515,11 @@
   owl_list errlist;
 } owl_errqueue;
 
+typedef struct _owl_colorpair_mgr {
+  char *used;
+  int **pairs;
+} owl_colorpair_mgr;
+
 typedef struct _owl_global {
   owl_mainwin mw;
   owl_popwin pw;
@@ -555,6 +562,7 @@
   int nextmsgid;
   int hascolors;
   int colorpairs;
+  owl_colorpair_mgr cpmgr;
   int searchactive;
   int newmsgproc_pid;
   int malloced, freed;

Modified: trunk/owl/perl/modules/jabber.pl
===================================================================
--- trunk/owl/perl/modules/jabber.pl	2007-01-19 00:09:12 UTC (rev 537)
+++ trunk/owl/perl/modules/jabber.pl	2007-01-21 02:49:55 UTC (rev 538)
@@ -72,7 +72,6 @@
     return unless $muc;
 
     $muc->Leave();
-    
     $self->{_BARNOWL_MUCS} = [grep {$_->BaseJID ne $muc->BaseJID} $self->MUCs];
 }
 
@@ -426,7 +425,7 @@
         );
         $client->SetPresenceCallBacks(
             available    => sub { BarnOwl::Jabber::process_presence_available(@_) },
-#            unavailable  => sub { BarnOwl::Jabber::process_presence_available(@_) },
+            unavailable  => sub { BarnOwl::Jabber::process_presence_available(@_) },
             subscribe    => sub { BarnOwl::Jabber::process_presence_subscribe(@_) },
             subscribed   => sub { BarnOwl::Jabber::process_presence_subscribed(@_) },
             unsubscribe  => sub { BarnOwl::Jabber::process_presence_unsubscribe(@_) },
@@ -1006,9 +1005,9 @@
         $props{loginout} = 'logout';
     }
     $props{replysendercmd} = $props{replycmd} = "jwrite $from -i $sid";
-    if(BarnOwl::getvar('debug') eq 'on') {
+#    if(BarnOwl::getvar('debug') eq 'on') {
         BarnOwl::queue_message(BarnOwl::Message->new(%props));
-    }
+#    }
 }
 
 sub process_presence_subscribe {


home help back first fref pref prev next nref lref last post