Unit Pullbar;
Interface

Const maxbars=50;

Type PullModerec = Record
                    OnString,OffString : Array[1..maxbars] of String[40];
                    X           : Array[1..Maxbars] of 1..80;
                    Y           : Array[1..Maxbars] of 1..25;
                    Choices     : 1..Maxbars;
                    pointercmd  : Array[1..maxbars] of 1..50;
                    FirstOption : 1..Maxbars;
                   end;

Function Pullbars(Pull:pullmoderec):integer;
Function Strr (N : LongInt) : string;
Procedure print(S : String);
Implementation

uses dos,crt;
Function Strr (N : LongInt) : string;
Var Q : string;
Begin
  Str (N, 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,Code : Byte;
    Error  : Integer;
    Total : Byte;
Begin
Total := Length(S);
For X := 1 to Total do
 Begin
  If S[X] <> '|' then Write(S[X])

   Else
         if s[x+1]='B' then begin
                          textbackground(valu(s[x+2]));
                          inc(x,2);
                          end
                          else
 Begin
         Val(Copy(S,X + 1,2),Code,Error);
         If Error>0 then Write(S[X])
                     Else Begin
                            If Code<16 then Textcolor(Code)
                             Else Textbackground(Code-16);
                            If X + 2 > total then Inc(X,1) else Inc(X,2);
                           End;
        End;
 End;
End;

Function Pullbars(Pull:pullmoderec):integer;
var On:1..maxbars;
    ch:char;

Procedure Write_Options;
Var dummy:1..maxbars;
Begin
 For dummy := 1 to pull.choices do
  begin
   gotoxy(pull.x[dummy],pull.y[dummy]);
   print(pull.offstring[Dummy]);
  end;
  pull.firstoption:=on;
  gotoxy(pull.x[on],pull.y[on]);
  print(pull.onstring[on]);
End;

procedure Update_Options(Down:boolean); {true:forward/false:backwards}
Begin
 gotoxy(pull.x[on],pull.y[on]);
 print(pull.offstring[on]);
 If Down then
  Begin
   If On < Pull.choices then Inc(on) else On := 1;
  End else
   Begin
    If On > 1 then Dec(On) else On := Pull.Choices;
   End;
 gotoxy(pull.x[on],pull.y[on]);
 print(pull.onstring[on]);
End;

Function Get_Input : Byte;
Var CH : Char;
Begin
 CH := ReadKey;
 If CH = #0 then CH :=Readkey;
 Case CH of
  'A' : Get_Input := 8;
  'B' : Get_Input := 2;
  #75 : Get_Input := 8;
  #77 : Get_Input := 2;
  #72 : Get_Input := 8;
  #80 : Get_Input := 2;

  #13 : Get_Input := 5;
 End;
End;

Var Key : Byte;

begin
 On := 1;
 Write_Options;
  Repeat
   Key := Get_input;
   Case Key of
    8 : update_options(False);
    2 : update_options(True)
   End;
  Until (Key = 5);
  Pullbars := On;
end;

begin
end.
