From f5be24d4ed330859f7bfe23224338ec9458bf1ae Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Tue, 24 Jul 2007 16:39:00 -0700 Subject: [PATCH] Simple menu system: add support for "menu hidden" --- README.menu | 6 ++++ com32/modules/menu.h | 1 + com32/modules/menumain.c | 86 +++++++++++++++++++++++++++++++++++----------- com32/modules/readconfig.c | 3 ++ 4 files changed, 75 insertions(+), 21 deletions(-) diff --git a/README.menu b/README.menu index 3fd50f3..cf5882d 100644 --- a/README.menu +++ b/README.menu @@ -41,6 +41,11 @@ MENU TITLE title Give the menu a title. The title is presented at the top of the menu. +MENU HIDDEN + + Do not display the actual menu unless the user presses a key. + All that is displayed is a timeout message. + MENU LABEL label (Only valid after a LABEL statement.) @@ -281,6 +286,7 @@ MENU PASSWORDROW 11 MENU TIMEOUTROW 20 MENU HELPMSGROW 22 MENU HELPMSGENDROW -1 +MENU HIDDENROW 20 MENU HSHIFT 0 MENU VSHIFT 0 diff --git a/com32/modules/menu.h b/com32/modules/menu.h index 17fa554..78382ef 100644 --- a/com32/modules/menu.h +++ b/com32/modules/menu.h @@ -94,6 +94,7 @@ extern int defentry; extern int allowedit; extern int timeout; extern int shiftkey; +extern int hiddenmenu; extern long long totaltimeout; extern char *ontimeout; diff --git a/com32/modules/menumain.c b/com32/modules/menumain.c index 2af4e8c..e75223f 100644 --- a/com32/modules/menumain.c +++ b/com32/modules/menumain.c @@ -93,6 +93,7 @@ struct menu_parameter mparm[] = { { "helpmsgendrow", -1 }, { "hshift", 0 }, { "vshift", 0 }, + { "hiddenrow", 20 }, { NULL, 0 } }; @@ -109,6 +110,7 @@ struct menu_parameter mparm[] = { #define HELPMSGEND_ROW mparm[10].value #define HSHIFT mparm[11].value #define VSHIFT mparm[12].value +#define HIDDEN_ROW mparm[13].value void set_msg_colors_global(unsigned int fg, unsigned int bg, enum color_table_shadow shadow) @@ -728,6 +730,58 @@ shift_is_held(void) return !!(shift_bits & 0x5d); /* Caps/Scroll/Alt/Shift */ } +static void +print_timeout_message(int tol, int row, const char *msg) +{ + char buf[256]; + int nc = 0, nnc; + const char *tp = msg; + char tc; + char *tq = buf; + + while ((size_t)(tq-buf) < (sizeof buf-16) && (tc = *tp)) { + if (tc == '#') { + nnc = sprintf(tq, "\2#15%d\2#14", tol); + tq += nnc; + nc += nnc-8; /* 8 formatting characters */ + } else { + *tq++ = tc; + nc++; + } + tp++; + } + *tq = '\0'; + + printf("\033[%d;%dH\2#14 %s ", row, HSHIFT+1+((WIDTH-nc-2)>>1), buf); +} + +static const char * +do_hidden_menu(void) +{ + int key; + int timeout_left, this_timeout; + + if ( !setjmp(timeout_jump) ) { + timeout_left = timeout; + + while (!timeout || timeout_left) { + int tol = timeout_left/CLK_TCK; + + print_timeout_message(tol, HIDDEN_ROW, messages[MSG_AUTOBOOT].msg); + + this_timeout = min(timeout_left, CLK_TCK); + key = mygetkey(this_timeout); + + if (key != KEY_NONE) + return NULL; /* Key pressed */ + + timeout_left -= this_timeout; + } + } + + return menu_entries[defentry].cmdline; /* Default entry */ +} + static const char * run_menu(void) { @@ -747,6 +801,16 @@ run_menu(void) return menu_entries[defentry].cmdline; } + /* Handle hiddenmenu */ + if ( hiddenmenu ) { + cmdline = do_hidden_menu(); + if (cmdline) + return cmdline; + + /* Otherwise display the menu now */ + hiddenmenu = 0; + } + /* Handle both local and global timeout */ if ( setjmp(timeout_jump) ) { entry = defentry; @@ -798,28 +862,8 @@ run_menu(void) key_timeout = 0; if ( key_timeout ) { - char buf[256]; int tol = timeout_left/CLK_TCK; - int nc = 0, nnc; - const char *tp = messages[MSG_AUTOBOOT].msg; - char tc; - char *tq = buf; - - while ((size_t)(tq-buf) < (sizeof buf-16) && (tc = *tp)) { - if (tc == '#') { - nnc = sprintf(tq, "\2#15%d\2#14", tol); - tq += nnc; - nc += nnc-8; /* 8 formatting characters */ - } else { - *tq++ = tc; - nc++; - } - tp++; - } - *tq = '\0'; - - printf("\033[%d;%dH\2#14 %s ", TIMEOUT_ROW, - HSHIFT+1+((WIDTH-nc-2)>>1), buf); + print_timeout_message(tol, TIMEOUT_ROW, messages[MSG_AUTOBOOT].msg); to_clear = 1; } else { to_clear = 0; diff --git a/com32/modules/readconfig.c b/com32/modules/readconfig.c index 21bbc80..844ef8a 100644 --- a/com32/modules/readconfig.c +++ b/com32/modules/readconfig.c @@ -30,6 +30,7 @@ int defentry = 0; int allowedit = 1; /* Allow edits of the command line */ int timeout = 0; int shiftkey = 0; /* Only display menu if shift key pressed */ +int hiddenmenu = 0; long long totaltimeout = 0; char *ontimeout = NULL; @@ -506,6 +507,8 @@ static void parse_config_file(FILE *f) if (menu_background) free(menu_background); menu_background = dup_word(&p); + } else if ( (ep = looking_at(p, "hidden")) ) { + hiddenmenu = 1; } else if ( (ep = is_message_name(p, &msgptr)) ) { free(msgptr->msg); msgptr->msg = strdup(skipspace(ep)); -- 2.7.4