NAME Term::Graille::Menu

Modal hierarchical Menu system

SYNOPSIS

use Term::Graille::Interact;
use Term::Graille::Menu ;   # provides Term::Graille::Menu

my $menu=new Term::Graille::Menu(
      menu=>[["File","New","Save","Load","Quit"],
             ["Edit","Clear",["Reformat","2x4","4x4"],["Scroll","left","right","up","down"]],
             "About"],
      redraw=>\&main::refreshScreen,
      dispatcher=>\&main::menuActions,
      );

DESCRIPTION

Developed to allow user interaction using a hierarchical menu in command line applications. The menu is activated using a key press, and navigated typically using arrow keys. It does not handle or capture the key presses directly, and in Graille is used in conjunction with Term::Graille::Interact

FUNCTIONS

my $menu=Term::Graille::Menu->new(%params)

Creates a new $menu; params are menu The menu tree as an Array ref containing strings and arrayrefs. Branches are Array refs, and end nodes are strings. See above example to visualise structure. redraw This is a function that needs to be supplied to redraw the application screen. The menu will overwrite parts of the application screen, and this function needs to be provided to restore the screen. dispatcher The menu does not call any functions, instead returns the leaf string selected. It is upto the main application to use this string to in a dispatch routine (the dispatcher function supplied) pos Optional. The default position is [2,2], but setting this parameter allows the menu to be placed elsewhere highlightColour Optional. The selected item is highlighted default "black on_white" normalColour Optional. The normal colour of menu items "white on_black"

$menu->setMenu($menu,$reset)

Changes the menu. if reset is set then the menu "pointer" is set at the first item in menmu tree.

$menu->redraw()

Calls the application' s redraw function. This is required for the menu to be overwritten with application screen.

$menu->nextItem(), my $menu->prevItem(), my $menu->closeItem(), my $menu->openItem()

Navigate the menu, select items.

$menu->drillDown(),

An internal routione that drills down the breadcrumbs to get the currently highlighted item, and whether it as any children. results returned an arrayRef containing two items [Label,Children?1:0]

$menu->drawMenu(),

Draws the menu tree, obviously. Overwrites parts of the canvas, therefore these may need to be redrawn after menu closed.

$menu->drawLevel(),

Internal function to draw each level of the path to the selected item

$menu->depth(),

Internal function to identify which level of the menu tree has been descended; I.e. the number of items in $menu-{breadCrumbs}>

$menu->highlight()

Internal function to highlight selected items