From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1J6c7f-0000ia-JJ for mharc-grub-devel@gnu.org; Sun, 23 Dec 2007 20:28:51 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1J6c7e-0000iV-Bb for grub-devel@gnu.org; Sun, 23 Dec 2007 20:28:50 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1J6c7c-0000iJ-NU for grub-devel@gnu.org; Sun, 23 Dec 2007 20:28:49 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J6c7c-0000iG-Hb for grub-devel@gnu.org; Sun, 23 Dec 2007 20:28:48 -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 1J6c7c-0004j0-3o for grub-devel@gnu.org; Sun, 23 Dec 2007 20:28:48 -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 1J6c7W-00035y-Mh for grub-devel@gnu.org; Mon, 24 Dec 2007 02:28:47 +0100 Received: from rmh by thorin with local (Exim 4.63) (envelope-from ) id 1J6c78-0005t1-Pv for grub-devel@gnu.org; Mon, 24 Dec 2007 02:28:18 +0100 Date: Mon, 24 Dec 2007 02:28:18 +0100 From: Robert Millan To: grub-devel@gnu.org Message-ID: <20071224012818.GA22510@thorin> References: <20071223210936.GA27776@thorin> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="5vNYLRcllDrimb99" Content-Disposition: inline In-Reply-To: <20071223210936.GA27776@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] colored menu 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: Mon, 24 Dec 2007 01:28:50 -0000 --5vNYLRcllDrimb99 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline New patch. Corrects a minor mistake when filling the last colum in the menu. Also, it doesn't change the colors on gfxterm since some reasjustments were needed for that, and there's also a bug that makes it impossible to change colors on the fly with gfxterm/vbe (I'll write more on that later). -- 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 /.) --5vNYLRcllDrimb99 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="colored_menu.diff" * 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. (grub_menu_init_page): Likewise. Fill an additional colored space that would otherwise be left blank. * term/efi/console.c (grub_console_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. * term/gfxterm.c (grub_virtual_screen_setcolor): Remove function. (struct grub_console_term.setcolor): Remove variable. diff -ur grub2/include/grub/term.h grub2.color/include/grub/term.h --- grub2/include/grub/term.h 2007-07-22 01:32:22.000000000 +0200 +++ grub2.color/include/grub/term.h 2007-12-24 02:21:30.000000000 +0100 @@ -164,6 +164,10 @@ 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_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 -ur grub2/kern/term.c grub2.color/kern/term.c --- grub2/kern/term.c 2007-07-22 01:32:26.000000000 +0200 +++ grub2.color/kern/term.c 2007-12-24 02:21:30.000000000 +0100 @@ -230,6 +230,13 @@ (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 -ur grub2/normal/menu.c grub2.color/normal/menu.c --- grub2/normal/menu.c 2007-11-10 21:32:32.000000000 +0100 +++ grub2.color/normal/menu.c 2007-12-24 02:21:30.000000000 +0100 @@ -25,6 +25,9 @@ #include #include +#define GRUB_COLOR_MENU_NORMAL 0x13 +#define GRUB_COLOR_MENU_HIGHLIGHT 0x1f + static void draw_border (void) { @@ -105,7 +108,8 @@ 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 @@ 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); @@ -153,8 +159,12 @@ x++; } } + grub_setcolorstate (GRUB_TERM_COLOR_NORMAL); + grub_putchar (' '); + grub_gotoxy (GRUB_TERM_CURSOR_X, y); + grub_setcolor (normal_code, highlight_code); grub_setcolorstate (GRUB_TERM_COLOR_STANDARD); grub_free (unicode_title); } @@ -199,9 +209,15 @@ 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_normal_init_page (); draw_border (); print_message (nested, edit); + + grub_setcolor (normal_code, highlight_code); } /* Return the current timeout. If the variable "timeout" is not set or diff -ur grub2/term/efi/console.c grub2.color/term/efi/console.c --- grub2/term/efi/console.c 2007-07-22 01:32:30.000000000 +0200 +++ grub2.color/term/efi/console.c 2007-12-24 02:21:30.000000000 +0100 @@ -260,6 +260,13 @@ } 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 @@ .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 -ur grub2/term/gfxterm.c grub2.color/term/gfxterm.c --- grub2/term/gfxterm.c 2007-07-22 01:32:30.000000000 +0200 +++ grub2.color/term/gfxterm.c 2007-12-24 02:21:30.000000000 +0100 @@ -840,14 +840,6 @@ } static void -grub_virtual_screen_setcolor (grub_uint8_t normal_color, - grub_uint8_t highlight_color) -{ - virtual_screen.fg_color_setting = grub_video_map_color (normal_color); - virtual_screen.bg_color_setting = grub_video_map_color (highlight_color); -} - -static void grub_gfxterm_setcursor (int on) { if (virtual_screen.cursor_state != on) @@ -882,7 +874,6 @@ .gotoxy = grub_gfxterm_gotoxy, .cls = grub_gfxterm_cls, .setcolorstate = grub_virtual_screen_setcolorstate, - .setcolor = grub_virtual_screen_setcolor, .setcursor = grub_gfxterm_setcursor, .refresh = grub_gfxterm_refresh, .flags = 0, diff -ur grub2/term/i386/pc/console.c grub2.color/term/i386/pc/console.c --- grub2/term/i386/pc/console.c 2007-07-22 01:32:30.000000000 +0200 +++ grub2.color/term/i386/pc/console.c 2007-12-24 02:21:30.000000000 +0100 @@ -117,6 +117,13 @@ 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 @@ .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 -ur grub2/term/i386/pc/serial.c grub2.color/term/i386/pc/serial.c --- grub2/term/i386/pc/serial.c 2007-11-10 21:23:14.000000000 +0100 +++ grub2.color/term/i386/pc/serial.c 2007-12-24 02:21:30.000000000 +0100 @@ -454,13 +454,6 @@ } 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 @@ .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 -ur grub2/term/i386/pc/vesafb.c grub2.color/term/i386/pc/vesafb.c --- grub2/term/i386/pc/vesafb.c 2007-07-22 01:32:31.000000000 +0200 +++ grub2.color/term/i386/pc/vesafb.c 2007-12-24 02:21:30.000000000 +0100 @@ -565,13 +565,6 @@ } 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 @@ .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 -ur grub2/term/i386/pc/vga.c grub2.color/term/i386/pc/vga.c --- grub2/term/i386/pc/vga.c 2007-11-10 19:34:48.000000000 +0100 +++ grub2.color/term/i386/pc/vga.c 2007-12-24 02:21:30.000000000 +0100 @@ -460,13 +460,6 @@ } 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 @@ .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 -ur grub2/term/ieee1275/ofconsole.c grub2.color/term/ieee1275/ofconsole.c --- grub2/term/ieee1275/ofconsole.c 2007-07-22 11:05:11.000000000 +0200 +++ grub2.color/term/ieee1275/ofconsole.c 2007-12-24 02:21:30.000000000 +0100 @@ -129,6 +129,13 @@ 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 @@ .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, --5vNYLRcllDrimb99--