Changed highlight state code for hercules, console and serial.

The state was 0 - normal or 1 - highlight.
        The state is now defined using an enum called color_state.

        * stage2/term.h (color_state): New enum.
        (COLOR_STATE_STANDARD): Standard color to use when not using user defined.
        (COLOR_STATE_NORMAL): User defined normal color.
        (COLOR_STATE_HIGHLIGHT): User defined highlight color.
        (console_highlight): Renamed to console_setcolorstate.
        (serial_highlight): Renamed to serial_setcolorstate.
        (hercules_highlight): Renamed to hercules_setcolorstate.
        * stage2/hercules.c (herc_highlight_state): Removed.
        (herc_standard_color): New variable.
        (herc_color_state): Likewise.
        (herc_highlight): Renamed to herc_setcolorstate.
        (herc_setcolorstate): Added switch to handle new states.
        * stage2/console.c (console_highlight_state): Removed.
        (console_standard_color): New variable.
        (console_color_state): Likewise.
        (console_highlight): Renamed to console_setcolorstate.
        (console_setcolorstate): Added switch to handle new states.
        * stage2/serial.c (serial_highlight): Renamed to serial_setcolorstate.
        (serial_setcolorstate): Adjusted 'if' to suit new states.
        * grub/asmstub.c (console_highlight): Renamed to console_setcolorstate.
        (console_setcolorstate): Adjusted 'if' to suit new states.
        * stage2/stage2.c (print_entry): Set color states using new states.
        (print_border): Likewise.
        * stage2/stage2.c (run_menu): Reverse if (!) to if () for uniformitty.
This commit is contained in:
jthomas 2002-08-22 05:59:55 +00:00
parent 51955d52d8
commit d932c071e9
8 changed files with 119 additions and 38 deletions

View file

@ -1,3 +1,34 @@
2002-09-20 Jason Thomas <jason@topic.com.au>
Changed highlight state code for hercules, console and serial.
The state was 0 - normal or 1 - highlight.
The state is now defined using an enum called color_state.
* stage2/term.h (color_state): New enum.
(COLOR_STATE_STANDARD): Standard color to use when not using user defined.
(COLOR_STATE_NORMAL): User defined normal color.
(COLOR_STATE_HIGHLIGHT): User defined highlight color.
(console_highlight): Renamed to console_setcolorstate.
(serial_highlight): Renamed to serial_setcolorstate.
(hercules_highlight): Renamed to hercules_setcolorstate.
* stage2/hercules.c (herc_highlight_state): Removed.
(herc_standard_color): New variable.
(herc_color_state): Likewise.
(herc_highlight): Renamed to herc_setcolorstate.
(herc_setcolorstate): Added switch to handle new states.
* stage2/console.c (console_highlight_state): Removed.
(console_standard_color): New variable.
(console_color_state): Likewise.
(console_highlight): Renamed to console_setcolorstate.
(console_setcolorstate): Added switch to handle new states.
* stage2/serial.c (serial_highlight): Renamed to serial_setcolorstate.
(serial_setcolorstate): Adjusted 'if' to suit new states.
* grub/asmstub.c (console_highlight): Renamed to console_setcolorstate.
(console_setcolorstate): Adjusted 'if' to suit new states.
* stage2/stage2.c (print_entry): Set color states using new states.
(print_border): Likewise.
* stage2/stage2.c (run_menu): Reverse if (!) to if () for uniformitty.
2002-07-12 Yoshinori K. Okuji <okuji@enbug.org> 2002-07-12 Yoshinori K. Okuji <okuji@enbug.org>
* stage2/boot.c (load_image): Rewrite the Linux booting support * stage2/boot.c (load_image): Rewrite the Linux booting support

View file

@ -727,9 +727,10 @@ console_cls (void)
} }
void void
console_highlight (int state) console_setcolorstate (color_state state)
{ {
console_current_color = state ? A_REVERSE : A_NORMAL; console_current_color =
(state == COLOR_STATE_HIGHLIGHT) ? A_REVERSE : A_NORMAL;
} }
void void
@ -1250,9 +1251,9 @@ hercules_cls (void)
} }
void void
hercules_highlight (int state) hercules_setcolorstate (color_state state)
{ {
console_highlight (state); console_setcolorstate (state);
} }
void void

View file

