From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1J9l4b-0004Ce-JV for mharc-grub-devel@gnu.org; Tue, 01 Jan 2008 12:38:41 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1J9l4a-0004CX-7P for grub-devel@gnu.org; Tue, 01 Jan 2008 12:38:40 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1J9l4V-0004C8-KC for grub-devel@gnu.org; Tue, 01 Jan 2008 12:38:39 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J9l4V-0004C5-DU for grub-devel@gnu.org; Tue, 01 Jan 2008 12:38:35 -0500 Received: from aybabtu.com ([69.60.117.155]) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1J9l4U-0004us-SZ for grub-devel@gnu.org; Tue, 01 Jan 2008 12:38:35 -0500 Received: from [192.168.10.6] (helo=thorin) by aybabtu.com with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1J9l4O-0002ug-Lk for grub-devel@gnu.org; Tue, 01 Jan 2008 18:38:33 +0100 Received: from rmh by thorin with local (Exim 4.63) (envelope-from ) id 1J9l42-0000wg-DO for grub-devel@gnu.org; Tue, 01 Jan 2008 18:38:06 +0100 Date: Tue, 1 Jan 2008 18:38:06 +0100 From: Robert Millan To: The development of GRUB 2 Message-ID: <20080101173806.GA3440@thorin> References: <20080101124728.GA30417@thorin> <477A3CCA.4090908@nic.fi> <20080101134026.GA32057@thorin> <477A456B.2010209@nic.fi> <20080101144530.GA11162@thorin> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="XsQoSWH+UP9D9v3l" Content-Disposition: inline In-Reply-To: <20080101144530.GA11162@thorin> Organization: free as in freedom X-Message-Flag: Worried about Outlook viruses? Switch to Thunderbird! www.mozilla.com/thunderbird X-Debbugs-No-Ack: true User-Agent: Mutt/1.5.13 (2006-08-11) X-detected-kernel: by monty-python.gnu.org: Genre and OS details not recognized. Subject: Re: [PATCH] allow user-configurable menucolor X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Jan 2008 17:38:40 -0000 --XsQoSWH+UP9D9v3l Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Some rework to support user-defined colors in non-menu as well. This is most desirable when using the new background image feature implemented by Vesa, since light-grey may not be properly readable depending on the image you're using. Example for bios console, setting up only menu color: set menu_color_normal=cyan/blue set menu_color_highlight=white/blue Example for gfxterm, setting up white foreground to match with loaded image: insmod video insmod vbe insmod gfxterm insmod tga font (hd0)/unifont.pff terminal gfxterm set color_normal=white/black set color_highlight=black/white color background_image (hd0)/bg.tga `color' command is necessary to propagate user setting from environment variables to the internal color of our current terminal. Please comment on the design, etc first. I still have to write a ChangeLog entry, update the missing *.rmk files, etc. -- Robert Millan I know my rights; I want my phone call! What use is a phone call, if you are unable to speak? (as seen on /.) --XsQoSWH+UP9D9v3l Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="menucolor.diff" diff -x '*.mk' -Nurp grub2/conf/i386-pc.rmk grub2.color/conf/i386-pc.rmk --- grub2/conf/i386-pc.rmk 2007-12-26 08:51:18.000000000 +0100 +++ grub2.color/conf/i386-pc.rmk 2008-01-01 17:43:27.000000000 +0100 @@ -111,7 +111,7 @@ grub_emu_SOURCES = commands/boot.c comma kern/loader.c kern/main.c kern/misc.c kern/parser.c \ grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c \ normal/arg.c normal/cmdline.c normal/command.c normal/function.c\ - normal/completion.c normal/main.c \ + normal/completion.c normal/main.c normal/color.c \ normal/menu.c normal/menu_entry.c normal/misc.c normal/script.c \ partmap/amiga.c partmap/apple.c partmap/pc.c partmap/sun.c \ partmap/acorn.c partmap/gpt.c \ @@ -168,6 +168,7 @@ normal_mod_DEPENDENCIES = grub_script.ta normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \ normal/completion.c normal/execute.c \ normal/function.c normal/lexer.c normal/main.c normal/menu.c \ + normal/color.c \ normal/menu_entry.c normal/misc.c grub_script.tab.c \ normal/script.c normal/i386/setjmp.S normal_mod_CFLAGS = $(COMMON_CFLAGS) diff -x '*.mk' -Nurp grub2/include/grub/normal.h grub2.color/include/grub/normal.h --- grub2/include/grub/normal.h 2007-07-22 01:32:22.000000000 +0200 +++ grub2.color/include/grub/normal.h 2008-01-01 18:06:36.000000000 +0100 @@ -154,6 +154,8 @@ grub_err_t grub_normal_print_device_info grub_err_t grub_normal_menu_addentry (const char *title, struct grub_script *script, const char *sourcecode); +void grub_normal_color_reload (void); +void wait_after_message (void); #ifdef GRUB_UTIL void grub_normal_init (void); diff -x '*.mk' -Nurp grub2/normal/color.c grub2.color/normal/color.c --- grub2/normal/color.c 1970-01-01 01:00:00.000000000 +0100 +++ grub2.color/normal/color.c 2008-01-01 18:03:28.000000000 +0100 @@ -0,0 +1,119 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 1999,2000,2001,2002,2003,2004,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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include + +/* 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 int +parse_color_name (grub_uint8_t *ret, char *name) +{ + grub_uint8_t i; + for (i = 0; i < sizeof (color_list) / sizeof (*color_list); i++) + if (! grub_strcmp (name, color_list[i])) + { + *ret = i; + return 0; + } + return -1; +} + +void +grub_parse_color_name_pair (grub_uint8_t *ret, char *name) +{ + grub_uint8_t fg, bg; + char *fg_name, *bg_name; + + /* nothing specified by user */ + if (name == NULL) + return; + + fg_name = grub_strdup (name); + if (fg_name == NULL) + { + /* "out of memory" message was printed by grub_strdup() */ + wait_after_message (); + return; + } + + bg_name = grub_strchr (fg_name, '/'); + if (bg_name == NULL) + { + grub_printf ("Warning: syntax error (missing slash) in `%s'\n", fg_name); + wait_after_message (); + goto free_and_return; + } + + *(bg_name++) = '\0'; + + if (parse_color_name (&fg, fg_name) == -1) + { + grub_printf ("Warning: invalid foreground color `%s'\n", fg_name); + wait_after_message (); + goto free_and_return; + } + if (parse_color_name (&bg, bg_name) == -1) + { + grub_printf ("Warning: invalid background color `%s'\n", bg_name); + wait_after_message (); + goto free_and_return; + } + + *ret = (bg << 4) | fg; + +free_and_return: + grub_free (fg_name); +} + +/* Replace default console colors with the ones specified by + user (if any). */ +void +grub_normal_color_reload (void) +{ + grub_uint8_t color_normal, color_highlight; + + grub_getcolor (&color_normal, &color_highlight); + + grub_parse_color_name_pair (&color_normal, grub_env_get ("color_normal")); + grub_parse_color_name_pair (&color_highlight, grub_env_get ("color_highlight")); + + grub_setcolor (color_normal, color_highlight); + grub_setcolorstate (GRUB_TERM_COLOR_NORMAL); +} diff -x '*.mk' -Nurp grub2/normal/command.c grub2.color/normal/command.c --- grub2/normal/command.c 2007-07-22 01:32:29.000000000 +0200 +++ grub2.color/normal/command.c 2008-01-01 18:06:16.000000000 +0100 @@ -365,6 +365,14 @@ lsmod_command (struct grub_arg_list *sta return 0; } +static grub_err_t +color_command (struct grub_arg_list *state __attribute__ ((unused)), + int argc __attribute__ ((unused)), char **args __attribute__ ((unused))) +{ + grub_normal_color_reload (); + return 0; +} + void grub_command_init (void) { @@ -391,4 +399,7 @@ grub_command_init (void) grub_register_command ("lsmod", lsmod_command, GRUB_COMMAND_FLAG_BOTH, "lsmod", "Show loaded modules.", 0); + + grub_register_command ("color", color_command, GRUB_COMMAND_FLAG_BOTH, + "color", "Set colors in the current terminal.", 0); } diff -x '*.mk' -Nurp grub2/normal/main.c grub2.color/normal/main.c --- grub2/normal/main.c 2007-07-22 01:32:29.000000000 +0200 +++ grub2.color/normal/main.c 2008-01-01 18:04:33.000000000 +0100 @@ -268,12 +268,7 @@ read_config_file (const char *config, in grub_file_close (file); if (errors > 0) - { - /* 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 (); return newmenu; } diff -x '*.mk' -Nurp grub2/normal/menu.c grub2.color/normal/menu.c --- grub2/normal/menu.c 2007-12-25 12:10:46.000000000 +0100 +++ grub2.color/normal/menu.c 2008-01-01 18:29:05.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 @@ -25,8 +25,17 @@ #include #include -#define GRUB_COLOR_MENU_NORMAL 0x07 -#define GRUB_COLOR_MENU_HIGHLIGHT 0x70 +static grub_uint8_t grub_color_menu_normal; +static grub_uint8_t grub_color_menu_highlight; + +/* Wait until the user pushes any key so that the user + can see what happened. */ +void +wait_after_message (void) +{ + grub_printf ("\nPress any key to continue..."); + (void) grub_getkey (); +} static void draw_border (void) @@ -57,7 +66,7 @@ draw_border (void) grub_putcode (GRUB_TERM_DISP_HLINE); grub_putcode (GRUB_TERM_DISP_LR); - grub_setcolorstate (GRUB_TERM_COLOR_STANDARD); + grub_setcolorstate (GRUB_TERM_COLOR_NORMAL); grub_gotoxy (GRUB_TERM_MARGIN, (GRUB_TERM_TOP_BORDER_Y + GRUB_TERM_NUM_ENTRIES @@ -67,6 +76,8 @@ draw_border (void) static void print_message (int nested, int edit) { + grub_setcolorstate (GRUB_TERM_COLOR_NORMAL); + if (edit) { grub_printf ("\n\ @@ -108,7 +119,7 @@ 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; + grub_uint8_t old_color_normal, old_color_highlight; title = entry ? entry->title : ""; unicode_title = grub_malloc (grub_strlen (title) * sizeof (*unicode_title)); @@ -124,9 +135,9 @@ print_entry (int y, int highlight, grub_ grub_free (unicode_title); 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,8 +175,8 @@ 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_setcolor (old_color_normal, old_color_highlight); + grub_setcolorstate (GRUB_TERM_COLOR_NORMAL); grub_free (unicode_title); } @@ -209,15 +220,23 @@ print_entries (grub_menu_t menu, int fir 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_getcolor (&old_color_normal, &old_color_highlight); + + /* By default, use the same colors for the menu. */ + grub_color_menu_normal = old_color_normal; + grub_color_menu_highlight = old_color_highlight; + + /* Then give user a chance to replace them. */ + grub_parse_color_name_pair (&grub_color_menu_normal, grub_env_get ("menu_color_normal")); + grub_parse_color_name_pair (&grub_color_menu_highlight, grub_env_get ("menu_color_highlight")); grub_normal_init_page (); + grub_setcolor (grub_color_menu_normal, grub_color_menu_highlight); draw_border (); + grub_setcolor (old_color_normal, old_color_highlight); print_message (nested, edit); - - grub_setcolor (normal_code, highlight_code); } /* Return the current timeout. If the variable "timeout" is not set or @@ -501,10 +520,7 @@ grub_menu_run (grub_menu_t menu, int nes 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 (); } } } diff -x '*.mk' -Nurp grub2/normal/menu_entry.c grub2.color/normal/menu_entry.c --- grub2/normal/menu_entry.c 2007-12-30 09:52:05.000000000 +0100 +++ grub2.color/normal/menu_entry.c 2008-01-01 17:30:37.000000000 +0100 @@ -1030,10 +1030,7 @@ run (struct screen *screen) { 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 (); } return 1; --XsQoSWH+UP9D9v3l--