TerminalIO.mx
Copyright Ó 1989, 1992 by Xerox Corporation. All rights reserved.
Created by Bob Krivacic, December 18, 1989 1:38:28 pm PST
Documentation
Interface from Scheme to the Cedar TerminalIO routines. Now Scheme code can interact with the ChipNDale terminal log.
Cedar Primitives
(cedar-imports "TerminalIO" "Scheme")
add strings to DIRECTORY and IMPORT clauses
(cedar-directory "Rope" "Ascii")
add strings to DIRECTORY clause only
(define-proc (TerminalIO.TOS)
"PROC [] RETURNS [stream: IO.STREAM]; Creates an output stream which writes its output into the terminal viewer. This procedure is lightweight; the viewer is only created when output is done. No signals or errors are raised, neither on call nor on sequential output."
result ← TerminalIO.TOS[];
)
(define-proc (TerminalIO.TIS)
"PROC [] RETURNS [stream: IO.STREAM]; Creates an Input stream which reads from the terminal viewer. This procedure is lightweight; the viewer is only created when Input is done. No signals or errors are raised, neither on call nor on sequential output."
result ← TerminalIO.TIS[];
)
(define-proc (TerminalIO.PutRope rope)
"Output a Scheme Rope to TerminalIO.PutRope"
TerminalIO.PutRope[Scheme.TheROPE[rope]];
)
(define-proc (TerminalIO.PutRopes rope1 (rope2) (rope3))
"PROC [text: Rope.ROPE];"
TerminalIO.PutRopes[Scheme.TheROPE[rope1], IF rope2=undefined THEN NIL ELSE Scheme.TheROPE[rope2], IF rope3=undefined THEN NIL ELSE Scheme.TheROPE[rope3]];
)
(define-proc (TerminalIO.RequestRope (prompt) (timeout))
"PROC [prompt: Rope.ROPENIL, timeOut: NAT𡤀] RETURNS [Rope.ROPE]; Requests user to type in a rope. May raise UserAbort and TimeOut. prompt: NIL is ok, but others are better. timeOut: in seconds; 0 for no timeout [the user can always abort]."
result ← TerminalIO.RequestRope[
IF prompt=undefined THEN NIL ELSE Scheme.TheROPE[prompt],
IF timeout=undefined THEN 0 ELSE TheNAT[timeout]];
)
(define-proc (TerminalIO.RequestInt (prompt) (timeout))
"PROC [prompt: Rope.ROPENIL, timeOut: NAT𡤀] RETURNS [INT]; Shortcut; calls RequestRope and converts rope to integer."
result ← MakeFixnum[TerminalIO.RequestInt[
IF prompt=undefined THEN NIL ELSE Scheme.TheROPE[prompt],
IF timeout=undefined THEN 0 ELSE TheNAT[timeout]]];
)
(define-proc (TerminalIO.Confirm text (help) (timeout) (dontlog))
"PROC [text: Rope.ROPE, help: Rope.ROPENIL, timeOut: NAT ← 0, dontLog: BOOLFALSE] RETURNS [BOOL]; Requests user for confirmation; defaults to FALSE. timeOut: in seconds; 0 for no timeout. dontLog: prevent loging in viewer and log file."
result ← MakeBoolean[TerminalIO.Confirm[
Scheme.TheROPE[text],
IF help=undefined THEN NIL ELSE TheROPE[help],
IF timeout=undefined THEN 0 ELSE TheNAT[timeout],
IF dontlog=undefined THEN FALSE ELSE TheBOOL[dontlog]
]];
)
(define-proc (TerminalIO.RequestSelection header choice (headerdoc) (choicedoc) (default) (timeout) (position) (dontlog))
"PROC [header: Rope.ROPENIL, choice: LIST OF Rope.ROPE, headerDoc: Rope.ROPENIL, choiceDoc: LIST OF Rope.ROPENIL,default: NAT ← 0, timeOut: NAT ← 0, position: REFNIL, dontLog: BOOL FALSE] RETURNS [INT]; Shows a pop-up menu and returns the number of the selected entry."
result ← MakeFixnum[TerminalIO.RequestSelection[
TheROPE[header],
TheROPELIST[choice],
IF headerdoc=undefined THEN NIL ELSE TheROPE[headerdoc],
IF choicedoc=undefined THEN NIL ELSE TheROPELIST[choicedoc],
IF default=undefined THEN 0 ELSE TheNAT[default],
IF timeout=undefined THEN 0 ELSE TheNAT[timeout],
IF position=undefined THEN NIL ELSE TheREF[position],
IF dontlog=undefined THEN FALSE ELSE TheBOOL[dontlog]
]];
)
ROPE: TYPE ~ Rope.ROPE; -- a node with top-level Cedar code. This is underlined if you have the right style.
TheNAT: PROC [val: Any] RETURNS [result: NAT] = {
RETURN[Scheme.TheCARD[val]];
};
TheREF: PROC [val: Any] RETURNS [result: REF] = TRUSTED {
RETURN[LOOPHOLE[val]];
};
TheROPELIST: PROC [val: Any] RETURNS [ropes: LIST OF ROPE] = {
WITH val SELECT FROM
val: LIST OF ROPE => RETURN [val];
ENDCASE => Complain[val, "is not a LIST OF ROPE"];
};
Scheme Code