home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
BEEHIVE
/
UTILITYS
/
FNTM2-11.ARK
/
MENU.INC
< prev
next >
Wrap
Text File
|
1989-09-27
|
3KB
|
91 lines
{This module needs to come after the SCRH.INC, WINDOWS.INC modules, seeing
as it uses certain routines from these modules. MENU.INC needs to have defined a global
constant max_menu_items which is the maximum size of the menus.
Summary of routines in this include file:
Menu(x,y,string) The string is evaluated as a menu list with
individual items delimited by |. This list is
printed with right-justification and a border
at x,y. What's behind it is saved. Returns the
selected option's number or 0 if ESC is pressed.
}
function menu (mx,my: integer; menu_str: str80): integer;
var
menu_items: array[1..max_menu_items] of string[20];
menu_size,menu_width,i,j: integer;
within_menu: boolean;
ch:char;
function rjust(work:str80):str80;
begin
while length(work)<menu_width do insert(' ',work,1);
rjust:=work;
end;
begin
within_menu:=true;
for i:=1 to max_menu_items do menu_items[i]:='';
menu_size:=1; {current menu size}
for i:=1 to length(menu_str) do
begin
if menu_str[i]='|' then menu_size:=menu_size+1
else
menu_items[menu_size]:=menu_items[menu_size]+menu_str[i];
end; {parse out menu options}
menu_width:=0;
for i:=1 to menu_size do
begin
if length(menu_items[i])>menu_width then menu_width:=length(menu_items[i]);
end; {now we have the maximum width of the menu}
pushwind(mx,my,menu_width+2,menu_size);
use('P'); setcolor(3);
for i:=1 to menu_size do
begin
putat(mx,my+i-1); {print up options}
print(' '+rjust(menu_items[i])+' ');
end;
j:=1; {option on menu}
repeat
begin
putat(mx+1,my+j-1);
setcolor(11); use('p'); print (rjust(menu_items[j])); setcolor(3); use('P');
zapcursor; {cursor off}
read(kbd,ch); {get a key from keyboard}
case ch of
'1'..'9' : begin
if ord(ch)-$30<=menu_size then
begin
putat(mx+1,my+j-1);
print(rjust(menu_items[j]));
j:=ord(ch)-$30;
end;
end;
^X : begin
if j<menu_size then
begin
putat(mx+1,my+j-1);
print(rjust(menu_items[j]));
j:=j+1;
end;
end;
^E : begin
if j>1 then
begin
putat(mx+1,my+j-1);
print(rjust(menu_items[j]));
j:=j-1;
end;
end;
end; {case}
end {repeat}
until (ch=^M) or (ch=^[);
write (^[,'(');
if ch=^M then menu:=j else menu:=0; {return option code}
within_menu:=false;
use('p');
popwind;
end; {menu procedure}