unit pullmode;
interface
uses crt,dos;
const
  maxchoices=30;
type
PULLD=RECORD
    CURRENTCHOICE:INTEGER;
    MAXC:INTEGER;
    CH:ARRAY[1..MAXCHOICES] OF CHAR;
    OFF:ARRAY[1..MAXCHOICES] OF STRING[30];
    ON:ARRAY[1..MAXCHOICES] OF STRING[30];
    CX:ARRAY[1..MAXCHOICES] OF byte;
    CY:ARRAY[1..MAXCHOICES] OF byte;
    END;

FUNCTION PULLMENU(VAR PM:PULLD):INTEGER;
Procedure PRINT (S:String);
Function valu(q:string):Integer;
Function strr(l:longint):string;
implementation

Function strr(l:longint):string;
    Var q:string;
    Begin
      Str(l,q);
      strr:=q
    End;

  Function valu(q:string):Integer;
    Var i,s,pu:Integer;
      r:Real;
    Begin
      valu:=0;
      If Length(q)=0 Then exit;
      If Not(q[1] In ['0'..'9','-']) Then exit;
      If Length(q)>5 Then exit;
      Val(q,r,s);
      If s<>0 Then exit;
      If (r<=32767.0) And (r>=-32767.0)
      Then valu:=Round(r)
    End;

Procedure PRINT (S:String);
VAR X,Y:INTEGER;
    R:STRING;
    G:INTEGER;
BEGIN
G:=1;
R:='';
Y:=0;
FOR X:=1 TO LENGTH(S) DO BEGIN
CASE S[X] OF '|':BEGIN
CASE S[X+1] OF 'B':BEGIN
Y:=VALU(S[X+2]);
CRT.TEXTBACKGROUND(Y);
INC(X,2);
END ELSE BEGIN
R:=S[X+1]+S[X+2];
Y:=VALU(R);
CRT.TEXTCOLOR(Y);
INC(X,2);
END;
END;
END ELSE WRITE(S[X]);
END;
END;
END;


FUNCTION PULLMENU(VAR PM:PULLD):INTEGER;
    VAR X:INTEGER;
    CINPUT:CHAR;
    C:CHAR;
    COUNTR:BYTE;
BEGIN
FOR X:=1 TO pm.MAXC DO BEGIN
GOTOXY(pm.CX[X],pm.CY[X]);
PRINT(pm.OFF[X]);
END;
GOTOXY(pm.CX[pm.CURRENTCHOICE],pm.CY[pm.CURRENTCHOICE]);
print(pm.ON[pm.CURRENTCHOICE]);
REPEAT
    C:=UPCASE(READKEY);
    COUNTR:=1;

REPEAT
IF PM.CH[COUNTR]=C THEN BEGIN
    GOTOXY(pm.CX[pm.CURRENTCHOICE],pm.CY[pm.CURRENTCHOICE]);
    print(pm.OFF[pm.CURRENTCHOICE]);

                        PM.CURRENTCHOICE:=COUNTR;
                        COUNTR:=PM.MAXC;
    GOTOXY(pm.CX[pm.CURRENTCHOICE],pm.CY[pm.CURRENTCHOICE]);
    print(pm.ON[pm.CURRENTCHOICE]);

                        END;
INC(COUNTR);
UNTIL COUNTR=PM.MAXC+1;

IF C=#0 THEN BEGIN
C:=READKEY;
IF ORD(C) IN [72,75] THEN BEGIN
    GOTOXY(pm.CX[pm.CURRENTCHOICE],pm.CY[pm.CURRENTCHOICE]);
    print(pm.OFF[pm.CURRENTCHOICE]);
    DEC(pm.CURRENTCHOICE);
    IF pm.CURRENTCHOICE=0 THEN pm.CURRENTCHOICE:=pm.MAXC;
    GOTOXY(pm.CX[pm.CURRENTCHOICE],pm.CY[pm.CURRENTCHOICE]);
    print(pm.ON[pm.CURRENTCHOICE]);
    END ELSE
IF ORD(C) IN [77,80] THEN BEGIN
    GOTOXY(pm.CX[pm.CURRENTCHOICE],pm.CY[pm.CURRENTCHOICE]);
    print(pm.OFF[pm.CURRENTCHOICE]);
    INC(pm.CURRENTCHOICE);
    IF pm.CURRENTCHOICE=pm.MAXC+1 THEN pm.CURRENTCHOICE:=1;
    GOTOXY(pm.CX[pm.CURRENTCHOICE],pm.CY[pm.CURRENTCHOICE]);
    print(pm.ON[pm.CURRENTCHOICE]);
    END;
END;
UNTIL ORD(C) IN [27,13];

PULLMENU:=pm.CURRENTCHOICE;
END;


begin
end.