TF normally does its output through "streams", which are analagous to the streams of C stdio.
Output from most tf commands, including /echo, are output to the "tfout" stream, which is normally attached to the screen. tfout may be redirected with a command /quote, $() command substitution, or %| pipe.
Many TF error messages, hook messages, and the output of "/echo -e" are output to the "tferr" stream, which is always attached to the screen, and may not be redirected.
Some TF error messages, hook messages, and the output of "/echo -A" are output to the "alert" stream. In visual mode, text sent to the alert stream is displayed briefly on the status line status line, where it can be seen immediately even if you're at a more prompt. The duration of the alert display is determined by %alert_time. In nonvisual mode, text sent to the alert stream is redirected to the tferr stream.
Text from a world or "/echo -w" is sent to a stream for that world. Text sent to a world stream will be stored in the history of that world. If that world is the foreground world, the text is sent to the screen immediately; otherwise, it will not be displayed until world is brought into the foreground.
Commands that read input (using tfread()) read by default from "tfin", which is normally attached to the keyboard. tfin may be redirected with a %| pipe.
All streams have a handle which can be used as an argument to the tfio functions. The handles for tfin, tfout, and tferr are "i", "o", and "e", respectively. The handles for streams opened with tfopen() are integers.
If successful, the tfopen() function returns a positive number which is the handle of the new stream, which should be used in subsequent calls to tfread(), tfwrite(), and tfclose(). If it fails, the tfopen() function returns -1.
A call to tfwrite() or tfread() on a stream opened with a mode that does not allow that operation will return -1.
The /liststreams command will display a list of open streams.
If an OS file (mode "w" or "a") is set to autoflush (the default), then each line written is flushed to the file immediately. If you are writing a large number of lines, it is more efficient to disable autoflushing with tfflush(handle, "off"), and manually force a flush with tfflush(handle) or tfclose(handle) after writing the large block. tfflush() has no meaning on files of mode "p", "q", or "r". Streams are flushed automatically when closed.
A read from the keyboard (and the macro that called it) can be interrupted with a SIGINT, normally generated by typing CTRL-C.
During a keyboard read, if a macro
calls /dokey newline,
the newline will not be executed immediately, but will be held until
the rest of the commands in the macro
are processed.
For example, consider the keybinding
"/def
-b'^[^M' =
/dokey newline%; /send go
". Normally, typing ^[^M would execute
the current input buffer, then send "go" to the server. But during a
keyboard read, typing ^[^M would send "go" first, and then do the newline
that completes the read.
The library file textutil.tf defines several commands that are useful with tfio.
See: interface, /liststreams, /input, expressions, nread(), functions, textutil.tf