[818] in BarnOwl Developers

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

[D-O-H] r813 - branches/barnowl_unicode/owl

daemon@ATHENA.MIT.EDU (asedeno@MIT.EDU)
Thu Oct 29 18:10:02 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: Wed,  9 Jan 2008 14:32:01 -0500 (EST)

Author: asedeno
Date: 2008-01-09 14:32:01 -0500 (Wed, 09 Jan 2008)
New Revision: 813

Modified:
   branches/barnowl_unicode/owl/fmtext.c
Log:
Preserve colors when highlighting search terms.

Modified: branches/barnowl_unicode/owl/fmtext.c
===================================================================
--- branches/barnowl_unicode/owl/fmtext.c	2008-01-09 19:18:31 UTC (rev 812)
+++ branches/barnowl_unicode/owl/fmtext.c	2008-01-09 19:32:01 UTC (rev 813)
@@ -244,6 +244,21 @@
   if (attrs & OWL_FMTEXT_ATTR_REVERSE) wattron(w, A_REVERSE);
   if (attrs & OWL_FMTEXT_ATTR_UNDERLINE) wattron(w, A_UNDERLINE);
 }
+
+void _owl_fmtext_update_colorpair(short fg, short bg, short *pair) /*noproto*/
+{
+  if (owl_global_get_hascolors(&g)) {
+    *pair = owl_fmtext_get_colorpair(fg, bg);
+  }
+}
+
+void _owl_fmtext_wcolor_set(WINDOW *w, short pair) /*noproto*/
+{
+  if (owl_global_get_hascolors(&g)) {
+      wcolor_set(w,pair,NULL);
+  }
+}
+
 /* add the formatted text to the curses window 'w'.  The window 'w'
  * must already be initiatlized with curses
  */
@@ -253,7 +268,7 @@
   /* int position, trans1, trans2, trans3, len, lastsame; */
   char *s, *p;
   char attr;
-  short fg, bg;
+  short fg, bg, pair;
   int search_results, search_len;
   
   if (w==NULL) {
@@ -273,13 +288,8 @@
   fg = f->default_fgcolor;
   bg = f->default_bgcolor;
   _owl_fmtext_wattrset(w, attr);
-  if (owl_global_get_hascolors(&g)) {
-    short pair;
-    pair = owl_fmtext_get_colorpair(fg, bg);
-    if (pair != -1) {
-      wcolor_set(w,pair,NULL);
-    }
-  }
+  _owl_fmtext_update_colorpair(fg, bg, &pair);
+  _owl_fmtext_wcolor_set(w, pair);
 
   /* Find next possible format character. */
   p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8);
@@ -303,13 +313,15 @@
 	  ss[0] = tmp2;
 
 	  _owl_fmtext_wattrset(w, attr ^ OWL_FMTEXT_ATTR_REVERSE);
-
+	  _owl_fmtext_wcolor_set(w, pair);
+	  
 	  tmp2 = ss[search_len];
 	  ss[search_len] = '\0';
 	  waddstr(w, ss);
 	  ss[search_len] = tmp2;
 
-	  _owl_fmtext_wattrset(w,attr);
+	  _owl_fmtext_wattrset(w, attr);
+	  _owl_fmtext_wcolor_set(w, pair);
 
 	  s = ss + search_len;
 	  ss = stristr(s, owl_global_get_search_string(&g));
@@ -329,15 +341,11 @@
 	p = g_utf8_next_char(p);
       }
       _owl_fmtext_wattrset(w, attr | f->default_attrs);
-      if (owl_global_get_hascolors(&g)) {
-	if (fg == OWL_COLOR_DEFAULT) fg = f->default_fgcolor;
-	if (bg == OWL_COLOR_DEFAULT) bg = f->default_bgcolor;
-	short pair;
-	pair = owl_fmtext_get_colorpair(fg, bg);
-	if (pair != -1) {
-	  wcolor_set(w,pair,NULL);
-	}
-      }
+      if (fg == OWL_COLOR_DEFAULT) fg = f->default_fgcolor;
+      if (bg == OWL_COLOR_DEFAULT) bg = f->default_bgcolor;
+      _owl_fmtext_update_colorpair(fg, bg, &pair);
+      _owl_fmtext_wcolor_set(w, pair);
+
       /* Advance to next non-formatting character. */
       s = p;
       p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8);


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