I've added support for symbolic color names to GRUB. No documentation is
written yet, but it works as follows:
* You can give numeric values, just like before. Example:
color=0x17 0x70
* You can give symbolic names, with syntax:
color=foreground/background [highlight-foreground/highlight-background]
Example:
color=blue/green
(highlight is set to green/blue)
color=blue/green red/black
color=blue/green red/white
(Invalid! White background is not allowed)
Patch included below. Comments are appreciated.
---
diff -u4 -r --exclude-from=diffexclude cvsgrub/stage2/cmdline.c grub/stage2/cmdline.c
--- cvsgrub/stage2/cmdline.c Thu Jun 24 02:03:11 1999
+++ grub/stage2/cmdline.c Mon Jul 5 21:43:41 1999
@@ -81,8 +81,31 @@
/* Color settings */
int normal_color;
int highlight_color;
+/* Symbolic color names */
+static char *colors[16] =
+{
+ "black",
+ "blue",
+ "green",
+ "cyan",
+ "red",
+ "magenta",
+ "brown",
+ "lightgray",
+
+ /* Only available for foreground */
+ "darkgray",
+ "lightblue",
+ "lightgreen",
+ "lightcyan",
+ "lightred",
+ "lightmagenta",
+ "yellow",
+ "white"
+};
+
char *
skip_to(int after_equal, char *cmdline)
{
while (*cmdline && (*cmdline != (after_equal ? '=' : ' ')))
@@ -96,9 +119,8 @@
return cmdline;
}
-
void
init_cmdline(void)
{
printf(" [ Minimal BASH-like line editing is supported. For the first word, TAB
@@ -641,24 +663,106 @@
}
}
else if (substring ("color", cur_heap) < 1)
{
- char *normal;
- char *highlight;
+ char *normal, *highlight;
+ char *normal_fg, *normal_bg;
+ char *highlight_fg, *highlight_bg;
+ int i, error = 0, new_normal, new_highlight;
+ /* Separate the arguments */
normal = cur_cmdline;
- highlight = skip_to (0, normal);
+ /* Skip to first space or EOF */
+ while (*cur_cmdline && (*cur_cmdline != ' '))
+ cur_cmdline++;
+ if (*cur_cmdline == ' ') {
+ /* We found space. Terminate 'normal' */
+ *cur_cmdline = '\0';
+ cur_cmdline++;
+ }
+ /* Skip to first non-space */
+ while (*cur_cmdline && (*cur_cmdline == ' '))
+ cur_cmdline++;
+ highlight = cur_cmdline;
- 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));
+
+ /* Handle first argument */
+ normal_fg = normal;
+ /* Skip to first slash */
+ while (*normal && (*normal != '/'))
+ normal++;
+ if (!(*normal)) {
+ /* Couldn't find slash. Try safe_parse instead. */
+ safe_parse_maxint (&normal_fg, &new_normal);
+ } else {
+ /* Try symbolic parsing */
+ *normal = '\0';
+ normal++;
+ normal_bg = normal;
+
+ /* Translate foreground */
+ for (i = 0; i < 16; i++)
+ if (strcmp(colors[i], normal_fg) == 0) {
+ new_normal = i;
+ break;
+ }
+ if (i>15) error = 1;
+
+ /* Translate background */
+ for (i = 0; i < 8; i++)
+ if (strcmp(colors[i], normal_bg) == 0) {
+ new_normal += i << 4;
+ break;
+ }
+ if (i>7) error = 1;
+ }
+
+ /* Handle second argument */
+ if (*highlight) {
+ highlight_fg = highlight;
+ /* Skip to first slash */
+ while (*highlight && (*highlight != '/'))
+ highlight++;
+
+ if (!(*highlight)) {
+ /* Couldn't find slash. Try safe_parse instead. */
+ safe_parse_maxint (&highlight_fg, &new_highlight);
+ } else {
+ /* Try symbolic parsing */
+ *highlight = '\0';
+ highlight++;
+ highlight_bg = highlight;
+
+ /* Translate foreground */
+ for (i = 0; i < 16; i++)
+ if (strcmp(colors[i], highlight_fg) == 0) {
+ new_highlight = i;
+ break;
+ }
+ if (i>15) error = 1;
+
+ /* Translate background */
+ for (i = 0; i < 8; i++)
+ if (strcmp(colors[i], highlight_bg) == 0) {
+ new_highlight += i << 4;
+ break;
+ }
+ if (i>7) error = 1;
}
- }
+ } else {
+ /* No second argument was given. Use the inverted first argument. */
+ new_highlight = ((new_normal >> 4) |
+ ((new_normal & 0xf) << 4));
+ }
+ if (error)
+ printf("Error while parsing symbolic color names\n");
+ else {
+ normal_color = new_normal;
+ highlight_color = new_highlight;
+ }
+
+ } /* Color ends */
+
else if (substring ("quit", cur_heap) < 1)
{
#ifdef GRUB_UTIL
return CMDLINE_ABORT;
---
/////
o o
-... said Peter.