Oberon || Library || Module Index || Search Engine || Definition || Module

Ulm's Oberon Library:


Terminals - abstraction for terminals


(* terminal characteristics *)
CONST autoleftmargin = 0; autorightmargin = 1; 
CONST overstrikes = 2; safelastcolumn = 3;
(* errorcodes *)
CONST cannotSetEcho = 0;
CONST cannotSetTermMode = 1;
CONST cannotSetCursor = 2;
CONST cannotMoveCursor = 3;
CONST cannotSetAppearance = 4;
CONST cannotScroll = 5;
CONST cannotSetScrollRegion = 6;
CONST cannotClearScreen = 7;
CONST invalidDirection = 8;
CONST invalidRegion = 9;
CONST invalidPosition = 10;
CONST notSupported = 11;
CONST errorcodes = 12;
(* echo *)
CONST on = 0; off = 1;
(* terminal modes *)
CONST raw = 0; cooked = 1;
(* directions *)
CONST forward = 0; reverse = 1;
(* cursor shapes *)
CONST visible = 0; invisible = 1;
(* capabilities *)
CONST setEcho = 0;
CONST setTermMode = 1;
CONST setCursor = 2;
CONST moveCursor = 3;
CONST setAppearance = 4;
CONST scroll = 5;
CONST setScrollRegion = 6;
CONST clearScreen = 7;

TYPE CapabilitySet = SET; TYPE Echomode = SHORTINT; TYPE Termmode = SHORTINT; TYPE Direction = SHORTINT; TYPE Shape = SHORTINT; TYPE Stream = POINTER TO StreamRec; TYPE WindowChangeEvent = POINTER TO WindowChangeEventRec; TYPE WindowChangeEventRec = RECORD (Events.EventRec) stream: Streams.Stream; END; TYPE InterruptEvent = POINTER TO InterruptEventRec; TYPE InterruptEventRec = RECORD (Events.EventRec) stream: Streams.Stream; END; TYPE QuitEvent = POINTER TO QuitEventRec; TYPE QuitEventRec = RECORD (Events.EventRec) stream: Streams.Stream; END; TYPE HangupEvent = POINTER TO HangupEventRec; TYPE HangupEventRec = RECORD (Events.EventRec) stream: Streams.Stream; END; TYPE ErrorEvent = POINTER TO ErrorEventRec; TYPE ErrorEventRec = RECORD (Events.EventRec) errorcode: SHORTINT; END; (* interface procedures *) TYPE SetTermModeProc = PROCEDURE (s: Streams.Stream; mode: Termmode); TYPE SetEchoProc = PROCEDURE (s: Streams.Stream; mode: Echomode); TYPE SetCursorProc = PROCEDURE (s: Streams.Stream; line, column: INTEGER); TYPE MoveCursorProc = PROCEDURE(s: Streams.Stream; fromline, fromcolumn, toline, tocolumn: INTEGER); TYPE SetAppearanceProc = PROCEDURE(s: Streams.Stream; ap: Shape); TYPE ScrollProc = PROCEDURE(s: Streams.Stream; dir: Direction); TYPE SetScrollRegionProc = PROCEDURE(s: Streams.Stream; top, bottom: INTEGER); TYPE ClearProc = PROCEDURE(s: Streams.Stream); TYPE Interface = POINTER TO InterfaceRec; TYPE InterfaceRec = RECORD (Objects.ObjectRec) setEcho: SetEchoProc; setTermMode: SetTermModeProc; setCursor: SetCursorProc; moveCursor: MoveCursorProc; setAppearance: SetAppearanceProc; scroll: ScrollProc; setScrollRegion: SetScrollRegionProc; clearScreen: ClearProc; END; TYPE Status = RECORD (Objects.ObjectRec) lines, columns: INTEGER; (* of physical screen *) scrtop, scrbottom: INTEGER; (* top and bottom of scroll region *) echo: Echomode; (* on or off *) mode: Termmode; (* raw or cooked *) characteristics: SET; (* of terminal characteristics *) scrollDirections: SET; (* up, down *) cursorShape: Shape; (* current shape of cursor *) END; TYPE StreamRec = RECORD (Streams.StreamRec) END;

VAR console: Streams.Stream; VAR windowchanged: Events.EventType; VAR interrupt: Events.EventType; VAR quit: Events.EventType; VAR hangup: Events.EventType; VAR error: Events.EventType; VAR errormsg: ARRAY errorcodes OF Events.Message;

