chiark / gitweb /
*** empty log message ***
[sympathy.git] / src / ansi.c
index 1b8e893906be0cb001a10f00e1b26a9a08d253bc..f70a2d55e844c7a890579f7babad27e7f5a920fa 100644 (file)
@@ -10,6 +10,12 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.14  2008/02/07 12:21:16  james
+ * *** empty log message ***
+ *
+ * Revision 1.13  2008/02/07 12:16:04  james
+ * *** empty log message ***
+ *
  * Revision 1.12  2008/02/07 11:32:41  james
  * *** empty log message ***
  *
@@ -226,6 +232,41 @@ ansi_force_attr_normal (ANSI * a)
 {
   ansi_write (a, "\033[0m", 4);
   a->attr = CRT_ATTR_NORMAL;
+  a->color = ANSI_INVAL;
+}
+
+void
+ansi_set_color (ANSI * a, int color)
+{
+  int dif;
+  char buf[16];
+  int i;
+  int fg,bg;
+
+   if ((a->color == ANSI_INVAL) || (color!=a->color)) {
+       fg=CRT_COLOR_FG(color);
+       bg=CRT_COLOR_BG(color);
+
+       if (fg & CRT_COLOR_INTENSITY) {
+               fg+=90;
+       } else {
+               fg+=30;
+       }
+
+       if (bg & CRT_COLOR_INTENSITY) {
+               bg+=100;
+       } else {
+               bg+=40;
+       }
+
+       i=sprintf(buf,"\033[%d;%dm",fg,bg);
+#if 0
+       fprintf(stderr,"Color set to %d %d %x\n",fg,bg,color);
+#endif
+
+        ansi_write (a,buf,i); 
+       a->color=color;
+   }
 }
 
 void
@@ -240,11 +281,13 @@ ansi_set_attr (ANSI * a, int attr)
 
   a->attr = attr;
 
+#if 0
   if (attr == CRT_ATTR_NORMAL)
     {
       ansi_force_attr_normal (a);
       return;
     }
+#endif
 
   if (dif & CRT_ATTR_UNDERLINE)
     {
@@ -295,6 +338,7 @@ ansi_render (ANSI * a, CRT_CA ca)
     ca.chr = ' ';
 
   ansi_set_attr (a, ca.attr);
+  ansi_set_color(a,ca.color);
 
   ansi_write (a, &ca.chr, 1);
 
@@ -316,6 +360,7 @@ ansi_cls (ANSI * a)
   crt_cls (&a->crt);
 
   ansi_force_attr_normal (a);
+  ansi_set_color(a,CRT_COLOR_NORMAL);
   ansi_move (a, p);
   ansi_write (a, "\033[2J", 4);
 /*different emulators leave cursor in different places after cls differently*/
@@ -359,6 +404,7 @@ ansi_draw (ANSI * a, CRT * c)
 
       ansi_showhide_cursor (a, 1);
       ansi_set_attr (a, CRT_ATTR_REVERSE);
+      ansi_set_color(a,CRT_MAKE_COLOR(CRT_COLOR_WHITE,CRT_COLOR_RED));
       ansi_move (a, p);
 
       ansi_write (a, msg, sizeof (msg));
@@ -593,7 +639,7 @@ ansi_dispatch (ANSI * a, VT102 * v,TTY *t)
     return -1;
 #endif
 
-#if 1
+#if 0
   if (*buf == 1) 
        return 1;
 #endif