external class terminal;
/*
   ttest.sim                              V0.1    (Cim 3.29 / Win32)  

   Simula test program for class terminal          

   by Petr Novak 1999
*/

terminal begin
  ref (Attributes) old;
  text t;

  open (25, 80);

  outtext ("Hi! ");
  outint (maxx, 3);
  outchar ('x');
  outint (maxy, 3);
  outimage;
  outtext ("Hit a key: ");
  inchar;
  outline (" (hitted)");

  outline ("hidden cursor in 1 s with beep:");
  sleep (1000);
  beep;
  hideCursor;
  sleep (2000);
  beep;
  outline ("shown cursor");
  showCursor;
  outtext ("setcolor: ");
  old :- curAttr;
  curAttr :- colours (Blue, Magenta);
  outline ("colored text and 2 new lines (WORKS DIFFERENT!!! on NT & 95");
  outimage;
  curAttr :- curAttr.blink;
  outtext ("blinking means background highlighting");
  curAttr :- old;
  outline (" and returned to normal atttrs");
  curAttr :- curAttr.bold;
  outtext ("bold");
  curattr :- old;
  outimage;
  outline ("look around !? what you see?");
  message ("and see message, press any key!");

  editAttr :- editattr.withBackground (BLUE).blink;
  outtext ("input text: ");
  t :- edittext ("here", 10);
  outline ("<- cursor continues");
  outline ("you entered: " & t);
  begin
    integer fr;
    real r;
    outtext ("enter frac: ");
    fr := infrac (10);
    outtext ("->");
    outfrac (fr, 3, 10);
    outline ("<-");
    outtext ("enter int:  ");
    fr := inint  (10);
    outtext ("->");
    outint  (fr, 10);
    outline ("<-");
    outtext ("enter real: ");
    r := inreal (10);
    outtext ("->");
    outreal (r, 6, 15);
    outline ("<-");
    outtext ("->");
    outfix (r, 10, 20);
    outline ("<-");
  end;

  flushinput;
  outline ("hit a key (among 3 seconds), I will try ifchar");
  sleep (3000);
  ifchar;
  if (lastkey.map <> '!0!') then 
    outline ("you hit a key")
  else 
    outline ("you didn't hit any key in the 3 sec.");

  outline ("hit a key (among 3 seconds), I will try flushinput");
  sleep (3000);
  flushinput;                           /* flush input first and then */
  ifchar;                               /* check for some input record*/

  if (lastkey.map <> '!0!') then 
    outline ("flushinput doesn't work")
  else 
    outline ("you may not hit any kye or flushinput works well");

  outimage;
  outline ("When there is autowrap  default,  you can, what it will do at the end of very long line.");
  outimage;
  autowrap (true);
  outline ("When there is autowrap 'enable',  you can, what it will do at the end of very long line."); 
  outimage;
  autowrap (false);
  outline ("When there is autowrap 'disable', you can, what it will do at the end of very long line.");
  outimage;

  outline ("Hit a key: ");
  inchar;
  erasePage;

  outline ("Now let's have a look at atribute palette (0-255) (attributecode)");
  outline ("(Note that the lines are not filled with attribute colour on NT!)");
  outline ("(You should write programs that deal with it)");
  begin
    integer i;
    for i := 0 step 1 until 255 do begin
      curAttr :- attributeCode (i);
      outchar ('X');
      if (rem(i,16) = 15) then outimage;
    end;
  end;
  curAttr :- old;

  outline ("Hit a key: ");
  inchar;
  erasePage;

  outline ("Seting outpumode to all 'printAll (true)'");
  printAll (true);
  outline (" and see ASCII table:");
  begin
    integer i;
    for i := 0 step 1 until 255 do begin
      outchar (char (i));
      if (rem(i,16) = 15) then outimage;
    end;
  end;
  
  outline ("Hit a key: ");
  inchar;
  erasepage;

  outline ("Seting outpumode to all 'printAll (false)'");
  printAll (false);
  outline (" and see ASCII table:");
  begin
    integer i;
    for i := 0 step 1 until 255 do begin
      outchar (char (i));
      if (rem(i,16) = 15) then outimage;
    end;
  end;
  
  outline ("bye!");
  close;
end;
