spec_menu()
create interactive menu from specifications
DESCRIPTION
The spec_menu() function creates interactive menus that might be used for configuring macros and other spec options. When the menu is active, the user can use arrow and control keys to navigate the options and edit strings.
While waiting for input in spec_menu(), spec will continue to poll hardware and respond to client commands if in server mode, just as spec does while waiting for input at the main command prompt.
USAGE
spec_menu(menu [, modes [, dumbterm]])
The menu argument is a two-dimensional associative array that completely describes the menu as detailed below. The first index of the array is a number that identifies an item. The second index of the array is a string that matches one of a set of keys that identify an attribute for the item. The value of the array element depends on the key.
The optional modes argument is a single value where each bit can be associated with a menu item. Up to 52 items may have associated bits.
If the number of menu items plus the number of lines needed to display the hints and "info" strings is greater than the number of rows in the terminal window, the menu items will be scrollable. The number of additional lines above or below the visible window will be displayed in the left of the screen. Navigating past the top or bottom will automatically scroll the menu.
If the width of the menu is greater than the width of the window, the menu items will be compressed or scrolled horizontally, to fit the available space.
If dumbterm is nonzero, spec_menu() will not use cursor positioning. Instead, the menu options will be displayed one at a time in sequence and the user will be prompted for a value. In this mode, entering a single - for any response will jump back and prompt again for the previous item in the sequence.
The function will return a possibly modified value for modes, reflecting the user's choices. If the menu is exited with ^C or the x command, the values of the menu items on entry are restored.
RETURN VALUES
On a normal return with the q or ^D keys, spec_menu() will return an updated value for modes that reflects the new values of all the "bit" items. In addition, new values for "value", "svalue" and variables passed indirectly using "@" will be assigned. Finally, for any items that have been modified an element will be added to the menu array with a second index named "updated" and a value set to one.
EXAMPLES
The standard spec macros setplot, setshow, mstartup and plotselect all use the spec_menu() function. Here is another example:
def menu1 '{
local i, menu[], modes
local group_size
modes = 1
group_size = 512
menu[++i]["title"] = "Menu Example"
menu[++i]["desc"] = "Enable List Examples"
menu[ i]["bit"] = 0x0001
menu[++i]["desc"] = " List Example 1"
menu[ i]["bit_and"] = 0x0001
menu[ i]["list"] = "Now is the time for all good men"
menu[ i]["svalue"] = "time"
menu[++i]["desc"] = " List Example 2"
menu[ i]["bit_and"] = 0x0001
menu[ i]["list"] = "The quick::brown fox::jumps over::the lazy dog"
menu[ i]["delim"] = "::"
menu[ i]["value"] = 3
menu[++i]["desc"] = " List Example 3"
menu[ i]["bit_and"] = 0x0001
menu[ i]["list"] = "128 256 512 1024 2048 4096 8192"
menu[ i]["@"] = "group_size"
menu[++i]["desc"] = ""
menu[++i]["desc"] = "Use logarithmic y-axis"
menu[ i]["bit"] = PL_YLOG
menu[++i]["desc"] = "Force y-axis minimum to zero"
menu[ i]["bit"] = PL_YZERO
menu[ i]["bit_not"] = PL_YLOG
modes = spec_menu(menu, modes)
print modes, group_size
}'
