chiark / gitweb /
*** empty log message ***
authorjames <james>
Thu, 7 Feb 2008 12:16:04 +0000 (12:16 +0000)
committerjames <james>
Thu, 7 Feb 2008 12:16:04 +0000 (12:16 +0000)
src/ansi.c
src/ansi.h
src/crt.c
src/crt.h
src/vt102.c
src/vt102.h

index 1b8e893906be0cb001a10f00e1b26a9a08d253bc..30022edabeb23bf15f1e16ed1257d024d09fc281 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * 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 ***
  *
  * Revision 1.12  2008/02/07 11:32:41  james
  * *** empty log message ***
  *
@@ -226,6 +229,39 @@ ansi_force_attr_normal (ANSI * a)
 {
   ansi_write (a, "\033[0m", 4);
   a->attr = CRT_ATTR_NORMAL;
 {
   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);
+       fprintf(stderr,"Color set to %d %d %x\n",fg,bg,color);
+
+        ansi_write (a,buf,i); 
+       a->color=color;
+   }
 }
 
 void
 }
 
 void
@@ -240,11 +276,13 @@ ansi_set_attr (ANSI * a, int attr)
 
   a->attr = attr;
 
 
   a->attr = attr;
 
+#if 0
   if (attr == CRT_ATTR_NORMAL)
     {
       ansi_force_attr_normal (a);
       return;
     }
   if (attr == CRT_ATTR_NORMAL)
     {
       ansi_force_attr_normal (a);
       return;
     }
+#endif
 
   if (dif & CRT_ATTR_UNDERLINE)
     {
 
   if (dif & CRT_ATTR_UNDERLINE)
     {
@@ -295,6 +333,7 @@ ansi_render (ANSI * a, CRT_CA ca)
     ca.chr = ' ';
 
   ansi_set_attr (a, ca.attr);
     ca.chr = ' ';
 
   ansi_set_attr (a, ca.attr);
+  ansi_set_color(a,ca.color);
 
   ansi_write (a, &ca.chr, 1);
 
 
   ansi_write (a, &ca.chr, 1);
 
@@ -316,6 +355,7 @@ ansi_cls (ANSI * a)
   crt_cls (&a->crt);
 
   ansi_force_attr_normal (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*/
   ansi_move (a, p);
   ansi_write (a, "\033[2J", 4);
 /*different emulators leave cursor in different places after cls differently*/
@@ -359,6 +399,7 @@ ansi_draw (ANSI * a, CRT * c)
 
       ansi_showhide_cursor (a, 1);
       ansi_set_attr (a, CRT_ATTR_REVERSE);
 
       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));
       ansi_move (a, p);
 
       ansi_write (a, msg, sizeof (msg));
index bc245243b0eec1a291bb89a6f66ee077dea5c866..e88f076c27c8967d3d6bfee82060fe5c9c94e161 100644 (file)
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * Revision 1.5  2008/02/07 12:16:04  james
+ * *** empty log message ***
+ *
  * Revision 1.4  2008/02/07 00:43:27  james
  * *** empty log message ***
  *
  * Revision 1.4  2008/02/07 00:43:27  james
  * *** empty log message ***
  *
@@ -51,6 +54,7 @@ typedef struct
   CRT_Pos size;
   int hide_cursor;
   int attr;
   CRT_Pos size;
   int hide_cursor;
   int attr;
+  int color;
 
   ANSI_Parser parser;
 } ANSI;
 
   ANSI_Parser parser;
 } ANSI;
index b8391506796b569da77acbb52a3959b2ca9354e2..e2f49c3e887c89d4a6af2aa2c276c46cd89fad4d 100644 (file)
--- a/src/crt.c
+++ b/src/crt.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * Revision 1.6  2008/02/07 12:16:04  james
+ * *** empty log message ***
+ *
  * Revision 1.5  2008/02/06 11:30:37  james
  * *** empty log message ***
  *
  * Revision 1.5  2008/02/06 11:30:37  james
  * *** empty log message ***
  *
@@ -38,8 +41,10 @@ crt_erase (CRT * c, CRT_Pos s, CRT_Pos e, int ea)
   while (ps <= pe)
     {
       ps->chr = ' ';
   while (ps <= pe)
     {
       ps->chr = ' ';
-      if (ea)
+      if (ea){
         ps->attr = CRT_ATTR_NORMAL;
         ps->attr = CRT_ATTR_NORMAL;
+        ps->color = CRT_COLOR_NORMAL;
+       }
       ps++;
     }
 
       ps++;
     }
 
@@ -54,14 +59,6 @@ crt_cls (CRT * c)
 
   crt_erase (c, s, e, 1);
 
 
   crt_erase (c, s, e, 1);
 
