Fix color problem the grub-emu
PATCH 1/1 Fix color problem the grub-emu
Hi,
Currently, the color handling in grub-emu is broken, sometimes you see nothing on screen. This patch fix it, now variable menu_color_normal and menu_color_highlight works properly in grub-emu.
2008-08-02 Bean <[email protected]>
* util/console.c (grub_console_cur_color): New variable. (grub_console_standard_color): Likewise. (grub_console_normal_color): Likewise. (grub_console_highlight_color): Likewise.
(color_map): Likewise.
(use_color): Likewise.
(NUM_COLORS): New macro.
(grub_ncurses_setcolorstate): Handle color properly. (grub_ncurses_setcolor): Don't change color here, just remember the settings, color will be set in grub_ncurses_setcolorstate. (grub_ncurses_getcolor): New function. (grub_ncurses_init): Initialize color pairs.
(grub_term grub_ncurses_term): New member grub_ncurses_getcolor.
Signature · 1 line
Bean
util/console.c +63 -2
@@ -41,6 +41,28 @@static int grub_console_attr =A_NORMAL ; +grub_uint8_t grub_console_cur_color =7 ; + +static grub_uint8_t grub_console_standard_color =0x7 ; +static grub_uint8_t grub_console_normal_color =0x7 ; +static grub_uint8_t grub_console_highlight_color =0x70 ; + +#define NUM_COLORS 8 + +static grub_uint8_t color_map[NUM_COLORS ] = +{ +COLOR_BLACK , +COLOR_BLUE , +COLOR_GREEN , +COLOR_CYAN , +COLOR_RED , +COLOR_MAGENTA , +COLOR_YELLOW , +COLOR_WHITE +}; + +static int use_color; +static void grub_ncurses_putchar (grub_uint32_t c) {
@@ -100,24 +122,46 @@ grub_ncurses_setcolorstate (grub_term_color_state state)switch (state) {case GRUB_TERM_COLOR_STANDARD : + grub_console_cur_color = grub_console_standard_color; grub_console_attr =A_NORMAL ;break ;case GRUB_TERM_COLOR_NORMAL : + grub_console_cur_color = grub_console_normal_color; grub_console_attr =A_NORMAL ;break ;case GRUB_TERM_COLOR_HIGHLIGHT : + grub_console_cur_color = grub_console_highlight_color; grub_console_attr =A_STANDOUT ;break ;default :break ; } + +if (use_color) + { +grub_uint8_t fg, bg; + + fg = (grub_console_cur_color &7 ); + bg = (grub_console_cur_color >>4 ) &7 ; + + grub_console_attr = (grub_console_cur_color &8 ) ?A_BOLD :A_NORMAL ; +color_set ((bg <<3 ) + fg,0 ); + } }/* XXX: This function is never called. */ static void grub_ncurses_setcolor (grub_uint8_t normal_color,grub_uint8_t highlight_color) { -color_set (normal_color <<8 | highlight_color,0 ); + grub_console_normal_color = normal_color; + grub_console_highlight_color = highlight_color; +} + +static void +grub_ncurses_getcolor (grub_uint8_t *normal_color,grub_uint8_t *highlight_color) +{ + *normal_color = grub_console_normal_color; + *highlight_color = grub_console_highlight_color; }static int saved_char =ERR ;
@@ -272,7 +316,23 @@ grub_ncurses_init (void)nonl ();intrflush (stdscr, FALSE);keypad (stdscr, TRUE); -start_color (); + +if (has_colors ()) + { +start_color (); + +if ((COLORS >=NUM_COLORS ) && (COLOR_PAIRS >=NUM_COLORS *NUM_COLORS )) + { +int i, j, n; + + n =0 ; +for (i =0 ; i <NUM_COLORS ; i++) +for (j =0 ; j <NUM_COLORS ; j++) +init_pair (n++, color_map[j], color_map[i]); + + use_color =1 ; + } + }return 0 ; }
@@ -300,6 +360,7 @@ static struct grub_term grub_ncurses_term = .cls = grub_ncurses_cls, .setcolorstate = grub_ncurses_setcolorstate, .setcolor = grub_ncurses_setcolor, + .getcolor = grub_ncurses_getcolor, .setcursor = grub_ncurses_setcursor, .refresh = grub_ncurses_refresh, .flags = 0,
Quoted 9 lines · Bean
Hi,
Currently, the color handling in grub-emu is broken, sometimes you see nothing on screen. This patch fix it, now variable
menu_color_normalandmenu_color_highlightworks properly in grub-emu.util/console.c +3
-0+ +static grub_uint8_t color_map[NUM_COLORS ] = +{
util/console.c line 63
Quoted 10 lines
util/console.c +10
-0+COLOR_BLACK , +COLOR_BLUE , +COLOR_GREEN , +COLOR_CYAN , +COLOR_RED , +COLOR_MAGENTA , +COLOR_YELLOW , + COLOR_WHITE +}; +
Doesn't also ncurses have 16 different colors for foreground and 8 for background? This is at least quite common for terminals.
On some terminals there is one bit controlling background highlight colors or text blinking.
Quoted 25 lines · Vesa Jääskeläinen
Quoted 10 lines · Bean
Hi,
Currently, the color handling in grub-emu is broken, sometimes you see nothing on screen. This patch fix it, now variable
menu_color_normalandmenu_color_highlightworks properly in grub-emu.util/console.c +3
-0+ +static grub_uint8_t color_map[NUM_COLORS ] = +{util/console.c line 63
Quoted 10 lines
util/console.c +10
-0+COLOR_BLACK , +COLOR_BLUE , +COLOR_GREEN , +COLOR_CYAN , +COLOR_RED , +COLOR_MAGENTA , +COLOR_YELLOW , + COLOR_WHITE +}; +Doesn't also ncurses have 16 different colors for foreground and 8 for background? This is at least quite common for terminals.
Quoted 2 lines
On some terminals there is one bit controlling background highlight colors or text blinking.
Hi,
I check my system, it only has 8 foreground and 8 background, the highlight color can be enabled with the A_BOLD flag.
Signature · 1 line
Bean
Hi,
Quoted 6 lines · Bean
Currently, the color handling in grub-emu is broken, sometimes you see nothing on screen. This patch fix it, now variable
menu_color_normalandmenu_color_highlightworks properly in grub-emu.2008-08-02 Bean <[email protected]>
Quoted 13 lines
*
util/console.c(grub_console_cur_color): New variable. (grub_console_standard_color): Likewise. (grub_console_normal_color): Likewise. (grub_console_highlight_color): Likewise.
(color_map): Likewise.
(use_color): Likewise.
(NUM_COLORS): New macro.
(grub_ncurses_setcolorstate): Handle color properly. (grub_ncurses_setcolor): Don't change color here, just remember the settings, color will be set ingrub_ncurses_setcolorstate. (grub_ncurses_getcolor): New function. (grub_ncurses_init): Initialize color pairs.
(grub_termgrub_ncurses_term): New membergrub_ncurses_getcolor.
This should be:
(grub_ncurses_term): New member grub_ncurses_getcolor.
util/console.c line 44
Quoted 12 lines
Signature · 1 line
Beanutil/console.c +1
-0@@ -41,6 +41,28 @@static int grub_console_attr =A_NORMAL ; +grub_uint8_t grub_console_cur_color =7 ;
Any reason why this is not static?
Otherwise, like usual, your patch looks fine at first sight. If it works and no one else has objections just commit it after making these two changes :-)
--
Marco
Quoted 37 lines · Marco Gerards
Hi,
Quoted 6 lines · Bean
Currently, the color handling in grub-emu is broken, sometimes you see nothing on screen. This patch fix it, now variable
menu_color_normalandmenu_color_highlightworks properly in grub-emu.2008-08-02 Bean <[email protected]>
Quoted 13 lines
*
util/console.c(grub_console_cur_color): New variable. (grub_console_standard_color): Likewise. (grub_console_normal_color): Likewise. (grub_console_highlight_color): Likewise.
(color_map): Likewise.
(use_color): Likewise.
(NUM_COLORS): New macro.
(grub_ncurses_setcolorstate): Handle color properly. (grub_ncurses_setcolor): Don't change color here, just remember the settings, color will be set ingrub_ncurses_setcolorstate. (grub_ncurses_getcolor): New function. (grub_ncurses_init): Initialize color pairs.
(grub_termgrub_ncurses_term): New membergrub_ncurses_getcolor.This should be:
(
grub_ncurses_term): New membergrub_ncurses_getcolor.Quoted 9 lines
--
Beanutil/console.c +0
-0@@ -41,6 +41,28 @@
Quoted 5 lines
util/console.c line 44
Quoted 3 lines
util/console.c +1
-0static int grub_console_attr =A_NORMAL ; +grub_uint8_t grub_console_cur_color =7 ;Any reason why this is not static?
Hi,
This files include <grub/i386/pc/console.h>, which define grub_console_cur_color as global variable. Although grub-emu doesn't use this variable itself, but if I define it as static, it will generate a warning message.
Signature · 1 line
Bean
Quoted 44 lines · Bean
Quoted 37 lines · Marco Gerards
Hi,
Quoted 6 lines · Bean
Currently, the color handling in grub-emu is broken, sometimes you see nothing on screen. This patch fix it, now variable
menu_color_normalandmenu_color_highlightworks properly in grub-emu.2008-08-02 Bean <[email protected]>
Quoted 13 lines
*
util/console.c(grub_console_cur_color): New variable. (grub_console_standard_color): Likewise. (grub_console_normal_color): Likewise. (grub_console_highlight_color): Likewise.
(color_map): Likewise.
(use_color): Likewise.
(NUM_COLORS): New macro.
(grub_ncurses_setcolorstate): Handle color properly. (grub_ncurses_setcolor): Don't change color here, just remember the settings, color will be set ingrub_ncurses_setcolorstate. (grub_ncurses_getcolor): New function. (grub_ncurses_init): Initialize color pairs.
(grub_termgrub_ncurses_term): New membergrub_ncurses_getcolor.This should be:
(
grub_ncurses_term): New membergrub_ncurses_getcolor.Quoted 9 lines
--
Beanutil/console.c +0
-0@@ -41,6 +41,28 @@Quoted 5 lines
util/console.c line 44
Quoted 3 lines
util/console.c +1
-0static int grub_console_attr =A_NORMAL ; +grub_uint8_t grub_console_cur_color =7 ;Any reason why this is not static?
Quoted 6 lines
Hi,
This files include <
grub/i386/pc/console.h>, which definegrub_console_cur_coloras global variable. Although grub-emu doesn't use this variable itself, but if I define it as static, it will generate a warning message.
Ah, ok :-)
--
Marco
Quoted 46 lines · Marco Gerards
Quoted 44 lines · Bean
Quoted 42 lines · Marco Gerards
Hi,
Quoted 6 lines · Bean
Currently, the color handling in grub-emu is broken, sometimes you see nothing on screen. This patch fix it, now variable
menu_color_normalandmenu_color_highlightworks properly in grub-emu.2008-08-02 Bean <[email protected]>
Quoted 13 lines
*
util/console.c(grub_console_cur_color): New variable. (grub_console_standard_color): Likewise. (grub_console_normal_color): Likewise. (grub_console_highlight_color): Likewise.
(color_map): Likewise.
(use_color): Likewise.
(NUM_COLORS): New macro.
(grub_ncurses_setcolorstate): Handle color properly. (grub_ncurses_setcolor): Don't change color here, just remember the settings, color will be set ingrub_ncurses_setcolorstate. (grub_ncurses_getcolor): New function. (grub_ncurses_init): Initialize color pairs.
(grub_termgrub_ncurses_term): New membergrub_ncurses_getcolor.This should be:
(
grub_ncurses_term): New membergrub_ncurses_getcolor.util/console.c line 44
Quoted 12 lines
--
Beanutil/console.c +1
-0@@ -41,6 +41,28 @@static int grub_console_attr =A_NORMAL ; +grub_uint8_t grub_console_cur_color =7 ;Any reason why this is not static?
Quoted 8 lines
Quoted 6 lines
Hi,
This files include <
grub/i386/pc/console.h>, which definegrub_console_cur_coloras global variable. Although grub-emu doesn't use this variable itself, but if I define it as static, it will generate a warning message.Ah, ok :-)
Committed.
Signature · 1 line
Bean