This patch allows the following to work:

  set color_normal=cyan/blue
  set color_highlight=white/blue
which is equivalent to this command in GRUB Legacy:

  color cyan/blue white/blue

I haven't written a ChangeLog entry yet, because I'd like to receive comments
on the function names.  I don't really like `parse_single_color_name' and
`parse_color_name' but I don't know what to call them :-(.  What conventions
are there for referring to single colors (i.e. those that describe only FG or
only BG, not both) and complete colors (FG + BG) ?

-- 
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)
diff -ur grub2.vesa/normal/menu.c grub2.gfxterm/normal/menu.c
--- grub2.vesa/normal/menu.c	2007-12-25 12:10:46.000000000 +0100
+++ grub2.gfxterm/normal/menu.c	2008-01-01 13:44:15.000000000 +0100
@@ -1,6 +1,6 @@
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2003,2004,2005,2006,2007  Free Software Foundation, Inc.
+ *  Copyright (C) 2003,2004,2005,2006,2007,2008  Free Software Foundation, Inc.
  *
  *  GRUB is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -28,6 +28,76 @@
 #define GRUB_COLOR_MENU_NORMAL		0x07
 #define GRUB_COLOR_MENU_HIGHLIGHT	0x70
 
+static grub_uint8_t grub_color_menu_normal = GRUB_COLOR_MENU_NORMAL;
+static grub_uint8_t grub_color_menu_highlight = GRUB_COLOR_MENU_HIGHLIGHT;
+
+static void
+wait_after_message (void)
+{
+  /* Wait until the user pushes any key so that the user
+     can see what happened.  */
+  grub_printf ("\nPress any key to continue...");
+  (void) grub_getkey ();
+}
+
+/* Borrowed from GRUB Legacy */
+static char *color_list[16] =
+{
+  "black",
+  "blue",
+  "green",
+  "cyan",
+  "red",
+  "magenta",
+  "brown",
+  "light-gray",
+  "dark-gray",
+  "light-blue",
+  "light-green",
+  "light-cyan",
+  "light-red",
+  "light-magenta",
+  "yellow",
+  "white"
+};
+
+static grub_uint8_t
+parse_single_color_name (char *name)
+{
+  grub_uint8_t i;
+  for (i = 0; i < 0x10; i++)
+    if (! grub_strcmp (name, color_list[i]))
+      break;
+  return i;
+}
+
+static grub_uint8_t
+parse_color_name (char *name)
+{
+  grub_uint8_t ret_fg, ret_bg;
+  char *fg, *bg;
+
+  /* not specified by user */
+  if (name == NULL)
+    return GRUB_COLOR_MENU_NORMAL;
+
+  fg = grub_strdup (name);
+  bg = grub_strchr (fg, '/');
+  *(bg++) = '\0';
+  ret_fg = parse_single_color_name (fg);
+  ret_bg = parse_single_color_name (bg);
+  grub_free (fg);
+
+  if ((ret_fg | ret_bg) > 0x0f)
+    {
+      grub_printf ("Warning: invalid color name, reverting to defaults\n");
+      wait_after_message ();
+      return GRUB_COLOR_MENU_NORMAL;
+    }
+  else
+    return (ret_bg << 4) | ret_fg;
+}
+
 static void
 draw_border (void)
 {
@@ -108,7 +178,7 @@
   grub_ssize_t len;
   grub_uint32_t *unicode_title;
   grub_ssize_t i;
-  grub_uint8_t normal_code, highlight_code;
+  grub_uint8_t old_color_normal, old_color_highlight;
 
   title = entry ? entry->title : "";
   unicode_title = grub_malloc (grub_strlen (title) * sizeof (*unicode_title));
@@ -125,8 +195,8 @@
       return;
     }
   
-  grub_getcolor (&normal_code, &highlight_code);
-  grub_setcolor (GRUB_COLOR_MENU_NORMAL, GRUB_COLOR_MENU_HIGHLIGHT);
+  grub_getcolor (&old_color_normal, &old_color_highlight);
+  grub_setcolor (grub_color_menu_normal, grub_color_menu_highlight);
   grub_setcolorstate (highlight
 		      ? GRUB_TERM_COLOR_HIGHLIGHT
 		      : GRUB_TERM_COLOR_NORMAL);
@@ -164,7 +234,7 @@
 
   grub_gotoxy (GRUB_TERM_CURSOR_X, y);
 
-  grub_setcolor (normal_code, highlight_code);
+  grub_setcolor (old_color_normal, old_color_highlight);
   grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
   grub_free (unicode_title);
 }
@@ -209,15 +279,19 @@
 void
 grub_menu_init_page (int nested, int edit)
 {
-  grub_uint8_t normal_code, highlight_code;
-  grub_getcolor (&normal_code, &highlight_code);
-  grub_setcolor (GRUB_COLOR_MENU_NORMAL, GRUB_COLOR_MENU_HIGHLIGHT);
+  grub_uint8_t old_color_normal, old_color_highlight;
+
+  grub_color_menu_normal = parse_color_name (grub_env_get ("color_normal"));
+  grub_color_menu_highlight = parse_color_name (grub_env_get ("color_highlight"));
+
+  grub_getcolor (&old_color_normal, &old_color_highlight);
+  grub_setcolor (grub_color_menu_normal, grub_color_menu_highlight);
 
   grub_normal_init_page ();
   draw_border ();
   print_message (nested, edit);
 
-  grub_setcolor (normal_code, highlight_code);
+  grub_setcolor (old_color_normal, old_color_highlight);
 }
 
 /* Return the current timeout. If the variable "timeout" is not set or
@@ -501,10 +575,7 @@
 	  grub_print_error ();
 	  grub_errno = GRUB_ERR_NONE;
 
-	  /* Wait until the user pushes any key so that the user
-	     can see what happened.  */
-	  grub_printf ("\nPress any key to continue...");
-	  (void) grub_getkey ();
+	  wait_after_message ();
 	}
     }
 }
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to