Subject: Re: [SWIPL] writing in another window

From: Jan Wielemaker <[email-masked]>
Date: Thu, 27 Sep 2001 11:27:32 +0200

On Tue, 31 Jul 2001, Sebastian Sardina wrote:
>I use SWI on Linux. I know how to read from and write on files using
>the open, read, and write predicates with explicit streams.
>
>Now, I want to make my Prolog program to write messages in a special
>window.
>That is, I want to use a special Linux window to show special messages
>instead
>of showing them in the same window in which Prolog was called.
>
>I think my problem is how to create a named xterm window that I can
>refer from
>Prolog and write on it. Can anyone help me on that? Thanks a lot.

It requires a bit of C-hacking.  It is done in the file pl-xterm.c,
which deals with attaching an xterm to a Prolog thread for the
multi-threaded version.  This code is only used in the MT version,
but you could use it as an example for writing your own version
usable in the single-thread version.

Simpler though is to use XPCE:

open_window :-
	send(new(V, view('My output')), open),
	pce_open(V, write, Stream),
	set_stream(Stream, alias(my_out)),
	set_stream(Stream, buffer(line)).

?- format(my_out, 'Hello World~n', []).

You need 4.0.9 for the set_stream/2 support used here, but
of course you can also write your own wrapper to record the
stream reference and provide the required output buffering.

	Regards --- Jan