Cmenu
view release on metacpan or search on metacpan
#****************************************************************************
# Cmenu.pm -- Perl Menu Support Facility
#
# Last updated Time-stamp: <01/10/20 22:32:56 devel>
#
#
# Date: Version 1.0 -- May, 1992 -- Original version
# Version 1.1 -- Aug, 1992 -- Minor enhancements, bugfixes
# Version 1.2 -- Nov, 1992 -- Selection bugfix
# Version 1.3 -- Dec, 1992 -- "top" and "latch" functions added
# Version 1.4 -- Apr, 1993 -- "r=refresh" added to bottom line
# Version 2.0 -- Sep, 1993 -- Radio-button, Multiple-selection,
# shell-escape, new "hot-keys", and
# "menu_getstr" routine.
# Version 2.1 -- Oct, 1993 -- Bug fixes
# Version 2.2 -- Mar, 1994 -- Menu sub-titles
# Version 2.3 -- Jun, 1994 -- Bug fixes
# Version 3.0 -- Jan, 1995 -- Templates, lots of new options on
# many calls, Perl5 interfacing.
# Version 3.1 -- Mar, 1995 -- Bug fixes, new "menu_template_setexit"
# call, new menu_pref.
# Version 3.2 -- Jun, 1995 -- Bug fixes, template "required field"
# support, template Control-L refresh.
# Version 3.3 -- Feb, 1996 -- Bug fixes, help routines, templates
# from arrays ("menu_load_template_array")
# Version 4.0 -- Feb, 1997 -- Converted to "pm" module, highlighted
#****************************************************************************
# Cmenu.pm -- Perl Curses Menu Support Facility
#
# Last updated Time-stamp: <01/10/20 23:14:23 devel>
#
#
# Author: Andy Ferguson (cmenu@afccommercial.co.uk)
# AFC Commercial
# Bangor, Northern Ireland
# BT19 1PF
#
# derived from [perlmenu] (Version +4.0):
my $menu_item_pos; # where menu items will start
my $menu_indent; # where menu item labels will start
my $menu_index; # counter of menu items
# Extent of display screen - fixed - unchangeable - from TERM settings
# Always starts at 0,0
my $menu_screen_cols=0; # - COLS from Curses } size of the full screen
my $menu_screen_lines=0; # - LINES from Curses }
# Extent of Menu Inlay - size and position of main window
# Amendable via preferences
# Mono screens lose the shadow so get a bigger inlay
my $menu_inlay_lines=0;
my $menu_inlay_cols=0;
my $menu_inlay_y=3; # 2 for mono
my $menu_inlay_x=6; # 4 for mono
# Extent of Menu text pane
# All defined at runtime depending on the menu items
my $menu_pane_lines=0;
my $menu_pane_cols=0;
my $menu_pane_y=0;
my $menu_pane_x=0;
my $menu_pane_scroll;
my $menu_resized=0; # trigger for terminal resizing
my $menu_style=0; #
my $max_item_len=0; # longest menu item
my $max_sel_len=0; # longest label length
my $menu_top_option=0; # current menu item at the top of the display
my $menu_cur_option=0; # the active menu option during navigation
# define global colour variables
my %menu_attributes=(); # load and hold color definitions
my $menu_hascolor; # terminal colour capability flag
# Initialise menu item arrays
my @menu_sel_text =(); # Menu item text
my @menu_sel_style =(); # Menu item type
my @menu_sel_label = (); # Menu item label
my @menu_sel_flag = (); # Menu item special
my @menu_sel_return = (); # value to be returned on selection
my @menu_sel_pos = (); # Menu item position (data fields)
# max length + dec.places + 0
# User hacks
my($menu_hack25)=0; # hack to make a small screen bigger
# Set the default file for help display
my $menu_help="help.txt";
my $menu_help_root="/etc/Cmenu/";
#**********
# MENU_INITIALISE
#
# Function: Setups Curses elements and prepares a backdrop
# Also define terminal atributes and defines default colours
# (these can be changed after this function has been called)
#
# Call format: &menu_initialise("title string","advice note string");
#
# Arguments: - the title of the Menu application
# this is displayed in the top left-hand corner of all screens
# - an advice note to be displayed on all pages
# normally displayed at the foot of each screen
# may be replaced by user comments with &menu_advice routine
#
# Returns: Main window - this can be referenced externally for
# direct drawing by user program (untested)
#**********
sub menu_initialise {
my ($title,$advice)=@_;
$menu_resized=0; # flag to detect subsequent resizing
# this only works on a direct xterm - spawned xterms such
# as mc sub-shells will not be detected
# Draw title on the backdrop
# Backdrop fills whole screen with a title at the top (left-just)
# and a small advice note at the foot (centred)
&bkgd($menu_screen,$menu_attributes{"backdrop"});
&clear($menu_screen);
if(length($menu_title)<1) {
&addstr($menu_screen,0,1,"Cmenu Menu");
} else {
&addstr($menu_screen,0,1,$menu_title);
}
&move($menu_screen,1,1);
&hline($menu_screen,ACS_HLINE,$menu_screen_cols-2);
# Display system advice message
&attrset($menu_screen,$menu_attributes{"advice"});
&move($menu_screen,$menu_screen_lines-1,0);
if(length($menu_advice)>0) {
&addstr($menu_screen,$menu_screen_lines-1,($menu_screen_cols-length($menu_advice))/2,$menu_advice);
&standend();
&clear();
&refresh(); # clears the screen
&curs_set(1); # turn the cursor back on
&endwin(); # closes all structures and auto restores tty
print "$message\r\n";
exit();
}
# ##################################################################################
# Menu Processing and Navigation
# ##################################################################################
#**********
# MENU_INIT
#
# Function: Initialize a new menu structure: menu arrays, title, and "top" flags.
#
# Call format: &menu_init("Top Title","Sub Titles","HelpFile");
#
# Arguments: - "Top Title" is the title of the menu displayed centred in
# ------------------------------------------------------------------------------
# Switch construct for dealing with key sequence input
# ------------------------------------------------------------------------------
KEYWAIT: for ($action) {
# Set return value as current option
$ret=$menu_sel_return[$menu_cur_option].$menu_sep;
# General cursor movement
/LEFT/ && do { # Left arrow
# Treat this like an UP-Menu request
$action="UP";
# redo KEYWAIT;
};
/RITE/ && do { # Right arrow
# Treat this like a RETURN
$action="DOWN";
# redo KEYWAIT;
};
/LYNXL/ && do { # Left arrow
# Treat this like an UP-Menu request
$action="QUIT";
redo KEYWAIT;
};
/LYNXR/ && do { # Right arrow
# Treat this like a RETURN
$action="RET";
redo KEYWAIT;
};
/DOWN/ && do { # down arrow
if($menu_cur_option==$menu_index-1) {
attrset($menu_inlay,$menu_attributes{"dull"});
move($menu_inlay,$menu_inlay_lines-1,1);
hline($menu_inlay,ACS_HLINE, $menu_inlay_cols-2);
addch($menu_inlay, $menu_inlay_lines-1,$menu_inlay_cols-1,ACS_LRCORNER);
addch($menu_inlay,0, $menu_inlay_cols-1, ACS_URCORNER);
move($menu_inlay,1,$menu_inlay_cols-1);
vline($menu_inlay,ACS_VLINE, $menu_inlay_lines-2);
addch($menu_inlay,$menu_inlay_lines-3,$menu_inlay_cols-1,ACS_RTEE);
# Draw the Menu title
attrset($menu_inlay,$menu_attributes{"title"});
move($menu_inlay,0,($menu_inlay_cols-length($menu_top_title)-2)/2);
addstr($menu_inlay," $menu_top_title ");
# Process any sub-titles like the title.
attrset($menu_inlay,$menu_attributes{"dull"});
if(length($menu_sub_title)>$menu_inlay_cols-4) {
# Do multi-line subtitle
@words=split(/ /,$menu_sub_title);
$menu_sub_title_lines=1;
$ret;
}
#**********
# MENU_DRAW_LINE
#
# Function: Draws a menu item line in appropriate style
#
# Call format: $menu_draw_line(menu_item,indent)
#
# Arguments: - Menu item : pointer to menu item list
# - indent from left edge of window (for centreing)
#
# Returns: nuffink
#
#**********
sub menu_draw_line {
my ($m_item,$m_indent)=@_;
my $i=0;
my ($numtext);
move($menu_pane,$m_item-$menu_top_option,$m_indent);
clrtoeol($menu_pane);
&noutrefresh($menu_window);
}
# ##################################################################################
# ***************************************************************************
# Button Bar
# ~~~~~~~~~~
# A button bar can appear at the foot of each Menu. Button labels are
# user definable using the menu_button_set function
# Buttons perform
# ACTION - select the current menu option
# HELP - display user provided help information
# EXIT - exit back from the current menu
# These functions are pre-set
# ***************************************************************************
# ##################################################################################
#**********
For edited data fields, more complex values are returned. All editable fields
on a menu will have a token (whether edited or not) returned. Each token has two
fields - the field label and the new field contents; these are seperated by
$Cmenu::menu_sepn.
Since any type of item can be included in a menu, return values may be
equally complex. For complex return values, tokens can be split out using
a command fragment such as
chop($return_value=&menu_display("Menu Prompt",$start_on_menu_item));
@selection=split(/$Cmenu::menu_sep/,$return_value);
for($loop=1;$loop<=$#selection;$i++) {
# deal with each token
($field_label,$field_content) = split(/$Cmenu::menu_sepn,$selection[$i]);
# processing each field accordingly
...
}
The first token returned ($selection[0]) is usually the key pressed to close the
menu was closed; this will rarely be a valid menu item - check it to make sure
****************************************************************************
Cmenu.pm -- Perl Menu Support Facility
****** ****** ***** ******
****** ****** ****** ******
** ** ** ** ** ** **
** ****** ****** ******
** ****** ***** ******
Version: 1.1
****************************************************************************
contrib/sqlmenu view on Meta::CPAN
#!/usr/bin/perl
#
# Last updated Time-stamp: <01/04/07 18:31:56 devel>
#
# Foody Menu
# ----------
# Packages to use
# Curses for colour and character positioning
use Curses;
use Pg;
use Cmenu;
contrib/sqlmenu view on Meta::CPAN
if($fields[0] eq "%EMPTY%") {
$set=$type;
} else {
$set=($fields[1]-1);
}
return($set);
}
# ===< end of addressmenu >=============================================
# ===< foodmenu >====================================================
# Main Foody Menu
sub foodmenu {
my ($cat,$head,$newresult,$i);
my @hacks = ();
$last_option=0;
do {
&menu_button_set(1,"Select");
&menu_button_set(2,"");
&menu_button_set(3,"Exit");
$top_item=0; # used to remember the position of the menu selector
# ---< main menu >----------------------------------------------
do {
# Simple List
# -----------
# This is the simplest type of menu with a list of options and labels; each label
# has a highlight letter which can be used for quick jumps through the menu.
#
&menu_init("Main Menu","Standard menu options with Text Labels. You can use <Arrows Keys>, <Page Keys>, <Home> and <End> keys and option letters to navigate this menu. Paging only works if the menu options exceed the depth of the screen. The menu w...
# Create three buttons
# Meaning of buttons is fixed but label can be changed and individual
# buttons can be enabled or disabled
&menu_button_set(1,"Select"); # switch on a button labelled "Okay"
&menu_button_set(2,"Help"); # switch on a button labelled "Help"
&menu_button_set(3,"Exit"); # switch on a button labelled "Exit"
# Now follows a list of menu_item calls defining menu options
&menu_item("Type 1 Numbered Menus", "numbers");
&menu_item("Type 2 Radio Buttons", "radio");
&menu_item("Type 3 Check List", "check");
&menu_item("Type 4 Left Aligned List", "left");
&menu_item("Type 5 Right Aligned List", "right");
&menu_item("- Splash Screens", "splash");
&menu_item("Editing Functions ", "-------",9); # option seperator
&menu_item("Type 6 Edit Alpha Fields", "alpha");
&menu_item("Type 7 Edit Numeric Fields","numeric");
&menu_item("---------------------"," ",9); # option seperator
&menu_item("Type 8 A data list", "list");
} until($sel eq "%EMPTY%");
# ---< terminating >--------------------------------------------
&menu_terminate("Reached the end safely");
# ===< END >====================================================
# ---< menu 01 >----------------------------------------------------
# This is a primitive numbered menu
# Menu numbers are allocated automatically by the module in the order
# items are declared
sub menu01 {
&menu_button_set(2,""); # switch off "Help"
&menu_init("Numbered List","A simple numbered list of menu options; nothing special happens here");
# Here are the list of options
&menu_item("First option", "one",1);
&menu_item("Second option", "two",1);
&menu_item("Third option", "three",1);
&menu_item("Fourth option", "four",1);
&menu_item("Fifth option", "five",1);
&menu_item("Sixth option", "six",1);
&menu_item("Seventh option", "seven",1);
&menu_item("Eighth option", "eight",1);
&menu_item("Splash Results", "splash");
# Menu just returns to the main menu without doing any thing
chop($sel=&menu_display("Choose an Number with the Arrow keys"));
if($sel eq "splash") {
&menu_button_set(1,"Continue");
&menu_button_set(2,"");
&menu_button_set(3,"");
&menu_show("Numbers"," You last chose the <".$numbers."> option from this menu","HELP");
} else {
$numbers=$sel;
}
&menu_init("Radio List- Rainbow Colours","Radio items are toggled with the <SPACE> bar");
# Here are the option calls
for($i=0;$i<=7;$i++) {
if($i==$colours) {
&menu_item($colour[$i],$i,2,1); # starting option
} else {
&menu_item($colour[$i],$i,2);
}
}
# Menu just returns to the main menu without doing any thing
$sel=&menu_display("Choose an Colour");
chop($sel);
(undef,$col)=split(/$Cmenu::menu_sep/,$sel);
&menu_button_set(1,"Continue");
&menu_button_set(2,"");
&menu_button_set(3,"");
&menu_show("Colours","Selected colour is ".$col." ".$colour[$col]);
$colours=$col;
}
&menu_button_set(2,""); # switch off "Help"
&menu_init("Data Offset List","Lists a number of data fields, left alighned. You can press a letter to jump to a particular item. The values returned from this menu are a numeric reference rather than a text label");
# Here are the option calls
for($i=0;$i<=7;$i++) {
&menu_item($data[$i],$label[$i],8,$i);
}
$sel=&menu_display("Choose an Item");
chop($sel);
if(($sel eq "%EMPTY%")||($sel eq "%UP%")) {
&menu_show("Results","Menu type 8 returns an offset marker for the menu item selected rather than the label used in other types. This is useful for displaying data from databases where the label may be used to describe the text while the offset i...
} else {
&menu_show("Results","Menu type 8 returns an offset marker for the menu item selected rather than the label used in other types. This is useful for displaying data from databases where the label may be used to describe the text while the offset i...
}
}
# ---< menu 10 >---------------------------------------------------
# Demonstrates a mizture of item types in theone menu
sub menu10 {
&menu_button_set(1,"Accept");
&menu_button_set(2,"");
doc/Cmenu.tex view on Meta::CPAN
\begin{center}
\textbf{Sample Script\\}
\begin{tabular}{rll}
\hline
1&\#!/usr/bin/perl\\
2&\\
3&\# Sample Cmenu script\\
4&\\
5&\textbf{menu\_initialise}(\textit{"Cmenu Sample Script"});\\
6&\\
7&\textbf{menu\_init}(\textit{"Menu Title"},\textit{"Menu Help Text"});\\
8&\\
9&\textbf{menu\_item}(\textit{"Option 1"},\textit{"gimme1"});\\
10&\textbf{menu\_item}(\textit{"Option 2"},\textit{"gimme2"});\\
11&\\
12&chop(\$sel $=$ \textbf{menu\_display}(\textit{"Menu Prompt"}));\\
13&\\
14&\textbf{menu\_terminate}(\textit{"bye bye"});\\
15&\\
\hline
\end{tabular}
\end{center}
\section{Function Reference}
This section provides a comprehensive list of user functions provided by the module explaining their use and calling parameters.
doc/Cmenu.tex view on Meta::CPAN
\item [menu\_initialise] initialise the module; called at the beginning of a script once only
\item [menu\_item] define a menu option
\item [menu\_popup] popup a display while processing is occurring
\item [menu\_show] splash data to the screen
\item [menu\_terminate] terminate all Curse and menuing structures; called on exit from script
\end{description}
\subsection{menu\_initialise}
Its job is to create a Curses environment and configure Cmenu to operate effectively with your terminal providing some default values for variables. It accepts tow variables and is called like this;
\begin{center}
menu\_initialise("My System","Menu Prompt");
\end{center}
\begin{description}
\item [My System] the name of your system displayed in the top left-hand corner of the display - it is always present
\item [Menu prompt] a standard propmpt displayed at the foot of the screen; can be over-ridden during menu specification
\end{description}
\subsection{menu\_init}
Create a menu structure. It is normally called like;
\begin{center}
menu\_init("My Menu","Interesting text","help\_file");
\end{center}
\begin{description}
\item [My Menu] the title of your menu displayed at the centre-top of the menu window
\item [Interesting Text] supplementary text usually enhancing a users experience as they enjoy your finely crafted program
\item [help\_file] a file to display when the user panics and presses the \textit{help} button (a function key can be defined as a help button rather than a soft button on the screen).
\textbf{NB} this feature is untested and may be broken
\end{description}
\subsection{menu\_item}
Creates a menu item; the main element of the module. Called like this;
\begin{center}
menu\_item("menu text","label",\$type,"tag","format");
doc/Cmenu.tex view on Meta::CPAN
\item [menu\_refresh] redraw the whole screen especially after resizing a terminal window
\end{description}
\section{Application Preferences}
Cmenu provides a facility to read a \textit{preferences} file to configure a common look-and-feel for all your applications. Preferences can be setup for all users (using file \textit{/etc/Cmenu/cmenurc}). individual users (using \textit{\~/.cmenurc}...
\begin{description}
\item [colour] the colours to be used in all screen renditions including special mono-chrome renderings. Cmenu allows a combination of explicit colours and terminal attributes like bold and dim.
\item [keyboard] cmenu is pre-configured to interpret a variety of key-sequences as specific cursor commands; these can be tailored, disabled or supplemented. This includes use of functions keys.\\
Menu navigation uses normal cursor keys and page keys for larger movement; navigation can also behave like \textit{lynx} where right and left move between menus - this can be disabled.
\item [helpfiles] help files can be stored in locations other than running directories
\item [hacks] when rendered on 25-line mono-screens, a large amount of screen space is taken up with superfluous cosmetic frippery; ultra-serious people can reclaim an extra-line.
\end{description}
A heavily commented sample preferences files is included with the distribution. The preferences file is strictly structured; not following the prescribed layout may corrupt display elements or deactivate certain features.
\section{tic file}
Provided with the module is a tic file for VT100 emulation on a Wyse 60 terminal. This has some of the function keys defined correctly. You will need to define function strings if you want to use the 16 F keys. Page and some of the character keys are...
%%%% Body ends here
doc/html/node17.html view on Meta::CPAN
Application Preferences</A>
</H1>
Cmenu provides a facility to read a <I>preferences</I> file to configure a common look-and-feel for all your applications. Preferences can be setup for all users (using file <I>/etc/Cmenu/cmenurc</I>). individual users (using <I>/.cmenurc</I>) or by ...
<DL>
<DT><STRONG>colour</STRONG></DT>
<DD>the colours to be used in all screen renditions including special mono-chrome renderings. Cmenu allows a combination of explicit colours and terminal attributes like bold and dim.
</DD>
<DT><STRONG>keyboard</STRONG></DT>
<DD>cmenu is pre-configured to interpret a variety of key-sequences as specific cursor commands; these can be tailored, disabled or supplemented. This includes use of functions keys.
<BR>
Menu navigation uses normal cursor keys and page keys for larger movement; navigation can also behave like <I>lynx</I> where right and left move between menus - this can be disabled.
</DD>
<DT><STRONG>helpfiles</STRONG></DT>
<DD>help files can be stored in locations other than running directories
</DD>
<DT><STRONG>hacks</STRONG></DT>
<DD>when rendered on 25-line mono-screens, a large amount of screen space is taken up with superfluous cosmetic frippery; ultra-serious people can reclaim an extra-line.
</DD>
</DL>
A heavily commented sample preferences files is included with the distribution. The preferences file is strictly structured; not following the prescribed layout may corrupt display elements or deactivate certain features.
doc/html/node5.html view on Meta::CPAN
</TR>
<TR><TD ALIGN="RIGHT">5</TD>
<TD ALIGN="LEFT"><B>menu_initialise</B>(<I>"Cmenu Sample Script"</I>);</TD>
<TD ALIGN="LEFT"> </TD>
</TR>
<TR><TD ALIGN="RIGHT">6</TD>
<TD ALIGN="LEFT"> </TD>
<TD ALIGN="LEFT"> </TD>
</TR>
<TR><TD ALIGN="RIGHT">7</TD>
<TD ALIGN="LEFT"><B>menu_init</B>(<I>"Menu Title"</I>,<I>"Menu Help Text"</I>);</TD>
<TD ALIGN="LEFT"> </TD>
</TR>
<TR><TD ALIGN="RIGHT">8</TD>
<TD ALIGN="LEFT"> </TD>
<TD ALIGN="LEFT"> </TD>
</TR>
<TR><TD ALIGN="RIGHT">9</TD>
<TD ALIGN="LEFT"><B>menu_item</B>(<I>"Option 1"</I>,<I>"gimme1"</I>);</TD>
<TD ALIGN="LEFT"> </TD>
</TR>
doc/html/node5.html view on Meta::CPAN
<TD ALIGN="LEFT"> </TD>
</TR>
<TR><TD ALIGN="RIGHT">11</TD>
<TD ALIGN="LEFT"> </TD>
<TD ALIGN="LEFT"> </TD>
</TR>
<TR><TD ALIGN="RIGHT">12</TD>
<TD ALIGN="LEFT">chop($sel <IMG
WIDTH="20" HEIGHT="19" ALIGN="BOTTOM" BORDER="0"
SRC="img1.png"
ALT="$=$"> <B>menu_display</B>(<I>"Menu Prompt"</I>));</TD>
<TD ALIGN="LEFT"> </TD>
</TR>
<TR><TD ALIGN="RIGHT">13</TD>
<TD ALIGN="LEFT"> </TD>
<TD ALIGN="LEFT"> </TD>
</TR>
<TR><TD ALIGN="RIGHT">14</TD>
<TD ALIGN="LEFT"><B>menu_terminate</B>(<I>"bye bye"</I>);</TD>
<TD ALIGN="LEFT"> </TD>
</TR>
doc/html/node8.html view on Meta::CPAN
HREF="node1.html">Contents</A></B>
<BR>
<BR>
<!--End of Navigation Panel-->
<H2><A NAME="SECTION00052000000000000000">
menu_initialise</A>
</H2>
Its job is to create a Curses environment and configure Cmenu to operate effectively with your terminal providing some default values for variables. It accepts tow variables and is called like this;
<DIV ALIGN="CENTER">
menu_initialise("My System","Menu Prompt");
</DIV>
<P>
<DL>
<DT><STRONG>My System</STRONG></DT>
<DD>the name of your system displayed in the top left-hand corner of the display - it is always present
</DD>
<DT><STRONG>Menu prompt</STRONG></DT>
<DD>a standard propmpt displayed at the foot of the screen; can be over-ridden during menu specification
</DD>
</DL>
<P>
<BR><HR>
<ADDRESS>
Andy Ferguson (AFC)
2001-10-20
</ADDRESS>
doc/html/node9.html view on Meta::CPAN
HREF="node1.html">Contents</A></B>
<BR>
<BR>
<!--End of Navigation Panel-->
<H2><A NAME="SECTION00053000000000000000">
menu_init</A>
</H2>
Create a menu structure. It is normally called like;
<DIV ALIGN="CENTER">
menu_init("My Menu","Interesting text","help_file");
</DIV>
<P>
<DL>
<DT><STRONG>My Menu</STRONG></DT>
<DD>the title of your menu displayed at the centre-top of the menu window
</DD>
<DT><STRONG>Interesting Text</STRONG></DT>
<DD>supplementary text usually enhancing a users experience as they enjoy your finely crafted program
</DD>
<DT><STRONG>help_file</STRONG></DT>
<DD>a file to display when the user panics and presses the <I>help</I> button (a function key can be defined as a help button rather than a soft button on the screen).
<P>
<B>NB</B> this feature is untested and may be broken
Menu navigation can be performed using various keys;
UP & DOWN move through menu
LEFT & RIGHT previous or next menu
PAGE keys page through menu
HOME & END top and bottom of menu
TAB change buttons
SPACE toggle radio and check list items
letters jump to highlighted options
RETURN actions the highlighted button
Also, Function keys may be defined
( run in 0.804 second using v1.01-cache-2.11-cpan-49f99fa48dc )