-#if 0
-  for (i = 0; i < CRT_ROWS; ++i)
-    {
-      c->screen[CRT_ADDR (i, i)].chr = '@' + i;
-      c->screen[CRT_ADDR (i, i)].attr = CRT_ATTR_NORMAL;
-    }
-#endif
-
 }
 
 void
 }
 
 void
index 002f67fe4d8e650d0deb65997a895cb140b8837e..f92c99ad6d249020ad5c377f9824d3c6361a90fa 100644 (file)
--- a/src/crt.h
+++ b/src/crt.h
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * Revision 1.4  2008/02/07 12:16:04  james
+ * *** empty log message ***
+ *
  * Revision 1.3  2008/02/06 11:30:37  james
  * *** empty log message ***
  *
  * Revision 1.3  2008/02/06 11:30:37  james
  * *** empty log message ***
  *
 #define CRT_ATTR_BLINK    0x4
 #define CRT_ATTR_BOLD     0x8
 
 #define CRT_ATTR_BLINK    0x4
 #define CRT_ATTR_BOLD     0x8
 
+
+#define CRT_COLOR_BLACK                0x0     
+#define CRT_COLOR_RED          0x1
+#define CRT_COLOR_GREEN                0x2
+#define CRT_COLOR_YELLOW       0x3
+#define CRT_COLOR_BLUE         0x4
+#define CRT_COLOR_MAGENTA      0x5
+#define CRT_COLOR_CYAN         0x6
+#define CRT_COLOR_WHITE                0x7
+#define CRT_COLOR_INTENSITY    0x8
+
+#define CRT_COLOR_FG_MASK      0xf0
+#define CRT_COLOR_FG_SHIFT     4
+
+#define CRT_COLOR_BG_MASK      0xf
+#define CRT_COLOR_BG_SHIFT     0
+
+#define CRT_COLOR_BG(a)                (((a) & CRT_COLOR_BG_MASK) >> CRT_COLOR_BG_SHIFT)
+#define CRT_COLOR_FG(a)                (((a) & CRT_COLOR_FG_MASK) >> CRT_COLOR_FG_SHIFT)
+
+#define CRT_MAKE_COLOR(f,b)    (((f) << CRT_COLOR_FG_SHIFT)|(b))
+
+#define CRT_BGCOLOR_NORMAL     CRT_COLOR_BLACK
+#define CRT_FGCOLOR_NORMAL     CRT_COLOR_WHITE
+
+#define CRT_COLOR_NORMAL       CRT_MAKE_COLOR(CRT_FGCOLOR_NORMAL,CRT_BGCOLOR_NORMAL)
+
 typedef struct
 {
   uint8_t chr;
   uint8_t attr;
 typedef struct
 {
   uint8_t chr;
   uint8_t attr;
+  uint8_t color;
 } CRT_CA;
 
 typedef struct
 } CRT_CA;
 
 typedef struct
index 399952a1f23c6cfa94ee2be25a7fc534fa8c5be5..869cca66a568c98e12668566213133c54785b5b1 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * Revision 1.20  2008/02/07 12:16:04  james
+ * *** empty log message ***
+ *
  * Revision 1.19  2008/02/07 11:27:02  james
  * *** empty log message ***
  *
  * Revision 1.19  2008/02/07 11:27:02  james
  * *** empty log message ***
  *
@@ -463,6 +466,7 @@ vt102_insert_into_line (VT102 * v, CRT_Pos p)
 
   v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
   v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].attr = CRT_ATTR_NORMAL;
 
   v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
   v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].attr = CRT_ATTR_NORMAL;
+  v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].color = CRT_COLOR_NORMAL;
 }
 
 
 }
 
 
