\ *****************
\ *  MyConsole.f  *
\ *****************

\ Words to open a console for TYPE and QUERY I/O (i.e. setup INFILE & 
\      OUTFILE) for an application running in background,
\      as with RUN from CLI.

cr ." loading MyConsole.f..." 

Global MyConsoleID   0 to MyConsoleID


\ open a console if we are running in background and are in a turnkey
\ 0$addr is a string defining the console as in:
\      0" CON:0/10/640/120/ Multi-Forth "

\ If value zero is given for the 0$addr; a default console is opened

: ?open.console  ( 0$addr-- )
	depth 0= if 0 then  locals| 0$addr |
	background @ BOOLEAN ?turnkey AND
	IF 0$addr 0=
	   IF    0" CON:0/10/640/100/Multi-Forth "
	   ELSE  0$addr
	   THEN
	   open dup to MyConsoleID
	   IF   MyConsoleID dup  INFILE ! OUTFILE !
	   ELSE
	        error" Unable to open Console!..."
	   THEN
	ELSE
	   0 to MyConsoleID
	THEN ;


\ close the console if it was open

: ?close.console  ( -- )
	MyConsoleID ?dup
	IF  close
	    INFILE off  OUTFILE off
	    0 to MyConsoleID
	THEN ;

