Here's a patch which adds color support to the curses UI.  It does a 
fairly good job with text-mode DOS programs if you use an xterm with the 
'vga' font.

--Josh




-- 
Josh Wilmes  ([EMAIL PROTECTED]) | http://www.hitchhiker.org


Index: curses.cc
===================================================================
RCS file: /cvsroot-plex86/plex86/user/plugins/bochs/gui/curses.cc,v
retrieving revision 1.3
diff -u -r1.3 curses.cc
--- curses.cc	2000/11/17 16:46:14	1.3
+++ curses.cc	2000/11/21 10:49:39
@@ -17,7 +17,8 @@
  */
 
 /* This is a bare-bones implementation of a text-mode (curses) GUI for
- * plex86's bochs UI code.  It only supports basic monochrome text mode.
+ * plex86's bochs UI code.  It support monochrome and color text modes.
+ * For best results, use an 80x24 xterm with the 'vga' font.
  * I have only tested this with ncurses, but it's simple enough that I would
  * expect it to work with regular curses with very minor changes, if any. */
 
@@ -27,6 +28,9 @@
 
 static int in_graphics_mode = 0;
 
+/* include support for color ncurses */
+#define CURSES_COLOR 1
+
 #define NO_MOD    0x01
 #define SHIFT_MOD 0x02
 #define CTRL_MOD  0x04
@@ -172,6 +176,20 @@
   /* 0x7F */ {  BX_KEY_BACKSPACE    ,  NO_MOD     },
 };
 
+#ifdef CURSES_COLOR
+short curses_colors[8] = {
+  /* 0 */ COLOR_BLACK,
+  /* 1 */ COLOR_BLUE,
+  /* 2 */ COLOR_GREEN,
+  /* 3 */ COLOR_CYAN,
+  /* 4 */ COLOR_RED,
+  /* 5 */ COLOR_MAGENTA,
+  /* 6 */ COLOR_YELLOW,
+  /* 7 */ COLOR_WHITE
+};
+
+short curses_color_map[8][8];
+#endif /* CURSES_COLOR */
 
 // ::SPECIFIC_INIT()
 //
@@ -210,6 +228,30 @@
   nonl();
   keypad(stdscr, TRUE);
   nodelay(stdscr, TRUE);
+
+  fprintf(stderr, "curses.cc: For best results, use the 'vga' font\n");
+
+#ifdef CURSES_COLOR
+  start_color();
+  if (has_colors() == TRUE)
+    fprintf(stderr, "curses.cc: Color is supported by this terminal\n");
+  else 
+    fprintf(stderr, "curses.cc: Color is not supported by this terminal\n");
+
+  /* allocate color pairs */
+  int pairno = 1;
+  for (int i = 0; i < 8; i++) {
+    for (int j = 0; j < 8; j++) {
+      if (i == 0 && j == 0) continue;
+      if (init_pair(pairno, curses_colors[i], curses_colors[j]) == ERR) {
+        fprintf(stderr, "error allocating color pair (%d/%d)\n", i, j);
+        return;
+      }
+      curses_color_map[i][j] = pairno;
+      pairno++;
+    }
+  }
+#endif /* CURSES_COLOR */
 }
 
 
@@ -359,11 +401,26 @@
 
   for (unsigned int i=0; i<rows; i++)
     for (unsigned int j=0; j<80; j++) {
-//      char style = new_text[(i*80+j)*2 - 1];
-      char c = new_text[(i*80+j)*2];
+      chtype c = new_text[(i*80+j)*2];
+      char style = new_text[(i*80+j)*2 + 1];      
+      char fgbold  = style & 0x08;
+      char bgbold  = (style & 0x80) >> 4;
+#ifdef CURSES_COLOR
+      char fgcolor = style & 0x07;
+      char bgcolor = (style & 0x70) >> 4;      
+#endif
+
+      /* remap any characters as necessary */
       switch (c) {
       case 0x00:  c=' ';
-      }      
+      }
+
+      if (fgbold) c = c | A_BOLD;
+      if (bgbold) c = c | A_REVERSE;
+#ifdef CURSES_COLOR
+      c = c | COLOR_PAIR(curses_color_map[fgcolor][bgcolor]);
+#endif CURSES_COLOR
+
       addch(c);
     }
 

Reply via email to