bug-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Various menu related enhancements


From: Adam Lackorzynski
Subject: [PATCH] Various menu related enhancements
Date: Mon, 14 Oct 2002 16:48:35 +0200
User-agent: Mutt/1.4i

Hello,

I have prepared several menu related patches which implement some (IMHO)
useful features. Each feature is in its own patch and should work on its
own. They will need to be applied one after another, though.

 - 01_menu_vi_up_down.diff:
   * Add vi like up and down in menu (j and k keys).
 
 - 02_menu_reload.diff:
   * Key 'r' for reload of the current menu. Useful when the config
     comes via TFTP and is modified when the menu is already loaded.

 - 03_menu_entry_display.diff:
   * Display the number of the current entry in the top right corner of
     the menu frame. It's useful to know which number to put in the
     "Default" directive when the config menu is a longer than usual.

 - 04_menu_page_up_down.diff:
   * Add page up and page down in the menu.

 - 05_menu_go_on_with_right.diff:
   * Make key right to do the same as enter in menu.

 - 06_menu_history.diff:
   * Add a history for the menu. Use key left to get to the previous
     menu.

All patches including an all-in-one patch are also available at
   http://os.inf.tu-dresden.de/~adam/grub/

They patches are against the CVS version of GRUB as of today.


01_menu_vi_up_down.diff:

--- grub/ChangeLog      10 Oct 2002 01:26:16 -0000
+++ grub/ChangeLog      14 Oct 2002 13:02:39 -0000
@@ -1,3 +1,8 @@
+2002-10-14  Adam Lackorzynski  <address@hidden>
+
+       * stage2/stage2.c (run_menu): Add vi like up and down keys
+       ("j" and "k").
+
 2002-10-10  Jason Thomas  <address@hidden>
 
        * stage2/builtins.c (setup_func): Added missing space to --force-lba
--- grub/stage2/stage2.c        22 Aug 2002 05:59:55 -0000
+++ grub/stage2/stage2.c        27 Sep 2002 13:10:24 -0000
@@ -392,7 +392,7 @@
 
          /* We told them above (at least in SUPPORT_SERIAL) to use
             '^' or 'v' so accept these keys.  */
-         if (c == 16 || c == '^')
+         if (c == 16 || c == '^' || c == 'k')
            {
              if (current_term->flags & TERM_DUMB)
                {
@@ -421,7 +421,7 @@
                    }
                }
            }