@@ -582,6 +586,7 @@ vt102_change_attr (VT102 * v, char *na)
     {
     case 0:
       v->attr = CRT_ATTR_NORMAL;
     {
     case 0:
       v->attr = CRT_ATTR_NORMAL;
+      v->color= CRT_COLOR_NORMAL;
       break;
     case 1:
       v->attr |= CRT_ATTR_BOLD;
       break;
     case 1:
       v->attr |= CRT_ATTR_BOLD;
@@ -608,6 +613,61 @@ vt102_change_attr (VT102 * v, char *na)
     case 27:
       v->attr &= ~CRT_ATTR_REVERSE;
       break;
     case 27:
       v->attr &= ~CRT_ATTR_REVERSE;
       break;
+    case 30:
+    case 31:
+    case 32:
+    case 33:
+    case 34:
+    case 35:
+    case 36:
+    case 37:
+       v->color &= CRT_COLOR_FG_MASK;
+       v->color |= ((a-30) << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK;
+       break;
+    case 90:
+    case 91:
+    case 92:
+    case 93:
+    case 94:
+    case 95:
+    case 96:
+    case 97:
+       v->color &= CRT_COLOR_FG_MASK;
+       v->color |= (((a-90)|CRT_COLOR_INTENSITY) << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK;
+       break;
+    case 39:
+    case 99:
+       v->color &= CRT_COLOR_FG_MASK;
+       v->color |= (CRT_FGCOLOR_NORMAL << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK;
+       break;
+    case 40:
+    case 41:
+    case 42:
+    case 43:
+    case 44:
+    case 45:
+    case 46:
+    case 47:
+       v->color &= CRT_COLOR_BG_MASK;
+       v->color |= ((a-40) << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK;
+       break;
+    case 100:
+    case 101:
+    case 102:
+    case 103:
+    case 104:
+    case 105:
+    case 106:
+    case 107:
+       v->color &= CRT_COLOR_BG_MASK;
+       v->color |= (((a-100)|CRT_COLOR_INTENSITY) << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK;
+       break;
+    case 49:
+    case 109:
+       v->color &= CRT_COLOR_BG_MASK;
+       v->color |= (CRT_BGCOLOR_NORMAL << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK;
+       break;
     default:
       ;
 #if 0
     default:
       ;
 #if 0
@@ -662,6 +722,7 @@ vt102_save_state (VT102 * v)
 {
   v->saved.pos = v->pos;
   v->saved.attr = v->attr;
 {
   v->saved.pos = v->pos;
   v->saved.attr = v->attr;
+  v->saved.color= v->color;
   v->saved.origin_mode = v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE];
 }
 
   v->saved.origin_mode = v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE];
 }
 
@@ -670,6 +731,7 @@ vt102_restore_state (VT102 * v)
 {
   v->pos = v->saved.pos;
   v->attr = v->saved.attr;
 {
   v->pos = v->saved.pos;
   v->attr = v->saved.attr;
+  v->color= v->saved.color;
   v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE] = v->saved.origin_mode;
   vt102_cursor_normalize (v);
   v->pending_wrap = 0;
   v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE] = v->saved.origin_mode;
   vt102_cursor_normalize (v);
   v->pending_wrap = 0;
@@ -933,6 +995,7 @@ vt102_status_line (VT102 * v, char *str)
   while (i--)
     {
       ca->attr = CRT_ATTR_REVERSE;
   while (i--)
     {
       ca->attr = CRT_ATTR_REVERSE;
+      ca->color=CRT_COLOR_NORMAL;
       ca->chr = *str;
       if (*str)
         str++;
       ca->chr = *str;
       if (*str)
         str++;
@@ -1053,6 +1116,7 @@ vt102_parse_char (VT102 * v, int c,TTY *tty)
 
           v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = c;
           v->crt.screen[CRT_ADDR_POS (&v->pos)].attr = v->attr;
 
           v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = c;
           v->crt.screen[CRT_ADDR_POS (&v->pos)].attr = v->attr;
+          v->crt.screen[CRT_ADDR_POS (&v->pos)].color = v->color;
           vt102_cursor_advance (v);
         }
     }
           vt102_cursor_advance (v);
         }
     }
@@ -1259,6 +1323,8 @@ vt102_reset (VT102 * v)
   vt102_parser_reset (p);
   crt_cls (&v->crt);
 
   vt102_parser_reset (p);
   crt_cls (&v->crt);
 
+  v->attr=CRT_ATTR_NORMAL;
+  v->color=CRT_COLOR_NORMAL;
 
   v->application_keypad_mode = 0;
 
 
   v->application_keypad_mode = 0;
 
index f0d4e91fb12bb9f0624de2a56b8c900f52a06b3f..e8caf5ed291ca57f3296ad4f2dd12d9b67aa1e0d 100644 (file)
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * Revision 1.10  2008/02/07 12:16:04  james
+ * *** empty log message ***
+ *
  * Revision 1.9  2008/02/07 01:57:46  james
  * *** empty log message ***
  *
  * Revision 1.9  2008/02/07 01:57:46  james
  * *** empty log message ***
  *
@@ -65,6 +68,7 @@ typedef struct
 {
   CRT_Pos pos;
   int attr;
 {
   CRT_Pos pos;
   int attr;
+  int color;
   int origin_mode;
 } VT102_State;
 
   int origin_mode;
 } VT102_State;
 
@@ -75,6 +79,7 @@ typedef struct
   CRT_Pos screen_start, screen_end;
   VT102_parser parser;
   int attr;
   CRT_Pos screen_start, screen_end;
   VT102_parser parser;
   int attr;
+  int color;
   CRT crt;
 
   int pending_wrap;
   CRT crt;
 
   int pending_wrap;