The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME Term::Graille::Menu

SYNOPSIS

    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,
          callback=>\&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 conjunctyion with Term::Graille::IO

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 visuialise structure. redraw This is a function to redraws the application screen. The menu will overwrite parts of the application screen, and this allows function needs to be provided to restire the screen. callback 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 callback function supplied)

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

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

my $menu->redraw()

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

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

Navigate the menu, select items.

my $menu->closeMenu()

Closes the menu, redraws the screen (using $menu-redraw();>) and sends undef to $menu-{callback}>;

my $menu->upArrow(), my $menu->downArrow(), my $menu->leftArraow(), my $menu->rightArrow()

The menu does not acpture key presses, but provides methods to allow key presses to trigger navigation.