This patch adds a nice looking colored menu like the one you'd obtain on GRUB Legacy with "color cyan/blue white/blue" command. Screenshot is attached as well.
A pair of notes: - The *_setcolor function stubs are being removed from some terminals because grub_setcolor() from kernel already skips undefined *_setcolor implementations so there's no need for an empty stub. In fact, not needed for this patch but adds confusion (I had to inspect all them to see if *_getcolor() had to be added). - I know that hardcoding colors is not so nice, but I was unsure how would the selection interface have to look like (and lacking time to implement it), and in comparison with defaulting to hardcoded 0x07 (grey on black) I see it as an improvement. -- 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 /.)
* include/grub/term.h (struct grub_term): Add `getcolor' function.
(grub_getcolor): New function.
* kern/term.c (grub_getcolor): New function.
* normal/menu.c (GRUB_COLOR_MENU_NORMAL): New macro.
(GRUB_COLOR_MENU_HIGHLIGHT): New macro.
(print_entry): Set normal and highlight colors to
`GRUB_COLOR_MENU_NORMAL' and `GRUB_COLOR_MENU_HIGHLIGHT',
respectively, before printing and restore them to old
values afterwards.
(run_menu): Likewise.
* term/efi/console.c (grub_console_getcolor): New function.
(struct grub_console_term.getcolor): New variable.
* term/gfxterm.c (grub_virtual_screen_getcolor): New function.
(struct grub_console_term.getcolor): New variable.
* term/i386/pc/console.c (grub_console_getcolor): New function.
(struct grub_console_term.getcolor): New variable.
* term/ieee1275/ofconsole.c (grub_ofconsole_getcolor): New function.
(struct grub_console_term.getcolor): New variable.
* term/i386/pc/serial.c (grub_serial_setcolor): Remove function.
(struct grub_console_term.setcolor): Remove variable.
* term/i386/pc/vesafb.c (grub_virtual_screen_setcolor): Remove function.
(struct grub_console_term.setcolor): Remove variable.
* term/i386/pc/vga.c (grub_vga_setcolor): Remove function.
(struct grub_console_term.setcolor): Remove variable.
diff -x '*~' -x configure -Nurp ../grub2/include/grub/term.h ./include/grub/term.h
--- ../grub2/include/grub/term.h 2007-07-22 01:32:22.000000000 +0200
+++ ./include/grub/term.h 2007-12-23 21:20:42.000000000 +0100
@@ -164,6 +164,10 @@ struct grub_term
color is VGA's. */
void (*setcolor) (grub_uint8_t normal_color, grub_uint8_t highlight_color);
+ /* Get the normal color and the highlight color. The format of each
+ color is VGA's. */
+ void (*getcolor) (grub_uint8_t *normal_color, grub_uint8_t *highlight_color);
+
/* Turn on/off the cursor. */
void (*setcursor) (int on);
@@ -197,6 +201,8 @@ void EXPORT_FUNC(grub_cls) (void);
void EXPORT_FUNC(grub_setcolorstate) (grub_term_color_state state);
void EXPORT_FUNC(grub_setcolor) (grub_uint8_t normal_color,
grub_uint8_t highlight_color);
+void EXPORT_FUNC(grub_getcolor) (grub_uint8_t *normal_color,
+ grub_uint8_t *highlight_color);
int EXPORT_FUNC(grub_setcursor) (int on);
int EXPORT_FUNC(grub_getcursor) (void);
void EXPORT_FUNC(grub_refresh) (void);
diff -x '*~' -x configure -Nurp ../grub2/kern/term.c ./kern/term.c
--- ../grub2/kern/term.c 2007-07-22 01:32:26.000000000 +0200
+++ ./kern/term.c 2007-12-23 21:08:10.000000000 +0100
@@ -230,6 +230,13 @@ grub_setcolor (grub_uint8_t normal_color
(grub_cur_term->setcolor) (normal_color, highlight_color);
}
+void
+grub_getcolor (grub_uint8_t *normal_color, grub_uint8_t *highlight_color)
+{
+ if (grub_cur_term->getcolor)
+ (grub_cur_term->getcolor) (normal_color, highlight_color);
+}
+
int
grub_setcursor (int on)
{
diff -x '*~' -x configure -Nurp ../grub2/normal/menu.c ./normal/menu.c
--- ../grub2/normal/menu.c 2007-11-10 21:32:32.000000000 +0100
+++ ./normal/menu.c 2007-12-23 21:35:23.000000000 +0100
@@ -25,6 +25,9 @@
#include <grub/env.h>
#include <grub/script.h>
+#define GRUB_COLOR_MENU_NORMAL 0x13
+#define GRUB_COLOR_MENU_HIGHLIGHT 0x1f
+
static void
draw_border (void)
{
@@ -105,7 +108,8 @@ print_entry (int y, int highlight, grub_
grub_ssize_t len;
grub_uint32_t *unicode_title;
grub_ssize_t i;
-
+ grub_uint8_t normal_code, highlight_code;
+
title = entry ? entry->title : "";
unicode_title = grub_malloc (grub_strlen (title) * sizeof (*unicode_title));
if (! unicode_title)
@@ -121,6 +125,8 @@ print_entry (int y, int highlight, grub_
return;
}
+ grub_getcolor (&normal_code, &highlight_code);
+ grub_setcolor (GRUB_COLOR_MENU_NORMAL, GRUB_COLOR_MENU_HIGHLIGHT);
grub_setcolorstate (highlight
? GRUB_TERM_COLOR_HIGHLIGHT
: GRUB_TERM_COLOR_NORMAL);
@@ -128,7 +134,7 @@ print_entry (int y, int highlight, grub_
grub_gotoxy (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN, y);
for (x = GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + 1, i = 0;
- x < GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH - GRUB_TERM_MARGIN;
+ x <= GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH - GRUB_TERM_MARGIN;
i++)
{
if (i < len
@@ -155,6 +161,7 @@ print_entry (int y, int highlight, grub_
}
grub_gotoxy (GRUB_TERM_CURSOR_X, y);
+ grub_setcolor (normal_code, highlight_code);
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
grub_free (unicode_title);
}
@@ -279,6 +286,7 @@ run_menu (grub_menu_t menu, int nested)
int first, offset;
unsigned long saved_time;
int default_entry;
+ grub_uint8_t normal_code, highlight_code;
first = 0;
@@ -301,8 +309,11 @@ run_menu (grub_menu_t menu, int nested)
refresh:
grub_setcursor (0);
+ grub_getcolor (&normal_code, &highlight_code);
+ grub_setcolor (GRUB_COLOR_MENU_NORMAL, GRUB_COLOR_MENU_HIGHLIGHT);
grub_menu_init_page (nested, 0);
print_entries (menu, first, offset);
+ grub_setcolor (normal_code, highlight_code);
grub_refresh ();
while (1)
diff -x '*~' -x configure -Nurp ../grub2/term/efi/console.c ./term/efi/console.c
--- ../grub2/term/efi/console.c 2007-07-22 01:32:30.000000000 +0200
+++ ./term/efi/console.c 2007-12-23 21:42:35.000000000 +0100
@@ -260,6 +260,13 @@ grub_console_setcolor (grub_uint8_t norm
}
static void
+grub_console_getcolor (grub_uint8_t *normal_color, grub_uint8_t *highlight_color)
+{
+ *normal_color = grub_console_normal_color;
+ *highlight_color = grub_console_highlight_color;
+}
+
+static void
grub_console_setcursor (int on)
{
grub_efi_simple_text_output_interface_t *o;
@@ -283,6 +290,7 @@ static struct grub_term grub_console_ter
.cls = grub_console_cls,
.setcolorstate = grub_console_setcolorstate,
.setcolor = grub_console_setcolor,
+ .getcolor = grub_console_getcolor,
.setcursor = grub_console_setcursor,
.flags = 0,
.next = 0
diff -x '*~' -x configure -Nurp ../grub2/term/gfxterm.c ./term/gfxterm.c
--- ../grub2/term/gfxterm.c 2007-07-22 01:32:30.000000000 +0200
+++ ./term/gfxterm.c 2007-12-23 21:43:40.000000000 +0100
@@ -848,6 +848,13 @@ grub_virtual_screen_setcolor (grub_uint8
}
static void
+grub_virtual_screen_getcolor (grub_uint8_t *normal_color, grub_uint8_t *highlight_color)
+{
+ *normal_color = virtual_screen.fg_color_setting;
+ *highlight_color = virtual_screen.bg_color_setting;
+}
+
+static void
grub_gfxterm_setcursor (int on)
{
if (virtual_screen.cursor_state != on)
@@ -883,6 +890,7 @@ static struct grub_term grub_video_term
.cls = grub_gfxterm_cls,
.setcolorstate = grub_virtual_screen_setcolorstate,
.setcolor = grub_virtual_screen_setcolor,
+ .getcolor = grub_virtual_screen_getcolor,
.setcursor = grub_gfxterm_setcursor,
.refresh = grub_gfxterm_refresh,
.flags = 0,
diff -x '*~' -x configure -Nurp ../grub2/term/i386/pc/console.c ./term/i386/pc/console.c
--- ../grub2/term/i386/pc/console.c 2007-07-22 01:32:30.000000000 +0200
+++ ./term/i386/pc/console.c 2007-12-23 21:09:59.000000000 +0100
@@ -117,6 +117,13 @@ grub_console_setcolor (grub_uint8_t norm
grub_console_highlight_color = highlight_color;
}
+static void
+grub_console_getcolor (grub_uint8_t *normal_color, grub_uint8_t *highlight_color)
+{
+ *normal_color = grub_console_normal_color;
+ *highlight_color = grub_console_highlight_color;
+}
+
static struct grub_term grub_console_term =
{
.name = "console",
@@ -132,6 +139,7 @@ static struct grub_term grub_console_ter
.cls = grub_console_cls,
.setcolorstate = grub_console_setcolorstate,
.setcolor = grub_console_setcolor,
+ .getcolor = grub_console_getcolor,
.setcursor = grub_console_setcursor,
.flags = 0,
.next = 0
diff -x '*~' -x configure -Nurp ../grub2/term/i386/pc/serial.c ./term/i386/pc/serial.c
--- ../grub2/term/i386/pc/serial.c 2007-11-10 21:23:14.000000000 +0100
+++ ./term/i386/pc/serial.c 2007-12-23 21:41:22.000000000 +0100
@@ -454,13 +454,6 @@ grub_serial_setcolorstate (const grub_te
}
static void
-grub_serial_setcolor (grub_uint8_t normal_color __attribute__ ((unused)),
- grub_uint8_t highlight_color __attribute__ ((unused)))
-{
- /* FIXME */
-}
-
-static void
grub_serial_setcursor (const int on)
{
if (on)
@@ -483,7 +476,6 @@ static struct grub_term grub_serial_term
.gotoxy = grub_serial_gotoxy,
.cls = grub_serial_cls,
.setcolorstate = grub_serial_setcolorstate,
- .setcolor = grub_serial_setcolor,
.setcursor = grub_serial_setcursor,
.flags = 0,
.next = 0
diff -x '*~' -x configure -Nurp ../grub2/term/i386/pc/vesafb.c ./term/i386/pc/vesafb.c
--- ../grub2/term/i386/pc/vesafb.c 2007-07-22 01:32:31.000000000 +0200
+++ ./term/i386/pc/vesafb.c 2007-12-23 21:41:09.000000000 +0100
@@ -565,13 +565,6 @@ grub_virtual_screen_setcolorstate (grub_
}
static void
-grub_virtual_screen_setcolor (grub_uint8_t normal_color __attribute__ ((unused)),
- grub_uint8_t highlight_color __attribute__ ((unused)))
-{
- /* FIXME */
-}
-
-static void
grub_vesafb_setcursor (int on)
{
if (virtual_screen.cursor_state != on)
@@ -599,7 +592,6 @@ static struct grub_term grub_vesafb_term
.gotoxy = grub_vesafb_gotoxy,
.cls = grub_vesafb_cls,
.setcolorstate = grub_virtual_screen_setcolorstate,
- .setcolor = grub_virtual_screen_setcolor,
.setcursor = grub_vesafb_setcursor,
.flags = 0,
.next = 0
diff -x '*~' -x configure -Nurp ../grub2/term/i386/pc/vga.c ./term/i386/pc/vga.c
--- ../grub2/term/i386/pc/vga.c 2007-11-10 19:34:48.000000000 +0100
+++ ./term/i386/pc/vga.c 2007-12-23 21:40:50.000000000 +0100
@@ -460,13 +460,6 @@ grub_vga_setcolorstate (grub_term_color_
}
static void
-grub_vga_setcolor (grub_uint8_t normal_color __attribute__ ((unused)),
- grub_uint8_t highlight_color __attribute__ ((unused)))
-{
- /* FIXME */
-}
-
-static void
grub_vga_setcursor (int on)
{
if (cursor_state != on)
@@ -494,7 +487,6 @@ static struct grub_term grub_vga_term =
.gotoxy = grub_vga_gotoxy,
.cls = grub_vga_cls,
.setcolorstate = grub_vga_setcolorstate,
- .setcolor = grub_vga_setcolor,
.setcursor = grub_vga_setcursor,
.flags = 0,
.next = 0
diff -x '*~' -x configure -Nurp ../grub2/term/ieee1275/ofconsole.c ./term/ieee1275/ofconsole.c
--- ../grub2/term/ieee1275/ofconsole.c 2007-07-22 11:05:11.000000000 +0200
+++ ./term/ieee1275/ofconsole.c 2007-12-23 21:45:11.000000000 +0100
@@ -129,6 +129,13 @@ grub_ofconsole_setcolor (grub_uint8_t no
bgcolor = highlight_color;
}
+static void
+grub_ofconsole_getcolor (grub_uint8_t *normal_color, grub_uint8_t *highlight_color)
+{
+ *normal_color = fgcolor;
+ *highlight_color = bgcolor;
+}
+
static int
grub_ofconsole_readkey (int *key)
{
@@ -364,6 +371,7 @@ static struct grub_term grub_ofconsole_t
.cls = grub_ofconsole_cls,
.setcolorstate = grub_ofconsole_setcolorstate,
.setcolor = grub_ofconsole_setcolor,
+ .getcolor = grub_ofconsole_getcolor,
.setcursor = grub_ofconsole_setcursor,
.refresh = grub_ofconsole_refresh,
.flags = 0,
<<attachment: colored_menu.png>>
_______________________________________________ Grub-devel mailing list [email protected] http://lists.gnu.org/mailman/listinfo/grub-devel
