Node: Appendix - read/print User Interface (rpUI), Next: , Previous: Programming Cautions, Up: Top



Appendix - read/print User Interface (rpUI)

Lpp comes bundled with rpUI, a read/print User Interface, that is implemented using the Lpp library. By providing a selection of simple menus rpUI makes it easy to create complete applications using Lpp. Read/print interfaces are also good for creating debugging interfaces to applications and regression testing procedures.

Two kinds of menus are available: First, Static Numerical menus present the same fix list of choices for the user with sequential integers prefixing each choice. The user types in an integer to make a selection. Second, Dynamic Symbolic menus just prompts for a symbol and a choice is made based on the symbol that the user enters.

rpSnMenu spec Function

This function returns an Lpp object representing a Static Numerical menu based on the specification spec provided. The menu object returned can be used in subsequent calls to chooseRpMenu where the user needs to make a menu selection. spec is a list of Lpp Strings. The first entry in the list will be the menu header. The rest of the list will specify sequential menu selections. When chooseRpMenu is called the user will be presented with the header followed by the choices prefixed with integers and then a prompt for an integer. If the user enters anything other than one of the integers corresponding to a choice the user is notified of a bad entry and the menu is presented again. If the user enters an integer corresponding to a choice that integer is returned from chooseRpMenu as in int.

rpDsMenu spec Function

This function returns an Lpp object representing a Dynamic Symbolic menu based on the specification spec provided. The menu object returned can be used in subsequent calls to chooseRpMenu where the user needs to make a menu selection. spec is a list of Lpp Strings. The first entry in the list will be the menu prompt. The rest of the list is alternating symbol description Strings where symbol will be the expected symbol that the user is expected to enter for that choice and description is a String describing the choice. When chooseRpMenu is called the user will be presented with the prompt. If the user enters anything other than one of the symbols corresponding to a choice the user is notified of a bad entry and then menu of choices with symbol description pairs is presented. If the user enters a symbol corresponding to a choice then an integer is returned from chooseRpMenu as an int. The integer corresponds to the position in the spec list of choices, where the first choice will return 0, the second 1 etc.

chooseRpMenu menu Function

This function is given the argument menu which is either an rpSnMenu or an rpDsMenu. The menu or prompt is presented as indicated above and when the user makes an entry an int of 0 to n is returned where there are n - 1 choices in the menu.

The following simple program illustrates the use of both kinds of menus:

     
     #include <rpMenu.hh>
     #include <Lpp.hh>
     
     main() {
       let menu1 = rpDsMenu
         (L("Enter command (or ? for help): "),
          listSEM("exit", "Exit program",
                  "fix", "Fix me",
                  "list", "List Sn menu", EM));
       let menu2 = rpSnMenu(L("Choose one of"),
                            listSEM("choice 0", "choice 1", EM));
       int choice; int doing = 1;
       while (doing) {
         switch (chooseRpMenu(menu1)) {
         case 0: doing = 0; cout << "Goodbye\n"; break;
         case 1: cout << "Thank you!\n"; break;
         case 2:
           choice = chooseRpMenu(menu2);
           cout << "\nChoice = " << choice << endl;}}}
     

When the above program is run it will produce the following dialog:

     
     Enter command (or ? for help):  ?
     
     Choose one of:
       exit = Exit program
       fix = Fix me
       list = List Sn menu
     Enter command (or ? for help):  list
     
     Choose one of
       0 = choice 0
       1 = choice 1
     Enter 0-1: 1
     
     Choice = 1
     
     Enter command (or ? for help):  exit
     Goodbye