~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to normal/color.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Robert Millan, Updated translations
  • Date: 2010-11-22 12:24:56 UTC
  • mfrom: (1.26.4 upstream) (17.3.36 sid)
  • mto: (17.3.43 sid)
  • mto: This revision was merged to the branch mainline in revision 89.
  • Revision ID: james.westby@ubuntu.com-20101122122456-y82z3sfb7k4zfdcc
Tags: 1.99~20101122-1
[ Colin Watson ]
* New Bazaar snapshot.  Too many changes to list in full, but some of the
  more user-visible ones are as follows:
  - GRUB script:
    + Function parameters, "break", "continue", "shift", "setparams",
      "return", and "!".
    + "export" command supports multiple variable names.
    + Multi-line quoted strings support.
    + Wildcard expansion.
  - sendkey support.
  - USB hotunplugging and USB serial support.
  - Rename CD-ROM to cd on BIOS.
  - Add new --boot-directory option to grub-install, grub-reboot, and
    grub-set-default; the old --root-directory option is still accepted
    but was often confusing.
  - Basic btrfs detection/UUID support (but no file reading yet).
  - bash-completion for utilities.
  - If a device is listed in device.map, always assume that it is
    BIOS-visible rather than using extra layers such as LVM or RAID.
  - Add grub-mknetdir script (closes: #550658).
  - Remove deprecated "root" command.
  - Handle RAID devices containing virtio components.
  - GRUB Legacy configuration file support (via grub-menulst2cfg).
  - Keyboard layout support (via grub-mklayout and grub-kbdcomp).
  - Check generated grub.cfg for syntax errors before saving.
  - Pause execution for at most ten seconds if any errors are displayed,
    so that the user has a chance to see them.
  - Support submenus.
  - Write embedding zone using Reed-Solomon, so that it's robust against
    being partially overwritten (closes: #550702, #591416, #593347).
  - GRUB_DISABLE_LINUX_RECOVERY and GRUB_DISABLE_NETBSD_RECOVERY merged
    into a single GRUB_DISABLE_RECOVERY variable.
  - Fix loader memory allocation failure (closes: #551627).
  - Don't call savedefault on recovery entries (closes: #589325).
  - Support triple-indirect blocks on ext2 (closes: #543924).
  - Recognise DDF1 fake RAID (closes: #603354).

[ Robert Millan ]
* Use dpkg architecture wildcards.

[ Updated translations ]
* Slovenian (Vanja Cvelbar).  Closes: #604003
* Dzongkha (dawa pemo via Tenzin Dendup).  Closes: #604102

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  GRUB  --  GRand Unified Bootloader
3
 
 *  Copyright (C) 1999,2000,2001,2002,2003,2004,2008  Free Software Foundation, Inc.
4
 
 *
5
 
 *  GRUB is free software: you can redistribute it and/or modify
6
 
 *  it under the terms of the GNU General Public License as published by
7
 
 *  the Free Software Foundation, either version 3 of the License, or
8
 
 *  (at your option) any later version.
9
 
 *
10
 
 *  GRUB is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
17
 
 */
18
 
 
19
 
#include <grub/misc.h>
20
 
#include <grub/mm.h>
21
 
#include <grub/normal.h>
22
 
#include <grub/term.h>
23
 
#include <grub/i18n.h>
24
 
 
25
 
/* Borrowed from GRUB Legacy */
26
 
static char *color_list[16] =
27
 
{
28
 
  "black",
29
 
  "blue",
30
 
  "green",
31
 
  "cyan",
32
 
  "red",
33
 
  "magenta",
34
 
  "brown",
35
 
  "light-gray",
36
 
  "dark-gray",
37
 
  "light-blue",
38
 
  "light-green",
39
 
  "light-cyan",
40
 
  "light-red",
41
 
  "light-magenta",
42
 
  "yellow",
43
 
  "white"
44
 
};
45
 
 
46
 
static int
47
 
parse_color_name (grub_uint8_t *ret, char *name)
48
 
{
49
 
  grub_uint8_t i;
50
 
  for (i = 0; i < sizeof (color_list) / sizeof (*color_list); i++)
51
 
    if (! grub_strcmp (name, color_list[i]))
52
 
      {
53
 
        *ret = i;
54
 
        return 0;
55
 
      }
56
 
  return -1;
57
 
}
58
 
 
59
 
void
60
 
grub_parse_color_name_pair (grub_uint8_t *ret, const char *name)
61
 
{
62
 
  grub_uint8_t fg, bg;
63
 
  char *fg_name, *bg_name;
64
 
 
65
 
  /* nothing specified by user */
66
 
  if (name == NULL)
67
 
    return;
68
 
 
69
 
  fg_name = grub_strdup (name);
70
 
  if (fg_name == NULL)
71
 
    {
72
 
      /* "out of memory" message was printed by grub_strdup() */
73
 
      grub_wait_after_message ();
74
 
      return;
75
 
    }
76
 
 
77
 
  bg_name = grub_strchr (fg_name, '/');
78
 
  if (bg_name == NULL)
79
 
    {
80
 
      grub_printf_ (N_("Warning: syntax error (missing slash) in `%s'\n"), fg_name);
81
 
      grub_wait_after_message ();
82
 
      goto free_and_return;
83
 
    }
84
 
 
85
 
  *(bg_name++) = '\0';
86
 
 
87
 
  if (parse_color_name (&fg, fg_name) == -1)
88
 
    {
89
 
      grub_printf_ (N_("Warning: invalid foreground color `%s'\n"), fg_name);
90
 
      grub_wait_after_message ();
91
 
      goto free_and_return;
92
 
    }
93
 
  if (parse_color_name (&bg, bg_name) == -1)
94
 
    {
95
 
      grub_printf_ (N_("Warning: invalid background color `%s'\n"), bg_name);
96
 
      grub_wait_after_message ();
97
 
      goto free_and_return;
98
 
    }
99
 
 
100
 
  *ret = (bg << 4) | fg;
101
 
 
102
 
free_and_return:
103
 
  grub_free (fg_name);
104
 
}
105
 
 
106
 
static grub_uint8_t color_normal, color_highlight;
107
 
 
108
 
static void
109
 
set_colors (void)
110
 
{
111
 
  struct grub_term_output *term;
112
 
 
113
 
  FOR_ACTIVE_TERM_OUTPUTS(term)
114
 
  {
115
 
    /* Reloads terminal `normal' and `highlight' colors.  */
116
 
    grub_term_setcolor (term, color_normal, color_highlight);
117
 
 
118
 
    /* Propagates `normal' color to terminal current color.  */
119
 
    grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL);
120
 
  }
121
 
}
122
 
 
123
 
/* Replace default `normal' colors with the ones specified by user (if any).  */
124
 
char *
125
 
grub_env_write_color_normal (struct grub_env_var *var __attribute__ ((unused)),
126
 
                             const char *val)
127
 
{
128
 
  grub_parse_color_name_pair (&color_normal, val);
129
 
 
130
 
  set_colors ();
131
 
 
132
 
  return grub_strdup (val);
133
 
}
134
 
 
135
 
/* Replace default `highlight' colors with the ones specified by user (if any).  */
136
 
char *
137
 
grub_env_write_color_highlight (struct grub_env_var *var __attribute__ ((unused)),
138
 
                                const char *val)
139
 
{
140
 
  grub_parse_color_name_pair (&color_highlight, val);
141
 
 
142
 
  set_colors ();
143
 
 
144
 
  return grub_strdup (val);
145
 
}