Curses::Menu - display menus for selecting items using Curses


NAME

Curses::Menu - display menus for selecting items using Curses


SYNOPSIS

 use Curses::Menu;
 my $menu = new Curses::Menu(title => "A Menu");
 $menu->additem("Item One");
 $menu->additem("Item Two" => 2);
 $menu->addescape(KEY_ESC, "Cancel", MENU_RETURN, MENU_CANCEL);
 $menu->addescape(KEY_ENTER, "Select", MENU_RETURN, MENU_OK);
 $menu->addescape(ORD('j'), undef, MENU_CALL, \&MENU_UP);
 $menu->addescape(KEY_UP, "Prev Item", MENU_CALL, \&MENU_UP);
 $menu->selected($value);
 $menu->display($window);
 if ($menu->escape() == MENU_OK) {
   $r3 = $menu->selected();
 }


DESCRIPTION

  Curses::Menu implements a flexible text menu system.  An object of
  this class represents a menu.


CONSTRUCTORS

  The following method constructs a Curses::Menu object:
$menu = Curses::Menu->new( %options );

The following options are supported:

title
The title to display when presenting this menu.

escaperows
The number of rows to use for displaying escape keys (default: 2)


METHODS

The methods described in this section can be called on a Curses::Method object.

additem ( $item )
additem ( $item => $keyvalue )
Adds an item to the menu. If a key value is not provided, the item value will be used instead. The key value must be unique.

addescape ( $keycode, $label, $actions, $argument )
Adds an escape to the menu. Escapes are action keys that perform some kind of action from moving the highlight, to calling callback functions.

This module only implements 3 actions: MENU_ACTION_NOP, MENU_ACTION_CALL and MENU_ACTION_RETURN.

MENU_ACTION_NOP does nothing (and supresses the unknown key beep as a result).

MENU_ACTION_CALL calls the subref specified in the argument field with the object reference as its first argument.

MENU_ACTION_RETURN causes the menu to return, setting the escape value to the argument.

display( $window )
Displays the menu. $window must be a valid curses window. display only returns when a escape is triggered with an action of MENU_ACTION_RETURN.

escape()
Returns the argument of the escape used to exit the menu. Not defined if called before display().

selected()
selected( $newvalue )
Returns or sets the selected item by key.


CALLBACKS

The module defines a number of useful callbacks which you will probably want to use with your menu.

MENU_CALLBACK_UP
Moves the highlight up one item.

MENU_CALLBACK_DOWN
Moves the highlight down one item.

MENU_CALLBACK_PGUP
Moves the highlight up a screenful of items.

MENU_CALLBACK_PGDOWN
Moves the highlight down a screenful of items.


CREDITS

Written by Chris Collins <xfire@xware.cx>.

Inspired partially by the long obsolete perlmenu package and my boss.

 Curses::Menu - display menus for selecting items using Curses