DEFINITION MODULE screenio;

(* Author:         Andrew Trevorrow
   Implementation: Modula-2 under VAX/UNIX 4.2 BSD
   Date Started:   June, 1986

   Description:
   These terminal i/o routines are highly system-dependent and have been
   designed for DVItoVDU and its auxiliary modules.

   Notes:
 - The implementation block saves the current tty characteristics,
   then sets the mode to cbreak with no echo.
   Clients should therefore call RestoreTerminal before terminating.
 - WriteBuffer or WriteLn must be called to explicitly update the terminal
   (e.g., just before a read) or to synchronize output with writes
   from other modules that don't use ScreenIO.
*)

EXPORT QUALIFIED
   Read, ReadString, BusyRead,
   Write, WriteString, WriteInt, WriteCard, WriteLn, WriteBuffer,
   RestoreTerminal;


PROCEDURE Read (VAR ch : CHAR);
(* Read one character from terminal keyboard. *)

PROCEDURE ReadString (VAR s : ARRAY OF CHAR);
(* Read a string of characters from terminal keyboard.
   DEL can be used to erase the last character entered.
   The routine is terminated upon carriage return.
   s is terminated by first NULL (unless full).
*)

PROCEDURE BusyRead (VAR ch : CHAR) : BOOLEAN;
(* Return TRUE if ch is read immediately (with no echo) from input buffer.
   If nothing in buffer then ch is undefined and we return FALSE.
*)

PROCEDURE Write (ch: CHAR);
(* Write given character to output buffer. *)

PROCEDURE WriteString (s: ARRAY OF CHAR);
(* Write given string of characters to output buffer.
   s is terminated by first NULL (unless full).
*)

PROCEDURE WriteInt (i : INTEGER);
(* Write a string of characters representing given integer to output buffer. *)

PROCEDURE WriteCard (c : CARDINAL);
(* Write a string of characters representing given cardinal to output buffer. *)

PROCEDURE WriteLn;
(* Write CR LF and then send output buffer to terminal. *)

PROCEDURE WriteBuffer;
(* Send output buffer to terminal; this is done automatically when it becomes
   full but an explicit call may be necessary to ensure the terminal screen
   is up-to-date.
*)

PROCEDURE RestoreTerminal;
(* Restore terminal characteristics to their original settings
   and send output buffer.
   Should be called just before any client module terminates.
*)

END screenio.
