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


Ulm's Oberon Library:
Terminals


NAME

Terminals - abstraction for terminals

SYNOPSIS

(* 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);

DESCRIPTION

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:

autoleftmargin
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.
autorightmargin
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.
overstrikes
terminal overstrikes characters rather than replacing them.
savelastcolumn
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:

cooked
in cooked mode terminal input is processed in units of lines, i.e. input can be edited before it is passed to an application.
raw
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:

windowchanged
raised when the size of the display has changed. This event appears mainly on terminal emulations of window systems.
interrupt
raised when a user presses the interrupt key.
quit
raised when a user presses the quit key.
hangup
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:

DIAGNOSTICS

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

Following errorcodes are currently implemented:

cannotSetEcho
terminal cannot set echo
cannotSetTermMode
terminal cannot set termmode
cannotSetCursor
terminal cannot set cursor
cannotMoveCursor
terminal cannot move cursor
cannotSetAppearance
terminal cannot change appearance of cursor
cannotScroll
terminal cannot scroll
cannotSetScrollRegion
terminal does not support scroll regions
cannotClearScreen
terminal cannot clear the screen
invalidDirection
invalid direction given to Scroll
invalidRegion
given scrollregion is beyond screen limits
invalidPosition
given position is beyond screen limits

SEE ALSO

RelatedEvents
error handling
Streams
streams interface
SysTermIO
UNIX Sytem V interface to the terminal driver
TermAttributes
support of display attributes on ASCII terminals
TermInfos
interface to the UNIX terminfo database
TermKeys
support of function keys on ASCII terminals
TermLineGraphics
support of line graphics on ASCII terminals
UnixTerminals
UNIX implementation of terminals

AUTHOR

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