From c758029be533c05d674251f204ca368be5d2c67f Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Tue, 19 Feb 2008 18:21:08 -0800 Subject: [PATCH] simple menu: remember the cursor position on a per-menu basis For each menu, remember what the current position of the cursor and the scroll is. --- com32/menu/menu.h | 3 +++ com32/menu/menumain.c | 17 +++++++++++------ com32/menu/readconfig.c | 2 ++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/com32/menu/menu.h b/com32/menu/menu.h index 638fece..5aeb48f 100644 --- a/com32/menu/menu.h +++ b/com32/menu/menu.h @@ -148,6 +148,9 @@ struct menu { int allowedit; int timeout; + int curentry; + int curtop; + const char *title; const char *ontimeout; const char *onerror; diff --git a/com32/menu/menumain.c b/com32/menu/menumain.c index f1398c8..d563198 100644 --- a/com32/menu/menumain.c +++ b/com32/menu/menumain.c @@ -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; diff --git a/com32/menu/readconfig.c b/com32/menu/readconfig.c index e14e858..9a0697f 100644 --- a/com32/menu/readconfig.c +++ b/com32/menu/readconfig.c @@ -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 ) -- 2.7.4