-         else if ((c == 14 || c == 'v')
+         else if ((c == 14 || c == 'v' || c == 'j')
                   && first_entry + entryno + 1 < num_entries)
            {
              if (current_term->flags & TERM_DUMB)


02_menu_reload.diff:

--- grub/ChangeLog.01   Mon Oct 14 15:02:44 2002
+++ grub/ChangeLog      Mon Oct 14 15:04:08 2002
@@ -1,5 +1,7 @@
 2002-10-14  Adam Lackorzynski  <address@hidden>
 
+       * stage2/stage2.c (run_menu): Add 'r' key to reload menu.
+
        * stage2/stage2.c (run_menu): Add vi like up and down keys
        ("j" and "k").
 
--- grub/stage2/stage2.c.01     Fri Sep 27 15:12:20 2002
+++ grub/stage2/stage2.c        Fri Sep 27 15:13:09 2002
@@ -314,7 +314,7 @@
          if (config_entries)
            printf ("\
       Press enter to boot the selected OS, \'e\' to edit the\n\
-      commands before booting, or \'c\' for a command-line.");
+      commands before booting, \'c\' for a command-line, or \'r\' to reload.");
          else
            printf ("\
       Press \'b\' to boot, \'e\' to edit the selected command in the\n\
@@ -450,6 +450,9 @@
 
          if (config_entries)
            {
+             if (c == 'r')
+               return;
+
              if ((c == '\n') || (c == '\r'))
                break;
            }


03_menu_entry_display.diff:

--- grub/ChangeLog.02   Mon Oct 14 15:04:40 2002
+++ grub/ChangeLog      Mon Oct 14 15:07:10 2002
@@ -1,5 +1,8 @@
 2002-10-14  Adam Lackorzynski  <address@hidden>
 
+       * stage2/stage2.c (run_menu): Display number of current entry
+       in the right upper corner of the menu frame.
+
        * stage2/stage2.c (run_menu): Add 'r' key to reload menu.
 
        * stage2/stage2.c (run_menu): Add vi like up and down keys
--- grub/stage2/stage2.c.02     Fri Sep 27 15:21:39 2002
+++ grub/stage2/stage2.c        Fri Sep 27 15:27:21 2002
@@ -362,6 +362,18 @@
          grub_timeout--;
        }
 
+      /* Print the number of the current entry in the right upper corner of
+       * the menu, up to 999 entries are supported, modify the coordinates
+       * and putchar command to add more */
+      if (! (current_term->flags & TERM_DUMB))
+       {
+         gotoxy(69, 3);
+         grub_printf("[%d]", first_entry + entryno);
+         grub_putchar(DISP_HORIZ);
+         grub_putchar(DISP_HORIZ);
+         gotoxy(74, 4 + entryno);
+       }
+
       /* Check for a keypress, however if TIMEOUT has been expired
         (GRUB_TIMEOUT == -1) relax in GETKEY even if no key has been
         pressed.  

04_menu_page_up_down.diff:

--- grub/ChangeLog.03   Mon Oct 14 15:07:38 2002
+++ grub/ChangeLog      Mon Oct 14 15:10:29 2002
@@ -1,5 +1,11 @@
 2002-10-14  Adam Lackorzynski  <address@hidden>
 
+       * stage2/stage2.c (run_menu): Add page up and page down support.
+       * stage2/asm.S (translation_table): Add 3 and 7 for page up and down.
+       * stage2/serial.c (serial_translate_key_sequence): Add page up and
+       down.
+       * grub/asmstub.c (console_translate_key): Likewise.
+
        * stage2/stage2.c (run_menu): Display number of current entry
        in the right upper corner of the menu frame.
 
--- grub/stage2/stage2.c.03     Fri Sep 27 15:29:20 2002
+++ grub/stage2/stage2.c        Mon Oct 14 01:07:02 2002
@@ -460,6 +460,73 @@
                }
            }
 
+         /* PAGE UP */
+         if (c == 7 && !(current_term->flags & TERM_DUMB))
+           {
+             if (first_entry > 11)
+               {
+                 first_entry -= 12;
+                 print_entries (3, 12, first_entry, entryno, menu_entries);
+               }
+             else if (first_entry)
+               {
+                 print_entry (4 + entryno, 0,
+                              get_entry (menu_entries,
+                                         first_entry + entryno,
+                                         0));
+                 if (entryno + first_entry - 12 < 0)
+                   entryno = 0;
+                 else
+                   entryno = first_entry + entryno - 12;
+                 first_entry = 0;
+                 print_entries (3, 12, first_entry, entryno, menu_entries);
+               }
+             else if (entryno)
+               {
+                 print_entry (4 + entryno, 0,
+                              get_entry (menu_entries,
+                                         first_entry + entryno,
+                                         0));
+                 entryno = 0;
+                 print_entry (4, 1, get_entry (menu_entries, 0, 0));
+
+               }
+           }
+         /* PAGE DOWN */
+         else if (c == 3 && !(current_term->flags & TERM_DUMB))
+           {
+             if (first_entry + 12 < num_entries)
+               {
+                 if (first_entry + 23 < num_entries)
+                   first_entry += 12;
+                 else
+                   {
+                     print_entry (4 + entryno, 0,
+                                  get_entry (menu_entries,
+                                             first_entry + entryno,
+                                             0));
+                     if (entryno + first_entry + 12 >= num_entries)
+                       entryno = 11;
+                     else
+                       entryno += 24 + first_entry - num_entries;
+                     first_entry = num_entries - 12;
+                   }
+                 print_entries (3, 12, first_entry, entryno, menu_entries);
+               }
+             else if (first_entry + entryno + 1 != num_entries)
+               {
+                 print_entry (4 + entryno, 0,
+                              get_entry (menu_entries,
+                                         first_entry + entryno,
+                                         0));
+                 entryno = num_entries - first_entry - 1;
+                 print_entry (4 + entryno, 1,
+                              get_entry (menu_entries,
+                                         first_entry + entryno,
+                                         0));
+               }
+           }
+
          if (config_entries)
            {
              if (c == 'r')
--- grub/stage2/asm.S.03        12 Jul 2002 09:55:55 -0000
+++ grub/stage2/asm.S           13 Oct 2002 23:11:39 -0000
@@ -1920,6 +1921,8 @@
        .word   KEY_END, 5
        .word   KEY_DC, 4
        .word   KEY_BACKSPACE, 8
+       .word   KEY_PPAGE, 3
+       .word   KEY_NPAGE, 7
        .word   0
        
 /*
--- grub/stage2/serial.c.03     13 Sep 2002 11:27:41 -0000
+++ grub/stage2/serial.c        13 Oct 2002 23:13:10 -0000
@@ -218,7 +218,9 @@
   four_code_table[] =
     {
       {('1' | ('~' << 8)), 1},
-      {('3' | ('~' << 8)), 4}
+      {('3' | ('~' << 8)), 4},
+      {('6' | (126 << 8)), 3},
+      {('5' | (126 << 8)), 7},
     };
   
   /* The buffer must start with ``ESC [''.  */
--- grub/grub/asmstub.c.03      22 Aug 2002 05:59:55 -0000
+++ grub/grub/asmstub.c         14 Oct 2002 12:42:03 -0000
@@ -627,6 +627,10 @@
       return 1;
     case KEY_END:
       return 5;
+    case KEY_NPAGE:
+      return 7;
+    case KEY_PPAGE:
+      return 3;
     default:
       break;
     }

05_menu_go_on_with_right.diff:

--- grub/ChangeLog.04   Mon Oct 14 15:11:03 2002
+++ grub/ChangeLog      Mon Oct 14 15:11:59 2002
@@ -1,5 +1,8 @@
 2002-10-14  Adam Lackorzynski  <address@hidden>
 
+       * stage2/stage2.c (run_menu): Make right key to do the same
+       as enter in the menu.
+
        * stage2/stage2.c (run_menu): Add page up and page down support.
        * stage2/asm.S (translation_table): Add 3 and 7 for page up and down.
        * stage2/serial.c (serial_translate_key_sequence): Add page up and
--- grub/stage2/stage2.c.04     Mon Oct 14 01:14:45 2002
+++ grub/stage2/stage2.c        Mon Oct 14 01:28:46 2002
@@ -313,8 +313,9 @@
        {
          if (config_entries)
            printf ("\
-      Press enter to boot the selected OS, \'e\' to edit the\n\
-      commands before booting, \'c\' for a command-line, or \'r\' to reload.");
+      Press enter or %c to boot the selected OS, \'e\' to edit the\n\
+      commands before booting, \'c\' for a command-line, or \'r\' to reload.",
+                   DISP_RIGHT);
          else
            printf ("\
       Press \'b\' to boot, \'e\' to edit the selected command in the\n\
@@ -532,7 +533,7 @@
              if (c == 'r')
                return;
 
-             if ((c == '\n') || (c == '\r'))
+             if ((c == '\n') || (c == '\r') || (c == 6))
                break;
            }
          else

06_menu_history.diff:

--- grub/ChangeLog.05   Mon Oct 14 15:12:34 2002
+++ grub/ChangeLog      Mon Oct 14 15:16:00 2002
@@ -1,5 +1,9 @@
 2002-10-14  Adam Lackorzynski  <address@hidden>
 
+       * stage2/stage2.c: Add menu history support.
+       (cmain): Save history in history buffer.
+       (run_menu): Add history, go one entry back in history on key left.
+
        * stage2/stage2.c (run_menu): Make right key to do the same
        as enter in the menu.
 
--- grub/stage2/stage2.c.05     Mon Oct 14 01:31:22 2002
+++ grub/stage2/stage2.c        Mon Oct 14 01:46:20 2002
@@ -76,6 +76,21 @@
 
 #endif /* ! PRESET_MENU_STRING && ! SUPPORT_DISKLESS */
 
+/* config_file is 128 Bytes long (see grub/asmstub.c) */
+#define CONFIG_FILE_LEN 128
+#define CONFIG_FILE_HISTORY_ENTRIES 10
+struct config_file_history_struct {
+  char filename[CONFIG_FILE_LEN];
+  int entryno;
+  int first_entry;
+};
+static struct config_file_history_struct
+       config_file_history[CONFIG_FILE_HISTORY_ENTRIES];
+static int config_file_history_pos, config_file_history_start,
+          config_file_history_prev_pos;
+static int config_file_history_menu_pos = -1;
+
+
 static char *
 get_entry (char *list, int num, int nested)
 {
@@ -234,6 +249,15 @@
    */
 
 restart:
+
+  if (config_file_history_menu_pos != -1)
+    {
+      /* we're in a history back movement, set menu values to previous ones */
+      entryno     = config_file_history[config_file_history_menu_pos].entryno;
+      first_entry = 
config_file_history[config_file_history_menu_pos].first_entry;
+      config_file_history_menu_pos = -1;
+    }
+
   /* Dumb terminal always use all entries for display 
      invariant for TERM_DUMB: first_entry == 0  */
   if (! (current_term->flags & TERM_DUMB))
@@ -314,8 +338,9 @@
          if (config_entries)
            printf ("\
       Press enter or %c to boot the selected OS, \'e\' to edit the\n\
-      commands before booting, \'c\' for a command-line, or \'r\' to reload.",
-                   DISP_RIGHT);
+      commands before booting, \'c\' for a command-line, \'r\' to reload or\n\
+      or %c to go back if possible.",
+                   DISP_RIGHT, DISP_LEFT);
          else
            printf ("\
       Press \'b\' to boot, \'e\' to edit the selected command in the\n\
@@ -534,7 +559,30 @@
                return;
 
              if ((c == '\n') || (c == '\r') || (c == 6))
-               break;
+               {
+                 config_file_history[config_file_history_prev_pos].entryno =
+                   entryno;
+                 config_file_history[config_file_history_prev_pos].first_entry 
=
+                   first_entry;
+
+                 break;
+               }
+
+             if (c == 2) /* KEY_LEFT */
+               {
+                 /* go back in history if possible */
+                 int p = config_file_history_prev_pos;
+                 if (p != config_file_history_start)
+                   {
+                     p = (p == 0) ? CONFIG_FILE_HISTORY_ENTRIES - 1 : p - 1;
+                     memmove(config_file, config_file_history[p].filename,
+                             CONFIG_FILE_LEN);
+                     config_file_history_pos = p;
+                     config_file_history_menu_pos = p;
+
+                     return;
+                   }
+               }
            }
          else
            {
@@ -1021,6 +1069,18 @@
                close_preset_menu ();
              else
                grub_close ();
+
+             /* Save history for config_file */
+             memmove(config_file_history[config_file_history_pos].filename,
+                     config_file,
+                     CONFIG_FILE_LEN);
+             config_file_history_prev_pos = config_file_history_pos;
+             if (++config_file_history_pos == CONFIG_FILE_HISTORY_ENTRIES)
+               config_file_history_pos = 0;
+             if (config_file_history_start == config_file_history_pos &&
+                 ++config_file_history_start == CONFIG_FILE_HISTORY_ENTRIES)
+               config_file_history_start = 0;
+
            }
          while (is_preset);
        }



Comments appreciated.

Adam
-- 
Adam                 address@hidden
  Lackorzynski         http://os.inf.tu-dresden.de/~adam/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]