% (C) Copyright International Business Machines Corporation 23 January 
% 1990.  All Rights Reserved. 
%  
% See the file USERAGREEMENT distributed with this software for full 
% terms and conditions of use. 
\subsection{Windows}
\label{windows}

If you are running Hermes on a SUN workstation with Sunview or an IBM
RS/6000 with X Windows, you may create {\em tty windows} from your
Hermes program.  You may then use the {\tt terminalio} operations {\tt
PutString}, {\tt PutLine}, {\tt GetString}, {\tt PutChar}, and {\tt
GetChar} to read from and write to these windows.

The preferred method to open a window is via the {\tt safewindow}
program that is supplied with the system.  After creating a process
running this program, make a call on its initialization port (of type
{\tt safeWindowInit!safeWindowInitFn}), passing the {\tt "Window"}
C-Hermes capability.  In return, you will recieve a capability of type
{\tt safeWindow!safeWindowFn} that can be used to create many windows.

To create a window, call the capability you received from {\tt
safewindow}, passing it a label string for the window's title strip
and a string specifying window options (size, colors, position, etc.)
in the style used by SunView.\footnote{See the section named ``Generic
Tool Arguments'' in the sunview(1) man page.} This call will return a
callmessage containing a {\tt terminalIO!terminalFunctions} record
containing capabilities to print to and read from the window.  You can
copy and give away these capabilities as you see fit so that other
processes can perform I/O to your window.  When you wish to destroy
the window, simply discard the callmessage you got from the window
creation call.\footnote{This is an example of a fairly tricky method
by which a process P can send capabilities to another process Q and be
guaranteed to receive notification when Q is finished with the
capabilities.  P creates a ``proxy'' process and gives it capabilities
to two of P's ports, A and B, as well as whatever data P intends to
send to Q.  The proxy process calls P on its port A, passing it the
data intended for Q.  P then sends this data, wrapped in the
callmessage received from the proxy, to Q in whatever fashion is
appropriate.  When Q is finished using the data, it discards the
callmessage.  This causes an exception to be raised in the proxy
process, and it can then call P back on port B to notify P that Q has
finished.  This scheme has the advantage that Q cannot terminate and
``forget'' to notify P; if Q terminates, the callmessage it received
from P will be discarded automatically, and the notification will take
place as required.  This is achieved without requiring P to block.}

The following code fragment creates a window and uses it to retrieve
the user's name, then destroys the window.

\begin{verbatim}
    linking (safeWindow)
    ...
    unwrap CLoad from args.rm.get("CLoader", "") {init};
    openWindow <- (create of process safeWindow)(CLoad);
    window <- openWindow("Query", "-Wh 1 -Ww 30");
    call window.terminal.terminal.putString("Your Name: ");
    name <- window.terminal.terminal.getString();
    discard window;
    ...
\end{verbatim}
