TestAnsiRequestPosition.mod 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. MODULE TestAnsiRequestPosition;
  2. (* Query cursor position with our ansi library (ESC[6n),
  3. read CPR reply ESC[row;colR with no RETURN needed,
  4. parse and print Row/Col. *)
  5. IMPORT Ansi, IO, Strings, NumberIO, SplitV1, STextIO;
  6. VAR
  7. str : ARRAY[0..31] OF CHAR;
  8. cc : Strings.String1;
  9. c : CHAR;
  10. x, y : CARDINAL;
  11. theStructure : SplitV1.Structure;
  12. BEGIN
  13. STextIO.WriteString("--- ANSI RequestPosition test ---");
  14. STextIO.WriteLn;
  15. Ansi.Unbuffered;
  16. (* place cursor at a known spot, then ask where it is *)
  17. Ansi.Position(10, 20);
  18. Ansi.RequestPosition;
  19. (* read reply char by char, no RETURN needed *)
  20. str := "";
  21. REPEAT
  22. IO.Read(c);
  23. cc[0] := c;
  24. Strings.Concat(str, cc, str);
  25. UNTIL c = "R";
  26. Ansi.Buffered;
  27. (* str = ESC [ row ; col R : strip ESC [ and trailing R *)
  28. Strings.Delete(str, 0, 2);
  29. Strings.Delete(str, Strings.Length(str) - 1, 1);
  30. SplitV1.SplitStr(str, ";", theStructure);
  31. NumberIO.StrToCard(theStructure[0].element, x);
  32. NumberIO.StrToCard(theStructure[1].element, y);
  33. STextIO.WriteString("Row=");
  34. NumberIO.WriteCard(x, 1);
  35. STextIO.WriteString(" Col=");
  36. NumberIO.WriteCard(y, 1);
  37. STextIO.WriteLn;
  38. STextIO.WriteString("--- end RequestPosition ---");
  39. STextIO.WriteLn;
  40. END TestAnsiRequestPosition.