editor.mod 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. MODULE editor2;
  2. (* based on the kilo editor building course*)
  3. (* Step 6 *)
  4. IMPORT IO, termios, FIO, libc ;
  5. VAR
  6. c : CHAR;
  7. theTermios : termios.TERMIOS;
  8. TCSAFLUSH : INTEGER;
  9. PROCEDURE disablerawMode() : INTEGER;
  10. VAR
  11. result : INTEGER;
  12. BEGIN
  13. IO.BufferedMode(0,TRUE);
  14. IO.BufferedMode(1,TRUE);
  15. result := termios.tcsetattr(FIO.StdIn, TCSAFLUSH, theTermios);
  16. IF result = -1 THEN
  17. theTermios := termios.KillTermios(theTermios);
  18. HALT
  19. ELSE
  20. RETURN result
  21. END;
  22. END disablerawMode;
  23. PROCEDURE enablerawMode;
  24. BEGIN
  25. libc.atexit(disablerawMode);
  26. theTermios := termios.InitTermios();
  27. IF termios.tcgetattr(FIO.StdIn, theTermios) = -1 THEN
  28. HALT
  29. END;
  30. IO.UnBufferedMode(0,TRUE);
  31. IO.UnBufferedMode(1,TRUE);
  32. END enablerawMode;
  33. BEGIN
  34. TCSAFLUSH := termios.tcsflush ();
  35. enablerawMode;
  36. LOOP
  37. IO.Read(c);
  38. IF c = "q" THEN
  39. EXIT
  40. END;
  41. END;
  42. END editor2.