simple menu: remember the cursor position on a per-menu basis
authorH. Peter Anvin <hpa@zytor.com>
Wed, 20 Feb 2008 02:21:08 +0000 (18:21 -0800)
committerH. Peter Anvin <hpa@zytor.com>
Wed, 20 Feb 2008 02:21:08 +0000 (18:21 -0800)
For each menu, remember what the current position of the cursor and
the scroll is.

com32/menu/menu.h
com32/menu/menumain.c
com32/menu/readconfig.c

index 638fece..5aeb48f 100644 (file)
@@ -148,6 +148,9 @@ struct menu {
   int allowedit;
   int timeout;
 
+  int curentry;
+  int curtop;
+
   const char *title;
   const char *ontimeout;
   const char *onerror;
index f1398c8..d563198 100644 (file)
@@ -31,7 +31,7 @@
 #include "menu.h"
 
 /* The symbol "cm" always refers to the current menu across this file... */
-static const struct menu *cm;
+static struct menu *cm;
 
 const struct menu_parameter mparm[NPARAMS] = {
   [P_WIDTH]            = { "width", 0 },
@@ -698,8 +698,10 @@ run_menu(void)
 {
   int key;
   int done = 0;
-  volatile int entry = cm->defentry, prev_entry = -1;
-  int top = 0, prev_top = -1;
+  volatile int entry = cm->curentry;
+  int prev_entry = -1;
+  volatile int top = cm->curtop;
+  int prev_top = -1;
   int clear = 1, to_clear;
   const char *cmdline = NULL;
   volatile clock_t key_timeout, timeout_left, this_timeout;
@@ -787,6 +789,8 @@ run_menu(void)
     }
 
     prev_entry = entry;  prev_top = top;
+    cm->curentry = entry;
+    cm->curtop = top;
 
     /* Cursor movement cancels timeout */
     if ( entry != cm->defentry )
@@ -850,8 +854,8 @@ run_menu(void)
          done = 0;
          clear = 2;
          cm = me->submenu;
-         entry = cm->defentry;
-         top = 0;
+         entry = cm->curentry;
+         top = cm->curtop;
          break;
        case MA_QUIT:
          /* Quit menu system */
@@ -978,7 +982,8 @@ run_menu(void)
       if ( cm->parent ) {
        cm = cm->parent;
        clear = 2;
-       entry = top = 0;
+       entry = cm->curentry;
+       top = cm->curtop;
       } else if ( cm->allowedit ) {
        done = 1;
        clear = 1;
index e14e858..9a0697f 100644 (file)
@@ -928,6 +928,8 @@ void parse_configs(char **argv)
   resolve_gotos();
 
   for (m = menu_list; m; m = m->next) {
+    m->curentry = m->defentry; /* All menus start at their defaults */
+
     if ( m->ontimeout )
       m->ontimeout = unlabel(m->ontimeout);
     if ( m->onerror )