@ -41,7 +41,7 @@ struct term_entry term_table[] =
console_getxy, console_getxy,
console_gotoxy, console_gotoxy,
console_cls, console_cls,
console_highlight, console_setcolorstate,
console_setcolor, console_setcolor,
console_nocursor console_nocursor
}, },
@ -56,7 +56,7 @@ struct term_entry term_table[] =
serial_getxy, serial_getxy,
serial_gotoxy, serial_gotoxy,
serial_cls, serial_cls,
serial_highlight, serial_setcolorstate,
0, 0,
0 0
}, },
@ -71,7 +71,7 @@ struct term_entry term_table[] =
hercules_getxy, hercules_getxy,
hercules_gotoxy, hercules_gotoxy,
hercules_cls, hercules_cls,
hercules_highlight, hercules_setcolorstate,
hercules_setcolor, hercules_setcolor,
hercules_nocursor hercules_nocursor
}, },
@ -1028,13 +1028,13 @@ grub_putchar (int c)
the following grub_printf call will print newlines. */ the following grub_printf call will print newlines. */
count_lines = -1; count_lines = -1;
if (current_term->highlight) if (current_term->setcolorstate)
current_term->highlight (1); current_term->setcolorstate (COLOR_STATE_HIGHLIGHT);
grub_printf ("\n[Hit return to continue]"); grub_printf ("\n[Hit return to continue]");
if (current_term->highlight) if (current_term->setcolorstate)
current_term->highlight (0); current_term->setcolorstate (COLOR_STATE_NORMAL);
do do
{ {

View file

@ -26,16 +26,30 @@
console_gotoxy, console_cls, and console_nocursor. */ console_gotoxy, console_cls, and console_nocursor. */
int console_current_color = A_NORMAL; int console_current_color = A_NORMAL;
static int console_standard_color = A_NORMAL;
static int console_normal_color = A_NORMAL; static int console_normal_color = A_NORMAL;
static int console_highlight_color = A_REVERSE; static int console_highlight_color = A_REVERSE;
static int console_highlight_state = 0; static color_state console_color_state = COLOR_STATE_STANDARD;
void void
console_highlight (int state) console_setcolorstate (color_state state)
{ {
console_current_color switch (state) {
= state ? console_highlight_color : console_normal_color; case COLOR_STATE_STANDARD:
console_highlight_state = state; console_current_color = console_standard_color;
break;
case COLOR_STATE_NORMAL:
console_current_color = console_normal_color;
break;
case COLOR_STATE_HIGHLIGHT:
console_current_color = console_highlight_color;
break;
default:
console_current_color = console_standard_color;
break;
}
console_color_state = state;
} }
void void
@ -44,5 +58,5 @@ console_setcolor (int normal_color, int highlight_color)
console_normal_color = normal_color; console_normal_color = normal_color;
console_highlight_color = highlight_color; console_highlight_color = highlight_color;
console_highlight (console_highlight_state); console_setcolorstate (console_color_state);
} }

View file

@ -28,10 +28,11 @@
static int herc_x; static int herc_x;
static int herc_y; static int herc_y;
static int herc_standard_color = A_NORMAL;
static int herc_normal_color = A_NORMAL; static int herc_normal_color = A_NORMAL;
static int herc_highlight_color = A_REVERSE; static int herc_highlight_color = A_REVERSE;
static int herc_current_color = A_NORMAL; static int herc_current_color = A_NORMAL;
static int herc_highlight_state = 0; static color_state herc_color_state = COLOR_STATE_STANDARD;
/* Write a byte to a port. */ /* Write a byte to a port. */
static inline void static inline void
@ -148,10 +149,24 @@ hercules_gotoxy (int x, int y)
} }
void void
hercules_highlight (int state) hercules_setcolorstate (color_state state)
{ {
herc_current_color = state ? herc_highlight_color : herc_normal_color; switch (state) {
herc_highlight_state = state; case COLOR_STATE_STANDARD:
herc_current_color = herc_standard_color;
break;
case COLOR_STATE_NORMAL:
herc_current_color = herc_normal_color;
break;
case COLOR_STATE_HIGHLIGHT:
herc_current_color = herc_highlight_color;
break;
default:
herc_current_color = herc_standard_color;
break;
}
herc_color_state = state;
} }
void void
@ -160,7 +175,7 @@ hercules_setcolor (int normal_color, int highlight_color)
herc_normal_color = normal_color; herc_normal_color = normal_color;
herc_highlight_color = highlight_color; herc_highlight_color = highlight_color;
hercules_highlight (herc_highlight_state); hercules_setcolorstate (herc_color_state);
} }
void void

View file

@ -414,10 +414,10 @@ serial_cls (void)
} }
void void
serial_highlight (int state) serial_setcolorstate (color_state state)
{ {
keep_track = 0; keep_track = 0;
grub_printf ("\e[%cm", state ? '7' : '0'); grub_printf ("\e[%cm", (state == COLOR_STATE_HIGHLIGHT) ? '7' : '0');
keep_track = 1; keep_track = 1;
} }

View file

