~ubuntu-branches/ubuntu/lucid/grub2/lucid

« back to all changes in this revision

Viewing changes to normal/menu.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Millan
  • Date: 2008-01-28 00:01:11 UTC
  • mto: (17.4.1 lenny) (1.10.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20080128000111-0764agvqzg601o1d
Tags: upstream-1.95+20080128
ImportĀ upstreamĀ versionĀ 1.95+20080128

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  GRUB  --  GRand Unified Bootloader
3
 
 *  Copyright (C) 2003,2004,2005,2006,2007  Free Software Foundation, Inc.
 
3
 *  Copyright (C) 2003,2004,2005,2006,2007,2008  Free Software Foundation, Inc.
4
4
 *
5
5
 *  GRUB is free software: you can redistribute it and/or modify
6
6
 *  it under the terms of the GNU General Public License as published by
25
25
#include <grub/env.h>
26
26
#include <grub/script.h>
27
27
 
 
28
static grub_uint8_t grub_color_menu_normal;
 
29
static grub_uint8_t grub_color_menu_highlight;
 
30
 
 
31
/* Wait until the user pushes any key so that the user
 
32
   can see what happened.  */
 
33
void
 
34
grub_wait_after_message (void)
 
35
{
 
36
  grub_printf ("\nPress any key to continue...");
 
37
  (void) grub_getkey ();
 
38
}
 
39
 
28
40
static void
29
41
draw_border (void)
30
42
{
54
66
    grub_putcode (GRUB_TERM_DISP_HLINE);
55
67
  grub_putcode (GRUB_TERM_DISP_LR);
56
68
 
57
 
  grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
 
69
  grub_setcolorstate (GRUB_TERM_COLOR_NORMAL);
58
70
 
59
71
  grub_gotoxy (GRUB_TERM_MARGIN,
60
72
               (GRUB_TERM_TOP_BORDER_Y + GRUB_TERM_NUM_ENTRIES
64
76
static void
65
77
print_message (int nested, int edit)
66
78
{
 
79
  grub_setcolorstate (GRUB_TERM_COLOR_NORMAL);
 
80
 
67
81
  if (edit)
68
82
    {
69
83
      grub_printf ("\n\
105
119
  grub_ssize_t len;
106
120
  grub_uint32_t *unicode_title;
107
121
  grub_ssize_t i;
108
 
  
 
122
  grub_uint8_t old_color_normal, old_color_highlight;
 
123
 
109
124
  title = entry ? entry->title : "";
110
125
  unicode_title = grub_malloc (grub_strlen (title) * sizeof (*unicode_title));
111
126
  if (! unicode_title)
120
135
      grub_free (unicode_title);
121
136
      return;
122
137
    }
123
 
  
 
138
 
 
139
  grub_getcolor (&old_color_normal, &old_color_highlight);
 
140
  grub_setcolor (grub_color_menu_normal, grub_color_menu_highlight);
124
141
  grub_setcolorstate (highlight
125
142
                      ? GRUB_TERM_COLOR_HIGHLIGHT
126
143
                      : GRUB_TERM_COLOR_NORMAL);
153
170
          x++;
154
171
        }
155
172
    }
 
173
  grub_setcolorstate (GRUB_TERM_COLOR_NORMAL);
 
174
  grub_putchar (' ');
 
175
 
156
176
  grub_gotoxy (GRUB_TERM_CURSOR_X, y);
157
177
 
158
 
  grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
 
178
  grub_setcolor (old_color_normal, old_color_highlight);
 
179
  grub_setcolorstate (GRUB_TERM_COLOR_NORMAL);
159
180
  grub_free (unicode_title);
160
181
}
161
182
 
199
220
void
200
221
grub_menu_init_page (int nested, int edit)
201
222
{
 
223
  grub_uint8_t old_color_normal, old_color_highlight;
 
224
 
 
225
  grub_getcolor (&old_color_normal, &old_color_highlight);
 
226
 
 
227
  /* By default, use the same colors for the menu.  */
 
228
  grub_color_menu_normal = old_color_normal;
 
229
  grub_color_menu_highlight = old_color_highlight;
 
230
 
 
231
  /* Then give user a chance to replace them.  */
 
232
  grub_parse_color_name_pair (&grub_color_menu_normal, grub_env_get ("menu_color_normal"));
 
233
  grub_parse_color_name_pair (&grub_color_menu_highlight, grub_env_get ("menu_color_highlight"));
 
234
 
202
235
  grub_normal_init_page ();
 
236
  grub_setcolor (grub_color_menu_normal, grub_color_menu_highlight);
203
237
  draw_border ();
 
238
  grub_setcolor (old_color_normal, old_color_highlight);
204
239
  print_message (nested, edit);
205
240
}
206
241
 
273
308
  return entry;
274
309
}
275
310
 
 
311
static void
 
312
print_timeout (int timeout, int offset, int second_stage)
 
313
{
 
314
  /* NOTE: Do not remove the trailing space characters.
 
315
     They are required to clear the line.  */
 
316
  char *msg = "   The highlighted entry will be booted automatically in %ds.    ";
 
317
  char *msg_end = grub_strchr (msg, '%');
 
318
  
 
319
  grub_gotoxy (second_stage ? (msg_end - msg) : 0, GRUB_TERM_HEIGHT - 3);
 
320
  grub_printf (second_stage ? msg_end : msg, timeout);
 
321
  grub_gotoxy (GRUB_TERM_CURSOR_X, GRUB_TERM_FIRST_ENTRY_Y + offset);
 
322
  grub_refresh ();
 
323
};
 
324
 
276
325
static int
277
326
run_menu (grub_menu_t menu, int nested)
278
327
{
279
328
  int first, offset;
280
329
  unsigned long saved_time;
281
330
  int default_entry;
 
331
  int timeout;
282
332
  
283
333
  first = 0;
284
334
  
305
355
  print_entries (menu, first, offset);
306
356
  grub_refresh ();
307
357
 
 
358
  timeout = get_timeout ();
 
359
 
 
360
  if (timeout > 0)
 
361
    print_timeout (timeout, offset, 0);
 
362
 
308
363
  while (1)
309
364
    {
310
365
      int c;
311
 
      int timeout;
312
 
 
313
366
      timeout = get_timeout ();
314
367
      
315
368
      if (timeout > 0)
322
375
              timeout--;
323
376
              set_timeout (timeout);
324
377
              saved_time = current_time;
 
378
              print_timeout (timeout, offset, 1);
325
379
            }
326
 
          
327
 
          grub_gotoxy (0, GRUB_TERM_HEIGHT - 3);
328
 
          /* NOTE: Do not remove the trailing space characters.
329
 
             They are required to clear the line.  */
330
 
          grub_printf ("\
331
 
   The highlighted entry will be booted automatically in %d s.    ",
332
 
                       timeout);
333
 
          grub_gotoxy (GRUB_TERM_CURSOR_X, GRUB_TERM_FIRST_ENTRY_Y + offset);
334
 
          grub_refresh ();
335
380
        }
336
381
 
337
382
      if (timeout == 0)
412
457
              goto refresh;
413
458
 
414
459
            case 'e':
415
 
              grub_menu_entry_run (get_entry (menu, first + offset));
 
460
                {
 
461
                  grub_menu_entry_t e = get_entry (menu, first + offset);
 
462
                  if (e)
 
463
                    grub_menu_entry_run (e);
 
464
                }
416
465
              goto refresh;
417
466
              
418
467
            default:
451
500
      if (boot_entry < 0)
452
501
        break;
453
502
 
 
503
      e = get_entry (menu, boot_entry);
 
504
      if (! e)
 
505
        continue; /* Menu is empty.  */
 
506
        
454
507
      grub_cls ();
455
508
      grub_setcursor (1);
456
509
 
457
 
      e = get_entry (menu, boot_entry);
458
510
      grub_printf ("  Booting \'%s\'\n\n", e->title);
459
511
  
460
512
      run_menu_entry (e);
478
530
          grub_print_error ();
479
531
          grub_errno = GRUB_ERR_NONE;
480
532
 
481
 
          /* Wait until the user pushes any key so that the user
482
 
             can see what happened.  */
483
 
          grub_printf ("\nPress any key to continue...");
484
 
          (void) grub_getkey ();
 
533
          grub_wait_after_message ();
485
534
        }
486
535
    }
487
536
}