editor.mod 1.1 KB

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