<<>> <> <> <> <<>> <> <> <> (cedar-imports "TerminalIO" "Scheme") <> (cedar-directory "Rope" "Ascii") <> (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.ROPE_NIL, timeOut: NAT_0] 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.ROPE _ NIL, timeOut: NAT_0] 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.ROPE_NIL, timeOut: NAT _ 0, dontLog: BOOL_FALSE] 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.ROPE _ NIL, choice: LIST OF Rope.ROPE, headerDoc: Rope.ROPE _ NIL, choiceDoc: LIST OF Rope.ROPE _ NIL,default: NAT _ 0, timeOut: NAT _ 0, position: REF _ NIL, 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"]; }; <>