[1778] 2008-08-05 Bean <[email protected]>

Bean <[email protected]>
Newsgroups gmane.comp.boot-loaders.grub.cvs
Message-ID <[email protected]>
Revision: 1778
          http://svn.sv.gnu.org/viewvc/?view=rev&root=grub&revision=1778
Author:   bean
Date:     2008-08-05 14:20:00 +0000 (Tue, 05 Aug 2008)

Log Message:
-----------
2008-08-05  Bean  <[email protected]>

	* util/console.c (grub_console_cur_color): New variable.
	(grub_console_standard_color): Likewise.
	(grub_console_normal_color): Likewise.
	(grub_console_highlight_color): Likewise.
	(color_map): Likewise.
	(use_color): Likewise.
	(NUM_COLORS): New macro.
	(grub_ncurses_setcolorstate): Handle color properly.
	(grub_ncurses_setcolor): Don't change color here, just remember the
	settings, color will be set in grub_ncurses_setcolorstate.
	(grub_ncurses_getcolor): New function.
	(grub_ncurses_init): Initialize color pairs.
	(grub_ncurses_term): New member grub_ncurses_getcolor.

Modified Paths:
--------------
    trunk/grub2/ChangeLog
    trunk/grub2/util/console.c

Modified: trunk/grub2/ChangeLog
===================================================================
--- trunk/grub2/ChangeLog	2008-08-05 12:38:12 UTC (rev 1777)
+++ trunk/grub2/ChangeLog	2008-08-05 14:20:00 UTC (rev 1778)
@@ -1,3 +1,19 @@
+2008-08-05  Bean  <[email protected]>
+
+	* util/console.c (grub_console_cur_color): New variable.
+	(grub_console_standard_color): Likewise.
+	(grub_console_normal_color): Likewise.
+	(grub_console_highlight_color): Likewise.
+	(color_map): Likewise.
+	(use_color): Likewise.
+	(NUM_COLORS): New macro.
+	(grub_ncurses_setcolorstate): Handle color properly.
+	(grub_ncurses_setcolor): Don't change color here, just remember the
+	settings, color will be set in grub_ncurses_setcolorstate.
+	(grub_ncurses_getcolor): New function.
+	(grub_ncurses_init): Initialize color pairs.
+	(grub_ncurses_term): New member grub_ncurses_getcolor.
+
 2008-08-05  Colin D Bennett  <[email protected]>
  
 	High resolution timer support.  Implemented for x86 CPUs using TSC.

Modified: trunk/grub2/util/console.c
===================================================================
--- trunk/grub2/util/console.c	2008-08-05 12:38:12 UTC (rev 1777)
+++ trunk/grub2/util/console.c	2008-08-05 14:20:00 UTC (rev 1778)
@@ -41,6 +41,28 @@
 
 static int grub_console_attr = A_NORMAL;
 
+grub_uint8_t grub_console_cur_color = 7;
+
+static grub_uint8_t grub_console_standard_color = 0x7;
+static grub_uint8_t grub_console_normal_color = 0x7;
+static grub_uint8_t grub_console_highlight_color = 0x70;
+
+#define NUM_COLORS	8
+
+static grub_uint8_t color_map[NUM_COLORS] =
+{
+  COLOR_BLACK,
+  COLOR_BLUE,
+  COLOR_GREEN,
+  COLOR_CYAN,
+  COLOR_RED,
+  COLOR_MAGENTA,
+  COLOR_YELLOW,
+  COLOR_WHITE
+};
+
+static int use_color;
+
 static void
 grub_ncurses_putchar (grub_uint32_t c)
 {
@@ -100,26 +122,48 @@
   switch (state) 
     {
     case GRUB_TERM_COLOR_STANDARD:
+      grub_console_cur_color = grub_console_standard_color;
       grub_console_attr = A_NORMAL;
       break;
     case GRUB_TERM_COLOR_NORMAL:
+      grub_console_cur_color = grub_console_normal_color;
       grub_console_attr = A_NORMAL;
       break;
     case GRUB_TERM_COLOR_HIGHLIGHT:
+      grub_console_cur_color = grub_console_highlight_color;
       grub_console_attr = A_STANDOUT;
       break;
     default:
       break;
     }
+
+  if (use_color)
+    {
+      grub_uint8_t fg, bg;
+
+      fg = (grub_console_cur_color & 7);
+      bg = (grub_console_cur_color >> 4) & 7;
+
+      grub_console_attr = (grub_console_cur_color & 8) ? A_BOLD : A_NORMAL;
+      color_set ((bg << 3) + fg, 0);
+    }
 }
 
 /* XXX: This function is never called.  */
 static void
 grub_ncurses_setcolor (grub_uint8_t normal_color, grub_uint8_t highlight_color)
 {
-  color_set (normal_color << 8 | highlight_color, 0);
+  grub_console_normal_color = normal_color;
+  grub_console_highlight_color = highlight_color;
 }
 
+static void
+grub_ncurses_getcolor (grub_uint8_t *normal_color, grub_uint8_t *highlight_color)
+{
+  *normal_color = grub_console_normal_color;
+  *highlight_color = grub_console_highlight_color;
+}
+
 static int saved_char = ERR;
 
 static int
@@ -272,8 +316,24 @@
   nonl ();
   intrflush (stdscr, FALSE);
   keypad (stdscr, TRUE);
-  start_color ();
 
+  if (has_colors ())
+    {
+      start_color ();
+
+      if ((COLORS >= NUM_COLORS) && (COLOR_PAIRS >= NUM_COLORS * NUM_COLORS))
+        {
+          int i, j, n;
+
+          n = 0;
+          for (i = 0; i < NUM_COLORS; i++)
+            for (j = 0; j < NUM_COLORS; j++)
+              init_pair(n++, color_map[j], color_map[i]);
+
+          use_color = 1;
+        }
+    }
+
   return 0;
 }
 
@@ -300,6 +360,7 @@
     .cls = grub_ncurses_cls,
     .setcolorstate = grub_ncurses_setcolorstate,
     .setcolor = grub_ncurses_setcolor,
+    .getcolor = grub_ncurses_getcolor,
     .setcursor = grub_ncurses_setcursor,
     .refresh = grub_ncurses_refresh,
     .flags = 0,
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.