]> git.proxmox.com Git - grub2.git/blobdiff - normal/menu.c
2005-02-19 Yoshinori K. Okuji <okuji@enbug.org>
[grub2.git] / normal / menu.c
index 1debeb27a13ca49af9cce28450602378952b8817..e8d77070a555720cec2ddf5bc484a610dfb11df2 100644 (file)
 #include <grub/mm.h>
 #include <grub/machine/time.h>
 
-/* FIXME: These below are all runaround.  */
-
-#define DISP_LEFT      0x2190
-#define DISP_UP                0x2191
-#define DISP_RIGHT     0x2192
-#define DISP_DOWN      0x2193
-#define DISP_HLINE     0x2501
-#define DISP_VLINE     0x2503
-#define DISP_UL                0x250F
-#define DISP_UR                0x2513
-#define DISP_LL                0x2517
-#define DISP_LR                0x251B
-
-/* FIXME: These should be dynamically obtained from a terminal.  */
-#define TERM_WIDTH     80
-#define TERM_HEIGHT    25
-
-/* The number of lines of "GRUB version..." at the top.  */
-#define TERM_INFO_HEIGHT       1
-
-/* The number of columns/lines between messages/borders/etc.  */
-#define TERM_MARGIN    1
-
-/* The number of columns of scroll information.  */
-#define TERM_SCROLL_WIDTH      1
-
-/* The Y position of the top border.  */
-#define TERM_TOP_BORDER_Y      (TERM_MARGIN + TERM_INFO_HEIGHT + TERM_MARGIN)
-
-/* The X position of the left border.  */
-#define TERM_LEFT_BORDER_X     TERM_MARGIN
-
-/* The width of the border.  */
-#define TERM_BORDER_WIDTH      (TERM_WIDTH \
-                                 - TERM_MARGIN * 3 \
-                                - TERM_SCROLL_WIDTH)
-
-/* The number of lines of messages at the bottom.  */
-#define TERM_MESSAGE_HEIGHT    8
-
-/* The height of the border.  */
-#define TERM_BORDER_HEIGHT     (TERM_HEIGHT \
-                                 - TERM_TOP_BORDER_Y \
-                                 - TERM_MESSAGE_HEIGHT)
-
-/* The number of entries shown at a time.  */
-#define TERM_NUM_ENTRIES       (TERM_BORDER_HEIGHT - 2)
-
-/* The Y position of the first entry.  */
-#define TERM_FIRST_ENTRY_Y     (TERM_TOP_BORDER_Y + 1)
-
-/* The max column number of an entry. The last "-1" is for a
-   continuation marker.  */
-#define TERM_ENTRY_WIDTH       (TERM_BORDER_WIDTH - 2 - TERM_MARGIN * 2 - 1)
-
-/* The standard X position of the cursor.  */
-#define TERM_CURSOR_X          (TERM_LEFT_BORDER_X \
-                                 + TERM_BORDER_WIDTH \
-                                 - TERM_MARGIN \
-                                 - 1)
-
 static void
 draw_border (void)
 {
@@ -92,29 +31,29 @@ draw_border (void)
   
   grub_setcolorstate (GRUB_TERM_COLOR_NORMAL);
   
-  grub_gotoxy (TERM_MARGIN, TERM_TOP_BORDER_Y);
-  grub_putcode (DISP_UL);
-  for (i = 0; i < TERM_BORDER_WIDTH - 2; i++)
-    grub_putcode (DISP_HLINE);
-  grub_putcode (DISP_UR);
+  grub_gotoxy (GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y);
+  grub_putcode (GRUB_TERM_DISP_UL);
+  for (i = 0; i < GRUB_TERM_BORDER_WIDTH - 2; i++)
+    grub_putcode (GRUB_TERM_DISP_HLINE);
+  grub_putcode (GRUB_TERM_DISP_UR);
 
-  for (i = 0; i < (unsigned) TERM_NUM_ENTRIES; i++)
+  for (i = 0; i < (unsigned) GRUB_TERM_NUM_ENTRIES; i++)
     {
-      grub_gotoxy (TERM_MARGIN, TERM_TOP_BORDER_Y + i + 1);
-      grub_putcode (DISP_VLINE);
-      grub_gotoxy (TERM_MARGIN + TERM_BORDER_WIDTH - 1, TERM_TOP_BORDER_Y + i + 1);
-      grub_putcode (DISP_VLINE);
+      grub_gotoxy (GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y + i + 1);
+      grub_putcode (GRUB_TERM_DISP_VLINE);
+      grub_gotoxy (GRUB_TERM_MARGIN + GRUB_TERM_BORDER_WIDTH - 1, GRUB_TERM_TOP_BORDER_Y + i + 1);
+      grub_putcode (GRUB_TERM_DISP_VLINE);
     }
 
-  grub_gotoxy (TERM_MARGIN, TERM_TOP_BORDER_Y + TERM_NUM_ENTRIES + 1);
-  grub_putcode (DISP_LL);
-  for (i = 0; i < TERM_BORDER_WIDTH - 2; i++)
-    grub_putcode (DISP_HLINE);
-  grub_putcode (DISP_LR);
+  grub_gotoxy (GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y + GRUB_TERM_NUM_ENTRIES + 1);
+  grub_putcode (GRUB_TERM_DISP_LL);
+  for (i = 0; i < GRUB_TERM_BORDER_WIDTH - 2; i++)
+    grub_putcode (GRUB_TERM_DISP_HLINE);
+  grub_putcode (GRUB_TERM_DISP_LR);
 
   grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
 
-  grub_gotoxy (TERM_MARGIN, TERM_TOP_BORDER_Y + TERM_NUM_ENTRIES + TERM_MARGIN + 1);
+  grub_gotoxy (GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y + GRUB_TERM_NUM_ENTRIES + GRUB_TERM_MARGIN + 1);
 }
 
 static void
