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>
* 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 command "embed" embeds a Stage 1.5 in the sectors after a MBR or
in the "bootloader" area in a FFS partition.
* Support symbolic color name syntax in the command "color".
New in 0.5.93:
* 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
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
inverted color of @var{normal} is used for the highlighted line. You
must specify an integer for a color value, where bits 0-3 represent
the foreground color, bits 4-6 represent the background color, and
bit 7 indicates that the foreground blinks.
inverted color of @var{normal} is used for the highlighted line.
The format of a color is @code{@var{fg}/@var{bg}}. @var{fg} and @var{bg}
are symbolic color names. A symbolic color name must be one of these:
These are the possible values and the meanings:
@table @asis
@item 0
@itemize @bullet
@item
black
@item 1
@item
blue
@item 2
@item
green
@item 3
@item
cyan
@item 4
@item
red
@item 5
@item
magenta
@item 6
@item
brown
@item 7
light gray
@item
light-gray
@strong{These below can be specified only for the foreground.}
@item 8
dark gray
@item
dark-gray
@item 9
light blue
@item
light-blue
@item A
light green
@item
light-green
@item B
light cyan
@item
light-cyan
@item C
light red
@item
light-red
@item D
light magenta
@item
light-magenta
@item E
@item
yellow
@item F
@item
white
@end table
@end itemize
The background is represented by 3 bits, so you cannot specify more than
7 for it.
But only the first eight names can be used for @var{bg}. You can prefix
@code{blink-} to @var{fg} if you want a blinking foreground color.
This command can be used in the configuration file and on the
command line, so you may write something like this in your configuration
file:
This command can be used in the configuration file and on the command
line, so you may write something like this in your configuration file:
@example
# Set default colors (light gray / blue, black / light gray).
color 0x17 0x70
# Set default colors.
color light-gray/blue black/light-gray
# Change the colors.
title OS-BS like
color 0x16 0x60
color magenta/blue black/magenta
@end example
@item chainloader @var{file}

View file

@ -8,6 +8,9 @@ timeout 30
# By default, boot the first entry.
default 0
# Fallback to the second entry.
fallback 1
# For booting the GNU Hurd
title GNU/Hurd
root (hd0,0)
@ -51,3 +54,7 @@ chainloader +1
title Install GRUB into the hard disk
root (hd0,0)
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 */
/* 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
color_func (char *arg, int flags)
{
char *normal;
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;
highlight = skip_to (0, arg);
if (safe_parse_maxint (&normal, &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
new_normal_color = color_number (normal);
if (new_normal_color < 0 && safe_parse_maxint (&normal, &new_normal_color))
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;
}
@ -215,11 +306,13 @@ static struct builtin builtin_color =
"Change the menu colors. The color NORMAL is used for most"
" lines in the menu, and the color HIGHLIGHT is used to highlight the"
" line where the cursor points. If you omit HIGHLIGHT, then the"
" inverted color of NORMAL is used for the highlighted line. You"
" must specify an integer for a color value, where bits 0-3"
" represent the foreground color, bits 4-6 represents the"
" background color, and bit 7 indicates that the foreground"
" blinks."
" inverted color of NORMAL is used for the highlighted line."
" The format of a color is \"FG/BG\". FG and BG are symbolic color names."
" A symbolic color name must be one of these: black, blue, green,"
" cyan, red, magenta, brown, light-gray, dark-gray, light-blue,"
" 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."
};