PROCEDURE Init(s: Streams.Stream; status: Status; caps: CapabilitySet; if: Interface); PROCEDURE ClearScreen(s: Streams.Stream); PROCEDURE Echo(s: Streams.Stream; mode: Echomode); PROCEDURE SetTermMode(s: Streams.Stream; mode: Termmode); PROCEDURE SetCursor(s: Streams.Stream; line, column: INTEGER); PROCEDURE MoveCursor(s: Streams.Stream; fromline, fromcolumn, toline, tocolumn: INTEGER); PROCEDURE CursorAppearance(s: Streams.Stream; ap: Shape); PROCEDURE Scroll(s: Streams.Stream; dir: Direction); PROCEDURE SetScrollRegion(s: Streams.Stream; top, bottom: INTEGER); PROCEDURE Capabilities(s: Streams.Stream): CapabilitySet; PROCEDURE GetStatus(s: Streams.Stream; VAR status: Status);


Terminals offers a general interface for terminals. Terminal devices enable users to communicate with a host machine, i.e. send data to a host and recieve data from it. Terminals usually use a keyboard for input and a display for output. Displays are organized in a number of lines and columns with a cursor designating the location where the next character will be printed. Lines and columns are counted relative to the upper left corner, which has the coordinates (0,0).

Terminals stores some characteristics of the terminal's display:

backspace or cursor-left in the first column forces the cursor to the last column of the previous line. The reaction is undefined if the cursor already was on the first line.
writing to the last column forces the cursor to the first column of the next line. The reaction is undefined if the cursor already was on the last line.
terminal overstrikes characters rather than replacing them.
writing a character in the lower right corner does not scroll the screen and the cursor position remains unchanged.

A terminal can operate in two modes:

in cooked mode terminal input is processed in units of lines, i.e. input can be edited before it is passed to an application.
in raw mode, input characters are not assembled into lines and therefore no input editing is possible.

The set of procedures which implement a terminal-abstraction of a specific form is given by an interface. Not every procedure must be implemented. The set of implemented procedures is given by the caps parameter of Init. The interface procedures should meet following specifications:

settermmode: PROCEDURE(s: Stream; mode: Termmode);
set terminals mode.

setecho: PROCEDURE(s: Stream; mode: Echomode);
turn echoing of input on or off.

setcursor: PROCEDURE(s: Stream; line, column: INTEGER);
place cursor at absolute position

movecursor: PROCEDURE(s: Stream; fromline, fromcolumn, toline, tocolumn);
move cursor from position (fromline, fromcolumn) to (toline, tocolumn).

setappearance: PROCEDURE(s: Stream; ap: Shape);
set the appearance of the cursor.

scroll: PROCEDURE(s: Stream; dir: Direction);
scroll scrollregion once in direction dir.

setscrollregion: PROCEDURE(s: Stream; top, bottom: INTEGER);
set the scrollregion.

clearscreen: PROCEDURE(s: Stream);
clear terminal's screen.

Init initializes the terminal s for the interface specified by if and caps. status has to hold the initial state of the terminal.

SetTermMode sets the terminal's mode to raw or cooked.

Echo turns echoing of input on or off.

ClearScreen clears the terminal's screen.

Scroll scrolls the contents of the scrollregion once in direction dir.

SetScrollRegion sets the scrollregion to (top, bottom).

SetCursor sets the cursor to the position denoted by line and column.

MoveCursor moves the cursor from position (fromline, fromcolumn) to to position (toline, tocolumn). Clients must track the current cursor position themselves in order to use this procedure properly.

CursorAppearance sets the cursor's appearance. Available modes are visible and invisible.

Capabilities returns the capabilities of the terminal.

GetStatus returns the status of the terminal.

Terminals defines four event types for handling of signals generated by terminals:

raised when the size of the display has changed. This event appears mainly on terminal emulations of window systems.
raised when a user presses the interrupt key.
raised when a user presses the quit key.
raised after the modem line was hung up.
When the signals occur the associated events must be raised by the terminal implementation.

The default handling for the events is:


All terminal related errors lead to events of type error which are passed to RelatedEvents for further handling.

Following errorcodes are currently implemented:

terminal cannot set echo
terminal cannot set termmode
terminal cannot set cursor
terminal cannot move cursor
terminal cannot change appearance of cursor
terminal cannot scroll
terminal does not support scroll regions
terminal cannot clear the screen
invalid direction given to Scroll
given scrollregion is beyond screen limits
given position is beyond screen limits


error handling
streams interface
UNIX Sytem V interface to the terminal driver
support of display attributes on ASCII terminals
interface to the UNIX terminfo database
support of function keys on ASCII terminals
support of line graphics on ASCII terminals
UNIX implementation of terminals


Ralf Beck with some minor corrections of Andreas Borchert
Edited by: rbeck, last change: 1996/01/11, revision: 1.5, converted to HTML: 2001/03/03

Oberon || Library || Module Index || Search Engine || Definition || Module