Hook up F-key help for the menu system, document
authorH. Peter Anvin <hpa@zytor.com>
Fri, 1 Jun 2007 00:05:02 +0000 (17:05 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Fri, 1 Jun 2007 00:05:02 +0000 (17:05 -0700)
README.menu
com32/modules/Makefile
com32/modules/menu.h
com32/modules/menumain.c

index 93cde52..437105b 100644 (file)
@@ -179,7 +179,9 @@ MENU COLOR element ansi foreground background shadow
        timeout_msg     Timeout message
        timeout         Timeout counter
        help            Help text
+       msgXX           Message (F-key) file attribute XX
 
+       ... where XX is two hexadecimal digits (the "plain text" is 07).
 
        "ansi" is a sequence of semicolon-separated ECMA-48 Set
        Graphics Rendition (<ESC>[m) sequences:
@@ -216,21 +218,18 @@ MENU COLOR element ansi foreground background shadow
        These are used (a) in text mode, and (b) on the serial
        console.
 
-
        "foreground" and "background" are color codes in #AARRGGBB
        notation, where AA RR GG BB are hexadecimal digits for alpha
        (opacity), red, green and blue, respectively.  #00000000
        represents fully transparent, and #ffffffff represents opaque
        white.
 
-
        "shadow" controls the handling of the graphical console text
        shadow.  Permitted values are "none" (no shadowing), "std" or
        "standard" (standard shadowing - foreground pixels are
        raised), "all" (both background and foreground raised), and
        "rev" or "reverse" (background pixels are raised.)
 
-
        If any field is set to "*" or omitted (at the end of the line)
        then that field is left unchanged.
 
@@ -254,6 +253,7 @@ MENU COLOR element ansi foreground background shadow
        menu color timeout_msg  37;40      #80ffffff #00000000 std
        menu color timeout      1;37;40    #c0ffffff #00000000 std
        menu color help         37;40      #c0ffffff #00000000 std
+       menu color msg07        37;40      #c0ffffff #40000000 std
 
 
 MENU WIDTH 80
@@ -277,6 +277,18 @@ MENU VSHIFT 0
        screen (25 for text mode, 28 for VESA graphics mode.)
 
 
+F1 textfile background
+...
+F12 textfile background
+
+       Displays full-screen help (also available at the command line.)
+       The same control code sequences as in the command line
+       interface are supported, although some are ignored.
+
+       Additionally, a second argument allows a different background
+       image to be displayed.
+
+
 The menu system honours the TIMEOUT command; if TIMEOUT is specified
 it will execute the ONTIMEOUT command if one exists, otherwise it will
 pick the default menu option.
index 9be0b85..b83a65c 100644 (file)
@@ -88,10 +88,10 @@ cpuidtest.elf : cpuidtest.o cpuid.o $(LIBS)
 dmitest.elf : dmitest.o dmi_utils.o dmi.o $(LIBS)
        $(LD) $(LDFLAGS) -o $@ $^
 
-menu.elf : menu.o menumain.o readconfig.o $(LIBS)
+menu.elf : menu.o menumain.o readconfig.o printmsg.o $(LIBS)
        $(LD) $(LDFLAGS) -o $@ $^
 
-vesamenu.elf : vesamenu.o menumain.o readconfig.o $(LIBS)
+vesamenu.elf : vesamenu.o menumain.o readconfig.o printmsg.o $(LIBS)
        $(LD) $(LDFLAGS) -o $@ $^
 
 ethersel.elf : ethersel.o $(LIBS)
index 51b767e..9bf25b5 100644 (file)
@@ -24,6 +24,7 @@
 #include <sys/times.h>
 #include <inttypes.h>
 #include <unistd.h>
+#include <colortbl.h>
 
 #ifndef CLK_TCK
 # define CLK_TCK sysconf(_SC_CLK_TCK)
@@ -122,4 +123,11 @@ int menu_main(int argc, char *argv[]);
 void console_prepare(void);
 void console_cleanup(void);
 
+void set_msg_colors_global(unsigned int fg, unsigned int bg,
+                          enum color_table_shadow shadow);
+
+extern const int message_base_color;
+int mygetkey(clock_t timeout);
+int show_message_file(const char *filename, const char *background);
+
 #endif /* MENU_H */
index 0f4bbc6..226212c 100644 (file)
@@ -79,6 +79,7 @@ static const struct color_table default_color_table[] = {
 };
 
 #define NCOLORS (sizeof default_color_table/sizeof(struct color_table))
+const int message_base_color = NCOLORS;
 
 struct menu_parameter mparm[] = {
   { "width", 80 },
@@ -111,13 +112,39 @@ struct menu_parameter mparm[] = {
 #define HSHIFT         mparm[11].value
 #define VSHIFT         mparm[12].value
 
+void set_msg_colors_global(unsigned int fg, unsigned int bg,
+                          enum color_table_shadow shadow)
+{
+  struct color_table *cp = console_color_table+message_base_color;
+  unsigned int i;
+  unsigned int fgh, bgh;
+
+  static const unsigned int pc2rgb[8] =
+    { 0x000000, 0x0000ff, 0x00ff00, 0x00ffff, 0xff0000, 0xff00ff, 0xffff00,
+      0xffffff };
+
+  fg &= 0xff000000;            /* Alpha only */
+  bg &= 0xff000000;            /* Alpha only */
+
+  fgh = (0x80000000+(fg >> 1)) & 0xff000000;
+  bgh = (0x80000000+(bg >> 1)) & 0xff000000;
+
+  for (i = 0; i < 256; i++) {
+    cp->argb_fg = pc2rgb[i & 7] | ((i & 0x08) ? fgh : fg);
+    cp->argb_bg = pc2rgb[(i >> 4) & 7] | ((i & 0x80) ? bgh : bg);
+    cp->shadow  = shadow;
+    cp++;
+  }
+}
+
 static void
 install_default_color_table(void)
 {
   unsigned int i;
   const struct color_table *dp;
   struct color_table *cp;
-  static struct color_table color_table[NCOLORS];
+  static struct color_table color_table[NCOLORS+256];
+  static const int pc2ansi[8] = {0, 4, 2, 6, 1, 5, 3, 7};
 
   dp = default_color_table;
   cp = color_table;
@@ -133,8 +160,23 @@ install_default_color_table(void)
     dp++;
   }
 
+  for (i = 0; i < 256; i++) {
+    if (!cp->name)
+      asprintf((char **)&cp->name, "msg%02x", i);
+
+    if (cp->ansi)
+      free((void *)cp->ansi);
+    
+    asprintf((char **)&cp->ansi, "%s3%d;4%d", (i & 8) ? "1;" : "",
+            pc2ansi[i & 7], pc2ansi[(i >> 4) & 7]);
+
+    cp++;
+  }
+
   console_color_table = color_table;
-  console_color_table_size = NCOLORS;
+  console_color_table_size = NCOLORS+256;
+
+  set_msg_colors_global(0xc0000000, 0x40000000, SHADOW_NORMAL);
 }
 
 static char *
@@ -250,7 +292,7 @@ passwd_compare(const char *passwd, const char *entry)
 
 static jmp_buf timeout_jump;
 
-static int mygetkey(clock_t timeout)
+int mygetkey(clock_t timeout)
 {
   clock_t t0, t;
   clock_t tto, to;
@@ -450,6 +492,38 @@ display_help(const char *text)
   }
 }
 
+static void show_fkey(int key)
+{
+  int fkey;
+
+  while (1) {
+    switch (key) {
+    case KEY_F1:  fkey =  0;  break;
+    case KEY_F2:  fkey =  1;  break;
+    case KEY_F3:  fkey =  2;  break;
+    case KEY_F4:  fkey =  3;  break;
+    case KEY_F5:  fkey =  4;  break;
+    case KEY_F6:  fkey =  5;  break;
+    case KEY_F7:  fkey =  6;  break;
+    case KEY_F8:  fkey =  7;  break;
+    case KEY_F9:  fkey =  8;  break;
+    case KEY_F10: fkey =  9;  break;
+    case KEY_F11: fkey = 10;  break;
+    case KEY_F12: fkey = 11;  break;
+    default: fkey = -1; break;
+    }
+    
+    if (fkey == -1)
+      break;
+
+    if (fkeyhelp[fkey].textname)
+      key = show_message_file(fkeyhelp[fkey].textname,
+                             fkeyhelp[fkey].background);
+    else
+      break;
+  }
+}
+
 static const char *
 edit_cmdline(char *input, int top)
 {
@@ -579,6 +653,22 @@ edit_cmdline(char *input, int top)
       }
       break;
 
+    case KEY_F1:
+    case KEY_F2:
+    case KEY_F3:
+    case KEY_F4:
+    case KEY_F5:
+    case KEY_F6:
+    case KEY_F7:
+    case KEY_F8:
+    case KEY_F9:
+    case KEY_F10:
+    case KEY_F11:
+    case KEY_F12:
+      show_fkey(key);
+      redraw = 1;
+      break;
+
     default:
       if ( key >= ' ' && key <= 0xFF && len < MAX_CMDLINE_LEN-1 ) {
        if ( cursor == len ) {
@@ -800,6 +890,22 @@ run_menu(void)
       top = max(0, nentries-MENU_ROWS);
       break;
 
+    case KEY_F1:
+    case KEY_F2:
+    case KEY_F3:
+    case KEY_F4:
+    case KEY_F5:
+    case KEY_F6:
+    case KEY_F7:
+    case KEY_F8:
+    case KEY_F9:
+    case KEY_F10:
+    case KEY_F11:
+    case KEY_F12:
+      show_fkey(key);
+      clear = 1;
+      break;
+
     case KEY_TAB:
       if ( allowedit ) {
        int ok = 1;