From: Robert Millan <rmh@aybabtu.com>
To: grub-devel@gnu.org
Subject: [PATCH] allow user-configurable menucolor
Date: Tue, 1 Jan 2008 13:47:28 +0100 [thread overview]
Message-ID: <20080101124728.GA30417@thorin> (raw)
[-- Attachment #1: Type: text/plain, Size: 691 bytes --]
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 /.)
[-- Attachment #2: menucolor.diff --]
[-- Type: text/x-diff, Size: 4285 bytes --]
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 ();
}
}
}
next reply other threads:[~2008-01-01 12:47 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-01 12:47 Robert Millan [this message]
2008-01-01 13:14 ` [PATCH] allow user-configurable menucolor Vesa Jääskeläinen
2008-01-01 13:40 ` Robert Millan
2008-01-01 13:51 ` Vesa Jääskeläinen
2008-01-01 14:45 ` Robert Millan
2008-01-01 17:38 ` Robert Millan
2008-01-02 21:48 ` Robert Millan
2008-01-02 23:55 ` Yoshinori K. Okuji
2008-01-03 0:56 ` Robert Millan
2008-01-02 23:42 ` Yoshinori K. Okuji
2008-01-03 1:04 ` Robert Millan
2008-01-03 15:35 ` Robert Millan
2008-01-03 16:04 ` Vesa Jääskeläinen
2008-01-03 16:38 ` Robert Millan
2008-01-23 8:56 ` Marco Gerards
2008-01-04 8:02 ` opening new context (was: [PATCH] allow user-configurable menucolor) Robert Millan
2008-01-05 1:34 ` Yoshinori K. Okuji
2008-01-05 11:49 ` Robert Millan
2008-01-05 12:03 ` Yoshinori K. Okuji
2008-01-05 12:09 ` Robert Millan
2008-01-05 21:45 ` [PATCH] allow user-configurable menucolor Jeroen Dekkers
2008-01-05 23:42 ` Robert Millan
2008-01-06 11:33 ` Jeroen Dekkers
2008-01-06 12:54 ` Robert Millan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080101124728.GA30417@thorin \
--to=rmh@aybabtu.com \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.