Control flushing to stdout... core.osthread.Thread + arsd.terminal
Adam D. Ruppe
destructionator at gmail.com
Fri Jun 5 20:35:40 UTC 2020
On Friday, 5 June 2020 at 20:11:16 UTC, aberba wrote:
> Didn't come to mind to lookup from terminal docs. Thought it
> was a Dlang/OS problem.
Yeah, the OS by itself rarely buffers output like this, but both
the C library (on which std.stdio is built) and my Terminal
object do (they do separately btw, which is why I suggest you
avoid mixing together terminal.writeln and regular
stdout.writeln, since they can intermix unpredictably as they
flush at different calls).
The C one tends to auto-flush on newline, unless it is piped to
another program... which confuses poor users on IDEs, since from
the program's perspective, the IDE console is another program! So
your output can be delayed differently there vs direct to the
user's screen. (My terminal.d will actually throw an exception if
you try to use it in such an environment. You need to check
Terminal.stdoutIsTerminal() if you want to handle that case
differently. This is another decision I semi-regret and might
change in the future, since a lot of things do work fine in that
environment, you just can't move the cursor around in it.)
Anyway the point is just that output functions often pretend to
succeed while actually just buffering it internally. Unless the
docs say otherwise when using one of these, there's no guarantee
it will actually display until you call the library's flush
function (in std.stdio btw it is `stdout.flush();`, in C it is
`fflush(stdio);`) or close the file.
More information about the Digitalmars-d-learn
mailing list