@ -99,10 +99,11 @@ print_entry (int y, int highlight, char *entry)
{ {
int x; int x;
highlight = (highlight && current_term->highlight); if (current_term->setcolorstate)
current_term->setcolorstate (COLOR_STATE_NORMAL);
if (highlight) if (highlight && current_term->setcolorstate)
current_term->highlight (1); current_term->setcolorstate (COLOR_STATE_HIGHLIGHT);
gotoxy (2, y); gotoxy (2, y);
grub_putchar (' '); grub_putchar (' ');
@ -115,8 +116,8 @@ print_entry (int y, int highlight, char *entry)
} }
gotoxy (74, y); gotoxy (74, y);
if (highlight) if (current_term->setcolorstate)
current_term->highlight (0); current_term->setcolorstate (COLOR_STATE_STANDARD);
} }
/* Print entries in the menu box. */ /* Print entries in the menu box. */
@ -187,6 +188,9 @@ print_border (int y, int size)
{ {
int i; int i;
if (current_term->setcolorstate)
current_term->setcolorstate (COLOR_STATE_NORMAL);
gotoxy (1, y); gotoxy (1, y);
grub_putchar (DISP_UL); grub_putchar (DISP_UL);
@ -213,6 +217,9 @@ print_border (int y, int size)
for (i = 0; i < 73; i++) for (i = 0; i < 73; i++)
grub_putchar (DISP_HORIZ); grub_putchar (DISP_HORIZ);
grub_putchar (DISP_LR); grub_putchar (DISP_LR);
if (current_term->setcolorstate)
current_term->setcolorstate (COLOR_STATE_STANDARD);
} }
static void static void
@ -287,10 +294,10 @@ restart:
init_page (); init_page ();
nocursor (); nocursor ();
if (! (current_term->flags & TERM_DUMB)) if (current_term->flags & TERM_DUMB)
print_border (3, 12);
else
print_entries_raw (num_entries, first_entry, menu_entries); print_entries_raw (num_entries, first_entry, menu_entries);
else
print_border (3, 12);
grub_printf ("\n\ grub_printf ("\n\
Use the %c and %c keys to select which entry is highlighted.\n", Use the %c and %c keys to select which entry is highlighted.\n",

View file

@ -21,6 +21,19 @@
#ifndef GRUB_TERM_HEADER #ifndef GRUB_TERM_HEADER
#define GRUB_TERM_HEADER 1 #define GRUB_TERM_HEADER 1
/* These are used to represent the various color states we use */
typedef enum
{
/* represents the color used to display all text that does not use the user
* defined colors below
*/
COLOR_STATE_STANDARD,
/* represents the user defined colors for normal text */
COLOR_STATE_NORMAL,
/* represents the user defined colors for highlighted text */
COLOR_STATE_HIGHLIGHT
} color_state;
#ifndef STAGE1_5 #ifndef STAGE1_5
/* Flags for representing the capabilities of a terminal. */ /* Flags for representing the capabilities of a terminal. */
@ -59,8 +72,8 @@ struct term_entry
void (*gotoxy) (int x, int y); void (*gotoxy) (int x, int y);
/* Clear the screen. */ /* Clear the screen. */
void (*cls) (void); void (*cls) (void);
/* Highlight characters written after this call, if STATE is true. */ /* Set the current color to be used */
void (*highlight) (int state); void (*setcolorstate) (color_state state);
/* Set the normal color and the highlight color. The format of each /* Set the normal color and the highlight color. The format of each
color is VGA's. */ color is VGA's. */
void (*setcolor) (int normal_color, int highlight_color); void (*setcolor) (int normal_color, int highlight_color);
@ -86,7 +99,7 @@ int console_getkey (void);
int console_getxy (void); int console_getxy (void);
void console_gotoxy (int x, int y); void console_gotoxy (int x, int y);
void console_cls (void); void console_cls (void);
void console_highlight (int state); void console_setcolorstate (color_state state);
void console_setcolor (int normal_color, int highlight_color); void console_setcolor (int normal_color, int highlight_color);
void console_nocursor (void); void console_nocursor (void);
#endif #endif
@ -98,7 +111,7 @@ int serial_getkey (void);
int serial_getxy (void); int serial_getxy (void);
void serial_gotoxy (int x, int y); void serial_gotoxy (int x, int y);
void serial_cls (void); void serial_cls (void);
void serial_highlight (int state); void serial_setcolorstate (color_state state);
#endif #endif
#ifdef SUPPORT_HERCULES #ifdef SUPPORT_HERCULES
@ -106,7 +119,7 @@ void hercules_putchar (int c);
int hercules_getxy (void); int hercules_getxy (void);
void hercules_gotoxy (int x, int y); void hercules_gotoxy (int x, int y);
void hercules_cls (void); void hercules_cls (void);
void hercules_highlight (int state); void hercules_setcolorstate (color_state state);
void hercules_setcolor (int normal_color, int highlight_color); void hercules_setcolor (int normal_color, int highlight_color);
void hercules_nocursor (void); void hercules_nocursor (void);
#endif #endif