Top |
Every window has an associated window stream; you print to the window by printing to this stream. However, it is possible to attach a second stream to a window. Any text printed to the window is also echoed to this second stream, which is called the window's “echo stream.”
Effectively, any call to glk_put_char()
(or the other output commands) which
is directed to the window's window stream, is replicated to the window's echo
stream. This also goes for the style commands such as glk_set_style()
.
Note that the echoing is one-way. You can still print text directly to the echo stream, and it will go wherever the stream is bound, but it does not back up and appear in the window.
An echo stream can be of any type, even another window's window stream.
This would be somewhat silly, since it would mean that any text printed to the window would be duplicated in another window. More commonly, you would set a window's echo stream to be a file stream, in order to create a transcript file from that window.
A window can only have one echo stream. But a single stream can be the echo stream of any number of windows, sequentially or simultaneously.
If a window is closed, its echo stream remains open; it is not automatically closed.
Do not confuse the window's window stream with its echo stream. The window stream is “owned” by the window, and dies with it. The echo stream is merely temporarily associated with the window.
If a stream is closed, and it is the echo stream of one or more windows,
those windows are reset to not echo anymore. (So then calling
glk_window_get_echo_stream()
on them will return NULL
.)
void glk_window_set_echo_stream (winid_t win
,strid_t str
);
Sets win
's echo stream to str
, which can be any valid output stream. You
can reset a window to stop echoing by calling
glk_window_set_echo_stream(win, NULL)
.
It is illegal to set a window's echo stream to be its own window stream. That would create an infinite loop, and is nearly certain to crash the Glk library. It is similarly illegal to create a longer loop (two or more windows echoing to each other.)