@@ -131,7 +70,7 @@ print_message (int nested, int edit)
     {
       grub_printf ("\n\
       Use the %C and %C keys to select which entry is highlighted.\n",
-                  (grub_uint32_t) DISP_UP, (grub_uint32_t) DISP_DOWN);
+                  (grub_uint32_t) GRUB_TERM_DISP_UP, (grub_uint32_t) GRUB_TERM_DISP_DOWN);
       grub_printf ("\
       Press enter to boot the selected OS, \'e\' to edit the\n\
       commands before booting or \'c\' for a command-line.");
@@ -165,23 +104,23 @@ print_entry (int y, int highlight, grub_menu_entry_t entry)
                      ? GRUB_TERM_COLOR_HIGHLIGHT
                      : GRUB_TERM_COLOR_NORMAL);
 
-  grub_gotoxy (TERM_LEFT_BORDER_X + TERM_MARGIN, y);
-  grub_putchar (' ');
-  for (x = TERM_LEFT_BORDER_X + TERM_MARGIN + 1;
-       x < TERM_LEFT_BORDER_X + TERM_BORDER_WIDTH - TERM_MARGIN;
+  grub_gotoxy (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN, y);
+
+  for (x = GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + 1;
+       x < GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH - GRUB_TERM_MARGIN;
        x++)
     {
-      if (*title && x <= TERM_LEFT_BORDER_X + TERM_BORDER_WIDTH - TERM_MARGIN - 1)
+      if (*title && x <= GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH - GRUB_TERM_MARGIN - 1)
        {
-         if (x == TERM_LEFT_BORDER_X + TERM_BORDER_WIDTH - TERM_MARGIN - 1)
-           grub_putcode (DISP_RIGHT);
+         if (x == GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH - GRUB_TERM_MARGIN - 1)
+           grub_putcode (GRUB_TERM_DISP_RIGHT);
          else
            grub_putchar (*title++);
        }
       else
        grub_putchar (' ');
     }
-  grub_gotoxy (TERM_CURSOR_X, y);
+  grub_gotoxy (GRUB_TERM_CURSOR_X, y);
 
   grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
 }
@@ -192,49 +131,45 @@ print_entries (grub_menu_t menu, int first, int offset)
   grub_menu_entry_t e;
   int i;
   
-  grub_gotoxy (TERM_LEFT_BORDER_X + TERM_BORDER_WIDTH,
-              TERM_FIRST_ENTRY_Y);
+  grub_gotoxy (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH,
+              GRUB_TERM_FIRST_ENTRY_Y);
 
   if (first)
-    grub_putcode (DISP_UP);
+    grub_putcode (GRUB_TERM_DISP_UP);
   else
     grub_putchar (' ');
 
   e = get_entry (menu, first);
 
-  for (i = 0; i < TERM_NUM_ENTRIES; i++)
+  for (i = 0; i < GRUB_TERM_NUM_ENTRIES; i++)
     {
-      print_entry (TERM_FIRST_ENTRY_Y + i, offset == i, e);
+      print_entry (GRUB_TERM_FIRST_ENTRY_Y + i, offset == i, e);
       if (e)
        e = e->next;
     }
 
-  grub_gotoxy (TERM_LEFT_BORDER_X + TERM_BORDER_WIDTH,
-              TERM_TOP_BORDER_Y + TERM_NUM_ENTRIES);
+  grub_gotoxy (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH,
+              GRUB_TERM_TOP_BORDER_Y + GRUB_TERM_NUM_ENTRIES);
 
   if (e)
-    grub_putcode (DISP_DOWN);
+    grub_putcode (GRUB_TERM_DISP_DOWN);
   else
     grub_putchar (' ');
 
-  grub_gotoxy (TERM_CURSOR_X, TERM_FIRST_ENTRY_Y + offset);
+  grub_gotoxy (GRUB_TERM_CURSOR_X, GRUB_TERM_FIRST_ENTRY_Y + offset);
 }
 
