This patch allows to boot entry with a single keypress

-- 
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
diff --git a/ChangeLog b/ChangeLog
index 1efb882..afb1bec 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2009-08-24  Vladimir Serbinenko  <phco...@gmail.com>
 
+       Hotkey support
+
+       * include/grub/menu.h (grub_menu_entry): New field 'hotkey'.
+       * normal/main.c (hotkey_aliases): New variable.
+       (grub_normal_add_menu_entry): Parse "--hotkey".
+       * normal/menu_text.c (run_menu): Handle hotkeys.
+
+2009-08-24  Vladimir Serbinenko  <phco...@gmail.com>
+
        Rename *_partition_map to part_*
 
        * partmap/acorn.c (grub_acorn_partition_map): Set name to 'part_acorn'.
diff --git a/include/grub/menu.h b/include/grub/menu.h
index 3bd25e8..fc3ccdd 100644
--- a/include/grub/menu.h
+++ b/include/grub/menu.h
@@ -41,6 +41,8 @@ struct grub_menu_entry
   /* The sourcecode of the menu entry, used by the editor.  */
   const char *sourcecode;
 
+  int hotkey;
+
   /* The next element.  */
   struct grub_menu_entry *next;
 };
diff --git a/normal/main.c b/normal/main.c
index 66d8418..52feb80 100644
--- a/normal/main.c
+++ b/normal/main.c
@@ -149,6 +149,17 @@ free_menu_entry_classes (struct grub_menu_entry_class 
*head)
     }
 }
 
+static struct
+{
+  char *name;
+  int key;
+} hotkey_aliases[] =
+  {
+    {"backspace", '\b'},
+    {"tab", '\t'},
+    {"delete", GRUB_TERM_DC}
+  };
+
 /* Add a menu entry to the current menu context (as given by the environment
    variable data slot `menu').  As the configuration file is read, the script
    parser calls this when a menu entry is to be created.  */
@@ -164,6 +175,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
   int i;
   struct grub_menu_entry_class *classes_head;  /* Dummy head node for list.  */
   struct grub_menu_entry_class *classes_tail;
+  int hotkey = 0;
 
   /* Allocate dummy head node for class list.  */
   classes_head = grub_zalloc (sizeof (struct grub_menu_entry_class));
@@ -218,6 +230,32 @@ grub_normal_add_menu_entry (int argc, const char **args,
              classes_tail = new_class;
              continue;
            }
+         else if (grub_strcmp(arg, "hotkey") == 0)
+           {
+             unsigned j;
+
+             i++;
+             if (args[i][1] == 0)
+               {
+                 hotkey = args[i][0];
+                 continue;
+               }
+
+             for (j = 0; j < ARRAY_SIZE (hotkey_aliases); j++)
+               if (grub_strcmp (args[i], hotkey_aliases[j].name) == 0)
+                 {
+                   hotkey = hotkey_aliases[j].key;
+                   break;
+                 }
+
+             if (j < ARRAY_SIZE (hotkey_aliases))
+               continue;
+
+             failed = 1;
+             grub_error (GRUB_ERR_MENU,
+                         "Invalid hotkey: '%s'.", args[i]);
+             break;
+           }
          else
            {
              /* Handle invalid argument.  */
@@ -274,6 +312,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
     }
 
   (*last)->title = menutitle;
+  (*last)->hotkey = hotkey;
   (*last)->classes = classes_head;
   (*last)->sourcecode = menusourcecode;
 
diff --git a/normal/menu_text.c b/normal/menu_text.c
index e0d96c4..698be65 100644
--- a/normal/menu_text.c
+++ b/normal/menu_text.c
@@ -500,6 +500,18 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
              goto refresh;
 
            default:
+             {
+               grub_menu_entry_t entry;
+               int i;
+               for (i = 0, entry = menu->entry_list; i < menu->size;
+                    i++, entry = entry->next)
+                 if (entry->hotkey == c)
+                   {
+                     grub_setcursor (1);
+                     *auto_boot = 0;
+                     return i;
+                   }
+             }
              break;
            }
 
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to