add symbolic color name syntax support into the command color.

This commit is contained in:
okuji 1999-10-13 10:24:57 +00:00
parent 191c0eea0a
commit 4e769ee998
5 changed files with 165 additions and 54 deletions

View file

@ -1,3 +1,18 @@
1999-10-13 OKUJI Yoshinori <okuji@kuicr.kyoto-u.ac.jp>
* stage2/builtins.c (color_func): Do not set NORMAL_COLOR or
HIGHLIGHT_COLOR directly, but use NEW_NORMAL_COLOR and
NEW_HIGHLIGHT_COLOR as temporary storages instead.
New internal function `color_number' is used to convert a
symbolic color representation into a color number.
Try color_number at first, and if fails, then try
safe_parse_maxint for each of NORMAL and HIGHLIGHT.
(builtin_color): The long doc does not describe the raw number
syntax but the symbolic color name syntax.
* docs/grub.texi (Commands): Adjusted to the long doc of
BUILTIN_COLOR.
* docs/menu.lst: Add examples of "fallback" and "color".
1999-10-13 OKUJI Yoshinori <okuji@kuicr.kyoto-u.ac.jp> 1999-10-13 OKUJI Yoshinori <okuji@kuicr.kyoto-u.ac.jp>
* stage2/char_io.c [!STAGE1_5] (get_cmdline): If C is a newline * stage2/char_io.c [!STAGE1_5] (get_cmdline): If C is a newline

1
NEWS
View file

@ -6,6 +6,7 @@ New in 0.5.94:
* The more automatic installation command "setup" is added. * The more automatic installation command "setup" is added.
* The command "embed" embeds a Stage 1.5 in the sectors after a MBR or * The command "embed" embeds a Stage 1.5 in the sectors after a MBR or
in the "bootloader" area in a FFS partition. in the "bootloader" area in a FFS partition.
* Support symbolic color name syntax in the command "color".
New in 0.5.93: New in 0.5.93:
* ELF format of FreeBSD kernel is supported. * ELF format of FreeBSD kernel is supported.

View file

@ -719,80 +719,75 @@ Display the contents of the file @var{file}.
Change the menu colors. The color @var{normal} is used for most Change the menu colors. The color @var{normal} is used for most
lines in the menu, and the color @var{highlight} is used to highlight the lines in the menu, and the color @var{highlight} is used to highlight the
line where the cursor points. If you omit @var{highlight}, then the line where the cursor points. If you omit @var{highlight}, then the
inverted color of @var{normal} is used for the highlighted line. You inverted color of @var{normal} is used for the highlighted line.
must specify an integer for a color value, where bits 0-3 represent The format of a color is @code{@var{fg}/@var{bg}}. @var{fg} and @var{bg}
the foreground color, bits 4-6 represent the background color, and are symbolic color names. A symbolic color name must be one of these:
bit 7 indicates that the foreground blinks.
These are the possible values and the meanings: @itemize @bullet
@item
@table @asis
@item 0
black black
@item 1 @item
blue blue
@item 2 @item
green green
@item 3 @item
cyan cyan
@item 4 @item
red red
@item 5 @item
magenta magenta
@item 6 @item
brown brown
@item 7
light gray
@item @item
light-gray
@strong{These below can be specified only for the foreground.} @strong{These below can be specified only for the foreground.}
@item 8 @item
dark gray dark-gray
@item 9 @item
light blue light-blue
@item A @item
light green light-green
@item B @item
light cyan light-cyan
@item C @item
light red light-red
@item D @item
light magenta light-magenta
@item E @item
yellow yellow
@item F @item
white white
@end table @end itemize
The background is represented by 3 bits, so you cannot specify more than But only the first eight names can be used for @var{bg}. You can prefix
7 for it. @code{blink-} to @var{fg} if you want a blinking foreground color.
This command can be used in the configuration file and on the This command can be used in the configuration file and on the command
command line, so you may write something like this in your configuration line, so you may write something like this in your configuration file:
file:
@example @example
# Set default colors (light gray / blue, black / light gray). # Set default colors.
color 0x17 0x70 color light-gray/blue black/light-gray
# Change the colors. # Change the colors.
title OS-BS like title OS-BS like
color 0x16 0x60 color magenta/blue black/magenta
@end example @end example
@item chainloader @var{file} @item chainloader @var{file}

View file

@ -8,6 +8,9 @@ timeout 30
# By default, boot the first entry. # By default, boot the first entry.
default 0 default 0
# Fallback to the second entry.
fallback 1
# For booting the GNU Hurd # For booting the GNU Hurd
title GNU/Hurd title GNU/Hurd
root (hd0,0) root (hd0,0)
@ -51,3 +54,7 @@ chainloader +1
title Install GRUB into the hard disk title Install GRUB into the hard disk
root (hd0,0) root (hd0,0)
install /boot/grub/stage1 d (hd0) /boot/grub/stage2 p install /boot/grub/stage1 d (hd0) /boot/grub/stage2 p
# Change the colors.
title Change the colors
color light-green/brown blink-red/blue

View file

@ -183,26 +183,117 @@ static struct builtin builtin_chainloader =
/* color */ /* color */
/* Set new colors used for the menu interface. Support two methods to
specify a color name: a direct integer representation and a symbolic
color name. An example of the latter is "blink-light-gray/blue". */
static int static int
color_func (char *arg, int flags) color_func (char *arg, int flags)
{ {
char *normal; char *normal;
char *highlight; char *highlight;
int new_normal_color;
int new_highlight_color;
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"
};
/* Convert the color name STR into the magical number. */
static int color_number (char *str)
{
char *ptr;
int i;
int color = 0;
/* Find the separator. */
for (ptr = str; *ptr && *ptr != '/'; ptr++)
;
/* If not found, return -1. */
if (! *ptr)
return -1;
/* Terminate the string STR. */
*ptr++ = 0;
/* If STR contains the prefix "blink-", then set the `blink' bit
in COLOR. */
if (substring ("blink-", str) <= 0)
{
color = 0x80;
str += 6;
}
/* Search for the color name. */
for (i = 0; i < 16; i++)
if (grub_strcmp (color_list[i], str) == 0)
{
color |= i;
break;
}
if (i == 16)
return -1;
str = ptr;
/* Find a space. */
for (; *ptr && ! grub_isspace (*ptr); ptr++)
;
/* Terminate the string STR. */
*ptr = 0;
/* Search for the color name. */
for (i = 0; i < 8; i++)
if (grub_strcmp (color_list[i], str) == 0)
{
color |= i << 4;
break;
}
if (i == 8)
return -1;
return color;
}
normal = arg; normal = arg;
highlight = skip_to (0, arg); highlight = skip_to (0, arg);
if (safe_parse_maxint (&normal, &normal_color)) new_normal_color = color_number (normal);
{ if (new_normal_color < 0 && safe_parse_maxint (&normal, &new_normal_color))
/* The second argument is optional, so set highlight_color
to inverted NORMAL_COLOR. */
if (*highlight == 0
|| ! safe_parse_maxint (&highlight, &highlight_color))
highlight_color = ((normal_color >> 4) | ((normal_color & 0xf) << 4));
}
else
return 1; return 1;
/* The second argument is optional, so set highlight_color
to inverted NORMAL_COLOR. */
if (! *highlight)
new_highlight_color = ((new_normal_color >> 4)
| ((new_normal_color & 0xf) << 4));
else
{
new_highlight_color = color_number (highlight);
if (new_highlight_color < 0
&& safe_parse_maxint (&highlight, &new_highlight_color))
return 1;
}
normal_color = new_normal_color;
highlight_color = new_highlight_color;
return 0; return 0;
} }
@ -215,11 +306,13 @@ static struct builtin builtin_color =
"Change the menu colors. The color NORMAL is used for most" "Change the menu colors. The color NORMAL is used for most"
" lines in the menu, and the color HIGHLIGHT is used to highlight the" " lines in the menu, and the color HIGHLIGHT is used to highlight the"
" line where the cursor points. If you omit HIGHLIGHT, then the" " line where the cursor points. If you omit HIGHLIGHT, then the"
" inverted color of NORMAL is used for the highlighted line. You" " inverted color of NORMAL is used for the highlighted line."
" must specify an integer for a color value, where bits 0-3" " The format of a color is \"FG/BG\". FG and BG are symbolic color names."
" represent the foreground color, bits 4-6 represents the" " A symbolic color name must be one of these: black, blue, green,"
" background color, and bit 7 indicates that the foreground" " cyan, red, magenta, brown, light-gray, dark-gray, light-blue,"
" blinks." " light-green, light-cyan, light-red, light-magenta, yellow and white."
" But only the first eight names can be used for BG. You can prefix"
" \"blink-\" to FG if you want a blinking foreground color."
}; };