-static void
-init_page (int nested, int edit)
+/* Initialize the screen.  If NESTED is non-zero, assume that this menu
+   is run from another menu or a command-line. If EDIT is non-zero, show
+   a message for the menu entry editor.  */
+void
+grub_menu_init_page (int nested, int edit)
 {
   grub_normal_init_page ();
   draw_border ();
   print_message (nested, edit);
 }
 
-/* Edit a menu entry with an Emacs-like interface.  */
-static void
-edit_menu_entry (grub_menu_entry_t entry)
-{
-  /* Not yet implemented.  */
-}
-
 static int
 run_menu (grub_menu_t menu, int nested)
 {
@@ -243,10 +178,10 @@ run_menu (grub_menu_t menu, int nested)
   
   first = 0;
   offset = menu->default_entry;
-  if (offset > TERM_NUM_ENTRIES - 1)
+  if (offset > GRUB_TERM_NUM_ENTRIES - 1)
     {
-      first = offset - (TERM_NUM_ENTRIES - 1);
-      offset = TERM_NUM_ENTRIES - 1;
+      first = offset - (GRUB_TERM_NUM_ENTRIES - 1);
+      offset = GRUB_TERM_NUM_ENTRIES - 1;
     }
 
   /* Initialize the time.  */
@@ -254,7 +189,7 @@ run_menu (grub_menu_t menu, int nested)
 
  refresh:
   grub_setcursor (0);
-  init_page (nested, 0);
+  grub_menu_init_page (nested, 0);
   print_entries (menu, first, offset);
   grub_refresh ();
 
@@ -273,13 +208,13 @@ run_menu (grub_menu_t menu, int nested)
              saved_time = current_time;
            }
          
-         grub_gotoxy (0, TERM_HEIGHT - 3);
+         grub_gotoxy (0, GRUB_TERM_HEIGHT - 3);
          /* NOTE: Do not remove the trailing space characters.
             They are required to clear the line.  */
          grub_printf ("\
    The highlighted entry will be booted automatically in %d seconds.    ",
                       menu->timeout);
-         grub_gotoxy (TERM_CURSOR_X, TERM_FIRST_ENTRY_Y + offset);
+         grub_gotoxy (GRUB_TERM_CURSOR_X, GRUB_TERM_FIRST_ENTRY_Y + offset);
          grub_refresh ();
        }
 
@@ -292,12 +227,12 @@ run_menu (grub_menu_t menu, int nested)
          
          if (menu->timeout >= 0)
            {
-             grub_gotoxy (0, TERM_HEIGHT - 3);
+             grub_gotoxy (0, GRUB_TERM_HEIGHT - 3);
               grub_printf ("\
                                                                         ");
               menu->timeout = -1;
               menu->fallback_entry = -1;
-             grub_gotoxy (TERM_CURSOR_X, TERM_FIRST_ENTRY_Y + offset);
+             grub_gotoxy (GRUB_TERM_CURSOR_X, GRUB_TERM_FIRST_ENTRY_Y + offset);
            }
          
          switch (c)
@@ -306,10 +241,10 @@ run_menu (grub_menu_t menu, int nested)
            case '^':
              if (offset > 0)
                {
-                 print_entry (TERM_FIRST_ENTRY_Y + offset, 0,
+                 print_entry (GRUB_TERM_FIRST_ENTRY_Y + offset, 0,
                               get_entry (menu, first + offset));
                  offset--;
-                 print_entry (TERM_FIRST_ENTRY_Y + offset, 1,
+                 print_entry (GRUB_TERM_FIRST_ENTRY_Y + offset, 1,
                               get_entry (menu, first + offset));
                }
              else if (first > 0)
@@ -323,12 +258,12 @@ run_menu (grub_menu_t menu, int nested)
            case 'v':
              if (menu->size > first + offset + 1)
                {
-                 if (offset < TERM_NUM_ENTRIES - 1)
+                 if (offset < GRUB_TERM_NUM_ENTRIES - 1)
                    {
-                     print_entry (TERM_FIRST_ENTRY_Y + offset, 0,
+                     print_entry (GRUB_TERM_FIRST_ENTRY_Y + offset, 0,
                                   get_entry (menu, first + offset));
                      offset++;
-                     print_entry (TERM_FIRST_ENTRY_Y + offset, 1,
+                     print_entry (GRUB_TERM_FIRST_ENTRY_Y + offset, 1,
                                   get_entry (menu, first + offset));
                    }
                  else
@@ -354,12 +289,11 @@ run_menu (grub_menu_t menu, int nested)
              break;
              
            case 'c':
-             grub_setcursor (1);
              grub_cmdline_run (1);
              goto refresh;
 
            case 'e':
-             edit_menu_entry (get_entry (menu, first + offset));
+             grub_menu_entry_run (get_entry (menu, first + offset));
              goto refresh;
              
            default: