aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ansi.c41
-rw-r--r--src/ansi.h4
-rw-r--r--src/crt.c15
-rw-r--r--src/crt.h31
-rw-r--r--src/vt102.c66
-rw-r--r--src/vt102.h5
6 files changed, 153 insertions, 9 deletions
diff --git a/src/ansi.c b/src/ansi.c
index 1b8e893..30022ed 100644
--- a/src/ansi.c
+++ b/src/ansi.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $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 ***
*
@@ -226,6 +229,39 @@ 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);
+ fprintf(stderr,"Color set to %d %d %x\n",fg,bg,color);
+
+ ansi_write (a,buf,i);
+ a->color=color;
+ }
}
void
@@ -240,11 +276,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 +333,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 +355,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 +399,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));
diff --git a/src/ansi.h b/src/ansi.h
index bc24524..e88f076 100644
--- a/src/ansi.h
+++ b/src/ansi.h
@@ -12,6 +12,9 @@
/*
* $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 ***
*
@@ -51,6 +54,7 @@ typedef struct
CRT_Pos size;
int hide_cursor;
int attr;
+ int color;
ANSI_Parser parser;
} ANSI;
diff --git a/src/crt.c b/src/crt.c
index b839150..e2f49c3 100644
--- a/src/crt.c
+++ b/src/crt.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $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 ***
*
@@ -38,8 +41,10 @@ crt_erase (CRT * c, CRT_Pos s, CRT_Pos e, int ea)
while (ps <= pe)
{
ps->chr = ' ';
- if (ea)
+ if (ea){
ps->attr = CRT_ATTR_NORMAL;
+ ps->color = CRT_COLOR_NORMAL;
+ }
ps++;
}
@@ -54,14 +59,6 @@ crt_cls (CRT * c)
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
diff --git a/src/crt.h b/src/crt.h
index 002f67f..f92c99a 100644
--- a/src/crt.h
+++ b/src/crt.h
@@ -12,6 +12,9 @@
/*
* $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 ***
*
@@ -39,10 +42,38 @@
#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;
+ uint8_t color;
} CRT_CA;
typedef struct
diff --git a/src/vt102.c b/src/vt102.c
index 399952a..869cca6 100644
--- a/src/vt102.c
+++ b/src/vt102.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $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 ***
*
@@ -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)].color = CRT_COLOR_NORMAL;
}
@@ -582,6 +586,7 @@ vt102_change_attr (VT102 * v, char *na)
{
case 0:
v->attr = CRT_ATTR_NORMAL;
+ v->color= CRT_COLOR_NORMAL;
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 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
@@ -662,6 +722,7 @@ vt102_save_state (VT102 * v)
{
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];
}
@@ -670,6 +731,7 @@ vt102_restore_state (VT102 * v)
{
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;
@@ -933,6 +995,7 @@ vt102_status_line (VT102 * v, char *str)
while (i--)
{
ca->attr = CRT_ATTR_REVERSE;
+ ca->color=CRT_COLOR_NORMAL;
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)].color = v->color;
vt102_cursor_advance (v);
}
}
@@ -1259,6 +1323,8 @@ vt102_reset (VT102 * v)
vt102_parser_reset (p);
crt_cls (&v->crt);
+ v->attr=CRT_ATTR_NORMAL;
+ v->color=CRT_COLOR_NORMAL;
v->application_keypad_mode = 0;
diff --git a/src/vt102.h b/src/vt102.h
index f0d4e91..e8caf5e 100644
--- a/src/vt102.h
+++ b/src/vt102.h
@@ -12,6 +12,9 @@
/*
* $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 ***
*
@@ -65,6 +68,7 @@ typedef struct
{
CRT_Pos pos;
int attr;
+ int color;
int origin_mode;
} VT102_State;
@@ -75,6 +79,7 @@ typedef struct
CRT_Pos screen_start, screen_end;
VT102_parser parser;
int attr;
+ int color;
CRT crt;
int pending_wrap;