2008-08-05 Bean <bean123ch@gmail.com>
* 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_ncurses_term): New member grub_ncurses_getcolor.
This commit is contained in:
parent
748d089ee3
commit
6977d49f98
2 changed files with 79 additions and 2 deletions
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
|||
2008-08-05 Bean <bean123ch@gmail.com>
|
||||
|
||||
* 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_ncurses_term): New member grub_ncurses_getcolor.
|
||||
|
||||
2008-08-05 Colin D Bennett <colin@gibibit.com>
|
||||
|
||||
High resolution timer support. Implemented for x86 CPUs using TSC.
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue